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

DomCR / ACadSharp / 17737836230

15 Sep 2025 03:12PM UTC coverage: 2.092% (-76.2%) from 78.245%
17737836230

push

github

web-flow
Merge pull request #790 from DomCR/addflag-refactor

addflag refactor

141 of 9225 branches covered (1.53%)

Branch coverage included in aggregate %.

0 of 93 new or added lines in 10 files covered. (0.0%)

24910 existing lines in 372 files now uncovered.

724 of 32119 relevant lines covered (2.25%)

5.76 hits per line

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

0.0
/src/ACadSharp/IO/CadWriterBase.cs
1
using CSUtilities.Text;
2
using System.Text;
3
using System;
4
using System.IO;
5
using ACadSharp.Classes;
6
using System.Linq;
7
using ACadSharp.Entities;
8
using ACadSharp.Tables;
9

10
namespace ACadSharp.IO
11
{
12
        /// <summary>
13
        /// Base class for the CAD writers.
14
        /// </summary>
15
        public abstract class CadWriterBase<T> : ICadWriter
16
                where T : CadWriterConfiguration, new()
17
        {
18
                /// <inheritdoc/>
19
                public event NotificationEventHandler OnNotification;
20

21
                /// <summary>
22
                /// Configuration for the writer.
23
                /// </summary>
UNCOV
24
                public T Configuration { get; set; } = new T();
×
25

26
                protected CadDocument _document;
27

28
                protected Encoding _encoding;
29

30
                protected Stream _stream;
31

UNCOV
32
                protected CadWriterBase(Stream stream, CadDocument document)
×
UNCOV
33
                {
×
UNCOV
34
                        this._stream = stream;
×
UNCOV
35
                        this._document = document;
×
UNCOV
36
                }
×
37

38
                /// <inheritdoc/>
39
                public abstract void Dispose();
40

41
                /// <inheritdoc/>
42
                public virtual void Write()
UNCOV
43
                {
×
UNCOV
44
                        this._document.UpdateDxfClasses(this.Configuration.ResetDxfClasses);
×
45

UNCOV
46
                        if (this.Configuration.UpdateDimensionsInModel)
×
47
                        {
×
48
                                this.updateDimensions(this._document.ModelSpace);
×
49
                        }
×
50

UNCOV
51
                        if (this.Configuration.UpdateDimensionsInBlocks)
×
52
                        {
×
53
                                foreach (var item in this._document.BlockRecords)
×
54
                                {
×
55
                                        if (item.Name.Equals(BlockRecord.ModelSpaceName, StringComparison.OrdinalIgnoreCase))
×
56
                                        {
×
57
                                                continue;
×
58
                                        }
59

60
                                        this.updateDimensions(item);
×
61
                                }
×
62
                        }
×
63

UNCOV
64
                        this._encoding = this.getListedEncoding(this._document.Header.CodePage);
×
UNCOV
65
                }
×
66

67
                protected Encoding getListedEncoding(string codePage)
UNCOV
68
                {
×
UNCOV
69
                        CodePage code = CadUtils.GetCodePage(codePage);
×
70

71
                        try
UNCOV
72
                        {
×
73
#if !NET48
UNCOV
74
                                Encoding.RegisterProvider(System.Text.CodePagesEncodingProvider.Instance);
×
75
#endif
UNCOV
76
                                return Encoding.GetEncoding((int)code);
×
77
                        }
78
                        catch (Exception ex)
×
79
                        {
×
80
                                this.triggerNotification($"Encoding with code {code} not found, using Windows-1252 as default", NotificationType.Warning, ex);
×
81
                        }
×
82

83
                        return TextEncoding.Windows1252();
×
UNCOV
84
                }
×
85

86
                protected void triggerNotification(string message, NotificationType notificationType, Exception ex = null)
87
                {
×
88
                        this.triggerNotification(this, new NotificationEventArgs(message, notificationType, ex));
×
89
                }
×
90

91
                protected void triggerNotification(object sender, NotificationEventArgs e)
UNCOV
92
                {
×
UNCOV
93
                        this.OnNotification?.Invoke(sender, e);
×
UNCOV
94
                }
×
95

96
                private void updateDimensions(BlockRecord record)
97
                {
×
98
                        foreach (var item in record.Entities.OfType<Dimension>())
×
99
                        {
×
100
                                item.UpdateBlock();
×
101
                        }
×
102
                }
×
103
        }
104
}
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