-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #4 from specklesystems/alan/misc-importer-fixes
Detachment and SDK updates for importer fixes
- Loading branch information
Showing
12 changed files
with
186 additions
and
46 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
using Speckle.Sdk.SQLite; | ||
|
||
namespace Speckle.Importer.Tester; | ||
|
||
public class DummySendCacheManager(Dictionary<string, string> objects) : ISqLiteJsonCacheManager | ||
{ | ||
public IEnumerable<string> GetAllObjects() => throw new NotImplementedException(); | ||
|
||
public void DeleteObject(string id) => throw new NotImplementedException(); | ||
|
||
public string? GetObject(string id) => null; | ||
|
||
public void SaveObject(string id, string json) => throw new NotImplementedException(); | ||
|
||
public bool HasObject(string objectId) => false; | ||
|
||
public void SaveObjects(IEnumerable<(string id, string json)> items) | ||
{ | ||
foreach (var (id, json) in items) | ||
{ | ||
objects[id] = json; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
using System.Text; | ||
using Speckle.Sdk.Dependencies.Serialization; | ||
using Speckle.Sdk.Serialisation.V2; | ||
using Speckle.Sdk.Transports; | ||
|
||
namespace Speckle.Importer.Tester; | ||
|
||
public class DummyServerObjectManager : IServerObjectManager | ||
{ | ||
public IAsyncEnumerable<(string, string)> DownloadObjects( | ||
IReadOnlyList<string> objectIds, | ||
IProgress<ProgressArgs>? progress, | ||
CancellationToken cancellationToken | ||
) => throw new NotImplementedException(); | ||
|
||
public Task<string?> DownloadSingleObject( | ||
string objectId, | ||
IProgress<ProgressArgs>? progress, | ||
CancellationToken cancellationToken | ||
) => throw new NotImplementedException(); | ||
|
||
public Task<Dictionary<string, bool>> HasObjects( | ||
IReadOnlyList<string> objectIds, | ||
CancellationToken cancellationToken | ||
) => throw new NotImplementedException(); | ||
|
||
public Task UploadObjects( | ||
IReadOnlyList<BaseItem> objects, | ||
bool compressPayloads, | ||
IProgress<ProgressArgs>? progress, | ||
CancellationToken cancellationToken | ||
) | ||
{ | ||
long totalBytes = 0; | ||
foreach (var item in objects) | ||
{ | ||
totalBytes += Encoding.Default.GetByteCount(item.Json); | ||
} | ||
|
||
progress?.Report(new(ProgressEvent.UploadBytes, totalBytes, totalBytes)); | ||
return Task.CompletedTask; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,50 @@ | ||
using Ara3D.IfcParser; | ||
using System.Diagnostics; | ||
using Ara3D.IfcParser; | ||
using Ara3D.Utils; | ||
using Microsoft.Extensions.DependencyInjection; | ||
using Speckle.Importer.Tester; | ||
using Speckle.Sdk.Serialisation.V2.Send; | ||
using Speckle.WebIfc.Importer; | ||
using Speckle.WebIfc.Importer.Converters; | ||
using Speckle.WebIfc.Importer.Ifc; | ||
|
||
var serviceProvider = Import.GetServiceProvider(); | ||
|
||
var graph = IfcGraph.Load( | ||
new FilePath( | ||
"C:\\Users\\adam\\Git\\speckle-server\\packages\\fileimport-service\\ifc-dotnet\\ifcs\\small.ifc" | ||
) | ||
var filePath = new FilePath( | ||
"C:\\Users\\adam\\Git\\speckle-server\\packages\\fileimport-service\\ifc-dotnet\\ifcs\\20210221PRIMARK.ifc" | ||
); | ||
|
||
Console.WriteLine(graph.Document.RawInstances.Length); | ||
var ifcFactory = serviceProvider.GetRequiredService<IIfcFactory>(); | ||
var stopwatch = Stopwatch.StartNew(); | ||
|
||
Console.WriteLine($"Opening with WebIFC: {filePath}"); | ||
var model = ifcFactory.Open(filePath); | ||
var ms = stopwatch.ElapsedMilliseconds; | ||
Console.WriteLine($"Opened with WebIFC: {ms} ms"); | ||
|
||
var graph = IfcGraph.Load(new FilePath(filePath)); | ||
var ms2 = stopwatch.ElapsedMilliseconds; | ||
Console.WriteLine($"Loaded with StepParser: {ms2 - ms} ms"); | ||
|
||
var converter = serviceProvider.GetRequiredService<IGraphConverter>(); | ||
var b = converter.Convert(model, graph); | ||
ms = ms2; | ||
ms2 = stopwatch.ElapsedMilliseconds; | ||
Console.WriteLine($"Converted to Speckle Bases: {ms2 - ms} ms"); | ||
var objects = new Dictionary<string, string>(); | ||
|
||
var process2 = new SerializeProcess( | ||
new Progress(true), | ||
new DummySendCacheManager(objects), | ||
new DummyServerObjectManager(), | ||
new BaseChildFinder(new BasePropertyGatherer()), | ||
new ObjectSerializerFactory(new BasePropertyGatherer()), | ||
new SerializeProcessOptions(true, true, true, true) | ||
); | ||
Console.ReadLine(); | ||
var (rootId, _) = await process2.Serialize(b, default).ConfigureAwait(false); | ||
Console.WriteLine(rootId); | ||
ms2 = stopwatch.ElapsedMilliseconds; | ||
Console.WriteLine($"Converted to JSON: {ms2 - ms} ms"); | ||
|
||
Console.ReadLine(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
using Speckle.Sdk.Transports; | ||
|
||
namespace Speckle.Importer.Tester; | ||
|
||
public class Progress(bool write) : IProgress<ProgressArgs> | ||
{ | ||
private readonly TimeSpan DEBOUNCE = TimeSpan.FromSeconds(1); | ||
private DateTime _lastTime = DateTime.UtcNow; | ||
|
||
private long _totalBytes; | ||
|
||
public void Report(ProgressArgs value) | ||
{ | ||
if (write) | ||
{ | ||
if (value.ProgressEvent == ProgressEvent.DownloadBytes) | ||
{ | ||
Interlocked.Add(ref _totalBytes, value.Count); | ||
} | ||
var now = DateTime.UtcNow; | ||
if (now - _lastTime >= DEBOUNCE) | ||
{ | ||
if (value.ProgressEvent == ProgressEvent.DownloadBytes) | ||
{ | ||
Console.WriteLine(value.ProgressEvent + " t " + _totalBytes); | ||
} | ||
else | ||
{ | ||
Console.WriteLine(value.ProgressEvent + " c " + value.Count + " t " + value.Total); | ||
} | ||
|
||
_lastTime = now; | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters