• 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/CadWriterBase.cs
1
using CSUtilities.Text;
2
using System.Text;
3
using System;
4
using System.IO;
5
using ACadSharp.Classes;
6
using ACadSharp.IO;
7
using ACadSharp.Exceptions;
8
using ACadSharp.IO.DWG;
9
using ACadSharp.IO.DWG.DwgStreamWriters;
10
using CSUtilities.IO;
11
using System.Collections.Generic;
12

13
namespace ACadSharp.IO
14
{
15
        /// <summary>
16
        /// Base class for the CAD writers.
17
        /// </summary>
18
        public abstract class CadWriterBase<T> : ICadWriter
19
                where T : CadWriterConfiguration, new()
20
        {
21
                /// <summary>
22
                /// Notification event to get information about the writing process.
23
                /// </summary>
24
                /// <remarks>
25
                /// The notification system informs about any issue or non critical errors during the writing.
26
                /// </remarks>
27
                public event NotificationEventHandler OnNotification;
28

29
                /// <summary>
30
                /// Configuration for the writer.
31
                /// </summary>
32
                public T Configuration { get; set; } = new T();
×
33

34
                protected Stream _stream;
35

36
                protected CadDocument _document;
37

38
                protected Encoding _encoding;
39

40
                protected CadWriterBase(Stream stream, CadDocument document)
×
41
                {
×
42
                        this._stream = stream;
×
43
                        this._document = document;
×
44
                }
×
45

46
                /// <inheritdoc/>
47
                public virtual void Write()
48
                {
×
49
                        DxfClassCollection.UpdateDxfClasses(_document);
×
50

51
                        this._encoding = this.getListedEncoding(this._document.Header.CodePage);
×
52
                }
×
53

54
                /// <inheritdoc/>
55
                public abstract void Dispose();
56

57
                protected Encoding getListedEncoding(string codePage)
58
                {
×
59
                        CodePage code = CadUtils.GetCodePage(codePage);
×
60

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

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

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

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