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

DomCR / ACadSharp / 12905761471

22 Jan 2025 10:03AM UTC coverage: 2.0% (-74.0%) from 75.963%
12905761471

push

github

DomCR
version 1.0.6

104 of 7676 branches covered (1.35%)

Branch coverage included in aggregate %.

590 of 27024 relevant lines covered (2.18%)

5.13 hits per line

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

0.0
/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
                /// <summary>
21
                /// Reader configuration.
22
                /// </summary>
23
                public T Configuration { get; set; } = new();
×
24

25
                protected CadDocument _document = new CadDocument(false);
×
26

27
                protected Encoding _encoding = Encoding.Default;
×
28

29
                internal readonly StreamIO _fileStream;
30

31
                protected CadReaderBase(NotificationEventHandler notification)
×
32
                {
×
33
                        this.OnNotification += notification;
×
34
                }
×
35

36
                protected CadReaderBase(string filename, NotificationEventHandler notification = null) : this(File.OpenRead(filename), notification)
×
37
                {
×
38
                }
×
39

40
                protected CadReaderBase(Stream stream, NotificationEventHandler notification = null) : this(notification)
×
41
                {
×
42
                        this._fileStream = new StreamIO(stream);
×
43
                }
×
44

45
                /// <inheritdoc/>
46
                public abstract CadDocument Read();
47

48
                /// <inheritdoc/>
49
                public abstract CadHeader ReadHeader();
50

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

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

71
                        return TextEncoding.Windows1252();
×
72
                }
×
73

74
                protected void triggerNotification(string message, NotificationType notificationType, Exception ex = null)
75
                {
×
76
                        this.onNotificationEvent(null, new NotificationEventArgs(message, notificationType, ex));
×
77
                }
×
78

79
                protected void onNotificationEvent(object sender, NotificationEventArgs e)
80
                {
×
81
                        this.OnNotification?.Invoke(this, e);
×
82
                }
×
83
        }
84
}
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