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

DomCR / ACadSharp / 24788042622

22 Apr 2026 03:47PM UTC coverage: 77.123% (+0.05%) from 77.076%
24788042622

push

github

web-flow
Merge pull request #1041 from DomCR/issue/1035_parse-hook

issue-1035 Add progress reporting to CAD file reading process

8457 of 11919 branches covered (70.95%)

Branch coverage included in aggregate %.

332 of 385 new or added lines in 12 files covered. (86.23%)

8 existing lines in 3 files now uncovered.

30460 of 38542 relevant lines covered (79.03%)

153328.51 hits per line

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

86.05
/src/ACadSharp/IO/CadReaderBase.cs
1
using ACadSharp.Header;
2
using CSUtilities.IO;
3
using CSUtilities.Text;
4
using System;
5
using System.IO;
6
using System.Text;
7

8
namespace ACadSharp.IO;
9

10
/// <summary>
11
/// Base class for the DWG and DXF readers.
12
/// </summary>
13
/// <typeparam name="T">Configuration type for the reader.</typeparam>
14
public abstract class CadReaderBase<T> : ICadReader
15
        where T : CadReaderConfiguration, new()
16
{
17
        /// <inheritdoc/>
18
        public event NotificationEventHandler OnNotification;
19

20
        public event ProgressEventHandler OnProgress;
21

22
        /// <summary>
23
        /// Reader configuration.
24
        /// </summary>
25
        public T Configuration { get; set; } = new();
1,439✔
26

27
        internal readonly StreamIO _fileStream;
28

29
        protected readonly CadDocument _document = new CadDocument(false);
482✔
30

31
        protected Encoding _encoding = Encoding.Default;
482✔
32

33
        protected CadReaderBase(NotificationEventHandler notification)
482✔
34
        {
482✔
35
                this.OnNotification += notification;
482✔
36
        }
482✔
37

38
        protected CadReaderBase(string filename, NotificationEventHandler notification = null) : this(File.Open(filename, FileMode.Open, FileAccess.Read, FileShare.ReadWrite), notification)
437✔
39
        {
437✔
40
        }
437✔
41

42
        protected CadReaderBase(Stream stream, NotificationEventHandler notification = null) : this(notification)
482✔
43
        {
482✔
44
                this._fileStream = new StreamIO(stream);
482✔
45
        }
482✔
46

47
        /// <inheritdoc/>
48
        public virtual void Dispose()
49
        {
482✔
50
                this._fileStream.Dispose();
482✔
51
        }
482✔
52

53
        /// <inheritdoc/>
54
        public abstract CadDocument Read();
55

56
        /// <inheritdoc/>
57
        public abstract CadHeader ReadHeader();
58

59
        protected Encoding getListedEncoding(int code)
60
        {
273✔
61
                try
62
                {
273✔
63
#if !NET48
64
                        Encoding.RegisterProvider(System.Text.CodePagesEncodingProvider.Instance);
273✔
65
#endif
66
                        return Encoding.GetEncoding(code);
273✔
67
                }
NEW
68
                catch (Exception ex)
×
UNCOV
69
                {
×
NEW
70
                        this.triggerNotification($"Encoding with codee {code} not found, using Windows-1252 as default", NotificationType.Warning, ex);
×
UNCOV
71
                }
×
72

NEW
73
                return TextEncoding.Windows1252();
×
74
        }
273✔
75

76
        protected void onNotificationEvent(object sender, NotificationEventArgs e)
77
        {
276,117✔
78
                this.OnNotification?.Invoke(this, e);
276,117✔
79
        }
276,117✔
80

81
        protected void onProgressEvent(object sender, ProgressEventArgs e)
82
        {
13,425✔
83
                this.OnProgress?.Invoke(this, e);
13,425!
84
        }
13,425✔
85

86
        protected bool onProgressEventEnabled()
87
        {
161✔
88
                return OnProgress != null;
161✔
89
        }
161✔
90

91
        protected void triggerNotification(string message, NotificationType notificationType, Exception ex = null)
92
        {
68✔
93
                this.onNotificationEvent(null, new NotificationEventArgs(message, notificationType, ex));
68✔
94
        }
68✔
95
}
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