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

DomCR / ACadSharp / 24669708962

20 Apr 2026 01:38PM UTC coverage: 77.118% (+0.04%) from 77.076%
24669708962

Pull #1041

github

web-flow
Merge 6a14a7067 into 98bd2e4f4
Pull Request #1041: issue-1035 Add progress reporting to CAD file reading process

8455 of 11917 branches covered (70.95%)

Branch coverage included in aggregate %.

74 of 84 new or added lines in 8 files covered. (88.1%)

2 existing lines in 1 file now uncovered.

30421 of 38494 relevant lines covered (79.03%)

153505.78 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 bool onProgressEventEnabled()
34
        {
161✔
35
                return OnProgress != null;
161✔
36
        }
161✔
37

38
        protected CadReaderBase(NotificationEventHandler notification)
482✔
39
        {
482✔
40
                this.OnNotification += notification;
482✔
41
        }
482✔
42

43
        protected CadReaderBase(string filename, NotificationEventHandler notification = null) : this(File.Open(filename, FileMode.Open, FileAccess.Read, FileShare.ReadWrite), notification)
437✔
44
        {
437✔
45
        }
437✔
46

47
        protected CadReaderBase(Stream stream, NotificationEventHandler notification = null) : this(notification)
482✔
48
        {
482✔
49
                this._fileStream = new StreamIO(stream);
482✔
50
        }
482✔
51

52
        /// <inheritdoc/>
53
        public virtual void Dispose()
54
        {
482✔
55
                this._fileStream.Dispose();
482✔
56
        }
482✔
57

58
        /// <inheritdoc/>
59
        public abstract CadDocument Read();
60

61
        /// <inheritdoc/>
62
        public abstract CadHeader ReadHeader();
63

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

NEW
78
                return TextEncoding.Windows1252();
×
79
        }
273✔
80

81
        protected void onNotificationEvent(object sender, NotificationEventArgs e)
82
        {
276,117✔
83
                this.OnNotification?.Invoke(this, e);
276,117✔
84
        }
276,117✔
85

86
        protected void onProgressEvent(object sender, ProgressEventArgs e)
87
        {
13,425✔
88
                this.OnProgress?.Invoke(this, e);
13,425!
89
        }
13,425✔
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