Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue 200 async Read #283

Open
wants to merge 27 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions src/ACadSharp.Tests/IO/DWG/DwgReaderTests.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using ACadSharp.IO;
using ACadSharp.Tests.TestModels;
using System.Threading.Tasks;
using Xunit;
using Xunit.Abstractions;

Expand All @@ -23,6 +24,18 @@ public override void ReadTest(FileModel test)
base.ReadTest(test);
}

[Theory]
[MemberData(nameof(DwgFilePaths))]
public async Task ReadAsyncTest(FileModel test)
{
CadDocument doc = null;
using (DwgReader reader = new DwgReader(test.Path))
{
reader.OnNotification += this.onNotification;
doc = await reader.ReadAsync();
}
}

[Theory]
[MemberData(nameof(DwgFilePaths))]
public override void AssertDocumentDefaults(FileModel test)
Expand Down
4 changes: 2 additions & 2 deletions src/ACadSharp.Tests/Internal/DwgFileHeaderExploration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,10 @@ public DwgFileHeaderExploration(ITestOutputHelper output) : base()
[MemberData(nameof(DwgFilePaths))]
public void PrintFileHeaderInfo(string test)
{
DwgFileHeader fh;
DwgFileHeader fh = null;
using (DwgReader reader = new DwgReader(test))
{
fh = reader.readFileHeader();
//fh = reader.readFileHeader();
}

printHeader(fh);
Expand Down
12 changes: 11 additions & 1 deletion src/ACadSharp/CadDocument.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,15 @@ public class CadDocument : IHandledCadObject
/// <summary>
/// Contains all the header variables for this document.
/// </summary>
public CadHeader Header { get; internal set; }
public CadHeader Header
{
get { return this._header; }
internal set
{
this._header = value;
this._header.Document = this;
}
}

/// <summary>
/// Accesses drawing properties such as the Title, Subject, Author, and Keywords properties
Expand Down Expand Up @@ -166,6 +174,8 @@ internal set
/// </summary>
public BlockRecord PaperSpace { get { return this.BlockRecords[BlockRecord.PaperSpaceName]; } }

private CadHeader _header = null;

private CadDictionary _rootDictionary = null;

//Contains all the objects in the document
Expand Down
9 changes: 1 addition & 8 deletions src/ACadSharp/DwgPreview.cs
Original file line number Diff line number Diff line change
@@ -1,13 +1,6 @@
#region copyright
//Copyright 2021, Albert Domenech.
//All rights reserved.
//This source code is licensed under the MIT license.
//See LICENSE file in the project root for full license information.
#endregion
namespace ACadSharp
namespace ACadSharp
{
public class DwgPreview
{

}
}
15 changes: 15 additions & 0 deletions src/ACadSharp/IO/CadDocumentBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -297,4 +297,19 @@ private void addToMap(ICadObjectTemplate template)
this.cadObjects.Add(template.CadObject.Handle, template.CadObject);
}
}

internal abstract class CadDocumentBuilder<T> : CadDocumentBuilder
where T : CadReaderConfiguration
{
public T Configuration { get; }

public override bool KeepUnknownEntities => this.Configuration.KeepUnknownEntities;

public override bool KeepUnknownNonGraphicalObjects => this.Configuration.KeepUnknownNonGraphicalObjects;

protected CadDocumentBuilder(ACadVersion version, CadDocument document, T configuration) : base(version, document)
{
this.Configuration = configuration;
}
}
}
5 changes: 5 additions & 0 deletions src/ACadSharp/IO/CadReaderBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
using System;
using System.IO;
using System.Text;
using System.Threading;
using System.Threading.Tasks;

namespace ACadSharp.IO
{
Expand Down Expand Up @@ -45,6 +47,9 @@ protected CadReaderBase(Stream stream, NotificationEventHandler notification = n
/// <inheritdoc/>
public abstract CadDocument Read();

/// <inheritdoc/>
public abstract Task<CadDocument> ReadAsync(CancellationToken cancellationToken = default);

/// <inheritdoc/>
public abstract CadHeader ReadHeader();

Expand Down
13 changes: 2 additions & 11 deletions src/ACadSharp/IO/DWG/DwgDocumentBuilder.cs
Original file line number Diff line number Diff line change
@@ -1,15 +1,11 @@
using ACadSharp.Entities;
using ACadSharp.IO.Templates;
using ACadSharp.Objects;
using System;
using System.Collections.Generic;

namespace ACadSharp.IO.DWG
{
internal class DwgDocumentBuilder : CadDocumentBuilder
internal class DwgDocumentBuilder : CadDocumentBuilder<DwgReaderConfiguration>
{
public DwgReaderConfiguration Configuration { get; }

public DwgHeaderHandlesCollection HeaderHandles { get; set; } = new();

public List<CadBlockRecordTemplate> BlockRecordTemplates { get; set; } = new();
Expand All @@ -18,14 +14,9 @@ internal class DwgDocumentBuilder : CadDocumentBuilder

public List<Entity> ModelSpaceEntities { get; } = new();

public override bool KeepUnknownEntities => this.Configuration.KeepUnknownEntities;

public override bool KeepUnknownNonGraphicalObjects => this.Configuration.KeepUnknownNonGraphicalObjects;

public DwgDocumentBuilder(ACadVersion version, CadDocument document, DwgReaderConfiguration configuration)
: base(version, document)
: base(version, document, configuration)
{
this.Configuration = configuration;
}

public override void BuildDocument()
Expand Down
Loading