• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

DomCR / ACadSharp / 18987310601

31 Oct 2025 11:09PM UTC coverage: 77.837% (+0.1%) from 77.732%
18987310601

Pull #851

github

web-flow
Merge 966d1431d into 481384afb
Pull Request #851: issue 845

6953 of 9729 branches covered (71.47%)

Branch coverage included in aggregate %.

2 of 2 new or added lines in 1 file covered. (100.0%)

5 existing lines in 3 files now uncovered.

26735 of 33551 relevant lines covered (79.68%)

101997.21 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

74.15
/src/ACadSharp/IO/DXF/DxfStreamReader/DxfBlockSectionReader.cs
1
using ACadSharp.Blocks;
2
using ACadSharp.Exceptions;
3
using ACadSharp.IO.Templates;
4
using ACadSharp.Tables;
5
using System;
6
using System.Diagnostics;
7

8
namespace ACadSharp.IO.DXF
9
{
10
        internal class DxfBlockSectionReader : DxfSectionReaderBase
11
        {
12
                public DxfBlockSectionReader(IDxfStreamReader reader, DxfDocumentBuilder builder)
13
                        : base(reader, builder)
280✔
14
                {
280✔
15
                }
280✔
16

17
                public override void Read()
18
                {
280✔
19
                        //Advance to the first value in the section
20
                        this._reader.ReadNext();
280✔
21

22
                        //Loop until the section ends
23
                        while (this._reader.ValueAsString != DxfFileToken.EndSection)
10,038✔
24
                        {
9,758✔
25
                                try
26
                                {
9,758✔
27
                                        if (this._reader.ValueAsString == DxfFileToken.Block)
9,758!
28
                                                this.readBlock();
9,758✔
29
                                        else
30
                                                throw new DxfException($"Unexpected token at the BLOCKS table: {this._reader.ValueAsString}", this._reader.Position);
×
31
                                }
9,758✔
32
                                catch (Exception ex)
×
33
                                {
×
34
                                        if (!this._builder.Configuration.Failsafe)
×
35
                                                throw;
×
36

37
                                        this._builder.Notify($"Error while reading a block at line {this._reader.Position}", NotificationType.Error, ex);
×
38

39
                                        while (!(this._reader.DxfCode == DxfCode.Start && this._reader.ValueAsString == DxfFileToken.EndSection)
×
40
                                                        && !(this._reader.DxfCode == DxfCode.Start && this._reader.ValueAsString == DxfFileToken.Block))
×
41
                                        {
×
42
                                                this._reader.ReadNext();
×
43
                                        }
×
44
                                }
×
45
                        }
9,758✔
46
                }
280✔
47

48
                private void readBlock()
49
                {
9,758✔
50
                        Debug.Assert(this._reader.ValueAsString == DxfFileToken.Block);
9,758✔
51

52
                        //Read the table name
53
                        this._reader.ReadNext();
9,758✔
54

55
                        DxfMap map = DxfMap.Create<Block>();
9,758✔
56

57
                        Block blckEntity = new Block();
9,758✔
58
                        CadEntityTemplate template = new CadEntityTemplate(blckEntity);
9,758✔
59

60
                        string name = null;
9,758✔
61
                        BlockRecord record = null;
9,758✔
62
                        CadBlockRecordTemplate recordTemplate = null;
9,758✔
63

64
                        while (this._reader.DxfCode != DxfCode.Start)
119,430✔
65
                        {
109,672✔
66
                                switch (this._reader.Code)
109,672✔
67
                                {
68
                                        case 2:
69
                                        case 3:
70
                                                name = this._reader.ValueAsString;
19,516✔
71
                                                if (name.Equals("$MODEL_SPACE", StringComparison.OrdinalIgnoreCase))
19,516✔
72
                                                {
76✔
73
                                                        name = BlockRecord.ModelSpaceName;
76✔
74
                                                }
76✔
75
                                                else if (name.Equals("$PAPER_SPACE", StringComparison.OrdinalIgnoreCase))
19,440✔
76
                                                {
76✔
77
                                                        name = BlockRecord.PaperSpaceName;
76✔
78
                                                }
76✔
79

80
                                                if (record == null && this._builder.TryGetTableEntry(name, out record))
19,516!
81
                                                {
×
82
                                                        record.BlockEntity = blckEntity;
×
83
                                                }
×
84
                                                else if (record == null)
19,516✔
85
                                                {
7,144✔
86
                                                        this._builder.Notify($"Block record [{name}] not found at line {this._reader.Position}", NotificationType.Warning);
7,144✔
87
                                                }
7,144✔
88
                                                break;
19,516✔
89
                                        case 330:
90
                                                if (record == null && this._builder.TryGetCadObject(this._reader.ValueAsHandle, out record))
6,186!
91
                                                {
6,186✔
92
                                                        record.BlockEntity = blckEntity;
6,186✔
93
                                                }
6,186✔
94
                                                else if (record == null)
×
95
                                                {
×
96
                                                        this._builder.Notify($"Block record with handle [{this._reader.ValueAsString}] not found at line {this._reader.Position}", NotificationType.Warning);
×
97
                                                }
×
98
                                                break;
6,186✔
99
                                        default:
100
                                                if (!this.tryAssignCurrentValue(template.CadObject, map.SubClasses[DxfSubclassMarker.BlockBegin]))
83,970✔
101
                                                {
34,976✔
102
                                                        this.readCommonEntityCodes(template, out bool isExtendedData, map);
34,976✔
103
                                                        if (isExtendedData)
34,976✔
104
                                                                continue;
×
105
                                                }
34,976✔
106
                                                break;
83,970✔
107
                                }
108

109
                                this._reader.ReadNext();
109,672✔
110
                        }
109,672✔
111

112
                        if (record == null)
9,758✔
113
                        {
3,572✔
114
                                record = new BlockRecord(name);
3,572✔
115
                                record.BlockEntity = blckEntity;
3,572✔
116
                                recordTemplate = new CadBlockRecordTemplate(record);
3,572✔
117

118
                                this._builder.AddTemplate(recordTemplate);
3,572✔
119
                                this._builder.BlockRecords.Add(record);
3,572✔
120

121
                                if (recordTemplate.CadObject.Name.Equals(BlockRecord.ModelSpaceName, StringComparison.OrdinalIgnoreCase))
3,572✔
122
                                {
38✔
123
                                        this._builder.ModelSpaceTemplate = recordTemplate;
38✔
124
                                }
38✔
125
                        }
3,572✔
126
                        else if (!this._builder.TryGetObjectTemplate<CadBlockRecordTemplate>(record.Handle, out recordTemplate))
6,186!
127
                        {
×
128
                                recordTemplate = new CadBlockRecordTemplate(record);
×
129
                        }
×
130

131
                        while (this._reader.ValueAsString != DxfFileToken.EndBlock)
134,816✔
132
                        {
125,058✔
133
                                CadEntityTemplate entityTemplate = null;
125,058✔
134

135
                                try
136
                                {
125,058✔
137
                                        entityTemplate = this.readEntity();
125,058✔
138
                                }
125,058✔
139
                                catch (Exception ex)
×
140
                                {
×
141
                                        if (!this._builder.Configuration.Failsafe)
×
142
                                                throw;
×
143

144
                                        this._builder.Notify($"Error while reading a block with name {record.Name} at line {this._reader.Position}", NotificationType.Error, ex);
×
145

146
                                        while (this._reader.DxfCode != DxfCode.Start)
×
147
                                                this._reader.ReadNext();
×
148
                                }
×
149

150
                                if (entityTemplate == null)
125,058✔
UNCOV
151
                                        continue;
×
152

153
                                //Add the object and the template to the builder
154
                                this._builder.AddTemplate(entityTemplate);
125,058✔
155

156
                                if (entityTemplate.OwnerHandle == null)
125,058✔
157
                                {
84,930✔
158
                                        recordTemplate.OwnedObjectsHandlers.Add(entityTemplate.CadObject.Handle);
84,930✔
159
                                }
84,930✔
160
                                else if (this._builder.TryGetObjectTemplate(entityTemplate.OwnerHandle, out CadBlockRecordTemplate owner))
40,128✔
161
                                {
40,128✔
162
                                        owner.OwnedObjectsHandlers.Add(entityTemplate.CadObject.Handle);
40,128✔
163
                                }
40,128✔
164
                        }
125,058✔
165

166
                        this.readBlockEnd(record.BlockEnd);
9,758✔
167
                        this._builder.AddTemplate(template);
9,758✔
168
                }
9,758✔
169

170
                private void readBlockEnd(BlockEnd block)
171
                {
9,758✔
172
                        DxfMap map = DxfMap.Create<BlockEnd>();
9,758✔
173
                        CadEntityTemplate template = new CadEntityTemplate(block);
9,758✔
174

175
                        if (this._reader.DxfCode == DxfCode.Start)
9,758✔
176
                        {
9,758✔
177
                                this._reader.ReadNext();
9,758✔
178
                        }
9,758✔
179

180
                        while (this._reader.DxfCode != DxfCode.Start)
54,372✔
181
                        {
44,614✔
182
                                switch (this._reader.Code)
44,614✔
183
                                {
184
                                        default:
185
                                                if (!this.tryAssignCurrentValue(template.CadObject, map.SubClasses[DxfSubclassMarker.BlockEnd]))
44,614✔
186
                                                {
44,614✔
187
                                                        this.readCommonEntityCodes(template, out bool isExtendedData, map);
44,614✔
188
                                                        if (isExtendedData)
44,614✔
189
                                                                continue;
×
190
                                                }
44,614✔
191
                                                break;
44,614✔
192
                                }
193

194
                                this._reader.ReadNext();
44,614✔
195
                        }
44,614✔
196

197
                        this._builder.AddTemplate(template);
9,758✔
198
                }
9,758✔
199
        }
200
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc