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

DomCR / ACadSharp / 29143042407

11 Jul 2026 06:34AM UTC coverage: 2.912% (-73.0%) from 75.918%
29143042407

push

github

web-flow
Merge pull request #1146 from ilCosmico/acds-read-payload-anchor

Read the AcDs payload area offset from the data segment header

264 of 12999 branches covered (2.03%)

Branch coverage included in aggregate %.

0 of 30 new or added lines in 1 file covered. (0.0%)

31243 existing lines in 465 files now uncovered.

1337 of 41984 relevant lines covered (3.18%)

5.38 hits per line

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

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

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

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

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

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

40
                                        while (!(this._reader.DxfCode == DxfCode.Start && this._reader.ValueAsString == DxfFileToken.EndSection)
×
41
                                                        && !(this._reader.DxfCode == DxfCode.Start && this._reader.ValueAsString == DxfFileToken.Block))
×
42
                                        {
×
43
                                                this._reader.ReadNext();
×
44
                                        }
×
45
                                }
×
UNCOV
46
                        }
×
UNCOV
47
                }
×
48

49
                private void readBlock()
UNCOV
50
                {
×
UNCOV
51
                        Debug.Assert(this._reader.ValueAsString == DxfFileToken.Block);
×
52

53
                        //Read the table name
UNCOV
54
                        this._reader.ReadNext();
×
55

UNCOV
56
                        DxfMap map = DxfMap.Create<Block>();
×
57

UNCOV
58
                        Block blckEntity = new Block();
×
UNCOV
59
                        CadBlockEntityTemplate template = new CadBlockEntityTemplate(blckEntity);
×
60

UNCOV
61
                        string name = null;
×
UNCOV
62
                        BlockRecord record = null;
×
UNCOV
63
                        CadBlockRecordTemplate recordTemplate = null;
×
64

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

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

UNCOV
110
                                this._reader.ReadNext();
×
UNCOV
111
                        }
×
112

UNCOV
113
                        if (record == null)
×
UNCOV
114
                        {
×
UNCOV
115
                                record = new BlockRecord(name);
×
UNCOV
116
                                record.BlockEntity = blckEntity;
×
UNCOV
117
                                recordTemplate = new CadBlockRecordTemplate(record);
×
118

UNCOV
119
                                this._builder.AddTemplate(recordTemplate);
×
UNCOV
120
                                this._builder.BlockRecords.Add(record);
×
121

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

132
                        //Add the entity template for owner information
UNCOV
133
                        recordTemplate.BlockEntityTemplate = template;
×
134

UNCOV
135
                        while (this._reader.ValueAsString != DxfFileToken.EndBlock)
×
UNCOV
136
                        {
×
UNCOV
137
                                CadEntityTemplate entityTemplate = null;
×
138

139
                                try
UNCOV
140
                                {
×
UNCOV
141
                                        entityTemplate = this.readEntity();
×
UNCOV
142
                                }
×
143
                                catch (Exception ex)
×
144
                                {
×
145
                                        if (!this._builder.Configuration.Failsafe)
×
146
                                                throw;
×
147

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

150
                                        while (this._reader.DxfCode != DxfCode.Start)
×
151
                                                this._reader.ReadNext();
×
152
                                }
×
153

UNCOV
154
                                if (entityTemplate == null)
×
155
                                        continue;
×
156

157
                                //Add the object and the template to the builder
UNCOV
158
                                this._builder.AddTemplate(entityTemplate);
×
159

UNCOV
160
                                if (entityTemplate.OwnerHandle == null)
×
UNCOV
161
                                {
×
UNCOV
162
                                        recordTemplate.ReferenceTemplates.Add(entityTemplate);
×
UNCOV
163
                                }
×
UNCOV
164
                                else if (this._builder.TryGetObjectTemplate(entityTemplate.OwnerHandle, out ICadOwnerTemplate owner))
×
UNCOV
165
                                {
×
UNCOV
166
                                        owner.OwnedObjectsHandlers.Add(entityTemplate.CadObject.Handle);
×
UNCOV
167
                                }
×
168
                                else
169
                                {
×
170
                                        this._builder.OrphanTemplates.Add(entityTemplate);
×
171
                                }
×
UNCOV
172
                        }
×
173

UNCOV
174
                        this.readBlockEnd(record.BlockEnd);
×
UNCOV
175
                        this._builder.AddTemplate(template);
×
UNCOV
176
                }
×
177

178
                private void readBlockEnd(BlockEnd block)
UNCOV
179
                {
×
UNCOV
180
                        DxfMap map = DxfMap.Create<BlockEnd>();
×
UNCOV
181
                        CadEntityTemplate template = new CadEntityTemplate(block);
×
182

UNCOV
183
                        if (this._reader.DxfCode == DxfCode.Start)
×
UNCOV
184
                        {
×
UNCOV
185
                                this._reader.ReadNext();
×
UNCOV
186
                        }
×
187

UNCOV
188
                        while (this._reader.DxfCode != DxfCode.Start)
×
UNCOV
189
                        {
×
UNCOV
190
                                switch (this._reader.Code)
×
191
                                {
192
                                        default:
UNCOV
193
                                                if (!this.tryAssignCurrentValue(template.CadObject, map.SubClasses[DxfSubclassMarker.BlockEnd]))
×
UNCOV
194
                                                {
×
UNCOV
195
                                                        this.readCommonEntityCodes(template, out bool isExtendedData, map);
×
UNCOV
196
                                                        if (isExtendedData)
×
197
                                                                continue;
×
UNCOV
198
                                                }
×
UNCOV
199
                                                break;
×
200
                                }
201

UNCOV
202
                                this._reader.ReadNext();
×
UNCOV
203
                        }
×
204

UNCOV
205
                        this._builder.AddTemplate(template);
×
UNCOV
206
                }
×
207
        }
208
}
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