Compare commits
70 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 3789898ea2 | |||
| 0b3318f9e1 | |||
| 7589ad5f05 | |||
| 6df32262bd | |||
| 001ca1c287 | |||
| 59e459559b | |||
| d305fe59cb | |||
| f163b2822e | |||
| 630bb38b8b | |||
| bacff2da34 | |||
| 129d5285ed | |||
| 5d07fe0ea0 | |||
| 062e3c2838 | |||
| f4cc4bc77e | |||
| d395f03219 | |||
| 56ed399d70 | |||
| 7e0766fc7f | |||
| 0df343ebe1 | |||
| 3cad57ceb3 | |||
| 11937ad7c9 | |||
| 8210fde69a | |||
| fa6f90621e | |||
| f6f1852664 | |||
| b3f4190614 | |||
| 2fc0024cd2 | |||
| 300a5627fd | |||
| 22f029fe33 | |||
| c728266c88 | |||
| 7f2d57cdad | |||
| 81a22bd4cc | |||
| f64da099ab | |||
| f4ba200640 | |||
| 404600a839 | |||
| 93d517eab7 | |||
| 4110d90107 | |||
| 2d134bf7e1 | |||
| 686d0fd31c | |||
| b06878bbe1 | |||
| 64114167a8 | |||
| 0c7cd75353 | |||
| 3c5679ad2a | |||
| b043623021 | |||
| bd0997913a | |||
| a79f0fd035 | |||
| 7a29d27e46 | |||
| 82e3d37dd1 | |||
| 9695ec8c51 | |||
| 15fa319433 | |||
| 793bbb9cd3 | |||
| 3291010d43 | |||
| 14732ce174 | |||
| ba655988b0 | |||
| 96822c4e66 | |||
| 08356de1ad | |||
| 375f5071ae | |||
| 5900a3c178 | |||
| d7bf324029 | |||
| c784fbf462 | |||
| 26f1802787 | |||
| a96e0f8c8e | |||
| 9f36c9cfe5 | |||
| 4959f277e8 | |||
| ea08b83f7a | |||
| b24dc685fa | |||
| 7cad14fe25 | |||
| 4d552b6834 | |||
| 378a91995e | |||
| 53b66dd26b | |||
| 9dd04c0881 | |||
| 474c18c29f |
@@ -1,32 +1,34 @@
|
||||
<Project>
|
||||
<ItemGroup>
|
||||
<PackageVersion Include="altcover" Version="9.0.1" />
|
||||
<PackageVersion Include="AwesomeAssertions" Version="8.0.0" />
|
||||
<PackageVersion Include="AwesomeAssertions" Version="8.1.0" />
|
||||
<PackageVersion Include="BenchmarkDotNet" Version="0.14.0" />
|
||||
<PackageVersion Include="Bullseye" Version="5.0.0" />
|
||||
<PackageVersion Include="Bullseye" Version="6.0.0" />
|
||||
<PackageVersion Include="GraphQL.Client" Version="6.0.0" />
|
||||
<PackageVersion Include="Glob" Version="1.1.9" />
|
||||
<PackageVersion Include="HttpMultipartParser" Version="9.0.0" />
|
||||
<PackageVersion Include="ILRepack.FullAuto" Version="1.6.0" />
|
||||
<PackageVersion Include="Microsoft.CSharp" Version="4.7.0" />
|
||||
<!-- Keep at exactly 7.0.5 for side by side with V2 -->
|
||||
<PackageVersion Include="Microsoft.Data.Sqlite" Version="[7.0.5,)" />
|
||||
<PackageVersion Include="Microsoft.Extensions.ObjectPool" Version="9.0.1" />
|
||||
<PackageVersion Include="Microsoft.Extensions.ObjectPool" Version="9.0.3" />
|
||||
<PackageVersion Include="Microsoft.NET.Test.Sdk" Version="17.13.0" />
|
||||
<PackageVersion Include="Microsoft.Extensions.DependencyInjection" Version="[2.2.0,)" />
|
||||
<PackageVersion Include="Microsoft.Extensions.DependencyInjection.Abstractions" Version="[2.2.0,)" />
|
||||
<PackageVersion Include="Microsoft.Extensions.Logging" Version="[2.2.0,)" />
|
||||
<PackageVersion Include="Microsoft.Bcl.AsyncInterfaces" Version="[5.0.0,)" />
|
||||
<PackageVersion Include="Moq" Version="4.20.70" />
|
||||
<PackageVersion Include="Moq" Version="4.20.72" />
|
||||
<PackageVersion Include="Open.ChannelExtensions" Version="9.0.0" />
|
||||
<PackageVersion Include="Polly" Version="7.2.3" />
|
||||
<PackageVersion Include="Polly.Contrib.WaitAndRetry" Version="1.1.1" />
|
||||
<PackageVersion Include="Polly.Extensions.Http" Version="3.0.0" />
|
||||
<PackageVersion Include="RichardSzalay.MockHttp" Version="7.0.0" />
|
||||
<PackageVersion Include="Speckle.Newtonsoft.Json" Version="13.0.2" />
|
||||
<PackageVersion Include="Speckle.DoubleNumerics" Version="4.1.0" />
|
||||
<PackageVersion Include="SimpleExec" Version="12.0.0" />
|
||||
<PackageVersion Include="System.Threading.Channels" Version="9.0.2" />
|
||||
<PackageVersion Include="Verify.Quibble" Version="2.1.1" />
|
||||
<PackageVersion Include="Verify.Xunit" Version="28.10.1" />
|
||||
<PackageVersion Include="Verify.Xunit" Version="29.2.0" />
|
||||
<PackageVersion Include="xunit" Version="2.9.3" />
|
||||
<PackageVersion Include="xunit.assert" Version="2.9.3" />
|
||||
<PackageVersion Include="xunit.runner.visualstudio" Version="3.0.2" />
|
||||
|
||||
@@ -8,7 +8,7 @@ Speckle | Sharp | SDK
|
||||
|
||||
### .NET SDK, Tests, and Objects
|
||||
|
||||
[](https://codecov.io/gh/specklesystems/speckle-sharp-sdk)
|
||||
[](https://codecov.io/gh/specklesystems/speckle-sharp-sdk)
|
||||
|
||||
> [!WARNING]
|
||||
> This is an early beta release, not meant for use in production! We're working to stabilise the 3.0 API, and until then there will be breaking changes. You have been warned!
|
||||
|
||||
+8
-8
@@ -42,7 +42,7 @@ Target(
|
||||
|
||||
Target(
|
||||
CLEAN,
|
||||
ForEach("**/output"),
|
||||
forEach: ["**/output"],
|
||||
dir =>
|
||||
{
|
||||
IEnumerable<string> GetDirectories(string d)
|
||||
@@ -68,13 +68,13 @@ Target(
|
||||
|
||||
Target(RESTORE_TOOLS, () => RunAsync("dotnet", "tool restore"));
|
||||
|
||||
Target(FORMAT, DependsOn(RESTORE_TOOLS), () => RunAsync("dotnet", "csharpier --check ."));
|
||||
Target(FORMAT, dependsOn: [RESTORE_TOOLS], () => RunAsync("dotnet", "csharpier --check ."));
|
||||
|
||||
Target(RESTORE, DependsOn(FORMAT), () => RunAsync("dotnet", "restore Speckle.Sdk.sln --locked-mode"));
|
||||
Target(RESTORE, dependsOn: [FORMAT], () => RunAsync("dotnet", "restore Speckle.Sdk.sln --locked-mode"));
|
||||
|
||||
Target(
|
||||
BUILD,
|
||||
DependsOn(RESTORE),
|
||||
dependsOn: [RESTORE],
|
||||
async () =>
|
||||
{
|
||||
var (version, fileVersion) = await GetVersions().ConfigureAwait(false);
|
||||
@@ -89,7 +89,7 @@ Target(
|
||||
|
||||
Target(
|
||||
TEST,
|
||||
DependsOn(BUILD),
|
||||
dependsOn: [BUILD],
|
||||
Glob.Files(".", "**/*.Tests.Unit.csproj").Concat(Glob.Files(".", "**/*.Tests.csproj")),
|
||||
async file =>
|
||||
{
|
||||
@@ -103,7 +103,7 @@ Target(
|
||||
|
||||
Target(
|
||||
INTEGRATION,
|
||||
DependsOn(BUILD),
|
||||
dependsOn: [BUILD],
|
||||
async () =>
|
||||
{
|
||||
await RunAsync("docker", "compose -f docker-compose.yml up --wait").ConfigureAwait(false);
|
||||
@@ -170,7 +170,7 @@ Target(
|
||||
|
||||
Target(
|
||||
PACK,
|
||||
DependsOn(BUILD),
|
||||
dependsOn: [TEST],
|
||||
async () =>
|
||||
{
|
||||
{
|
||||
@@ -182,6 +182,6 @@ Target(
|
||||
}
|
||||
);
|
||||
|
||||
Target("default", DependsOn(FORMAT, TEST, INTEGRATION), () => Console.WriteLine("Done!"));
|
||||
Target("default", dependsOn: [FORMAT, TEST, INTEGRATION], () => Console.WriteLine("Done!"));
|
||||
|
||||
await RunTargetsAndExitAsync(args).ConfigureAwait(true);
|
||||
|
||||
@@ -4,9 +4,9 @@
|
||||
"net8.0": {
|
||||
"Bullseye": {
|
||||
"type": "Direct",
|
||||
"requested": "[5.0.0, )",
|
||||
"resolved": "5.0.0",
|
||||
"contentHash": "bqyt+m17ym+5aN45C5oZRAjuLDt8jKiCm/ys1XfymIXSkrTFwvI/QsbY3ucPSHDz7SF7uON7B57kXFv5H2k1ew=="
|
||||
"requested": "[6.0.0, )",
|
||||
"resolved": "6.0.0",
|
||||
"contentHash": "vgwwXfzs7jJrskWH7saHRMgPzziq/e86QZNWY1MnMxd7e+De7E7EX4K3C7yrvaK9y02SJoLxNxcLG/q5qUAghw=="
|
||||
},
|
||||
"Glob": {
|
||||
"type": "Direct",
|
||||
|
||||
@@ -12,6 +12,13 @@ public class RevitObject : DataObject, IRevitObject
|
||||
public required string family { get; set; }
|
||||
public required string category { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// The level constraint of the object.
|
||||
/// For objects constrained by multiple levels, this represents the base constraint.
|
||||
/// For objects with no level constraint, this should be null.
|
||||
/// </summary>
|
||||
public required string? level { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// A Curve or Point object representing the location of a Revit element.
|
||||
/// </summary>
|
||||
|
||||
@@ -3,7 +3,6 @@ using Speckle.Newtonsoft.Json;
|
||||
using Speckle.Objects.Other;
|
||||
using Speckle.Objects.Primitive;
|
||||
using Speckle.Sdk.Common;
|
||||
using Speckle.Sdk.Host;
|
||||
using Speckle.Sdk.Models;
|
||||
|
||||
namespace Speckle.Objects.Geometry;
|
||||
@@ -31,7 +30,7 @@ public class Brep : Base, IHasArea, IHasVolume, IHasBoundingBox, ITransformable<
|
||||
/// <summary>
|
||||
/// Gets or sets the flat list of numbers representing the <see cref="Brep"/>'s surfaces.
|
||||
/// </summary>
|
||||
[DetachProperty, SchemaIgnore, Chunkable(31250)]
|
||||
[DetachProperty, Chunkable(31250)]
|
||||
public List<double> SurfacesValue
|
||||
{
|
||||
get
|
||||
@@ -77,7 +76,7 @@ public class Brep : Base, IHasArea, IHasVolume, IHasBoundingBox, ITransformable<
|
||||
/// <remarks>
|
||||
/// This is only used for the <see cref="Brep"/> class serialisation/deserialisation. You should use <see cref="Brep.Curve3D"/> instead.
|
||||
/// </remarks>
|
||||
[DetachProperty, SchemaIgnore, Chunkable(31250)]
|
||||
[DetachProperty, Chunkable(31250)]
|
||||
public List<double> Curve3DValues
|
||||
{
|
||||
get => CurveArrayEncodingExtensions.ToArray(Curve3D);
|
||||
@@ -102,7 +101,7 @@ public class Brep : Base, IHasArea, IHasVolume, IHasBoundingBox, ITransformable<
|
||||
/// <remarks>
|
||||
/// This is only used for the <see cref="Brep"/> class serialisation/deserialisation. You should use <see cref="Brep.Curve2D"/> instead.
|
||||
/// </remarks>
|
||||
[DetachProperty, SchemaIgnore, Chunkable(31250)]
|
||||
[DetachProperty, Chunkable(31250)]
|
||||
public List<double> Curve2DValues
|
||||
{
|
||||
get => CurveArrayEncodingExtensions.ToArray(Curve2D);
|
||||
@@ -127,7 +126,7 @@ public class Brep : Base, IHasArea, IHasVolume, IHasBoundingBox, ITransformable<
|
||||
/// <remarks>
|
||||
/// This is only used for the <see cref="Brep"/> class serialisation/deserialisation. You should use <see cref="Brep.Vertices"/> instead.
|
||||
/// </remarks>
|
||||
[DetachProperty, SchemaIgnore, Chunkable(31250)]
|
||||
[DetachProperty, Chunkable(31250)]
|
||||
public List<double> VerticesValue
|
||||
{
|
||||
get
|
||||
@@ -167,7 +166,7 @@ public class Brep : Base, IHasArea, IHasVolume, IHasBoundingBox, ITransformable<
|
||||
/// <remarks>
|
||||
/// This is only used for the <see cref="Brep"/> class serialisation/deserialisation. You should use <see cref="Brep.Edges"/> instead.
|
||||
/// </remarks>
|
||||
[DetachProperty, SchemaIgnore, Chunkable(62500)]
|
||||
[DetachProperty, Chunkable(62500)]
|
||||
public List<double?> EdgesValue
|
||||
{
|
||||
get =>
|
||||
@@ -241,7 +240,7 @@ public class Brep : Base, IHasArea, IHasVolume, IHasBoundingBox, ITransformable<
|
||||
/// <remarks>
|
||||
/// This is only used for the <see cref="Brep"/> class serialisation/deserialisation. You should use <see cref="Brep.Loops"/> instead.
|
||||
/// </remarks>
|
||||
[DetachProperty, SchemaIgnore, Chunkable(62500)]
|
||||
[DetachProperty, Chunkable(62500)]
|
||||
public List<int> LoopsValue
|
||||
{
|
||||
get =>
|
||||
@@ -297,7 +296,7 @@ public class Brep : Base, IHasArea, IHasVolume, IHasBoundingBox, ITransformable<
|
||||
/// <remarks>
|
||||
/// This is only used for the <see cref="Brep"/> class serialisation/deserialisation. You should use <see cref="Brep.Trims"/> instead.
|
||||
/// </remarks>
|
||||
[DetachProperty, SchemaIgnore, Chunkable(62500)]
|
||||
[DetachProperty, Chunkable(62500)]
|
||||
public List<int> TrimsValue
|
||||
{
|
||||
get
|
||||
@@ -363,7 +362,7 @@ public class Brep : Base, IHasArea, IHasVolume, IHasBoundingBox, ITransformable<
|
||||
/// <remarks>
|
||||
/// This is only used for the <see cref="Brep"/> class serialisation/deserialisation. You should use <see cref="Brep.Faces"/> instead.
|
||||
/// </remarks>
|
||||
[DetachProperty, SchemaIgnore, Chunkable(62500)]
|
||||
[DetachProperty, Chunkable(62500)]
|
||||
public List<int> FacesValue
|
||||
{
|
||||
get =>
|
||||
|
||||
@@ -22,4 +22,23 @@ public static class Collections
|
||||
public static class EnumerableExtensions
|
||||
{
|
||||
public static IEnumerable<int> RangeFrom(int from, int to) => Enumerable.Range(from, to - from + 1);
|
||||
|
||||
#if NETSTANDARD2_0
|
||||
public static IEnumerable<TSource> DistinctBy<TSource, TKey>(
|
||||
this IEnumerable<TSource> source,
|
||||
Func<TSource, TKey> keySelector
|
||||
)
|
||||
{
|
||||
var keys = new HashSet<TKey>();
|
||||
foreach (var element in source)
|
||||
{
|
||||
if (keys.Contains(keySelector(element)))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
keys.Add(keySelector(element));
|
||||
yield return element;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
@@ -19,13 +19,13 @@ public static class BatchExtensions
|
||||
public static void AddBatchItem<T>(this IMemoryOwner<T> batch, T item)
|
||||
where T : IHasByteSize => ((Batch<T>)batch).Add(item);
|
||||
|
||||
public static int GetBatchSize<T>(this IMemoryOwner<T> batch, Action<string> logAsWarning, int maxBatchSize)
|
||||
public static int GetBatchSize<T>(this IMemoryOwner<T> batch, int maxBatchSize)
|
||||
where T : IHasByteSize
|
||||
{
|
||||
var currentSize = ((Batch<T>)batch).BatchByteSize;
|
||||
if (currentSize > maxBatchSize)
|
||||
{
|
||||
logAsWarning($"Batch size exceeded. Current size: {currentSize} bytes. Max size: {maxBatchSize} bytes.");
|
||||
//doing this to say it's full since the channel reader only does full being equivalent
|
||||
return maxBatchSize;
|
||||
}
|
||||
|
||||
|
||||
@@ -8,7 +8,6 @@ public static class ChannelExtensions
|
||||
{
|
||||
public static BatchingChannelReader<T, IMemoryOwner<T>> BatchByByteSize<T>(
|
||||
this ChannelReader<T> source,
|
||||
Action<string> logAsWarning,
|
||||
int batchSize,
|
||||
bool singleReader = false,
|
||||
bool allowSynchronousContinuations = false
|
||||
@@ -16,7 +15,6 @@ public static class ChannelExtensions
|
||||
where T : IHasByteSize =>
|
||||
new SizeBatchingChannelReader<T>(
|
||||
source ?? throw new ArgumentNullException(nameof(source)),
|
||||
logAsWarning,
|
||||
batchSize,
|
||||
singleReader,
|
||||
allowSynchronousContinuations
|
||||
|
||||
@@ -5,7 +5,7 @@ using Speckle.Sdk.Serialisation.V2.Send;
|
||||
|
||||
namespace Speckle.Sdk.Dependencies.Serialization;
|
||||
|
||||
public abstract class ChannelSaver<T>(Action<string> logAsWarning, CancellationToken cancellationToken)
|
||||
public abstract class ChannelSaver<T>
|
||||
where T : IHasByteSize
|
||||
{
|
||||
private const int SEND_CAPACITY = 500;
|
||||
@@ -16,8 +16,6 @@ public abstract class ChannelSaver<T>(Action<string> logAsWarning, CancellationT
|
||||
private const int MAX_CACHE_WRITE_PARALLELISM = 4;
|
||||
private const int MAX_CACHE_BATCH = 500;
|
||||
|
||||
private readonly CancellationTokenSource _cts = CancellationTokenSource.CreateLinkedTokenSource(cancellationToken);
|
||||
|
||||
private readonly Channel<T> _checkCacheChannel = Channel.CreateBounded<T>(
|
||||
new BoundedChannelOptions(SEND_CAPACITY)
|
||||
{
|
||||
@@ -30,26 +28,26 @@ public abstract class ChannelSaver<T>(Action<string> logAsWarning, CancellationT
|
||||
_ => throw new NotImplementedException("Dropping items not supported.")
|
||||
);
|
||||
|
||||
public Task Start() =>
|
||||
public Task Start(CancellationToken cancellationToken) =>
|
||||
_checkCacheChannel
|
||||
.Reader.BatchByByteSize(logAsWarning, HTTP_SEND_CHUNK_SIZE)
|
||||
.Reader.BatchByByteSize(HTTP_SEND_CHUNK_SIZE)
|
||||
.WithTimeout(HTTP_BATCH_TIMEOUT)
|
||||
.PipeAsync(
|
||||
MAX_PARALLELISM_HTTP,
|
||||
async x => await SendToServer(x).ConfigureAwait(false),
|
||||
HTTP_CAPACITY,
|
||||
false,
|
||||
_cts.Token
|
||||
cancellationToken
|
||||
)
|
||||
.Join()
|
||||
.Batch(MAX_CACHE_BATCH)
|
||||
.WithTimeout(HTTP_BATCH_TIMEOUT)
|
||||
.ReadAllConcurrently(MAX_CACHE_WRITE_PARALLELISM, SaveToCache, _cts.Token)
|
||||
.ReadAllConcurrently(MAX_CACHE_WRITE_PARALLELISM, SaveToCache, cancellationToken)
|
||||
.ContinueWith(
|
||||
t =>
|
||||
{
|
||||
Exception? ex = t.Exception;
|
||||
if (ex is null && t.Status is TaskStatus.Canceled && !_cts.Token.IsCancellationRequested)
|
||||
if (ex is null && t.Status is TaskStatus.Canceled && !cancellationToken.IsCancellationRequested)
|
||||
{
|
||||
ex = new OperationCanceledException();
|
||||
}
|
||||
@@ -60,25 +58,26 @@ public abstract class ChannelSaver<T>(Action<string> logAsWarning, CancellationT
|
||||
}
|
||||
_checkCacheChannel.Writer.TryComplete(ex);
|
||||
},
|
||||
_cts.Token,
|
||||
cancellationToken,
|
||||
TaskContinuationOptions.ExecuteSynchronously,
|
||||
TaskScheduler.Current
|
||||
);
|
||||
|
||||
public async ValueTask Save(T item)
|
||||
public void Save(T item, CancellationToken cancellationToken)
|
||||
{
|
||||
if (Exception is not null || _cts.IsCancellationRequested)
|
||||
if (Exception is not null || cancellationToken.IsCancellationRequested)
|
||||
{
|
||||
return; //don't save if we're already done through an error
|
||||
}
|
||||
await _checkCacheChannel.Writer.WriteAsync(item).ConfigureAwait(false);
|
||||
// ReSharper disable once MethodSupportsCancellation
|
||||
_checkCacheChannel.Writer.TryWrite(item);
|
||||
}
|
||||
|
||||
private async Task<IMemoryOwner<T>> SendToServer(IMemoryOwner<T> batch)
|
||||
{
|
||||
try
|
||||
{
|
||||
await SendToServer((Batch<T>)batch).ConfigureAwait(false);
|
||||
await SendToServerInternal((Batch<T>)batch).ConfigureAwait(false);
|
||||
return batch;
|
||||
}
|
||||
#pragma warning disable CA1031
|
||||
@@ -90,20 +89,6 @@ public abstract class ChannelSaver<T>(Action<string> logAsWarning, CancellationT
|
||||
}
|
||||
}
|
||||
|
||||
public async Task SendToServer(Batch<T> batch)
|
||||
{
|
||||
try
|
||||
{
|
||||
await SendToServerInternal(batch).ConfigureAwait(false);
|
||||
}
|
||||
#pragma warning disable CA1031
|
||||
catch (Exception ex)
|
||||
#pragma warning restore CA1031
|
||||
{
|
||||
RecordException(ex);
|
||||
}
|
||||
}
|
||||
|
||||
protected abstract Task SendToServerInternal(Batch<T> batch);
|
||||
|
||||
public abstract void SaveToCache(List<T> item);
|
||||
@@ -118,13 +103,11 @@ public abstract class ChannelSaver<T>(Action<string> logAsWarning, CancellationT
|
||||
}
|
||||
}
|
||||
|
||||
protected Exception? Exception { get; set; }
|
||||
public Exception? Exception { get; set; }
|
||||
|
||||
private void RecordException(Exception ex)
|
||||
{
|
||||
Exception = ex;
|
||||
_checkCacheChannel.Writer.TryComplete(ex);
|
||||
//cancel everything!
|
||||
_cts.Cancel();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -11,7 +11,6 @@ public interface IHasByteSize
|
||||
|
||||
public sealed class SizeBatchingChannelReader<T>(
|
||||
ChannelReader<T> source,
|
||||
Action<string> logAsWarning,
|
||||
int batchSize,
|
||||
bool singleReader,
|
||||
bool syncCont = false
|
||||
@@ -34,5 +33,5 @@ public sealed class SizeBatchingChannelReader<T>(
|
||||
|
||||
protected override void AddBatchItem(IMemoryOwner<T> batch, T item) => batch.AddBatchItem(item);
|
||||
|
||||
protected override int GetBatchSize(IMemoryOwner<T> batch) => batch.GetBatchSize(logAsWarning, _batchSize);
|
||||
protected override int GetBatchSize(IMemoryOwner<T> batch) => batch.GetBatchSize(_batchSize);
|
||||
}
|
||||
|
||||
@@ -3,7 +3,7 @@ using Speckle.Sdk.Logging;
|
||||
|
||||
namespace Speckle.Sdk.Helpers;
|
||||
|
||||
public sealed class SpeckleHttpClientHandler : DelegatingHandler
|
||||
internal sealed class SpeckleHttpClientHandler : DelegatingHandler
|
||||
{
|
||||
private readonly IAsyncPolicy<HttpResponseMessage> _resiliencePolicy;
|
||||
private readonly ISdkActivityFactory _activityFactory;
|
||||
|
||||
@@ -40,8 +40,13 @@ public sealed class SpeckleHttpClientHandlerFactory(ISdkActivityFactory activity
|
||||
return Policy.WrapAsync(retryPolicy, timeoutPolicy);
|
||||
}
|
||||
|
||||
public SpeckleHttpClientHandler Create(
|
||||
public DelegatingHandler Create(
|
||||
HttpMessageHandler? innerHandler = null,
|
||||
int timeoutSeconds = DEFAULT_TIMEOUT_SECONDS
|
||||
) => new(innerHandler ?? new HttpClientHandler(), activityFactory, HttpAsyncPolicy(timeoutSeconds: timeoutSeconds));
|
||||
) =>
|
||||
new SpeckleHttpClientHandler(
|
||||
innerHandler ?? new HttpClientHandler(),
|
||||
activityFactory,
|
||||
HttpAsyncPolicy(timeoutSeconds: timeoutSeconds)
|
||||
);
|
||||
}
|
||||
|
||||
@@ -13,9 +13,9 @@
|
||||
},
|
||||
"Microsoft.Extensions.ObjectPool": {
|
||||
"type": "Direct",
|
||||
"requested": "[9.0.1, )",
|
||||
"resolved": "9.0.1",
|
||||
"contentHash": "r64veU9uYILp6pYqfo3qzRab8zLMALvXZgT4VRY79tXMLu8X79uTlJ6nqPLtPIVhfCPXycRh8ILyFz/gGBDQdQ=="
|
||||
"requested": "[9.0.3, )",
|
||||
"resolved": "9.0.3",
|
||||
"contentHash": "4uPdnj9hLRrb3ZSeVEDtwIm9nNrrT9vAXYC9o1/yTW8lGOPwTyI2QlkcICwYEGM1LESGTFidcPMFACznUZKbIQ=="
|
||||
},
|
||||
"Microsoft.SourceLink.GitHub": {
|
||||
"type": "Direct",
|
||||
@@ -174,9 +174,9 @@
|
||||
},
|
||||
"Microsoft.Extensions.ObjectPool": {
|
||||
"type": "Direct",
|
||||
"requested": "[9.0.1, )",
|
||||
"resolved": "9.0.1",
|
||||
"contentHash": "r64veU9uYILp6pYqfo3qzRab8zLMALvXZgT4VRY79tXMLu8X79uTlJ6nqPLtPIVhfCPXycRh8ILyFz/gGBDQdQ=="
|
||||
"requested": "[9.0.3, )",
|
||||
"resolved": "9.0.3",
|
||||
"contentHash": "4uPdnj9hLRrb3ZSeVEDtwIm9nNrrT9vAXYC9o1/yTW8lGOPwTyI2QlkcICwYEGM1LESGTFidcPMFACznUZKbIQ=="
|
||||
},
|
||||
"Microsoft.SourceLink.GitHub": {
|
||||
"type": "Direct",
|
||||
|
||||
@@ -4,6 +4,7 @@ using System.Reflection;
|
||||
using GraphQL;
|
||||
using GraphQL.Client.Http;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Speckle.InterfaceGenerator;
|
||||
using Speckle.Newtonsoft.Json;
|
||||
using Speckle.Newtonsoft.Json.Serialization;
|
||||
using Speckle.Sdk.Api.GraphQL;
|
||||
@@ -16,8 +17,14 @@ using Speckle.Sdk.Logging;
|
||||
|
||||
namespace Speckle.Sdk.Api;
|
||||
|
||||
public partial interface IClient : IDisposable
|
||||
{
|
||||
GraphQLHttpClient GQLClient { get; }
|
||||
}
|
||||
|
||||
[SuppressMessage("Maintainability", "CA1506:Avoid excessive class coupling", Justification = "Class needs refactor")]
|
||||
public sealed class Client : ISpeckleGraphQLClient, IDisposable
|
||||
[GenerateAutoInterface]
|
||||
public sealed class Client : ISpeckleGraphQLClient, IClient
|
||||
{
|
||||
private readonly ILogger<Client> _logger;
|
||||
private readonly ISdkActivityFactory _activityFactory;
|
||||
@@ -37,6 +44,7 @@ public sealed class Client : ISpeckleGraphQLClient, IDisposable
|
||||
|
||||
private HttpClient HttpClient { get; }
|
||||
|
||||
[AutoInterfaceIgnore]
|
||||
public GraphQLHttpClient GQLClient { get; }
|
||||
|
||||
/// <param name="account"></param>
|
||||
@@ -67,6 +75,7 @@ public sealed class Client : ISpeckleGraphQLClient, IDisposable
|
||||
GQLClient = CreateGraphQLClient(account, HttpClient);
|
||||
}
|
||||
|
||||
[AutoInterfaceIgnore]
|
||||
public void Dispose()
|
||||
{
|
||||
try
|
||||
@@ -132,6 +141,7 @@ public sealed class Client : ISpeckleGraphQLClient, IDisposable
|
||||
}
|
||||
}
|
||||
|
||||
[AutoInterfaceIgnore]
|
||||
IDisposable ISpeckleGraphQLClient.SubscribeTo<T>(GraphQLRequest request, Action<object, T> callback) =>
|
||||
SubscribeTo(request, callback);
|
||||
|
||||
|
||||
@@ -14,6 +14,6 @@ public class ClientFactory(
|
||||
ISpeckleHttp speckleHttp
|
||||
) : IClientFactory
|
||||
{
|
||||
public Client Create(Account account) =>
|
||||
new(loggerFactory.CreateLogger<Client>(), activityFactory, application, speckleHttp, account);
|
||||
public IClient Create(Account account) =>
|
||||
new Client(loggerFactory.CreateLogger<Client>(), activityFactory, application, speckleHttp, account);
|
||||
}
|
||||
|
||||
@@ -2,7 +2,9 @@
|
||||
|
||||
public enum ProjectVisibility
|
||||
{
|
||||
Private,
|
||||
Public,
|
||||
Unlisted,
|
||||
Private = 0,
|
||||
|
||||
[Obsolete("Use Unlisted instead", true)]
|
||||
Public = 1,
|
||||
Unlisted = 2,
|
||||
}
|
||||
|
||||
@@ -29,7 +29,7 @@ public partial class Operations
|
||||
metricsFactory.CreateCounter<long>("Receive").Add(1);
|
||||
|
||||
receiveActivity?.SetTag("objectId", objectId);
|
||||
var process = serializeProcessFactory.CreateDeserializeProcess(
|
||||
var process = deserializeProcessFactory.CreateDeserializeProcess(
|
||||
url,
|
||||
streamId,
|
||||
authorizationToken,
|
||||
|
||||
@@ -15,5 +15,6 @@ public partial class Operations(
|
||||
ILogger<Operations> logger,
|
||||
ISdkActivityFactory activityFactory,
|
||||
ISdkMetricsFactory metricsFactory,
|
||||
ISerializeProcessFactory serializeProcessFactory
|
||||
ISerializeProcessFactory serializeProcessFactory,
|
||||
IDeserializeProcessFactory deserializeProcessFactory
|
||||
) : IOperations;
|
||||
|
||||
@@ -0,0 +1,4 @@
|
||||
using System.Runtime.CompilerServices;
|
||||
|
||||
[assembly: InternalsVisibleTo("Speckle.Objects.Tests.Unit")]
|
||||
[assembly: InternalsVisibleTo("Speckle.Sdk.Tests.Performance")]
|
||||
@@ -399,8 +399,9 @@ public sealed class AccountManager(
|
||||
/// <summary>
|
||||
/// Refetches user and server info for each account
|
||||
/// </summary>
|
||||
/// <param name="app"> It is defaultAppId in the server. By default it is "sca" to not break existing parts that this function involves.</param>
|
||||
/// <returns></returns>
|
||||
public async Task UpdateAccounts(CancellationToken ct = default)
|
||||
public async Task UpdateAccounts(CancellationToken ct = default, string app = "sca")
|
||||
{
|
||||
// need to ToList() the GetAccounts call or the UpdateObject call at the end of this method
|
||||
// will not work because sqlite does not support concurrent db calls
|
||||
@@ -415,16 +416,9 @@ public sealed class AccountManager(
|
||||
//TODO: once we get a token expired exception from the server use that instead
|
||||
if (userServerInfo?.activeUser == null || userServerInfo.serverInfo == null)
|
||||
{
|
||||
var tokenResponse = await GetRefreshedToken(account.refreshToken, url).ConfigureAwait(false);
|
||||
userServerInfo = await GetUserServerInfo(tokenResponse.token, url, ct).ConfigureAwait(false);
|
||||
|
||||
if (userServerInfo?.activeUser == null || userServerInfo.serverInfo == null)
|
||||
{
|
||||
throw new SpeckleException("Could not refresh token");
|
||||
}
|
||||
|
||||
account.token = tokenResponse.token;
|
||||
account.refreshToken = tokenResponse.refreshToken;
|
||||
// We were initially was handling refresh token here bc quite a while ago server was returning null
|
||||
// for activeUser and serverInfo instead of throwing exception. In short, our logic moved into catch block to cover both.
|
||||
throw new SpeckleException("Token is expired");
|
||||
}
|
||||
|
||||
account.isOnline = true;
|
||||
@@ -437,11 +431,32 @@ public sealed class AccountManager(
|
||||
}
|
||||
catch (Exception ex) when (!ex.IsFatal())
|
||||
{
|
||||
account.isOnline = false;
|
||||
await RefreshAndSetAccountToken(account, app).ConfigureAwait(false);
|
||||
}
|
||||
|
||||
ct.ThrowIfCancellationRequested();
|
||||
_accountStorage.SaveObject(account.id, JsonConvert.SerializeObject(account));
|
||||
_accountStorage.UpdateObject(account.id, JsonConvert.SerializeObject(account));
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Mutates the account with new tokens.
|
||||
/// </summary>
|
||||
/// <param name="account"></param>
|
||||
/// <param name="app"></param>
|
||||
private async Task RefreshAndSetAccountToken(Account account, string app)
|
||||
{
|
||||
try
|
||||
{
|
||||
Uri url = new(account.serverInfo.url);
|
||||
var tokenResponse = await GetRefreshedToken(account.refreshToken, url, app).ConfigureAwait(false);
|
||||
account.token = tokenResponse.token;
|
||||
account.refreshToken = tokenResponse.refreshToken;
|
||||
account.isOnline = true;
|
||||
}
|
||||
catch (Exception ex) when (!ex.IsFatal())
|
||||
{
|
||||
account.isOnline = false;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -766,7 +781,7 @@ public sealed class AccountManager(
|
||||
}
|
||||
}
|
||||
|
||||
private async Task<TokenExchangeResponse> GetRefreshedToken(string refreshToken, Uri server)
|
||||
private async Task<TokenExchangeResponse> GetRefreshedToken(string refreshToken, Uri server, string app = "sca")
|
||||
{
|
||||
try
|
||||
{
|
||||
@@ -774,8 +789,8 @@ public sealed class AccountManager(
|
||||
|
||||
var body = new
|
||||
{
|
||||
appId = "sca",
|
||||
appSecret = "sca",
|
||||
appId = app,
|
||||
appSecret = app,
|
||||
refreshToken,
|
||||
};
|
||||
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.Text;
|
||||
using Speckle.Newtonsoft.Json;
|
||||
using Speckle.Sdk.Dependencies;
|
||||
@@ -5,6 +6,8 @@ using Speckle.Sdk.Serialisation;
|
||||
|
||||
namespace Speckle.Sdk.Helpers;
|
||||
|
||||
//just a wrapper around a lot of newtonsoft overloads
|
||||
[ExcludeFromCodeCoverage]
|
||||
public sealed class SerializerIdWriter : JsonWriter
|
||||
{
|
||||
private readonly JsonWriter _jsonWriter;
|
||||
|
||||
@@ -15,10 +15,15 @@ public class SpeckleHttp(ILogger<SpeckleHttp> logger, ISpeckleHttpClientHandlerF
|
||||
/// <param name="uri">The URI that should be pinged</param>
|
||||
/// <exception cref="System.Net.Http.HttpRequestException">Request to <paramref name="uri"/> failed</exception>
|
||||
public async Task<HttpResponseMessage> HttpPing(Uri uri)
|
||||
{
|
||||
using var httpClient = CreateHttpClient();
|
||||
return await HttpPing(uri, httpClient).ConfigureAwait(false);
|
||||
}
|
||||
|
||||
public async Task<HttpResponseMessage> HttpPing(Uri uri, HttpClient httpClient)
|
||||
{
|
||||
try
|
||||
{
|
||||
using var httpClient = CreateHttpClient();
|
||||
HttpResponseMessage response = await httpClient.GetAsync(uri).ConfigureAwait(false);
|
||||
response.EnsureSuccessStatusCode();
|
||||
logger.LogInformation("Successfully pinged {uri}", uri);
|
||||
@@ -1,63 +0,0 @@
|
||||
namespace Speckle.Sdk.Host;
|
||||
|
||||
[AttributeUsage(AttributeTargets.Constructor)]
|
||||
public sealed class SchemaInfoAttribute : Attribute
|
||||
{
|
||||
public SchemaInfoAttribute(string name, string description)
|
||||
: this(name, description, null, null) { }
|
||||
|
||||
public SchemaInfoAttribute(string name, string description, string? category, string? subcategory)
|
||||
{
|
||||
Name = name;
|
||||
Description = description;
|
||||
Category = category;
|
||||
Subcategory = subcategory;
|
||||
}
|
||||
|
||||
public string? Subcategory { get; }
|
||||
|
||||
public string? Category { get; }
|
||||
|
||||
public string Description { get; }
|
||||
|
||||
public string Name { get; }
|
||||
}
|
||||
|
||||
[AttributeUsage(AttributeTargets.Constructor)]
|
||||
public sealed class SchemaDeprecatedAttribute : Attribute { }
|
||||
|
||||
[AttributeUsage(AttributeTargets.Parameter)]
|
||||
public sealed class SchemaParamInfoAttribute : Attribute
|
||||
{
|
||||
public SchemaParamInfoAttribute(string description)
|
||||
{
|
||||
Description = description;
|
||||
}
|
||||
|
||||
public string Description { get; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Used to indicate which is the main input parameter of the schema builder component. Schema info will be attached to this object.
|
||||
/// </summary>
|
||||
[AttributeUsage(AttributeTargets.Parameter)]
|
||||
public sealed class SchemaMainParamAttribute : Attribute { }
|
||||
|
||||
// TODO: this could be nuked, as it's only used to hide props on Base,
|
||||
// which we might want to expose anyways...
|
||||
/// <summary>
|
||||
/// Used to ignore properties from expand objects etc
|
||||
/// </summary>
|
||||
[AttributeUsage(AttributeTargets.Property)]
|
||||
public sealed class SchemaIgnoreAttribute : Attribute { }
|
||||
|
||||
[AttributeUsage(AttributeTargets.Method)]
|
||||
public sealed class SchemaComputedAttribute : Attribute
|
||||
{
|
||||
public SchemaComputedAttribute(string name)
|
||||
{
|
||||
Name = name;
|
||||
}
|
||||
|
||||
public string Name { get; }
|
||||
}
|
||||
@@ -1,23 +0,0 @@
|
||||
namespace Speckle.Sdk.Host;
|
||||
|
||||
public enum HostAppVersion
|
||||
{
|
||||
v3,
|
||||
v6,
|
||||
v7,
|
||||
v8,
|
||||
v2019,
|
||||
v2020,
|
||||
v2021,
|
||||
v2022,
|
||||
v2023,
|
||||
v2024,
|
||||
v2025,
|
||||
v21,
|
||||
v22,
|
||||
v25,
|
||||
v26,
|
||||
v715,
|
||||
v716,
|
||||
v717,
|
||||
}
|
||||
@@ -1,13 +0,0 @@
|
||||
namespace Speckle.Sdk.Host;
|
||||
|
||||
public readonly struct HostApplication
|
||||
{
|
||||
public string Name { get; }
|
||||
public string Slug { get; }
|
||||
|
||||
public HostApplication(string name, string slug)
|
||||
{
|
||||
Name = name;
|
||||
Slug = slug;
|
||||
}
|
||||
}
|
||||
@@ -1,220 +0,0 @@
|
||||
using System.Diagnostics.Contracts;
|
||||
|
||||
namespace Speckle.Sdk.Host;
|
||||
|
||||
/// <summary>
|
||||
/// List of Host Applications - their slugs should match our ghost tags and ci/cd slugs
|
||||
/// </summary>
|
||||
public static class HostApplications
|
||||
{
|
||||
public static string GetVersion(HostAppVersion version) => version.ToString().TrimStart('v');
|
||||
|
||||
public static readonly HostApplication Rhino = new("Rhino", "rhino"),
|
||||
Grasshopper = new("Grasshopper", "grasshopper"),
|
||||
Revit = new("Revit", "revit"),
|
||||
Dynamo = new("Dynamo", "dynamo"),
|
||||
Unity = new("Unity", "unity"),
|
||||
GSA = new("GSA", "gsa"),
|
||||
Civil = new("Civil 3D", "civil3d"),
|
||||
Civil3D = new("Civil 3D", "civil3d"),
|
||||
AutoCAD = new("AutoCAD", "autocad"),
|
||||
MicroStation = new("MicroStation", "microstation"),
|
||||
OpenRoads = new("OpenRoads", "openroads"),
|
||||
OpenRail = new("OpenRail", "openrail"),
|
||||
OpenBuildings = new("OpenBuildings", "openbuildings"),
|
||||
ETABS = new("ETABS", "etabs"),
|
||||
SAP2000 = new("SAP2000", "sap2000"),
|
||||
CSiBridge = new("CSiBridge", "csibridge"),
|
||||
SAFE = new("SAFE", "safe"),
|
||||
TeklaStructures = new("Tekla Structures", "teklastructures"),
|
||||
Dxf = new("DXF Converter", "dxf"),
|
||||
Excel = new("Excel", "excel"),
|
||||
Unreal = new("Unreal", "unreal"),
|
||||
PowerBI = new("Power BI", "powerbi"),
|
||||
Blender = new("Blender", "blender"),
|
||||
QGIS = new("QGIS", "qgis"),
|
||||
ArcGIS = new("ArcGIS", "arcgis"),
|
||||
SketchUp = new("SketchUp", "sketchup"),
|
||||
Archicad = new("Archicad", "archicad"),
|
||||
TopSolid = new("TopSolid", "topsolid"),
|
||||
Python = new("Python", "python"),
|
||||
NET = new(".NET", "net"),
|
||||
Navisworks = new("Navisworks", "navisworks"),
|
||||
AdvanceSteel = new("Advance Steel", "advancesteel"),
|
||||
Other = new("Other", "other");
|
||||
|
||||
/// <summary>
|
||||
/// Gets a HostApplication form a string. It could be the versioned name or a string coming from a process running.
|
||||
/// </summary>
|
||||
/// <param name="appname">String with the name of the app</param>
|
||||
/// <returns></returns>
|
||||
[Pure]
|
||||
public static HostApplication GetHostAppFromString(string? appname)
|
||||
{
|
||||
if (appname == null)
|
||||
{
|
||||
return Other;
|
||||
}
|
||||
|
||||
appname = appname.ToLowerInvariant().Replace(" ", "");
|
||||
if (appname.Contains("dynamo"))
|
||||
{
|
||||
return Dynamo;
|
||||
}
|
||||
|
||||
if (appname.Contains("revit"))
|
||||
{
|
||||
return Revit;
|
||||
}
|
||||
|
||||
if (appname.Contains("autocad"))
|
||||
{
|
||||
return AutoCAD;
|
||||
}
|
||||
if (appname.Contains("civil3d"))
|
||||
{
|
||||
return Civil3D;
|
||||
}
|
||||
if (appname.Contains("civil"))
|
||||
{
|
||||
return Civil;
|
||||
}
|
||||
|
||||
if (appname.Contains("rhino"))
|
||||
{
|
||||
return Rhino;
|
||||
}
|
||||
|
||||
if (appname.Contains("grasshopper"))
|
||||
{
|
||||
return Grasshopper;
|
||||
}
|
||||
|
||||
if (appname.Contains("unity"))
|
||||
{
|
||||
return Unity;
|
||||
}
|
||||
|
||||
if (appname.Contains("gsa"))
|
||||
{
|
||||
return GSA;
|
||||
}
|
||||
|
||||
if (appname.Contains("microstation"))
|
||||
{
|
||||
return MicroStation;
|
||||
}
|
||||
|
||||
if (appname.Contains("openroads"))
|
||||
{
|
||||
return OpenRoads;
|
||||
}
|
||||
|
||||
if (appname.Contains("openrail"))
|
||||
{
|
||||
return OpenRail;
|
||||
}
|
||||
|
||||
if (appname.Contains("openbuildings"))
|
||||
{
|
||||
return OpenBuildings;
|
||||
}
|
||||
|
||||
if (appname.Contains("etabs"))
|
||||
{
|
||||
return ETABS;
|
||||
}
|
||||
|
||||
if (appname.Contains("sap"))
|
||||
{
|
||||
return SAP2000;
|
||||
}
|
||||
|
||||
if (appname.Contains("csibridge"))
|
||||
{
|
||||
return CSiBridge;
|
||||
}
|
||||
|
||||
if (appname.Contains("safe"))
|
||||
{
|
||||
return SAFE;
|
||||
}
|
||||
|
||||
if (appname.Contains("teklastructures"))
|
||||
{
|
||||
return TeklaStructures;
|
||||
}
|
||||
|
||||
if (appname.Contains("dxf"))
|
||||
{
|
||||
return Dxf;
|
||||
}
|
||||
|
||||
if (appname.Contains("excel"))
|
||||
{
|
||||
return Excel;
|
||||
}
|
||||
|
||||
if (appname.Contains("unreal"))
|
||||
{
|
||||
return Unreal;
|
||||
}
|
||||
|
||||
if (appname.Contains("powerbi"))
|
||||
{
|
||||
return PowerBI;
|
||||
}
|
||||
|
||||
if (appname.Contains("blender"))
|
||||
{
|
||||
return Blender;
|
||||
}
|
||||
|
||||
if (appname.Contains("qgis"))
|
||||
{
|
||||
return QGIS;
|
||||
}
|
||||
|
||||
if (appname.Contains("arcgis"))
|
||||
{
|
||||
return ArcGIS;
|
||||
}
|
||||
|
||||
if (appname.Contains("sketchup"))
|
||||
{
|
||||
return SketchUp;
|
||||
}
|
||||
|
||||
if (appname.Contains("archicad"))
|
||||
{
|
||||
return Archicad;
|
||||
}
|
||||
|
||||
if (appname.Contains("topsolid"))
|
||||
{
|
||||
return TopSolid;
|
||||
}
|
||||
|
||||
if (appname.Contains("python"))
|
||||
{
|
||||
return Python;
|
||||
}
|
||||
|
||||
if (appname.Contains("net"))
|
||||
{
|
||||
return NET;
|
||||
}
|
||||
|
||||
if (appname.Contains("navisworks"))
|
||||
{
|
||||
return Navisworks;
|
||||
}
|
||||
|
||||
if (appname.Contains("advancesteel"))
|
||||
{
|
||||
return AdvanceSteel;
|
||||
}
|
||||
|
||||
return new HostApplication(appname, appname);
|
||||
}
|
||||
}
|
||||
@@ -5,9 +5,9 @@ using Speckle.Sdk.Models;
|
||||
|
||||
namespace Speckle.Sdk.Host;
|
||||
|
||||
public record LoadedType(string Name, Type Type, List<string> DeprecatedNames);
|
||||
internal record LoadedType(string Name, Type Type, List<string> DeprecatedNames);
|
||||
|
||||
public static class TypeLoader
|
||||
internal static class TypeLoader
|
||||
{
|
||||
private static bool s_initialized;
|
||||
private static List<LoadedType> s_availableTypes = new();
|
||||
|
||||
@@ -28,20 +28,17 @@ public class Base : DynamicBase, ISpeckleObject
|
||||
/// <summary>
|
||||
/// A speckle object's id is an unique hash based on its properties. <b>NOTE: this field will be null unless the object was deserialised from a source. Use the <see cref="GetId"/> function to get it.</b>
|
||||
/// </summary>
|
||||
[SchemaIgnore]
|
||||
public virtual string? id { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Secondary, ideally host application driven, object identifier.
|
||||
/// </summary>
|
||||
[SchemaIgnore]
|
||||
public string? applicationId { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Holds the type information of this speckle object, derived automatically
|
||||
/// from its assembly name and inheritance.
|
||||
/// </summary>
|
||||
[SchemaIgnore]
|
||||
public virtual string speckle_type
|
||||
{
|
||||
get
|
||||
@@ -210,11 +207,7 @@ public class Base : DynamicBase, ISpeckleObject
|
||||
myDuplicate.id = id;
|
||||
myDuplicate.applicationId = applicationId;
|
||||
|
||||
foreach (
|
||||
var kvp in GetMembers(
|
||||
DynamicBaseMemberType.Instance | DynamicBaseMemberType.Dynamic | DynamicBaseMemberType.SchemaIgnored
|
||||
)
|
||||
)
|
||||
foreach (var kvp in GetMembers())
|
||||
{
|
||||
var propertyInfo = type.GetProperty(kvp.Key);
|
||||
if (propertyInfo is not null && !propertyInfo.CanWrite)
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
using System.Dynamic;
|
||||
using System.Reflection;
|
||||
using Speckle.Newtonsoft.Json;
|
||||
using Speckle.Sdk.Common;
|
||||
using Speckle.Sdk.Host;
|
||||
|
||||
namespace Speckle.Sdk.Models;
|
||||
@@ -233,16 +232,12 @@ public class DynamicBase : DynamicObject, IDynamicMetaObjectProvider
|
||||
.GetBaseProperties(GetType())
|
||||
.Where(x =>
|
||||
{
|
||||
var hasIgnored = x.IsDefined(typeof(SchemaIgnoreAttribute), true);
|
||||
var hasObsolete = x.IsDefined(typeof(ObsoleteAttribute), true);
|
||||
|
||||
// If obsolete is false and prop has obsolete attr
|
||||
// OR
|
||||
// If schemaIgnored is true and prop has schemaIgnore attr
|
||||
return !(
|
||||
!includeMembers.HasFlag(DynamicBaseMemberType.SchemaIgnored) && hasIgnored
|
||||
|| !includeMembers.HasFlag(DynamicBaseMemberType.Obsolete) && hasObsolete
|
||||
);
|
||||
return !(!includeMembers.HasFlag(DynamicBaseMemberType.Obsolete) && hasObsolete);
|
||||
});
|
||||
foreach (var pi in pinfos)
|
||||
{
|
||||
@@ -252,20 +247,6 @@ public class DynamicBase : DynamicObject, IDynamicMetaObjectProvider
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (includeMembers.HasFlag(DynamicBaseMemberType.SchemaComputed))
|
||||
{
|
||||
GetType()
|
||||
.GetMethods()
|
||||
.Where(e => e.IsDefined(typeof(SchemaComputedAttribute)) && !e.IsDefined(typeof(ObsoleteAttribute)))
|
||||
.ToList()
|
||||
.ForEach(e =>
|
||||
{
|
||||
var attr = e.GetCustomAttribute<SchemaComputedAttribute>().NotNull();
|
||||
dic[attr.Name] = e.Invoke(this, null);
|
||||
});
|
||||
}
|
||||
|
||||
return dic;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +1,3 @@
|
||||
using Speckle.Sdk.Host;
|
||||
|
||||
namespace Speckle.Sdk.Models;
|
||||
|
||||
/// <summary>
|
||||
@@ -23,23 +21,18 @@ public enum DynamicBaseMemberType
|
||||
/// </summary>
|
||||
Obsolete = 4,
|
||||
|
||||
/// <summary>
|
||||
/// The typed members flagged with <see cref="SchemaIgnoreAttribute"/> attribute.
|
||||
/// </summary>
|
||||
SchemaIgnored = 8,
|
||||
|
||||
/// <summary>
|
||||
/// The typed methods flagged with TODO:
|
||||
/// </summary>
|
||||
SchemaComputed = 16,
|
||||
|
||||
/// <summary>
|
||||
/// All the typed members, including ones with <see cref="ObsoleteAttribute"/> or <see cref="SchemaIgnoreAttribute"/> attributes.
|
||||
/// All the typed members, including ones with <see cref="ObsoleteAttribute"/> attributes.
|
||||
/// </summary>
|
||||
InstanceAll = Instance + Obsolete + SchemaIgnored,
|
||||
InstanceAll = Instance + Obsolete,
|
||||
|
||||
/// <summary>
|
||||
/// All the members, including dynamic and instance members flagged with <see cref="ObsoleteAttribute"/> or <see cref="SchemaIgnoreAttribute"/> attributes
|
||||
/// All the members, including dynamic and instance members flagged with <see cref="ObsoleteAttribute"/> attributes
|
||||
/// </summary>
|
||||
All = InstanceAll + Dynamic,
|
||||
}
|
||||
|
||||
@@ -0,0 +1,56 @@
|
||||
using System.Collections.Concurrent;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Speckle.InterfaceGenerator;
|
||||
using Speckle.Sdk.Serialisation.V2.Receive;
|
||||
using Speckle.Sdk.SQLite;
|
||||
using Speckle.Sdk.Transports;
|
||||
|
||||
namespace Speckle.Sdk.Serialisation.V2;
|
||||
|
||||
[GenerateAutoInterface]
|
||||
public class DeserializeProcessFactory(
|
||||
IBaseDeserializer baseDeserializer,
|
||||
ISqLiteJsonCacheManagerFactory sqLiteJsonCacheManagerFactory,
|
||||
IServerObjectManagerFactory serverObjectManagerFactory,
|
||||
ILoggerFactory loggerFactory
|
||||
) : IDeserializeProcessFactory
|
||||
{
|
||||
public IDeserializeProcess CreateDeserializeProcess(
|
||||
Uri url,
|
||||
string streamId,
|
||||
string? authorizationToken,
|
||||
IProgress<ProgressArgs>? progress,
|
||||
CancellationToken cancellationToken,
|
||||
DeserializeProcessOptions? options = null
|
||||
)
|
||||
{
|
||||
var sqLiteJsonCacheManager = sqLiteJsonCacheManagerFactory.CreateFromStream(streamId);
|
||||
var serverObjectManager = serverObjectManagerFactory.Create(url, streamId, authorizationToken);
|
||||
return new DeserializeProcess(
|
||||
sqLiteJsonCacheManager,
|
||||
serverObjectManager,
|
||||
progress,
|
||||
baseDeserializer,
|
||||
loggerFactory,
|
||||
cancellationToken,
|
||||
options
|
||||
);
|
||||
}
|
||||
|
||||
public IDeserializeProcess CreateDeserializeProcess(
|
||||
ConcurrentDictionary<Id, Json> jsonCache,
|
||||
ConcurrentDictionary<string, string> objects,
|
||||
IProgress<ProgressArgs>? progress,
|
||||
CancellationToken cancellationToken,
|
||||
DeserializeProcessOptions? options = null
|
||||
) =>
|
||||
new DeserializeProcess(
|
||||
new MemoryJsonCacheManager(jsonCache),
|
||||
new MemoryServerObjectManager(objects),
|
||||
progress,
|
||||
baseDeserializer,
|
||||
loggerFactory,
|
||||
cancellationToken,
|
||||
options
|
||||
);
|
||||
}
|
||||
@@ -1,68 +0,0 @@
|
||||
using System.Text;
|
||||
using Speckle.Sdk.Serialisation.V2.Send;
|
||||
using Speckle.Sdk.SQLite;
|
||||
using Speckle.Sdk.Transports;
|
||||
|
||||
namespace Speckle.Sdk.Serialisation.V2;
|
||||
|
||||
#pragma warning disable CA1063
|
||||
public class DummySqLiteJsonCacheManager : ISqLiteJsonCacheManager
|
||||
#pragma warning restore CA1063
|
||||
{
|
||||
#pragma warning disable CA1816
|
||||
#pragma warning disable CA1063
|
||||
public void Dispose() { }
|
||||
#pragma warning restore CA1063
|
||||
#pragma warning restore CA1816
|
||||
|
||||
public IReadOnlyCollection<(string, 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 void UpdateObject(string id, string json) => throw new NotImplementedException();
|
||||
|
||||
public virtual void SaveObjects(IEnumerable<(string id, string json)> items) => throw new NotImplementedException();
|
||||
|
||||
public bool HasObject(string objectId) => false;
|
||||
}
|
||||
|
||||
public class DummySendServerObjectManager : IServerObjectManager
|
||||
{
|
||||
public IAsyncEnumerable<(string, string)> DownloadObjects(
|
||||
IReadOnlyCollection<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(
|
||||
IReadOnlyCollection<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.Value);
|
||||
}
|
||||
|
||||
progress?.Report(new(ProgressEvent.UploadBytes, totalBytes, totalBytes));
|
||||
return Task.CompletedTask;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
using System.Collections.Concurrent;
|
||||
using Speckle.Sdk.SQLite;
|
||||
|
||||
namespace Speckle.Sdk.Serialisation.V2;
|
||||
|
||||
#pragma warning disable CA1063
|
||||
public class MemoryJsonCacheManager(ConcurrentDictionary<Id, Json> jsonCache) : ISqLiteJsonCacheManager
|
||||
#pragma warning restore CA1063
|
||||
{
|
||||
public IReadOnlyCollection<(string Id, string Json)> GetAllObjects() =>
|
||||
jsonCache.Select(x => (x.Key.Value, x.Value.Value)).ToList();
|
||||
|
||||
public void DeleteObject(string id) => jsonCache.TryRemove(new Id(id), out _);
|
||||
|
||||
public string? GetObject(string id) => jsonCache.TryGetValue(new Id(id), out var json) ? json.Value : null;
|
||||
|
||||
public void SaveObject(string id, string json) => jsonCache.TryAdd(new Id(id), new Json(json));
|
||||
|
||||
public void UpdateObject(string id, string json) => jsonCache[new Id(id)] = new Json(json);
|
||||
|
||||
public virtual void SaveObjects(IEnumerable<(string id, string json)> items)
|
||||
{
|
||||
foreach (var (id, json) in items)
|
||||
{
|
||||
SaveObject(id, json);
|
||||
}
|
||||
}
|
||||
|
||||
public bool HasObject(string objectId) => jsonCache.ContainsKey(new Id(objectId));
|
||||
|
||||
#pragma warning disable CA1063
|
||||
#pragma warning disable CA1816
|
||||
public void Dispose()
|
||||
#pragma warning restore CA1816
|
||||
#pragma warning restore CA1063
|
||||
{ }
|
||||
}
|
||||
@@ -0,0 +1,48 @@
|
||||
using System.Collections.Concurrent;
|
||||
using System.Runtime.CompilerServices;
|
||||
using Speckle.Sdk.Serialisation.V2.Send;
|
||||
using Speckle.Sdk.Transports;
|
||||
|
||||
namespace Speckle.Sdk.Serialisation.V2;
|
||||
|
||||
public class MemoryServerObjectManager(ConcurrentDictionary<string, string> objects) : IServerObjectManager
|
||||
{
|
||||
public virtual async IAsyncEnumerable<(string, string)> DownloadObjects(
|
||||
IReadOnlyCollection<string> objectIds,
|
||||
IProgress<ProgressArgs>? progress,
|
||||
[EnumeratorCancellation] CancellationToken cancellationToken
|
||||
)
|
||||
{
|
||||
foreach (var item in objects.Where(x => objectIds.Contains(x.Key)))
|
||||
{
|
||||
cancellationToken.ThrowIfCancellationRequested();
|
||||
yield return (item.Key, item.Value);
|
||||
}
|
||||
await Task.CompletedTask.ConfigureAwait(false);
|
||||
}
|
||||
|
||||
public virtual Task<string?> DownloadSingleObject(
|
||||
string objectId,
|
||||
IProgress<ProgressArgs>? progress,
|
||||
CancellationToken cancellationToken
|
||||
) => Task.FromResult(objects.TryGetValue(objectId, out var json) ? json : null);
|
||||
|
||||
public virtual Task<Dictionary<string, bool>> HasObjects(
|
||||
IReadOnlyCollection<string> objectIds,
|
||||
CancellationToken cancellationToken
|
||||
) => Task.FromResult(objectIds.ToDictionary(x => x, objects.ContainsKey));
|
||||
|
||||
public virtual Task UploadObjects(
|
||||
IReadOnlyList<BaseItem> objectToUpload,
|
||||
bool compressPayloads,
|
||||
IProgress<ProgressArgs>? progress,
|
||||
CancellationToken cancellationToken
|
||||
)
|
||||
{
|
||||
foreach (BaseItem baseItem in objectToUpload)
|
||||
{
|
||||
objects.TryAdd(baseItem.Id.Value, baseItem.Json.Value);
|
||||
}
|
||||
return Task.CompletedTask;
|
||||
}
|
||||
}
|
||||
@@ -6,8 +6,7 @@ namespace Speckle.Sdk.Serialisation.V2;
|
||||
public sealed class PriorityScheduler(
|
||||
ILogger<PriorityScheduler> logger,
|
||||
ThreadPriority priority,
|
||||
int maximumConcurrencyLevel,
|
||||
CancellationToken cancellationToken
|
||||
int maximumConcurrencyLevel
|
||||
) : TaskScheduler, IAsyncDisposable
|
||||
{
|
||||
private readonly BlockingCollection<Task> _tasks = new();
|
||||
@@ -56,7 +55,7 @@ public sealed class PriorityScheduler(
|
||||
while (true)
|
||||
{
|
||||
//we're done so leave
|
||||
if (_tasks.IsCompleted || cancellationToken.IsCancellationRequested)
|
||||
if (_tasks.IsCompleted)
|
||||
{
|
||||
break;
|
||||
}
|
||||
@@ -66,11 +65,6 @@ public sealed class PriorityScheduler(
|
||||
{
|
||||
break;
|
||||
}
|
||||
//cancelled just leave
|
||||
if (cancellationToken.IsCancellationRequested)
|
||||
{
|
||||
break;
|
||||
}
|
||||
//didn't get a task but just timed out so continue
|
||||
if (!success)
|
||||
{
|
||||
|
||||
@@ -54,8 +54,7 @@ public sealed class DeserializeProcess(
|
||||
private readonly PriorityScheduler _belowNormal = new(
|
||||
loggerFactory.CreateLogger<PriorityScheduler>(),
|
||||
ThreadPriority.BelowNormal,
|
||||
Environment.ProcessorCount * 2,
|
||||
cancellationToken
|
||||
Environment.ProcessorCount * 2
|
||||
);
|
||||
|
||||
private readonly DeserializeProcessOptions _options = options ?? new();
|
||||
|
||||
@@ -2,8 +2,7 @@ using System.Text;
|
||||
|
||||
namespace Speckle.Sdk.Serialisation.V2.Send;
|
||||
|
||||
public readonly record struct BaseItem(Id Id, Json Json, bool NeedsStorage, Dictionary<Id, int>? Closures)
|
||||
: IHasByteSize
|
||||
public sealed record BaseItem(Id Id, Json Json, bool NeedsStorage, Dictionary<Id, int>? Closures) : IHasByteSize
|
||||
{
|
||||
public int ByteSize { get; } = Encoding.UTF8.GetByteCount(Json.Value);
|
||||
|
||||
@@ -13,7 +12,7 @@ public readonly record struct BaseItem(Id Id, Json Json, bool NeedsStorage, Dict
|
||||
{
|
||||
return false;
|
||||
}
|
||||
return string.Equals(Id.Value, other.Value.Id.Value, StringComparison.OrdinalIgnoreCase);
|
||||
return string.Equals(Id.Value, other.Id.Value, StringComparison.OrdinalIgnoreCase);
|
||||
}
|
||||
|
||||
public override int GetHashCode() => Id.GetHashCode();
|
||||
|
||||
@@ -1,47 +0,0 @@
|
||||
using System.Collections;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
|
||||
namespace Speckle.Sdk.Serialisation.V2.Send;
|
||||
|
||||
public class EmptyDictionary<TKey, TValue> : IDictionary<TKey, TValue>
|
||||
{
|
||||
public IEnumerator<KeyValuePair<TKey, TValue>> GetEnumerator() => throw new NotImplementedException();
|
||||
|
||||
IEnumerator IEnumerable.GetEnumerator() => GetEnumerator();
|
||||
|
||||
public void Add(KeyValuePair<TKey, TValue> item) { }
|
||||
|
||||
public void Clear() => throw new NotImplementedException();
|
||||
|
||||
public bool Contains(KeyValuePair<TKey, TValue> item) => false;
|
||||
|
||||
public void CopyTo(KeyValuePair<TKey, TValue>[] array, int arrayIndex) => throw new NotImplementedException();
|
||||
|
||||
public bool Remove(KeyValuePair<TKey, TValue> item) => false;
|
||||
|
||||
public int Count => 0;
|
||||
public bool IsReadOnly => false;
|
||||
|
||||
public void Add(TKey key, TValue value) { }
|
||||
|
||||
public bool ContainsKey(TKey key) => false;
|
||||
|
||||
public bool Remove(TKey key) => false;
|
||||
|
||||
public bool TryGetValue(TKey key, [UnscopedRef] out TValue value)
|
||||
{
|
||||
value = default!;
|
||||
return false;
|
||||
}
|
||||
|
||||
public TValue this[TKey key]
|
||||
{
|
||||
#pragma warning disable CA1065
|
||||
get => throw new NotImplementedException();
|
||||
#pragma warning restore CA1065
|
||||
set { }
|
||||
}
|
||||
|
||||
public ICollection<TKey> Keys { get; }
|
||||
public ICollection<TValue> Values { get; }
|
||||
}
|
||||
@@ -0,0 +1,126 @@
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Speckle.Sdk.Dependencies;
|
||||
using Speckle.Sdk.Dependencies.Serialization;
|
||||
using Speckle.Sdk.SQLite;
|
||||
using Speckle.Sdk.Transports;
|
||||
|
||||
namespace Speckle.Sdk.Serialisation.V2.Send;
|
||||
|
||||
public interface IObjectSaver : IDisposable
|
||||
{
|
||||
Exception? Exception { get; set; }
|
||||
Task Start(CancellationToken cancellationToken);
|
||||
void DoneTraversing();
|
||||
Task DoneSaving();
|
||||
void SaveItem(BaseItem item, CancellationToken cancellationToken);
|
||||
}
|
||||
|
||||
public sealed class ObjectSaver(
|
||||
IProgress<ProgressArgs>? progress,
|
||||
ISqLiteJsonCacheManager sqLiteJsonCacheManager,
|
||||
IServerObjectManager serverObjectManager,
|
||||
ILogger<ObjectSaver> logger,
|
||||
CancellationToken cancellationToken,
|
||||
#pragma warning disable CS9107
|
||||
#pragma warning disable CA2254
|
||||
SerializeProcessOptions? options = null
|
||||
) : ChannelSaver<BaseItem>, IObjectSaver
|
||||
#pragma warning restore CA2254
|
||||
#pragma warning restore CS9107
|
||||
{
|
||||
private readonly CancellationTokenSource _cancellationTokenSource = CancellationTokenSource.CreateLinkedTokenSource(
|
||||
cancellationToken
|
||||
);
|
||||
|
||||
private readonly SerializeProcessOptions _options = options ?? new();
|
||||
|
||||
private long _uploaded;
|
||||
private long _cached;
|
||||
|
||||
private long _objectsSerialized;
|
||||
|
||||
protected override async Task SendToServerInternal(Batch<BaseItem> batch)
|
||||
{
|
||||
if (_cancellationTokenSource.IsCancellationRequested)
|
||||
{
|
||||
return;
|
||||
}
|
||||
try
|
||||
{
|
||||
if (!_options.SkipServer && batch.Items.Count != 0)
|
||||
{
|
||||
var objectBatch = batch.Items.Distinct().ToList();
|
||||
var hasObjects = await serverObjectManager
|
||||
.HasObjects(objectBatch.Select(x => x.Id.Value).Freeze(), _cancellationTokenSource.Token)
|
||||
.ConfigureAwait(false);
|
||||
objectBatch = batch.Items.Where(x => !hasObjects[x.Id.Value]).ToList();
|
||||
if (objectBatch.Count != 0)
|
||||
{
|
||||
await serverObjectManager
|
||||
.UploadObjects(objectBatch, true, progress, _cancellationTokenSource.Token)
|
||||
.ConfigureAwait(false);
|
||||
Interlocked.Add(ref _uploaded, batch.Items.Count);
|
||||
}
|
||||
|
||||
progress?.Report(new(ProgressEvent.UploadedObjects, _uploaded, null));
|
||||
}
|
||||
}
|
||||
catch (OperationCanceledException)
|
||||
{
|
||||
_cancellationTokenSource.Cancel();
|
||||
}
|
||||
#pragma warning disable CA1031
|
||||
catch (Exception e)
|
||||
#pragma warning restore CA1031
|
||||
{
|
||||
RecordException(e);
|
||||
}
|
||||
}
|
||||
|
||||
public void SaveItem(BaseItem item, CancellationToken cancellationToken)
|
||||
{
|
||||
Interlocked.Increment(ref _objectsSerialized);
|
||||
Save(item, cancellationToken);
|
||||
}
|
||||
|
||||
public override void SaveToCache(List<BaseItem> batch)
|
||||
{
|
||||
if (_cancellationTokenSource.IsCancellationRequested)
|
||||
{
|
||||
return;
|
||||
}
|
||||
try
|
||||
{
|
||||
if (!_options.SkipCacheWrite && batch.Count != 0)
|
||||
{
|
||||
sqLiteJsonCacheManager.SaveObjects(batch.Select(x => (x.Id.Value, x.Json.Value)));
|
||||
Interlocked.Add(ref _cached, batch.Count);
|
||||
progress?.Report(new(ProgressEvent.CachedToLocal, _cached, _objectsSerialized));
|
||||
}
|
||||
}
|
||||
catch (OperationCanceledException)
|
||||
{
|
||||
_cancellationTokenSource.Cancel();
|
||||
}
|
||||
#pragma warning disable CA1031
|
||||
catch (Exception e)
|
||||
#pragma warning restore CA1031
|
||||
{
|
||||
RecordException(e);
|
||||
}
|
||||
}
|
||||
|
||||
private void RecordException(Exception e)
|
||||
{
|
||||
//order here matters
|
||||
logger.LogError(e, "Error in SDK");
|
||||
Exception = e;
|
||||
_cancellationTokenSource.Cancel();
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
_cancellationTokenSource.Dispose();
|
||||
sqLiteJsonCacheManager.Dispose();
|
||||
}
|
||||
}
|
||||
@@ -4,9 +4,7 @@ using Microsoft.Extensions.Logging;
|
||||
using Speckle.InterfaceGenerator;
|
||||
using Speckle.Sdk.Common;
|
||||
using Speckle.Sdk.Dependencies;
|
||||
using Speckle.Sdk.Dependencies.Serialization;
|
||||
using Speckle.Sdk.Models;
|
||||
using Speckle.Sdk.SQLite;
|
||||
using Speckle.Sdk.Transports;
|
||||
|
||||
namespace Speckle.Sdk.Serialisation.V2.Send;
|
||||
@@ -28,28 +26,27 @@ public partial interface ISerializeProcess : IAsyncDisposable;
|
||||
[GenerateAutoInterface]
|
||||
public sealed class SerializeProcess(
|
||||
IProgress<ProgressArgs>? progress,
|
||||
ISqLiteJsonCacheManager sqLiteJsonCacheManager,
|
||||
IServerObjectManager serverObjectManager,
|
||||
IObjectSaver objectSaver,
|
||||
IBaseChildFinder baseChildFinder,
|
||||
IBaseSerializer baseSerializer,
|
||||
ILoggerFactory loggerFactory,
|
||||
CancellationToken cancellationToken,
|
||||
SerializeProcessOptions? options = null
|
||||
#pragma warning disable CS9107
|
||||
#pragma warning disable CA2254
|
||||
)
|
||||
: ChannelSaver<BaseItem>(x => loggerFactory.CreateLogger<SerializeProcess>().LogWarning(x), cancellationToken),
|
||||
ISerializeProcess
|
||||
#pragma warning restore CA2254
|
||||
#pragma warning restore CS9107
|
||||
) : ISerializeProcess
|
||||
{
|
||||
private static readonly Dictionary<Id, NodeInfo> EMPTY_CLOSURES = new();
|
||||
|
||||
private readonly CancellationTokenSource _processSource = CancellationTokenSource.CreateLinkedTokenSource(
|
||||
cancellationToken
|
||||
);
|
||||
private readonly ILogger<SerializeProcess> _logger = loggerFactory.CreateLogger<SerializeProcess>();
|
||||
|
||||
//async dispose
|
||||
[SuppressMessage("Usage", "CA2213:Disposable fields should be disposed")]
|
||||
private readonly PriorityScheduler _highest = new(
|
||||
loggerFactory.CreateLogger<PriorityScheduler>(),
|
||||
ThreadPriority.Highest,
|
||||
2,
|
||||
cancellationToken
|
||||
2
|
||||
);
|
||||
|
||||
//async dispose
|
||||
@@ -57,12 +54,9 @@ public sealed class SerializeProcess(
|
||||
private readonly PriorityScheduler _belowNormal = new(
|
||||
loggerFactory.CreateLogger<PriorityScheduler>(),
|
||||
ThreadPriority.BelowNormal,
|
||||
Environment.ProcessorCount * 2,
|
||||
cancellationToken
|
||||
Environment.ProcessorCount * 2
|
||||
);
|
||||
|
||||
private readonly SerializeProcessOptions _options = options ?? new();
|
||||
private readonly ILogger<SerializeProcess> _logger = loggerFactory.CreateLogger<SerializeProcess>();
|
||||
|
||||
private readonly Pool<Dictionary<Id, NodeInfo>> _currentClosurePool = Pools.CreateDictionaryPool<Id, NodeInfo>();
|
||||
private readonly Pool<ConcurrentDictionary<Id, NodeInfo>> _childClosurePool = Pools.CreateConcurrentDictionaryPool<
|
||||
@@ -75,25 +69,24 @@ public sealed class SerializeProcess(
|
||||
|
||||
private long _objectsSerialized;
|
||||
|
||||
private long _uploaded;
|
||||
private long _cached;
|
||||
|
||||
[AutoInterfaceIgnore]
|
||||
public async ValueTask DisposeAsync()
|
||||
{
|
||||
await WaitForSchedulerCompletion().ConfigureAwait(false);
|
||||
await _highest.DisposeAsync().ConfigureAwait(false);
|
||||
await _belowNormal.DisposeAsync().ConfigureAwait(false);
|
||||
sqLiteJsonCacheManager.Dispose();
|
||||
objectSaver.Dispose();
|
||||
_processSource.Dispose();
|
||||
}
|
||||
|
||||
public void ThrowIfFailed()
|
||||
private void ThrowIfFailed()
|
||||
{
|
||||
if (Exception is not null)
|
||||
//order here matters...null with cancellation means a user did it, otherwise it's a real Exception
|
||||
if (objectSaver.Exception is not null)
|
||||
{
|
||||
throw new SpeckleException("Error while sending", Exception);
|
||||
throw new SpeckleException("Error while sending", objectSaver.Exception);
|
||||
}
|
||||
cancellationToken.ThrowIfCancellationRequested();
|
||||
_processSource.Token.ThrowIfCancellationRequested();
|
||||
}
|
||||
|
||||
private async Task WaitForSchedulerCompletion()
|
||||
@@ -106,24 +99,25 @@ public sealed class SerializeProcess(
|
||||
{
|
||||
try
|
||||
{
|
||||
var channelTask = Start();
|
||||
var channelTask = objectSaver.Start(_processSource.Token);
|
||||
var findTotalObjectsTask = Task.CompletedTask;
|
||||
if (!_options.SkipFindTotalObjects)
|
||||
{
|
||||
ThrowIfFailed();
|
||||
findTotalObjectsTask = Task.Factory.StartNew(
|
||||
() => TraverseTotal(root),
|
||||
cancellationToken,
|
||||
_processSource.Token,
|
||||
TaskCreationOptions.AttachedToParent | TaskCreationOptions.PreferFairness,
|
||||
_highest
|
||||
);
|
||||
}
|
||||
|
||||
await Traverse(root).ConfigureAwait(false);
|
||||
DoneTraversing();
|
||||
await Traverse(root, _processSource.Token).ConfigureAwait(false);
|
||||
ThrowIfFailed();
|
||||
objectSaver.DoneTraversing();
|
||||
await Task.WhenAll(findTotalObjectsTask, channelTask).ConfigureAwait(false);
|
||||
ThrowIfFailed();
|
||||
await DoneSaving().ConfigureAwait(false);
|
||||
await objectSaver.DoneSaving().ConfigureAwait(false);
|
||||
ThrowIfFailed();
|
||||
await WaitForSchedulerCompletion().ConfigureAwait(false);
|
||||
ThrowIfFailed();
|
||||
@@ -138,6 +132,10 @@ public sealed class SerializeProcess(
|
||||
|
||||
private void TraverseTotal(Base obj)
|
||||
{
|
||||
if (_processSource.Token.IsCancellationRequested)
|
||||
{
|
||||
return;
|
||||
}
|
||||
foreach (var child in baseChildFinder.GetChildren(obj))
|
||||
{
|
||||
_objectsFound++;
|
||||
@@ -146,116 +144,144 @@ public sealed class SerializeProcess(
|
||||
}
|
||||
}
|
||||
|
||||
private async Task<Dictionary<Id, NodeInfo>> Traverse(Base obj)
|
||||
private async Task<Dictionary<Id, NodeInfo>> Traverse(Base obj, CancellationToken token)
|
||||
{
|
||||
var tasks = new List<Task<Dictionary<Id, NodeInfo>>>();
|
||||
foreach (var child in baseChildFinder.GetChildren(obj))
|
||||
if (token.IsCancellationRequested)
|
||||
{
|
||||
// tmp is necessary because of the way closures close over loop variables
|
||||
var tmp = child;
|
||||
cancellationToken.ThrowIfCancellationRequested();
|
||||
var t = Task
|
||||
.Factory.StartNew(
|
||||
async () => await Traverse(tmp).ConfigureAwait(false),
|
||||
cancellationToken,
|
||||
TaskCreationOptions.AttachedToParent | TaskCreationOptions.PreferFairness,
|
||||
_belowNormal
|
||||
)
|
||||
.Unwrap();
|
||||
tasks.Add(t);
|
||||
return EMPTY_CLOSURES;
|
||||
}
|
||||
|
||||
Dictionary<Id, NodeInfo>[] taskClosures = [];
|
||||
if (tasks.Count > 0)
|
||||
{
|
||||
taskClosures = await Task.WhenAll(tasks).ConfigureAwait(false);
|
||||
}
|
||||
var childClosures = _childClosurePool.Get();
|
||||
foreach (var childClosure in taskClosures)
|
||||
{
|
||||
foreach (var kvp in childClosure)
|
||||
{
|
||||
childClosures[kvp.Key] = kvp.Value;
|
||||
}
|
||||
_currentClosurePool.Return(childClosure);
|
||||
}
|
||||
|
||||
var items = baseSerializer.Serialise(obj, childClosures, _options.SkipCacheRead, cancellationToken);
|
||||
|
||||
var currentClosures = _currentClosurePool.Get();
|
||||
Interlocked.Increment(ref _objectCount);
|
||||
progress?.Report(new(ProgressEvent.FromCacheOrSerialized, _objectCount, Math.Max(_objectCount, _objectsFound)));
|
||||
foreach (var item in items)
|
||||
{
|
||||
if (item.NeedsStorage)
|
||||
{
|
||||
Interlocked.Increment(ref _objectsSerialized);
|
||||
await Save(item).ConfigureAwait(false);
|
||||
}
|
||||
|
||||
if (!currentClosures.ContainsKey(item.Id))
|
||||
{
|
||||
currentClosures.Add(item.Id, new NodeInfo(item.Json, item.Closures));
|
||||
}
|
||||
}
|
||||
_childClosurePool.Return(childClosures);
|
||||
return currentClosures;
|
||||
}
|
||||
|
||||
protected override async Task SendToServerInternal(Batch<BaseItem> batch)
|
||||
{
|
||||
try
|
||||
{
|
||||
if (!_options.SkipServer && batch.Items.Count != 0)
|
||||
var tasks = new List<Task<Dictionary<Id, NodeInfo>>>();
|
||||
using var childCancellationTokenSource = CancellationTokenSource.CreateLinkedTokenSource(token);
|
||||
foreach (var child in baseChildFinder.GetChildren(obj))
|
||||
{
|
||||
var objectBatch = batch.Items.Distinct().ToList();
|
||||
var hasObjects = await serverObjectManager
|
||||
.HasObjects(objectBatch.Select(x => x.Id.Value).Freeze(), cancellationToken)
|
||||
.ConfigureAwait(false);
|
||||
objectBatch = batch.Items.Where(x => !hasObjects[x.Id.Value]).ToList();
|
||||
if (objectBatch.Count != 0)
|
||||
// tmp is necessary because of the way closures close over loop variables
|
||||
var tmp = child;
|
||||
if (token.IsCancellationRequested)
|
||||
{
|
||||
await serverObjectManager.UploadObjects(objectBatch, true, progress, cancellationToken).ConfigureAwait(false);
|
||||
Interlocked.Exchange(ref _uploaded, _uploaded + batch.Items.Count);
|
||||
return EMPTY_CLOSURES;
|
||||
}
|
||||
var t = Task
|
||||
.Factory.StartNew(
|
||||
// ReSharper disable once AccessToDisposedClosure
|
||||
// don't need to capture here
|
||||
async () => await Traverse(tmp, childCancellationTokenSource.Token).ConfigureAwait(false),
|
||||
childCancellationTokenSource.Token,
|
||||
TaskCreationOptions.AttachedToParent | TaskCreationOptions.PreferFairness,
|
||||
_belowNormal
|
||||
)
|
||||
.Unwrap();
|
||||
tasks.Add(t);
|
||||
}
|
||||
|
||||
if (token.IsCancellationRequested)
|
||||
{
|
||||
return EMPTY_CLOSURES;
|
||||
}
|
||||
|
||||
List<Dictionary<Id, NodeInfo>> taskClosures = new();
|
||||
if (tasks.Count > 0)
|
||||
{
|
||||
var currentTasks = tasks.ToList();
|
||||
do
|
||||
{
|
||||
//grab when any Task is done and see if we're cancelling
|
||||
var t = await Task.WhenAny(currentTasks).ConfigureAwait(false);
|
||||
if (t.IsCanceled)
|
||||
{
|
||||
return EMPTY_CLOSURES;
|
||||
}
|
||||
if (t.IsFaulted)
|
||||
{
|
||||
if (t.Exception is not null)
|
||||
{
|
||||
RecordException(t.Exception);
|
||||
}
|
||||
return EMPTY_CLOSURES;
|
||||
}
|
||||
taskClosures.Add(t.Result);
|
||||
currentTasks.Remove(t);
|
||||
} while (currentTasks.Count > 0);
|
||||
}
|
||||
|
||||
if (token.IsCancellationRequested)
|
||||
{
|
||||
return EMPTY_CLOSURES;
|
||||
}
|
||||
|
||||
var childClosures = _childClosurePool.Get();
|
||||
foreach (var childClosure in taskClosures)
|
||||
{
|
||||
foreach (var kvp in childClosure)
|
||||
{
|
||||
childClosures[kvp.Key] = kvp.Value;
|
||||
}
|
||||
|
||||
progress?.Report(new(ProgressEvent.UploadedObjects, _uploaded, null));
|
||||
_currentClosurePool.Return(childClosure);
|
||||
}
|
||||
|
||||
if (token.IsCancellationRequested)
|
||||
{
|
||||
return EMPTY_CLOSURES;
|
||||
}
|
||||
|
||||
var items = baseSerializer.Serialise(obj, childClosures, _options.SkipCacheRead, token);
|
||||
if (token.IsCancellationRequested)
|
||||
{
|
||||
return EMPTY_CLOSURES;
|
||||
}
|
||||
|
||||
var currentClosures = _currentClosurePool.Get();
|
||||
try
|
||||
{
|
||||
Interlocked.Increment(ref _objectCount);
|
||||
progress?.Report(new(ProgressEvent.FromCacheOrSerialized, _objectCount, Math.Max(_objectCount, _objectsFound)));
|
||||
foreach (var item in items)
|
||||
{
|
||||
if (item.NeedsStorage)
|
||||
{
|
||||
if (token.IsCancellationRequested)
|
||||
{
|
||||
return EMPTY_CLOSURES;
|
||||
}
|
||||
|
||||
Interlocked.Increment(ref _objectsSerialized);
|
||||
objectSaver.SaveItem(item, childCancellationTokenSource.Token);
|
||||
}
|
||||
|
||||
if (!currentClosures.ContainsKey(item.Id))
|
||||
{
|
||||
currentClosures.Add(item.Id, new NodeInfo(item.Json, item.Closures));
|
||||
}
|
||||
}
|
||||
}
|
||||
finally
|
||||
{
|
||||
_childClosurePool.Return(childClosures);
|
||||
}
|
||||
|
||||
return currentClosures;
|
||||
}
|
||||
catch (OperationCanceledException)
|
||||
{
|
||||
throw;
|
||||
return EMPTY_CLOSURES;
|
||||
}
|
||||
#pragma warning disable CA1031
|
||||
catch (Exception e)
|
||||
#pragma warning restore CA1031
|
||||
{
|
||||
_logger.LogError(e, "Error sending objects to server");
|
||||
throw;
|
||||
RecordException(e);
|
||||
return EMPTY_CLOSURES;
|
||||
}
|
||||
}
|
||||
|
||||
public override void SaveToCache(List<BaseItem> batch)
|
||||
private void RecordException(Exception e)
|
||||
{
|
||||
try
|
||||
{
|
||||
if (!_options.SkipCacheWrite && batch.Count != 0)
|
||||
{
|
||||
sqLiteJsonCacheManager.SaveObjects(batch.Select(x => (x.Id.Value, x.Json.Value)));
|
||||
Interlocked.Exchange(ref _cached, _cached + batch.Count);
|
||||
progress?.Report(new(ProgressEvent.CachedToLocal, _cached, _objectsSerialized));
|
||||
}
|
||||
}
|
||||
catch (OperationCanceledException)
|
||||
{
|
||||
throw;
|
||||
}
|
||||
#pragma warning disable CA1031
|
||||
catch (Exception e)
|
||||
#pragma warning restore CA1031
|
||||
{
|
||||
_logger.LogError(e, "Error sending objects to server");
|
||||
throw;
|
||||
}
|
||||
//order here matters
|
||||
_logger.LogError(e, "Error in SDK");
|
||||
objectSaver.Exception = e;
|
||||
_processSource.Cancel();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,35 +1,16 @@
|
||||
using System.Collections.Concurrent;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Speckle.Sdk.Serialisation.V2.Receive;
|
||||
using Speckle.InterfaceGenerator;
|
||||
using Speckle.Sdk.Serialisation.V2.Send;
|
||||
using Speckle.Sdk.SQLite;
|
||||
using Speckle.Sdk.Transports;
|
||||
|
||||
namespace Speckle.Sdk.Serialisation.V2;
|
||||
|
||||
public interface ISerializeProcessFactory
|
||||
{
|
||||
ISerializeProcess CreateSerializeProcess(
|
||||
Uri url,
|
||||
string streamId,
|
||||
string? authorizationToken,
|
||||
IProgress<ProgressArgs>? progress,
|
||||
CancellationToken cancellationToken,
|
||||
SerializeProcessOptions? options = null
|
||||
);
|
||||
IDeserializeProcess CreateDeserializeProcess(
|
||||
Uri url,
|
||||
string streamId,
|
||||
string? authorizationToken,
|
||||
IProgress<ProgressArgs>? progress,
|
||||
CancellationToken cancellationToken,
|
||||
DeserializeProcessOptions? options = null
|
||||
);
|
||||
}
|
||||
|
||||
[GenerateAutoInterface]
|
||||
public class SerializeProcessFactory(
|
||||
IBaseChildFinder baseChildFinder,
|
||||
IObjectSerializerFactory objectSerializerFactory,
|
||||
IBaseDeserializer baseDeserializer,
|
||||
ISqLiteJsonCacheManagerFactory sqLiteJsonCacheManagerFactory,
|
||||
IServerObjectManagerFactory serverObjectManagerFactory,
|
||||
ILoggerFactory loggerFactory
|
||||
@@ -46,34 +27,54 @@ public class SerializeProcessFactory(
|
||||
{
|
||||
var sqLiteJsonCacheManager = sqLiteJsonCacheManagerFactory.CreateFromStream(streamId);
|
||||
var serverObjectManager = serverObjectManagerFactory.Create(url, streamId, authorizationToken);
|
||||
return new SerializeProcess(
|
||||
return CreateSerializeProcess(sqLiteJsonCacheManager, serverObjectManager, progress, cancellationToken, options);
|
||||
}
|
||||
|
||||
public ISerializeProcess CreateSerializeProcess(
|
||||
ISqLiteJsonCacheManager sqLiteJsonCacheManager,
|
||||
IServerObjectManager serverObjectManager,
|
||||
IProgress<ProgressArgs>? progress,
|
||||
CancellationToken cancellationToken,
|
||||
SerializeProcessOptions? options = null
|
||||
) =>
|
||||
new SerializeProcess(
|
||||
progress,
|
||||
sqLiteJsonCacheManager,
|
||||
serverObjectManager,
|
||||
new ObjectSaver(
|
||||
progress,
|
||||
sqLiteJsonCacheManager,
|
||||
serverObjectManager,
|
||||
loggerFactory.CreateLogger<ObjectSaver>(),
|
||||
cancellationToken
|
||||
),
|
||||
baseChildFinder,
|
||||
new BaseSerializer(sqLiteJsonCacheManager, objectSerializerFactory),
|
||||
loggerFactory,
|
||||
cancellationToken,
|
||||
options
|
||||
);
|
||||
}
|
||||
|
||||
public IDeserializeProcess CreateDeserializeProcess(
|
||||
Uri url,
|
||||
string streamId,
|
||||
string? authorizationToken,
|
||||
public ISerializeProcess CreateSerializeProcess(
|
||||
ConcurrentDictionary<Id, Json> jsonCache,
|
||||
ConcurrentDictionary<string, string> objects,
|
||||
IProgress<ProgressArgs>? progress,
|
||||
CancellationToken cancellationToken,
|
||||
DeserializeProcessOptions? options = null
|
||||
SerializeProcessOptions? options = null
|
||||
)
|
||||
{
|
||||
var sqLiteJsonCacheManager = sqLiteJsonCacheManagerFactory.CreateFromStream(streamId);
|
||||
var serverObjectManager = serverObjectManagerFactory.Create(url, streamId, authorizationToken);
|
||||
return new DeserializeProcess(
|
||||
sqLiteJsonCacheManager,
|
||||
serverObjectManager,
|
||||
#pragma warning disable CA2000
|
||||
var memoryJsonCacheManager = new MemoryJsonCacheManager(jsonCache);
|
||||
#pragma warning restore CA2000
|
||||
return new SerializeProcess(
|
||||
progress,
|
||||
baseDeserializer,
|
||||
new ObjectSaver(
|
||||
progress,
|
||||
memoryJsonCacheManager,
|
||||
new MemoryServerObjectManager(objects),
|
||||
loggerFactory.CreateLogger<ObjectSaver>(),
|
||||
cancellationToken
|
||||
),
|
||||
baseChildFinder,
|
||||
new BaseSerializer(memoryJsonCacheManager, objectSerializerFactory),
|
||||
loggerFactory,
|
||||
cancellationToken,
|
||||
options
|
||||
|
||||
@@ -13,6 +13,12 @@ using Speckle.Sdk.Transports.ServerUtils;
|
||||
|
||||
namespace Speckle.Sdk.Serialisation.V2;
|
||||
|
||||
public class ServerObjectManagerOptions(TimeSpan? timeout = null, string? boundary = null)
|
||||
{
|
||||
public TimeSpan Timeout => timeout ?? TimeSpan.FromSeconds(120);
|
||||
public string Boundary => boundary ??= Guid.NewGuid().ToString();
|
||||
}
|
||||
|
||||
[GenerateAutoInterface]
|
||||
public class ServerObjectManager : IServerObjectManager
|
||||
{
|
||||
@@ -21,6 +27,7 @@ public class ServerObjectManager : IServerObjectManager
|
||||
private readonly ISdkActivityFactory _activityFactory;
|
||||
private readonly HttpClient _client;
|
||||
private readonly string _streamId;
|
||||
private readonly ServerObjectManagerOptions _serverObjectManagerOptions;
|
||||
|
||||
public ServerObjectManager(
|
||||
ISpeckleHttp speckleHttp,
|
||||
@@ -28,13 +35,14 @@ public class ServerObjectManager : IServerObjectManager
|
||||
Uri baseUri,
|
||||
string streamId,
|
||||
string? authorizationToken,
|
||||
int timeoutSeconds = 120
|
||||
ServerObjectManagerOptions? options = null
|
||||
)
|
||||
{
|
||||
_serverObjectManagerOptions = options ?? new();
|
||||
_activityFactory = activityFactory;
|
||||
_client = speckleHttp.CreateHttpClient(
|
||||
new HttpClientHandler { AutomaticDecompression = DecompressionMethods.GZip },
|
||||
timeoutSeconds: timeoutSeconds,
|
||||
timeoutSeconds: (int)_serverObjectManagerOptions.Timeout.TotalSeconds,
|
||||
authorizationToken: authorizationToken
|
||||
);
|
||||
_client.BaseAddress = baseUri;
|
||||
@@ -139,10 +147,8 @@ public class ServerObjectManager : IServerObjectManager
|
||||
CancellationToken cancellationToken
|
||||
)
|
||||
{
|
||||
using var _ = _activityFactory.Start();
|
||||
cancellationToken.ThrowIfCancellationRequested();
|
||||
|
||||
// Stopwatch sw = new Stopwatch(); sw.Start();
|
||||
|
||||
string objectsPostParameter = JsonConvert.SerializeObject(objectIds);
|
||||
var payload = new Dictionary<string, string> { { "objects", objectsPostParameter } };
|
||||
string serializedPayload = JsonConvert.SerializeObject(payload);
|
||||
@@ -169,6 +175,7 @@ public class ServerObjectManager : IServerObjectManager
|
||||
CancellationToken cancellationToken
|
||||
)
|
||||
{
|
||||
using var _ = _activityFactory.Start();
|
||||
cancellationToken.ThrowIfCancellationRequested();
|
||||
|
||||
using HttpRequestMessage message = new()
|
||||
@@ -177,7 +184,7 @@ public class ServerObjectManager : IServerObjectManager
|
||||
Method = HttpMethod.Post,
|
||||
};
|
||||
|
||||
MultipartFormDataContent multipart = new();
|
||||
MultipartFormDataContent multipart = new(_serverObjectManagerOptions.Boundary);
|
||||
|
||||
int mpId = 0;
|
||||
var ctBuilder = new StringBuilder("[");
|
||||
|
||||
@@ -8,6 +8,13 @@ namespace Speckle.Sdk.Serialisation.V2;
|
||||
public class ServerObjectManagerFactory(ISpeckleHttp speckleHttp, ISdkActivityFactory activityFactory)
|
||||
: IServerObjectManagerFactory
|
||||
{
|
||||
public IServerObjectManager Create(Uri url, string streamId, string? authorizationToken, int timeoutSeconds = 120) =>
|
||||
new ServerObjectManager(speckleHttp, activityFactory, url, streamId, authorizationToken, timeoutSeconds);
|
||||
public IServerObjectManager Create(Uri url, string streamId, string? authorizationToken, TimeSpan? timeout = null) =>
|
||||
new ServerObjectManager(
|
||||
speckleHttp,
|
||||
activityFactory,
|
||||
url,
|
||||
streamId,
|
||||
authorizationToken,
|
||||
new ServerObjectManagerOptions(timeout: timeout)
|
||||
);
|
||||
}
|
||||
|
||||
@@ -7,25 +7,65 @@ using Speckle.Sdk.Logging;
|
||||
|
||||
namespace Speckle.Sdk;
|
||||
|
||||
public record Application(string Name, string Slug);
|
||||
|
||||
public record SpeckleSdkOptions(
|
||||
Application Application,
|
||||
string ApplicationVersion,
|
||||
string? SpeckleVersion,
|
||||
IEnumerable<Assembly>? Assemblies
|
||||
);
|
||||
|
||||
public static class ServiceRegistration
|
||||
{
|
||||
private static string GetAssemblyVersion() =>
|
||||
Assembly.GetExecutingAssembly().GetName().Version?.ToString() ?? "Unknown";
|
||||
|
||||
public static IServiceCollection AddSpeckleSdk(
|
||||
this IServiceCollection serviceCollection,
|
||||
HostApplication application,
|
||||
HostAppVersion version,
|
||||
string speckleVersion
|
||||
Application application,
|
||||
string applicationVersion,
|
||||
string? speckleVersion = null,
|
||||
IEnumerable<Assembly>? assemblies = null
|
||||
) => serviceCollection.AddSpeckleSdk(new(application, applicationVersion, speckleVersion, assemblies));
|
||||
|
||||
public static IServiceCollection AddSpeckleSdk(
|
||||
this IServiceCollection serviceCollection,
|
||||
Application application,
|
||||
string applicationVersion,
|
||||
string? speckleVersion,
|
||||
params Assembly[] assemblies
|
||||
) => serviceCollection.AddSpeckleSdk(new(application, applicationVersion, speckleVersion, assemblies));
|
||||
|
||||
public static IServiceCollection AddSpeckleSdk(
|
||||
this IServiceCollection serviceCollection,
|
||||
Application application,
|
||||
string applicationVersion,
|
||||
params Assembly[] assemblies
|
||||
) => serviceCollection.AddSpeckleSdk(new(application, applicationVersion, null, assemblies));
|
||||
|
||||
public static IServiceCollection AddSpeckleSdk(
|
||||
this IServiceCollection serviceCollection,
|
||||
SpeckleSdkOptions speckleSdkOptions
|
||||
)
|
||||
{
|
||||
var currentAssembly = Assembly.GetExecutingAssembly();
|
||||
var allAssembles = speckleSdkOptions.Assemblies?.ToList() ?? [];
|
||||
if (!allAssembles.Contains(currentAssembly))
|
||||
{
|
||||
allAssembles.Add(currentAssembly);
|
||||
}
|
||||
TypeLoader.Reset();
|
||||
TypeLoader.Initialize(allAssembles.ToArray());
|
||||
serviceCollection.AddLogging();
|
||||
string name = application.Name;
|
||||
|
||||
serviceCollection.AddSingleton<ISpeckleApplication>(
|
||||
new SpeckleApplication
|
||||
{
|
||||
HostApplication = name,
|
||||
SpeckleVersion = speckleVersion,
|
||||
HostApplicationVersion = HostApplications.GetVersion(version),
|
||||
Slug = application.Slug,
|
||||
HostApplication = speckleSdkOptions.Application.Name,
|
||||
HostApplicationVersion = speckleSdkOptions.ApplicationVersion,
|
||||
Slug = speckleSdkOptions.Application.Slug,
|
||||
SpeckleVersion = speckleSdkOptions.SpeckleVersion ?? GetAssemblyVersion(),
|
||||
}
|
||||
);
|
||||
serviceCollection.TryAddSingleton<ISdkActivityFactory, NullActivityFactory>();
|
||||
|
||||
@@ -1,128 +0,0 @@
|
||||
using System.Diagnostics;
|
||||
using System.Text;
|
||||
using Speckle.Sdk.Logging;
|
||||
|
||||
namespace Speckle.Sdk.Transports;
|
||||
|
||||
/// <summary>
|
||||
/// Writes speckle objects to disk.
|
||||
/// </summary>
|
||||
public class DiskTransport : ICloneable, ITransport
|
||||
{
|
||||
public DiskTransport(string? basePath = null)
|
||||
{
|
||||
basePath ??= Path.Combine(SpecklePathProvider.UserSpeckleFolderPath, "DiskTransportFiles");
|
||||
|
||||
RootPath = Path.Combine(basePath);
|
||||
|
||||
Directory.CreateDirectory(RootPath);
|
||||
}
|
||||
|
||||
public string RootPath { get; set; }
|
||||
|
||||
public object Clone()
|
||||
{
|
||||
return new DiskTransport
|
||||
{
|
||||
RootPath = RootPath,
|
||||
CancellationToken = CancellationToken,
|
||||
OnErrorAction = OnErrorAction,
|
||||
OnProgressAction = OnProgressAction,
|
||||
TransportName = TransportName,
|
||||
};
|
||||
}
|
||||
|
||||
public string TransportName { get; set; } = "Disk";
|
||||
|
||||
public Dictionary<string, object> TransportContext =>
|
||||
new()
|
||||
{
|
||||
{ "name", TransportName },
|
||||
{ "type", GetType().Name },
|
||||
{ "basePath", RootPath },
|
||||
};
|
||||
|
||||
public CancellationToken CancellationToken { get; set; }
|
||||
|
||||
public IProgress<ProgressArgs>? OnProgressAction { get; set; }
|
||||
|
||||
public Action<string, Exception>? OnErrorAction { get; set; }
|
||||
|
||||
public int SavedObjectCount { get; private set; }
|
||||
|
||||
public TimeSpan Elapsed { get; set; } = TimeSpan.Zero;
|
||||
|
||||
public void BeginWrite()
|
||||
{
|
||||
SavedObjectCount = 0;
|
||||
}
|
||||
|
||||
public void EndWrite() { }
|
||||
|
||||
public Task<string?> GetObject(string id)
|
||||
{
|
||||
CancellationToken.ThrowIfCancellationRequested();
|
||||
|
||||
var filePath = Path.Combine(RootPath, id);
|
||||
if (File.Exists(filePath))
|
||||
{
|
||||
return Task.FromResult<string?>(File.ReadAllText(filePath, Encoding.UTF8));
|
||||
}
|
||||
|
||||
return Task.FromResult<string?>(null);
|
||||
}
|
||||
|
||||
public void SaveObject(string id, string serializedObject)
|
||||
{
|
||||
var stopwatch = Stopwatch.StartNew();
|
||||
CancellationToken.ThrowIfCancellationRequested();
|
||||
|
||||
var filePath = Path.Combine(RootPath, id);
|
||||
if (File.Exists(filePath))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
File.WriteAllText(filePath, serializedObject, Encoding.UTF8);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
throw new TransportException(this, $"Failed to write object {id} to disk", ex);
|
||||
}
|
||||
|
||||
SavedObjectCount++;
|
||||
stopwatch.Stop();
|
||||
Elapsed += stopwatch.Elapsed;
|
||||
}
|
||||
|
||||
public Task WriteComplete()
|
||||
{
|
||||
return Task.CompletedTask;
|
||||
}
|
||||
|
||||
public async Task<string> CopyObjectAndChildren(string id, ITransport targetTransport)
|
||||
{
|
||||
string res = await TransportHelpers
|
||||
.CopyObjectAndChildrenAsync(id, this, targetTransport, CancellationToken)
|
||||
.ConfigureAwait(false);
|
||||
return res;
|
||||
}
|
||||
|
||||
public Task<Dictionary<string, bool>> HasObjects(IReadOnlyList<string> objectIds)
|
||||
{
|
||||
Dictionary<string, bool> ret = new();
|
||||
foreach (string objectId in objectIds)
|
||||
{
|
||||
var filePath = Path.Combine(RootPath, objectId);
|
||||
ret[objectId] = File.Exists(filePath);
|
||||
}
|
||||
return Task.FromResult(ret);
|
||||
}
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
return $"Disk Transport @{RootPath}";
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,7 @@
|
||||
using System.Runtime.CompilerServices;
|
||||
using Speckle.Objects.Geometry;
|
||||
using Speckle.Sdk.Host;
|
||||
using Speckle.Sdk.Models;
|
||||
using Speckle.Sdk.Testing;
|
||||
|
||||
namespace Speckle.Objects.Tests.Unit;
|
||||
@@ -12,6 +13,6 @@ public static class Module
|
||||
{
|
||||
SpeckleVerify.Initialize();
|
||||
TypeLoader.Reset();
|
||||
TypeLoader.Initialize(typeof(Polyline).Assembly);
|
||||
TypeLoader.Initialize(typeof(Base).Assembly, typeof(Polyline).Assembly);
|
||||
}
|
||||
}
|
||||
|
||||
+76
@@ -0,0 +1,76 @@
|
||||
[
|
||||
{
|
||||
"applicationId": null,
|
||||
"data": [
|
||||
3,
|
||||
0,
|
||||
1,
|
||||
2
|
||||
],
|
||||
"id": "13da8e855141b835e68bba721411046e",
|
||||
"speckle_type": "Speckle.Core.Models.DataChunk"
|
||||
},
|
||||
{
|
||||
"__closure": {
|
||||
"13da8e855141b835e68bba721411046e": 100,
|
||||
"cc9d42395b317ed25947b1285bbd5103": 100,
|
||||
"ede4848fc3abda9275a19fee3447ffbd": 100
|
||||
},
|
||||
"applicationId": "asdfasdf",
|
||||
"area": 42.0,
|
||||
"bbox": null,
|
||||
"colors": [
|
||||
{
|
||||
"__closure": null,
|
||||
"referencedId": "cc9d42395b317ed25947b1285bbd5103",
|
||||
"speckle_type": "reference"
|
||||
}
|
||||
],
|
||||
"faces": [
|
||||
{
|
||||
"__closure": null,
|
||||
"referencedId": "13da8e855141b835e68bba721411046e",
|
||||
"speckle_type": "reference"
|
||||
}
|
||||
],
|
||||
"id": "85fdad62ca935832449ffb359ebed7b8",
|
||||
"speckle_type": "Objects.Geometry.Mesh",
|
||||
"textureCoordinates": [],
|
||||
"units": "m",
|
||||
"vertexNormals": [],
|
||||
"vertices": [
|
||||
{
|
||||
"__closure": null,
|
||||
"referencedId": "ede4848fc3abda9275a19fee3447ffbd",
|
||||
"speckle_type": "reference"
|
||||
}
|
||||
],
|
||||
"volume": 420.0
|
||||
},
|
||||
{
|
||||
"applicationId": null,
|
||||
"data": [
|
||||
-10185235,
|
||||
-10185235,
|
||||
-10185235
|
||||
],
|
||||
"id": "cc9d42395b317ed25947b1285bbd5103",
|
||||
"speckle_type": "Speckle.Core.Models.DataChunk"
|
||||
},
|
||||
{
|
||||
"applicationId": null,
|
||||
"data": [
|
||||
0.0,
|
||||
0.0,
|
||||
0.0,
|
||||
1.0,
|
||||
0.0,
|
||||
0.0,
|
||||
1.0,
|
||||
1.0,
|
||||
0.0
|
||||
],
|
||||
"id": "ede4848fc3abda9275a19fee3447ffbd",
|
||||
"speckle_type": "Speckle.Core.Models.DataChunk"
|
||||
}
|
||||
]
|
||||
+11
@@ -0,0 +1,11 @@
|
||||
[
|
||||
{
|
||||
"applicationId": "iosdf;juasdfioj",
|
||||
"id": "035cad79be39e59c765b7946c4ea5f0c",
|
||||
"speckle_type": "Objects.Geometry.Point",
|
||||
"units": "ft",
|
||||
"x": 123.123,
|
||||
"y": 111.222,
|
||||
"z": -0.001
|
||||
}
|
||||
]
|
||||
+12
@@ -0,0 +1,12 @@
|
||||
[
|
||||
{
|
||||
"applicationId": "iosdf;juasdfioj",
|
||||
"bbox": null,
|
||||
"id": "282d78f7ca1a2ec37bf3fcf3f24e7a27",
|
||||
"speckle_type": "Objects.Geometry.Vector",
|
||||
"units": "in",
|
||||
"x": 321.321,
|
||||
"y": 222.111,
|
||||
"z": -1.001
|
||||
}
|
||||
]
|
||||
@@ -0,0 +1,33 @@
|
||||
using Speckle.Sdk.Models;
|
||||
using Speckle.Sdk.Serialisation;
|
||||
using Speckle.Sdk.Serialisation.V2.Send;
|
||||
using Speckle.Sdk.Testing;
|
||||
|
||||
namespace Speckle.Objects.SerializationTests;
|
||||
|
||||
public sealed class ObjectsSerializationTest
|
||||
{
|
||||
[Theory]
|
||||
[MemberData(nameof(ObjectsTestData.TheoryData), MemberType = typeof(ObjectsTestData))]
|
||||
public async Task SerializeAndVerify(Base testCase)
|
||||
{
|
||||
var serialized = Serialize(testCase);
|
||||
|
||||
await VerifySerialized(serialized).UseParameters(testCase);
|
||||
}
|
||||
|
||||
private static IReadOnlyList<(Id, Json, Dictionary<Id, int>)> Serialize(Base data)
|
||||
{
|
||||
using var serializer = new ObjectSerializerFactory(new BasePropertyGatherer()).Create(
|
||||
new Dictionary<Id, NodeInfo>(),
|
||||
default
|
||||
);
|
||||
return serializer.Serialize(data).ToList();
|
||||
}
|
||||
|
||||
private static SettingsTask VerifySerialized(IReadOnlyList<(Id, Json, Dictionary<Id, int>)> serializedResult)
|
||||
{
|
||||
var jsons = serializedResult.OrderBy(x => x.Item1.Value).Select(x => x.Item2).ToArray();
|
||||
return SpeckleVerify.VerifyJsons(jsons);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,46 @@
|
||||
using Speckle.Objects.Geometry;
|
||||
using Speckle.Sdk.Common;
|
||||
using Speckle.Sdk.Models;
|
||||
using Point = Speckle.Objects.Geometry.Point;
|
||||
|
||||
namespace Speckle.Objects.SerializationTests;
|
||||
|
||||
public static class ObjectsTestData
|
||||
{
|
||||
/// <summary>
|
||||
/// Data set of simple valid Speckle Objects
|
||||
/// Right now, we should have exactly one for each non-abstract object model.
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
private static IEnumerable<Base> Data()
|
||||
{
|
||||
yield return new Mesh()
|
||||
{
|
||||
vertices = [0d, 0d, 0d, 1d, 0d, 0d, 1d, 1d, 0d],
|
||||
faces = [3, 0, 1, 2],
|
||||
applicationId = "asdfasdf",
|
||||
units = Units.Meters,
|
||||
area = 42,
|
||||
volume = 420,
|
||||
colors = [-10185235, -10185235, -10185235],
|
||||
};
|
||||
yield return new Point()
|
||||
{
|
||||
x = 123.123,
|
||||
y = 111.222,
|
||||
z = -0.001,
|
||||
applicationId = "iosdf;juasdfioj",
|
||||
units = Units.Feet,
|
||||
};
|
||||
yield return new Vector()
|
||||
{
|
||||
x = 321.321,
|
||||
y = 222.111,
|
||||
z = -1.001,
|
||||
applicationId = "iosdf;juasdfioj",
|
||||
units = Units.Inches,
|
||||
};
|
||||
}
|
||||
|
||||
public static TheoryData<Base> TheoryData => new(Data());
|
||||
}
|
||||
@@ -10,9 +10,9 @@
|
||||
},
|
||||
"AwesomeAssertions": {
|
||||
"type": "Direct",
|
||||
"requested": "[8.0.0, )",
|
||||
"resolved": "8.0.0",
|
||||
"contentHash": "6fWiV7mGZUzZXzeiW3hWF0nJokuuNm4hnzuqbM3IXHqGYkWnHl65+wNpuQ73xfJXClX0fmfKcTdQ2Ula719IDg=="
|
||||
"requested": "[8.1.0, )",
|
||||
"resolved": "8.1.0",
|
||||
"contentHash": "IfNC4cpXPi9tclWvuNO9lfkuIxJsUTLTS1NXto55jDrAUQJYl0zLI9ByISrfkbBE2Xtg+IWaAXQ6jnUx3anDuw=="
|
||||
},
|
||||
"Microsoft.NET.Test.Sdk": {
|
||||
"type": "Direct",
|
||||
@@ -60,22 +60,30 @@
|
||||
},
|
||||
"Argon": {
|
||||
"type": "Transitive",
|
||||
"resolved": "0.26.0",
|
||||
"contentHash": "n7btGXdtRyprGnpLMpBs6rLScxlvPtVWwmTR8h7CtJvpZXBGhGvibEdZxRjeTZNrwf403jJ0ZPpt35Pz/NaNsw=="
|
||||
"resolved": "0.27.0",
|
||||
"contentHash": "LtZKATYeTwDyYq1AXrgVU/ly+nI6GvE0GK1isJYFPQOnb2uHUxvDA+yh40QYaITGTLViXK7rbWhNKpbZ5pb9XA=="
|
||||
},
|
||||
"Castle.Core": {
|
||||
"type": "Transitive",
|
||||
"resolved": "5.1.1",
|
||||
"contentHash": "rpYtIczkzGpf+EkZgDr9CClTdemhsrwA/W5hMoPjLkRFnXzH44zDLoovXeKtmxb1ykXK9aJVODSpiJml8CTw2g==",
|
||||
"dependencies": {
|
||||
"System.Diagnostics.EventLog": "6.0.0"
|
||||
}
|
||||
},
|
||||
"DiffEngine": {
|
||||
"type": "Transitive",
|
||||
"resolved": "15.9.0",
|
||||
"contentHash": "shE6+tO4w5BmQTX0z+WnUV4UfmPNn6oTqBINbkts6OP0Icyx5WROSDzjjb95EwVYC4IAS+PxxS4Vbapxz4hkdw==",
|
||||
"resolved": "16.1.0",
|
||||
"contentHash": "ImEFC6BN62paN0N7v8vrLY3x/LpfbJaJy5yDtL+/L2As6FI1npGJcFZwzz1A7pdDjIYPOXE91qv6BpgEUGjDkA==",
|
||||
"dependencies": {
|
||||
"EmptyFiles": "8.7.1",
|
||||
"System.Management": "9.0.1"
|
||||
"EmptyFiles": "8.8.0",
|
||||
"System.Management": "8.0.0"
|
||||
}
|
||||
},
|
||||
"EmptyFiles": {
|
||||
"type": "Transitive",
|
||||
"resolved": "8.7.1",
|
||||
"contentHash": "C8pvg0TvG2Mkn5LGNFGkFgFu8SUgYFwiu8U3y34qGQnnwKmGnlQTfTIUrtzfSjPxA4q7L/kRu09U5p32otZ2Aw=="
|
||||
"resolved": "8.8.0",
|
||||
"contentHash": "d0pgc/vMyKgQ9T3qiiJBn1uYUSZ1/OShh6tySnNSkELRSgM4A4IOrpdQhLqwCkPwYvdJqzKuxQ6wn3MQAd4GNA=="
|
||||
},
|
||||
"FSharp.Core": {
|
||||
"type": "Transitive",
|
||||
@@ -242,25 +250,30 @@
|
||||
},
|
||||
"System.CodeDom": {
|
||||
"type": "Transitive",
|
||||
"resolved": "9.0.1",
|
||||
"contentHash": "2J5uq+2smnj+u1jlyVJ6BGGqaK9fHcK/EwN7mbsuPqTI6dZr86br8Cg6o/5B+icQ9ANTvTDpJjnhDNtYYZijHQ=="
|
||||
"resolved": "8.0.0",
|
||||
"contentHash": "WTlRjL6KWIMr/pAaq3rYqh0TJlzpouaQ/W1eelssHgtlwHAH25jXTkUphTYx9HaIIf7XA6qs/0+YhtLEQRkJ+Q=="
|
||||
},
|
||||
"System.ComponentModel.Annotations": {
|
||||
"type": "Transitive",
|
||||
"resolved": "4.5.0",
|
||||
"contentHash": "UxYQ3FGUOtzJ7LfSdnYSFd7+oEv6M8NgUatatIN2HxNtDdlcvFAf+VIq4Of9cDMJEJC0aSRv/x898RYhB4Yppg=="
|
||||
},
|
||||
"System.Diagnostics.EventLog": {
|
||||
"type": "Transitive",
|
||||
"resolved": "6.0.0",
|
||||
"contentHash": "lcyUiXTsETK2ALsZrX+nWuHSIQeazhqPphLfaRxzdGaG93+0kELqpgEHtwWOlQe7+jSFnKwaCAgL4kjeZCQJnw=="
|
||||
},
|
||||
"System.IO.Hashing": {
|
||||
"type": "Transitive",
|
||||
"resolved": "9.0.1",
|
||||
"contentHash": "jY+E/PElNWQiazN0YHqZGvcSedcZ4Wt0Os1nnJ2SzR3gWZlhNRDkSXOhuHJcLuImD8SrJQQ8TfU0W4mVcit2hg=="
|
||||
"resolved": "9.0.3",
|
||||
"contentHash": "BrMGzDRLz410PE4qC8UeKeAc0hFRjBkiCUOLTwuod65NAjqg5tDNqYU7gP0A09taEXtecB+HJc1NNnnTjsKFAQ=="
|
||||
},
|
||||
"System.Management": {
|
||||
"type": "Transitive",
|
||||
"resolved": "9.0.1",
|
||||
"contentHash": "CLEo9O6FuO4GQ3ZQkGssg9CJ2w2TN7GMFf3wHTc7YVWJV4xoyJRPw+XIDQnCcSUJCrHhrAWOO60cAX29EV5LFQ==",
|
||||
"resolved": "8.0.0",
|
||||
"contentHash": "jrK22i5LRzxZCfGb+tGmke2VH7oE0DvcDlJ1HAKYU8cPmD8XnpUT0bYn2Gy98GEhGjtfbR/sxKTVb+dE770pfA==",
|
||||
"dependencies": {
|
||||
"System.CodeDom": "9.0.1"
|
||||
"System.CodeDom": "8.0.0"
|
||||
}
|
||||
},
|
||||
"System.Memory": {
|
||||
@@ -298,13 +311,13 @@
|
||||
},
|
||||
"Verify": {
|
||||
"type": "Transitive",
|
||||
"resolved": "28.10.1",
|
||||
"contentHash": "2B/VtFN5jtF5g28kaM4GdJZTwb3pisd4+wL2NEPi9ZYe2lghWsCzS30V6LF1ILApLBfAorAstkU/Vw3sDWRqrg==",
|
||||
"resolved": "29.2.0",
|
||||
"contentHash": "EhhwhXIeip9AJGWRPXh47NAUoiELnWzeBnAzFSl0+ryAfijTV1T+B4m6P6GbheWQ1CJ1cC1ZFLzgH276D5Bu3A==",
|
||||
"dependencies": {
|
||||
"Argon": "0.26.0",
|
||||
"DiffEngine": "15.9.0",
|
||||
"Argon": "0.27.0",
|
||||
"DiffEngine": "16.1.0",
|
||||
"SimpleInfoName": "3.1.0",
|
||||
"System.IO.Hashing": "9.0.1"
|
||||
"System.IO.Hashing": "9.0.3"
|
||||
}
|
||||
},
|
||||
"xunit.abstractions": {
|
||||
@@ -312,6 +325,20 @@
|
||||
"resolved": "2.0.3",
|
||||
"contentHash": "pot1I4YOxlWjIb5jmwvvQNbTrZ3lJQ+jUGkGjWE3hEFM0l5gOnBWS+H3qsex68s5cO52g+44vpGzhAt+42vwKg=="
|
||||
},
|
||||
"xunit.analyzers": {
|
||||
"type": "Transitive",
|
||||
"resolved": "1.18.0",
|
||||
"contentHash": "OtFMHN8yqIcYP9wcVIgJrq01AfTxijjAqVDy/WeQVSyrDC1RzBWeQPztL49DN2syXRah8TYnfvk035s7L95EZQ=="
|
||||
},
|
||||
"xunit.core": {
|
||||
"type": "Transitive",
|
||||
"resolved": "2.9.3",
|
||||
"contentHash": "BiAEvqGvyme19wE0wTKdADH+NloYqikiU0mcnmiNyXaF9HyHmE6sr/3DC5vnBkgsWaE6yPyWszKSPSApWdRVeQ==",
|
||||
"dependencies": {
|
||||
"xunit.extensibility.core": "[2.9.3]",
|
||||
"xunit.extensibility.execution": "[2.9.3]"
|
||||
}
|
||||
},
|
||||
"xunit.extensibility.core": {
|
||||
"type": "Transitive",
|
||||
"resolved": "2.9.3",
|
||||
@@ -354,9 +381,11 @@
|
||||
"type": "Project",
|
||||
"dependencies": {
|
||||
"Microsoft.NET.Test.Sdk": "[17.13.0, )",
|
||||
"Moq": "[4.20.72, )",
|
||||
"Speckle.Sdk": "[1.0.0, )",
|
||||
"Verify.Quibble": "[2.1.1, )",
|
||||
"Verify.Xunit": "[28.10.1, )",
|
||||
"Verify.Xunit": "[29.2.0, )",
|
||||
"xunit": "[2.9.3, )",
|
||||
"xunit.runner.visualstudio": "[3.0.2, )"
|
||||
}
|
||||
},
|
||||
@@ -405,6 +434,15 @@
|
||||
"Microsoft.Extensions.Options": "2.2.0"
|
||||
}
|
||||
},
|
||||
"Moq": {
|
||||
"type": "CentralTransitive",
|
||||
"requested": "[4.20.72, )",
|
||||
"resolved": "4.20.72",
|
||||
"contentHash": "EA55cjyNn8eTNWrgrdZJH5QLFp2L43oxl1tlkoYUKIE9pRwL784OWiTXeCV5ApS+AMYEAlt7Fo03A2XfouvHmQ==",
|
||||
"dependencies": {
|
||||
"Castle.Core": "5.1.1"
|
||||
}
|
||||
},
|
||||
"Speckle.DoubleNumerics": {
|
||||
"type": "CentralTransitive",
|
||||
"requested": "[4.1.0, )",
|
||||
@@ -430,18 +468,29 @@
|
||||
},
|
||||
"Verify.Xunit": {
|
||||
"type": "CentralTransitive",
|
||||
"requested": "[28.10.1, )",
|
||||
"resolved": "28.10.1",
|
||||
"contentHash": "mkG7agMlx8oAEGcHoRY72hyDyNTdLIrzbfmniXFQgQ3yKulAHSYvYc9quzhpg0Sy+jb3svbdLqnRSg0VRhet3A==",
|
||||
"requested": "[29.2.0, )",
|
||||
"resolved": "29.2.0",
|
||||
"contentHash": "MdcslVf40AzSA319ZHMzR+U4JqyquX28JFSrI9zA89yeZNaNcaSIb5PmE0XZ6p60Iy7eRYtnGEgSDimEUeXHZw==",
|
||||
"dependencies": {
|
||||
"Argon": "0.26.0",
|
||||
"DiffEngine": "15.9.0",
|
||||
"Argon": "0.27.0",
|
||||
"DiffEngine": "16.1.0",
|
||||
"SimpleInfoName": "3.1.0",
|
||||
"System.IO.Hashing": "9.0.1",
|
||||
"Verify": "28.10.1",
|
||||
"System.IO.Hashing": "9.0.3",
|
||||
"Verify": "29.2.0",
|
||||
"xunit.abstractions": "2.0.3",
|
||||
"xunit.extensibility.execution": "2.9.3"
|
||||
}
|
||||
},
|
||||
"xunit": {
|
||||
"type": "CentralTransitive",
|
||||
"requested": "[2.9.3, )",
|
||||
"resolved": "2.9.3",
|
||||
"contentHash": "TlXQBinK35LpOPKHAqbLY4xlEen9TBafjs0V5KnA4wZsoQLQJiirCR4CbIXvOH8NzkW4YeJKP5P/Bnrodm0h9Q==",
|
||||
"dependencies": {
|
||||
"xunit.analyzers": "1.18.0",
|
||||
"xunit.assert": "2.9.3",
|
||||
"xunit.core": "[2.9.3]"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,22 +1,14 @@
|
||||
#pragma warning disable CA1506
|
||||
using System.Reflection;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Microsoft.Extensions.Logging.Abstractions;
|
||||
using Speckle.Sdk;
|
||||
using Speckle.Sdk.Credentials;
|
||||
using Speckle.Sdk.Host;
|
||||
using Speckle.Sdk.Models;
|
||||
using Speckle.Sdk.Serialisation.V2;
|
||||
using Speckle.Sdk.Serialisation.V2.Receive;
|
||||
using Speckle.Sdk.Serialisation.V2.Send;
|
||||
using Speckle.Sdk.Serialization.Testing;
|
||||
using Speckle.Sdk.SQLite;
|
||||
|
||||
const bool skipCacheReceive = false;
|
||||
const bool skipCacheSendCheck = true;
|
||||
const bool skipCacheSendSave = false;
|
||||
TypeLoader.Reset();
|
||||
TypeLoader.Initialize(typeof(Base).Assembly, Assembly.GetExecutingAssembly());
|
||||
|
||||
var url = "https://latest.speckle.systems/projects/a3ac1b2706/models/59d3b0f3c6"; //small?
|
||||
var streamId = "a3ac1b2706";
|
||||
@@ -33,7 +25,7 @@ var streamId = "2099ac4b5f";
|
||||
var rootId = "30fb4cbe6eb2202b9e7b4a4fcc3dd2b6";*/
|
||||
|
||||
var serviceCollection = new ServiceCollection();
|
||||
serviceCollection.AddSpeckleSdk(HostApplications.Navisworks, HostAppVersion.v2023, "Test");
|
||||
serviceCollection.AddSpeckleSdk(new("Tests", "test"), "v3");
|
||||
var serviceProvider = serviceCollection.BuildServiceProvider();
|
||||
|
||||
Console.WriteLine("Attach");
|
||||
@@ -41,21 +33,15 @@ Console.WriteLine("Attach");
|
||||
var token = serviceProvider.GetRequiredService<IAccountManager>().GetDefaultAccount()?.token;
|
||||
var progress = new Progress(true);
|
||||
|
||||
var factory = new SerializeProcessFactory(
|
||||
new BaseChildFinder(new BasePropertyGatherer()),
|
||||
new ObjectSerializerFactory(new BasePropertyGatherer()),
|
||||
new BaseDeserializer(new ObjectDeserializerFactory()),
|
||||
serviceProvider.GetRequiredService<ISqLiteJsonCacheManagerFactory>(),
|
||||
serviceProvider.GetRequiredService<IServerObjectManagerFactory>(),
|
||||
new NullLoggerFactory()
|
||||
);
|
||||
var factory = serviceProvider.GetRequiredService<IDeserializeProcessFactory>();
|
||||
var process = factory.CreateDeserializeProcess(new Uri(url), streamId, token, progress, default, new(skipCacheReceive));
|
||||
var @base = await process.Deserialize(rootId).ConfigureAwait(false);
|
||||
Console.WriteLine("Deserialized");
|
||||
Console.ReadLine();
|
||||
Console.WriteLine("Executing");
|
||||
|
||||
var process2 = factory.CreateSerializeProcess(
|
||||
var serializeProcessFactory = serviceProvider.GetRequiredService<ISerializeProcessFactory>();
|
||||
var serializeProcess = serializeProcessFactory.CreateSerializeProcess(
|
||||
new Uri(url),
|
||||
streamId,
|
||||
token,
|
||||
@@ -63,8 +49,8 @@ var process2 = factory.CreateSerializeProcess(
|
||||
default,
|
||||
new SerializeProcessOptions(skipCacheSendCheck, skipCacheSendSave, true, true)
|
||||
);
|
||||
await process2.Serialize(@base).ConfigureAwait(false);
|
||||
await serializeProcess.Serialize(@base).ConfigureAwait(false);
|
||||
Console.WriteLine("Detach");
|
||||
Console.ReadLine();
|
||||
await process2.DisposeAsync().ConfigureAwait(false);
|
||||
await serializeProcess.DisposeAsync().ConfigureAwait(false);
|
||||
#pragma warning restore CA1506
|
||||
|
||||
@@ -1,4 +1,6 @@
|
||||
using Speckle.Sdk.Serialisation.V2;
|
||||
using System.Collections.Concurrent;
|
||||
using Speckle.Sdk.Serialisation;
|
||||
using Speckle.Sdk.Serialisation.V2;
|
||||
using Speckle.Sdk.Serialisation.V2.Send;
|
||||
using Speckle.Sdk.Testing.Framework;
|
||||
using Speckle.Sdk.Transports;
|
||||
@@ -6,7 +8,7 @@ using Speckle.Sdk.Transports;
|
||||
namespace Speckle.Sdk.Serialization.Tests;
|
||||
|
||||
public sealed class CancellationSqLiteJsonCacheManager(CancellationTokenSource cancellationTokenSource)
|
||||
: DummySqLiteJsonCacheManager
|
||||
: MemoryJsonCacheManager(new ConcurrentDictionary<Id, Json>())
|
||||
{
|
||||
public override void SaveObjects(IEnumerable<(string id, string json)> items)
|
||||
{
|
||||
@@ -24,7 +26,8 @@ public class CancellationSqLiteSendManager(CancellationTokenSource cancellationT
|
||||
}
|
||||
}
|
||||
|
||||
public class CancellationServerObjectManager(CancellationTokenSource cancellationTokenSource) : DummyServerObjectManager
|
||||
public class CancellationServerObjectManager(CancellationTokenSource cancellationTokenSource)
|
||||
: MemoryServerObjectManager(new ConcurrentDictionary<string, string>())
|
||||
{
|
||||
public override Task UploadObjects(
|
||||
IReadOnlyList<BaseItem> objects,
|
||||
|
||||
+12
-2
@@ -1,5 +1,15 @@
|
||||
{
|
||||
"Type": "System.OperationCanceledException",
|
||||
"CancellationToken": {
|
||||
"IsCancellationRequested": true,
|
||||
"CanBeCanceled": true,
|
||||
"WaitHandle": {
|
||||
"SafeWaitHandle": {
|
||||
"IsClosed": false,
|
||||
"IsInvalid": false
|
||||
}
|
||||
}
|
||||
},
|
||||
"Data": {},
|
||||
"Message": "The operation was canceled.",
|
||||
"Source": "System.Private.CoreLib"
|
||||
"Type": "OperationCanceledException"
|
||||
}
|
||||
|
||||
+12
-2
@@ -1,5 +1,15 @@
|
||||
{
|
||||
"Type": "System.OperationCanceledException",
|
||||
"CancellationToken": {
|
||||
"IsCancellationRequested": true,
|
||||
"CanBeCanceled": true,
|
||||
"WaitHandle": {
|
||||
"SafeWaitHandle": {
|
||||
"IsClosed": false,
|
||||
"IsInvalid": false
|
||||
}
|
||||
}
|
||||
},
|
||||
"Data": {},
|
||||
"Message": "The operation was canceled.",
|
||||
"Source": "System.Private.CoreLib"
|
||||
"Type": "OperationCanceledException"
|
||||
}
|
||||
|
||||
+12
-2
@@ -1,5 +1,15 @@
|
||||
{
|
||||
"Type": "System.OperationCanceledException",
|
||||
"CancellationToken": {
|
||||
"IsCancellationRequested": true,
|
||||
"CanBeCanceled": true,
|
||||
"WaitHandle": {
|
||||
"SafeWaitHandle": {
|
||||
"IsClosed": false,
|
||||
"IsInvalid": false
|
||||
}
|
||||
}
|
||||
},
|
||||
"Data": {},
|
||||
"Message": "The operation was canceled.",
|
||||
"Source": "System.Private.CoreLib"
|
||||
"Type": "OperationCanceledException"
|
||||
}
|
||||
|
||||
+12
-2
@@ -1,5 +1,15 @@
|
||||
{
|
||||
"Type": "System.OperationCanceledException",
|
||||
"CancellationToken": {
|
||||
"IsCancellationRequested": true,
|
||||
"CanBeCanceled": true,
|
||||
"WaitHandle": {
|
||||
"SafeWaitHandle": {
|
||||
"IsClosed": false,
|
||||
"IsInvalid": false
|
||||
}
|
||||
}
|
||||
},
|
||||
"Data": {},
|
||||
"Message": "The operation was canceled.",
|
||||
"Source": "System.Private.CoreLib"
|
||||
"Type": "OperationCanceledException"
|
||||
}
|
||||
|
||||
+12
-2
@@ -1,5 +1,15 @@
|
||||
{
|
||||
"Type": "System.OperationCanceledException",
|
||||
"CancellationToken": {
|
||||
"IsCancellationRequested": true,
|
||||
"CanBeCanceled": true,
|
||||
"WaitHandle": {
|
||||
"SafeWaitHandle": {
|
||||
"IsClosed": false,
|
||||
"IsInvalid": false
|
||||
}
|
||||
}
|
||||
},
|
||||
"Data": {},
|
||||
"Message": "The operation was canceled.",
|
||||
"Source": "System.Private.CoreLib"
|
||||
"Type": "OperationCanceledException"
|
||||
}
|
||||
|
||||
+12
-2
@@ -1,5 +1,15 @@
|
||||
{
|
||||
"Type": "System.OperationCanceledException",
|
||||
"CancellationToken": {
|
||||
"IsCancellationRequested": true,
|
||||
"CanBeCanceled": true,
|
||||
"WaitHandle": {
|
||||
"SafeWaitHandle": {
|
||||
"IsClosed": false,
|
||||
"IsInvalid": false
|
||||
}
|
||||
}
|
||||
},
|
||||
"Data": {},
|
||||
"Message": "The operation was canceled.",
|
||||
"Source": "System.Private.CoreLib"
|
||||
"Type": "OperationCanceledException"
|
||||
}
|
||||
|
||||
@@ -1,10 +1,11 @@
|
||||
using System.Collections.Concurrent;
|
||||
using FluentAssertions;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Microsoft.Extensions.Logging.Abstractions;
|
||||
using Speckle.Objects.Geometry;
|
||||
using Speckle.Sdk.Host;
|
||||
using Speckle.Sdk.Models;
|
||||
using Speckle.Sdk.Serialisation;
|
||||
using Speckle.Sdk.Serialisation.V2;
|
||||
using Speckle.Sdk.Serialisation.V2.Receive;
|
||||
using Speckle.Sdk.Serialisation.V2.Send;
|
||||
using Speckle.Sdk.Serialization.Tests.Framework;
|
||||
@@ -14,10 +15,15 @@ namespace Speckle.Sdk.Serialization.Tests;
|
||||
|
||||
public class CancellationTests
|
||||
{
|
||||
private readonly ISerializeProcessFactory _factory;
|
||||
|
||||
public CancellationTests()
|
||||
{
|
||||
TypeLoader.Reset();
|
||||
TypeLoader.Initialize(typeof(Base).Assembly, typeof(DetachedTests).Assembly, typeof(Polyline).Assembly);
|
||||
var serviceCollection = new ServiceCollection();
|
||||
serviceCollection.AddSpeckleSdk(new("Tests", "test"), "v3", typeof(TestClass).Assembly, typeof(Polyline).Assembly);
|
||||
var serviceProvider = serviceCollection.BuildServiceProvider();
|
||||
|
||||
_factory = serviceProvider.GetRequiredService<ISerializeProcessFactory>();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -26,13 +32,11 @@ public class CancellationTests
|
||||
var testClass = new TestClass() { RegularProperty = "Hello" };
|
||||
|
||||
using var cancellationSource = new CancellationTokenSource();
|
||||
await using var serializeProcess = new SerializeProcess(
|
||||
|
||||
await using var serializeProcess = _factory.CreateSerializeProcess(
|
||||
new ConcurrentDictionary<Id, Json>(),
|
||||
new ConcurrentDictionary<string, string>(),
|
||||
null,
|
||||
new DummySqLiteSendManager(),
|
||||
new DummyServerObjectManager(),
|
||||
new BaseChildFinder(new BasePropertyGatherer()),
|
||||
new BaseSerializer(new DummySqLiteSendManager(), new ObjectSerializerFactory(new BasePropertyGatherer())),
|
||||
new NullLoggerFactory(),
|
||||
cancellationSource.Token,
|
||||
new SerializeProcessOptions(true, true, false, true)
|
||||
);
|
||||
@@ -50,15 +54,13 @@ public class CancellationTests
|
||||
var testClass = new TestClass() { RegularProperty = "Hello" };
|
||||
|
||||
using var cancellationSource = new CancellationTokenSource();
|
||||
await using var serializeProcess = new SerializeProcess(
|
||||
null,
|
||||
|
||||
await using var serializeProcess = _factory.CreateSerializeProcess(
|
||||
new DummySqLiteSendManager(),
|
||||
new CancellationServerObjectManager(cancellationSource),
|
||||
new BaseChildFinder(new BasePropertyGatherer()),
|
||||
new BaseSerializer(new DummySqLiteSendManager(), new ObjectSerializerFactory(new BasePropertyGatherer())),
|
||||
new NullLoggerFactory(),
|
||||
null,
|
||||
cancellationSource.Token,
|
||||
new SerializeProcessOptions(true, false, false, true)
|
||||
new SerializeProcessOptions(true, true, false, true)
|
||||
);
|
||||
var ex = await Assert.ThrowsAsync<OperationCanceledException>(
|
||||
async () => await serializeProcess.Serialize(testClass)
|
||||
@@ -73,16 +75,14 @@ public class CancellationTests
|
||||
var testClass = new TestClass() { RegularProperty = "Hello" };
|
||||
|
||||
using var cancellationSource = new CancellationTokenSource();
|
||||
await using var serializeProcess = new SerializeProcess(
|
||||
await using var serializeProcess = _factory.CreateSerializeProcess(
|
||||
new DummySqLiteSendManager(),
|
||||
new CancellationServerObjectManager(cancellationSource),
|
||||
null,
|
||||
new CancellationSqLiteSendManager(cancellationSource),
|
||||
new DummyServerObjectManager(),
|
||||
new BaseChildFinder(new BasePropertyGatherer()),
|
||||
new BaseSerializer(new DummySqLiteSendManager(), new ObjectSerializerFactory(new BasePropertyGatherer())),
|
||||
new NullLoggerFactory(),
|
||||
cancellationSource.Token,
|
||||
new SerializeProcessOptions(true, false, false, true)
|
||||
new SerializeProcessOptions(true, true, false, true)
|
||||
);
|
||||
|
||||
var ex = await Assert.ThrowsAsync<OperationCanceledException>(
|
||||
async () => await serializeProcess.Serialize(testClass)
|
||||
);
|
||||
@@ -94,7 +94,7 @@ public class CancellationTests
|
||||
[InlineData("RevitObject.json.gz", "3416d3fe01c9196115514c4a2f41617b", 7818)]
|
||||
public async Task Cancellation_Receive_Cache(string fileName, string rootId, int oldCount)
|
||||
{
|
||||
var closures = await TestFileManager.GetFileAsClosures(fileName);
|
||||
var closures = TestFileManager.GetFileAsClosures(fileName);
|
||||
closures.Count.Should().Be(oldCount);
|
||||
|
||||
using var cancellationSource = new CancellationTokenSource();
|
||||
@@ -121,7 +121,7 @@ public class CancellationTests
|
||||
[InlineData("RevitObject.json.gz", "3416d3fe01c9196115514c4a2f41617b", 7818)]
|
||||
public async Task Cancellation_Receive_Server(string fileName, string rootId, int oldCount)
|
||||
{
|
||||
var closures = await TestFileManager.GetFileAsClosures(fileName);
|
||||
var closures = TestFileManager.GetFileAsClosures(fileName);
|
||||
closures.Count.Should().Be(oldCount);
|
||||
|
||||
using var cancellationSource = new CancellationTokenSource();
|
||||
@@ -148,7 +148,7 @@ public class CancellationTests
|
||||
[InlineData("RevitObject.json.gz", "3416d3fe01c9196115514c4a2f41617b", 7818)]
|
||||
public async Task Cancellation_Receive_Deserialize(string fileName, string rootId, int oldCount)
|
||||
{
|
||||
var closures = await TestFileManager.GetFileAsClosures(fileName);
|
||||
var closures = TestFileManager.GetFileAsClosures(fileName);
|
||||
closures.Count.Should().Be(oldCount);
|
||||
|
||||
using var cancellationSource = new CancellationTokenSource();
|
||||
|
||||
@@ -1,10 +1,9 @@
|
||||
using System.Collections.Concurrent;
|
||||
using System.Text;
|
||||
using FluentAssertions;
|
||||
using Microsoft.Extensions.Logging.Abstractions;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Speckle.Newtonsoft.Json.Linq;
|
||||
using Speckle.Objects.Geometry;
|
||||
using Speckle.Sdk.Host;
|
||||
using Speckle.Sdk.Models;
|
||||
using Speckle.Sdk.Serialisation;
|
||||
using Speckle.Sdk.Serialisation.V2;
|
||||
@@ -16,10 +15,15 @@ namespace Speckle.Sdk.Serialization.Tests;
|
||||
|
||||
public class DetachedTests
|
||||
{
|
||||
private readonly ISerializeProcessFactory _factory;
|
||||
|
||||
public DetachedTests()
|
||||
{
|
||||
TypeLoader.Reset();
|
||||
TypeLoader.Initialize(typeof(Base).Assembly, typeof(DetachedTests).Assembly, typeof(Polyline).Assembly);
|
||||
var serviceCollection = new ServiceCollection();
|
||||
serviceCollection.AddSpeckleSdk(new("Tests", "test"), "v3", typeof(TestClass).Assembly, typeof(Polyline).Assembly);
|
||||
var serviceProvider = serviceCollection.BuildServiceProvider();
|
||||
|
||||
_factory = serviceProvider.GetRequiredService<ISerializeProcessFactory>();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -30,19 +34,16 @@ public class DetachedTests
|
||||
@base.detachedProp = new SamplePropBase() { name = "detachedProp" };
|
||||
@base.attachedProp = new SamplePropBase() { name = "attachedProp" };
|
||||
|
||||
var objects = new Dictionary<string, string>();
|
||||
var objects = new ConcurrentDictionary<string, string>();
|
||||
|
||||
await using var process2 = new SerializeProcess(
|
||||
await using var serializeProcess = _factory.CreateSerializeProcess(
|
||||
new ConcurrentDictionary<Id, Json>(),
|
||||
objects,
|
||||
null,
|
||||
new DummySendCacheManager(objects),
|
||||
new DummyServerObjectManager(),
|
||||
new BaseChildFinder(new BasePropertyGatherer()),
|
||||
new BaseSerializer(new DummySendCacheManager(objects), new ObjectSerializerFactory(new BasePropertyGatherer())),
|
||||
new NullLoggerFactory(),
|
||||
default,
|
||||
new SerializeProcessOptions(false, false, true, true)
|
||||
);
|
||||
await process2.Serialize(@base);
|
||||
await serializeProcess.Serialize(@base);
|
||||
|
||||
await VerifyJsonDictionary(objects);
|
||||
}
|
||||
@@ -115,19 +116,16 @@ public class DetachedTests
|
||||
line = new Polyline() { units = "test", value = [3.0, 4.0] },
|
||||
};
|
||||
|
||||
var objects = new Dictionary<string, string>();
|
||||
var objects = new ConcurrentDictionary<string, string>();
|
||||
|
||||
await using var process2 = new SerializeProcess(
|
||||
await using var serializeProcess = _factory.CreateSerializeProcess(
|
||||
new ConcurrentDictionary<Id, Json>(),
|
||||
objects,
|
||||
null,
|
||||
new DummySendCacheManager(objects),
|
||||
new DummyServerObjectManager(),
|
||||
new BaseChildFinder(new BasePropertyGatherer()),
|
||||
new BaseSerializer(new DummySendCacheManager(objects), new ObjectSerializerFactory(new BasePropertyGatherer())),
|
||||
new NullLoggerFactory(),
|
||||
default,
|
||||
new SerializeProcessOptions(false, false, true, true)
|
||||
);
|
||||
var results = await process2.Serialize(@base);
|
||||
var results = await serializeProcess.Serialize(@base);
|
||||
|
||||
await VerifyJsonDictionary(objects);
|
||||
}
|
||||
@@ -185,19 +183,17 @@ public class DetachedTests
|
||||
@base.list = new List<double>() { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 };
|
||||
@base.list2 = new List<double>() { 1, 10 };
|
||||
|
||||
var objects = new Dictionary<string, string>();
|
||||
var objects = new ConcurrentDictionary<string, string>();
|
||||
|
||||
await using var process2 = new SerializeProcess(
|
||||
await using var serializeProcess = _factory.CreateSerializeProcess(
|
||||
new ConcurrentDictionary<Id, Json>(),
|
||||
objects,
|
||||
null,
|
||||
new DummySendCacheManager(objects),
|
||||
new DummyServerObjectManager(),
|
||||
new BaseChildFinder(new BasePropertyGatherer()),
|
||||
new BaseSerializer(new DummySendCacheManager(objects), new ObjectSerializerFactory(new BasePropertyGatherer())),
|
||||
new NullLoggerFactory(),
|
||||
default,
|
||||
new SerializeProcessOptions(false, false, true, true)
|
||||
);
|
||||
var results = await process2.Serialize(@base);
|
||||
|
||||
var results = await serializeProcess.Serialize(@base);
|
||||
|
||||
objects.Count.Should().Be(3);
|
||||
var x = JObject.Parse(objects["efeadaca70a85ae6d3acfc93a8b380db"]);
|
||||
@@ -220,19 +216,16 @@ public class DetachedTests
|
||||
@base.list2 = new List<double>() { 1, 10 };
|
||||
@base.arr = [1, 10];
|
||||
|
||||
var objects = new Dictionary<string, string>();
|
||||
var objects = new ConcurrentDictionary<string, string>();
|
||||
|
||||
await using var process2 = new SerializeProcess(
|
||||
await using var serializeProcess = _factory.CreateSerializeProcess(
|
||||
new ConcurrentDictionary<Id, Json>(),
|
||||
objects,
|
||||
null,
|
||||
new DummySendCacheManager(objects),
|
||||
new DummyServerObjectManager(),
|
||||
new BaseChildFinder(new BasePropertyGatherer()),
|
||||
new BaseSerializer(new DummySendCacheManager(objects), new ObjectSerializerFactory(new BasePropertyGatherer())),
|
||||
new NullLoggerFactory(),
|
||||
default,
|
||||
new SerializeProcessOptions(false, false, true, true)
|
||||
);
|
||||
var results = await process2.Serialize(@base);
|
||||
var results = await serializeProcess.Serialize(@base);
|
||||
await VerifyJsonDictionary(objects);
|
||||
}
|
||||
}
|
||||
|
||||
+8
-2
@@ -1,5 +1,11 @@
|
||||
{
|
||||
"Type": "Speckle.Sdk.SpeckleException",
|
||||
"Data": {},
|
||||
"InnerException": {
|
||||
"$type": "NotImplementedException",
|
||||
"Data": {},
|
||||
"Message": "The method or operation is not implemented.",
|
||||
"Type": "NotImplementedException"
|
||||
},
|
||||
"Message": "Error while sending",
|
||||
"Source": "Speckle.Sdk"
|
||||
"Type": "SpeckleException"
|
||||
}
|
||||
|
||||
+11
@@ -0,0 +1,11 @@
|
||||
{
|
||||
"Data": {},
|
||||
"InnerException": {
|
||||
"$type": "NotImplementedException",
|
||||
"Data": {},
|
||||
"Message": "The method or operation is not implemented.",
|
||||
"Type": "NotImplementedException"
|
||||
},
|
||||
"Message": "Error while sending",
|
||||
"Type": "SpeckleException"
|
||||
}
|
||||
+8
-2
@@ -1,5 +1,11 @@
|
||||
{
|
||||
"Type": "Speckle.Sdk.SpeckleException",
|
||||
"Data": {},
|
||||
"InnerException": {
|
||||
"$type": "NotImplementedException",
|
||||
"Data": {},
|
||||
"Message": "The method or operation is not implemented.",
|
||||
"Type": "NotImplementedException"
|
||||
},
|
||||
"Message": "Error while sending",
|
||||
"Source": "Speckle.Sdk"
|
||||
"Type": "SpeckleException"
|
||||
}
|
||||
|
||||
+2
-2
@@ -1,5 +1,5 @@
|
||||
{
|
||||
"Type": "System.NotImplementedException",
|
||||
"Data": {},
|
||||
"Message": "The method or operation is not implemented.",
|
||||
"Source": "Speckle.Sdk.Serialization.Tests"
|
||||
"Type": "NotImplementedException"
|
||||
}
|
||||
|
||||
+2
-2
@@ -1,5 +1,5 @@
|
||||
{
|
||||
"Type": "System.NotImplementedException",
|
||||
"Data": {},
|
||||
"Message": "The method or operation is not implemented.",
|
||||
"Source": "Speckle.Sdk.Serialization.Tests"
|
||||
"Type": "NotImplementedException"
|
||||
}
|
||||
|
||||
+2
-2
@@ -1,5 +1,5 @@
|
||||
{
|
||||
"Type": "Speckle.Sdk.SpeckleException",
|
||||
"Data": {},
|
||||
"Message": "Cannot skip server and cache. Please choose one.",
|
||||
"Source": "Speckle.Sdk"
|
||||
"Type": "SpeckleException"
|
||||
}
|
||||
|
||||
+8
-2
@@ -1,5 +1,11 @@
|
||||
{
|
||||
"Type": "Speckle.Sdk.SpeckleException",
|
||||
"Data": {},
|
||||
"InnerException": {
|
||||
"$type": "NotImplementedException",
|
||||
"Data": {},
|
||||
"Message": "The method or operation is not implemented.",
|
||||
"Type": "NotImplementedException"
|
||||
},
|
||||
"Message": "Error while sending",
|
||||
"Source": "Speckle.Sdk"
|
||||
"Type": "SpeckleException"
|
||||
}
|
||||
|
||||
@@ -1,8 +1,11 @@
|
||||
using System.Collections.Concurrent;
|
||||
using FluentAssertions;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Microsoft.Extensions.Logging.Abstractions;
|
||||
using Speckle.Objects.Geometry;
|
||||
using Speckle.Sdk.Host;
|
||||
using Speckle.Sdk.Models;
|
||||
using Speckle.Sdk.Serialisation;
|
||||
using Speckle.Sdk.Serialisation.V2;
|
||||
using Speckle.Sdk.Serialisation.V2.Receive;
|
||||
using Speckle.Sdk.Serialisation.V2.Send;
|
||||
using Speckle.Sdk.Serialization.Tests.Framework;
|
||||
@@ -12,10 +15,15 @@ namespace Speckle.Sdk.Serialization.Tests;
|
||||
|
||||
public class ExceptionTests
|
||||
{
|
||||
private readonly ISerializeProcessFactory _factory;
|
||||
|
||||
public ExceptionTests()
|
||||
{
|
||||
TypeLoader.Reset();
|
||||
TypeLoader.Initialize(typeof(Base).Assembly, typeof(DetachedTests).Assembly, typeof(Polyline).Assembly);
|
||||
var serviceCollection = new ServiceCollection();
|
||||
serviceCollection.AddSpeckleSdk(new("Tests", "test"), "v3", typeof(TestClass).Assembly, typeof(Polyline).Assembly);
|
||||
var serviceProvider = serviceCollection.BuildServiceProvider();
|
||||
|
||||
_factory = serviceProvider.GetRequiredService<ISerializeProcessFactory>();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -23,20 +31,18 @@ public class ExceptionTests
|
||||
{
|
||||
var testClass = new TestClass() { RegularProperty = "Hello" };
|
||||
|
||||
var objects = new Dictionary<string, string>();
|
||||
await using var process2 = new SerializeProcess(
|
||||
null,
|
||||
new DummySendCacheManager(objects),
|
||||
var objects = new ConcurrentDictionary<Id, Json>();
|
||||
|
||||
await using var serializeProcess = _factory.CreateSerializeProcess(
|
||||
new MemoryJsonCacheManager(objects),
|
||||
new ExceptionServerObjectManager(),
|
||||
new BaseChildFinder(new BasePropertyGatherer()),
|
||||
new BaseSerializer(new DummySendCacheManager(objects), new ObjectSerializerFactory(new BasePropertyGatherer())),
|
||||
new NullLoggerFactory(),
|
||||
null,
|
||||
default,
|
||||
new SerializeProcessOptions(false, false, false, true)
|
||||
);
|
||||
|
||||
//4 exceptions are fine because we use 4 threads for saving cache
|
||||
var ex = await Assert.ThrowsAsync<SpeckleException>(async () => await process2.Serialize(testClass));
|
||||
var ex = await Assert.ThrowsAsync<SpeckleException>(async () => await serializeProcess.Serialize(testClass));
|
||||
await Verify(ex);
|
||||
}
|
||||
|
||||
@@ -45,18 +51,32 @@ public class ExceptionTests
|
||||
{
|
||||
var testClass = new TestClass() { RegularProperty = "Hello" };
|
||||
|
||||
await using var process2 = new SerializeProcess(
|
||||
null,
|
||||
await using var serializeProcess = _factory.CreateSerializeProcess(
|
||||
new ExceptionSendCacheManager(),
|
||||
new DummyServerObjectManager(),
|
||||
new BaseChildFinder(new BasePropertyGatherer()),
|
||||
new BaseSerializer(new ExceptionSendCacheManager(), new ObjectSerializerFactory(new BasePropertyGatherer())),
|
||||
new NullLoggerFactory(),
|
||||
new MemoryServerObjectManager(new()),
|
||||
null,
|
||||
default,
|
||||
new SerializeProcessOptions(false, false, false, true)
|
||||
);
|
||||
|
||||
var ex = await Assert.ThrowsAsync<SpeckleException>(async () => await process2.Serialize(testClass));
|
||||
var ex = await Assert.ThrowsAsync<SpeckleException>(async () => await serializeProcess.Serialize(testClass));
|
||||
await Verify(ex);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task Test_Exceptions_Cache_ExceptionsAfter_10()
|
||||
{
|
||||
var testClass = new TestClass() { RegularProperty = "Hello" };
|
||||
|
||||
await using var serializeProcess = _factory.CreateSerializeProcess(
|
||||
new ExceptionSendCacheManager(exceptionsAfter: 10),
|
||||
new MemoryServerObjectManager(new()),
|
||||
null,
|
||||
default,
|
||||
new SerializeProcessOptions(false, false, false, true)
|
||||
);
|
||||
|
||||
var ex = await Assert.ThrowsAsync<SpeckleException>(async () => await serializeProcess.Serialize(testClass));
|
||||
await Verify(ex);
|
||||
}
|
||||
|
||||
@@ -89,7 +109,7 @@ public class ExceptionTests
|
||||
[InlineData("RevitObject.json.gz", "3416d3fe01c9196115514c4a2f41617b", 7818)]
|
||||
public async Task Test_Exceptions_Receive_Server(string fileName, string rootId, int oldCount)
|
||||
{
|
||||
var closures = await TestFileManager.GetFileAsClosures(fileName);
|
||||
var closures = TestFileManager.GetFileAsClosures(fileName);
|
||||
closures.Count.Should().Be(oldCount);
|
||||
|
||||
await using var process = new DeserializeProcess(
|
||||
@@ -114,7 +134,7 @@ public class ExceptionTests
|
||||
[InlineData("RevitObject.json.gz", "3416d3fe01c9196115514c4a2f41617b", 7818, true)]
|
||||
public async Task Test_Exceptions_Receive_Cache(string fileName, string rootId, int oldCount, bool? hasObject)
|
||||
{
|
||||
var closures = await TestFileManager.GetFileAsClosures(fileName);
|
||||
var closures = TestFileManager.GetFileAsClosures(fileName);
|
||||
closures.Count.Should().Be(oldCount);
|
||||
|
||||
await using var process = new DeserializeProcess(
|
||||
@@ -144,4 +164,23 @@ public class ExceptionTests
|
||||
}
|
||||
await Verify(ex).UseParameters(hasObject);
|
||||
}
|
||||
|
||||
[SpeckleType("Objects.Geometry.BadBase")]
|
||||
public class BadBase : Base
|
||||
{
|
||||
#pragma warning disable CA1065
|
||||
public string BadProp => throw new NotImplementedException();
|
||||
#pragma warning restore CA1065
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Test_SpeckleSerializerException()
|
||||
{
|
||||
var factory = new ObjectSerializerFactory(new BasePropertyGatherer());
|
||||
var serializer = factory.Create(new Dictionary<Id, NodeInfo>(), default);
|
||||
Assert.Throws<SpeckleSerializeException>(() =>
|
||||
{
|
||||
var _ = serializer.Serialize(new BadBase()).ToList();
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,16 +1,23 @@
|
||||
using Microsoft.Extensions.Logging.Abstractions;
|
||||
using Speckle.Sdk.Host;
|
||||
using System.Collections.Concurrent;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Speckle.Sdk.Models;
|
||||
using Speckle.Sdk.Serialisation;
|
||||
using Speckle.Sdk.Serialisation.V2;
|
||||
using Speckle.Sdk.Serialisation.V2.Send;
|
||||
|
||||
namespace Speckle.Sdk.Serialization.Tests;
|
||||
|
||||
public class ExplicitInterfaceTests
|
||||
{
|
||||
private readonly ISerializeProcessFactory _factory;
|
||||
|
||||
public ExplicitInterfaceTests()
|
||||
{
|
||||
TypeLoader.Reset();
|
||||
TypeLoader.Initialize(typeof(Base).Assembly, typeof(TestClass).Assembly);
|
||||
var serviceCollection = new ServiceCollection();
|
||||
serviceCollection.AddSpeckleSdk(new("Tests", "test"), "v3", typeof(TestClass).Assembly);
|
||||
var serviceProvider = serviceCollection.BuildServiceProvider();
|
||||
|
||||
_factory = serviceProvider.GetRequiredService<ISerializeProcessFactory>();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -18,19 +25,16 @@ public class ExplicitInterfaceTests
|
||||
{
|
||||
var testClass = new TestClass() { RegularProperty = "Hello" };
|
||||
|
||||
var objects = new Dictionary<string, string>();
|
||||
await using var process2 = new SerializeProcess(
|
||||
var objects = new ConcurrentDictionary<string, string>();
|
||||
await using var serializeProcess = _factory.CreateSerializeProcess(
|
||||
new ConcurrentDictionary<Id, Json>(),
|
||||
objects,
|
||||
null,
|
||||
new DummySendCacheManager(objects),
|
||||
new DummyServerObjectManager(),
|
||||
new BaseChildFinder(new BasePropertyGatherer()),
|
||||
new BaseSerializer(new DummySendCacheManager(objects), new ObjectSerializerFactory(new BasePropertyGatherer())),
|
||||
new NullLoggerFactory(),
|
||||
default,
|
||||
new SerializeProcessOptions(false, false, true, true)
|
||||
new SerializeProcessOptions(true, true, false, true)
|
||||
);
|
||||
|
||||
await process2.Serialize(testClass);
|
||||
await serializeProcess.Serialize(testClass);
|
||||
|
||||
await VerifyJsonDictionary(objects);
|
||||
}
|
||||
|
||||
@@ -2,21 +2,40 @@
|
||||
|
||||
namespace Speckle.Sdk.Serialization.Tests.Framework;
|
||||
|
||||
public class ExceptionSendCacheManager(bool? hasObject = null) : ISqLiteJsonCacheManager
|
||||
public class ExceptionSendCacheManager(bool? hasObject = null, int? exceptionsAfter = null) : ISqLiteJsonCacheManager
|
||||
{
|
||||
private int _count;
|
||||
|
||||
public void Dispose() { }
|
||||
|
||||
public IReadOnlyCollection<(string Id, string Json)> GetAllObjects() => throw new NotImplementedException();
|
||||
|
||||
public void DeleteObject(string id) => throw new NotImplementedException();
|
||||
public void DeleteObject(string id) => CheckExceptions();
|
||||
|
||||
public string? GetObject(string id) => null;
|
||||
|
||||
public void SaveObject(string id, string json) => throw new NotImplementedException();
|
||||
public void SaveObject(string id, string json) => CheckExceptions();
|
||||
|
||||
public void UpdateObject(string id, string json) => throw new NotImplementedException();
|
||||
public void UpdateObject(string id, string json) => CheckExceptions();
|
||||
|
||||
public void SaveObjects(IEnumerable<(string id, string json)> items) => throw new NotImplementedException();
|
||||
public void SaveObjects(IEnumerable<(string id, string json)> items) => CheckExceptions();
|
||||
|
||||
public bool HasObject(string objectId) => hasObject ?? throw new NotImplementedException();
|
||||
|
||||
private void CheckExceptions()
|
||||
{
|
||||
if (exceptionsAfter is not null)
|
||||
{
|
||||
if (exceptionsAfter.Value > _count)
|
||||
{
|
||||
_count++;
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new Exception("Count exceeded");
|
||||
}
|
||||
}
|
||||
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,7 +1,8 @@
|
||||
using System.IO.Compression;
|
||||
using System.Collections.Concurrent;
|
||||
using System.IO.Compression;
|
||||
using System.Reflection;
|
||||
using Speckle.Newtonsoft.Json.Linq;
|
||||
using Speckle.Objects.Data;
|
||||
using Speckle.Objects.Geometry;
|
||||
using Speckle.Sdk.Common;
|
||||
using Speckle.Sdk.Host;
|
||||
using Speckle.Sdk.Models;
|
||||
@@ -10,49 +11,50 @@ namespace Speckle.Sdk.Serialization.Tests.Framework;
|
||||
|
||||
public static class TestFileManager
|
||||
{
|
||||
static TestFileManager()
|
||||
{
|
||||
TypeLoader.Reset();
|
||||
TypeLoader.Initialize(typeof(Base).Assembly, typeof(DataObject).Assembly, _assembly);
|
||||
}
|
||||
private static readonly Assembly s_assembly = Assembly.GetExecutingAssembly(); //test
|
||||
private static readonly Assembly s_speckleAssembly = typeof(Base).Assembly; //speckle.sdk
|
||||
private static readonly Assembly s_speckleObjectsAssembly = typeof(Polyline).Assembly; //speckle.sdk
|
||||
private static readonly Dictionary<string, IReadOnlyDictionary<string, string>> s_objects = new();
|
||||
|
||||
private static readonly Assembly _assembly = Assembly.GetExecutingAssembly();
|
||||
private static readonly Dictionary<string, IReadOnlyDictionary<string, string>> _objects = new();
|
||||
|
||||
public static async Task<IReadOnlyDictionary<string, string>> GetFileAsClosures(string fileName)
|
||||
public static IReadOnlyDictionary<string, string> GetFileAsClosures(string fileName)
|
||||
{
|
||||
if (!_objects.TryGetValue(fileName, out var closure))
|
||||
lock (s_objects)
|
||||
{
|
||||
var fullName = _assembly.GetManifestResourceNames().Single(x => x.EndsWith(fileName));
|
||||
var json = await ReadJson(fullName);
|
||||
closure = ReadAsObjects(json);
|
||||
_objects.Add(fileName, closure);
|
||||
if (!s_objects.TryGetValue(fileName, out var closure))
|
||||
{
|
||||
TypeLoader.Reset();
|
||||
TypeLoader.Initialize(s_assembly, s_speckleAssembly, s_speckleObjectsAssembly);
|
||||
var fullName = s_assembly.GetManifestResourceNames().Single(x => x.EndsWith(fileName));
|
||||
var json = ReadJson(fullName);
|
||||
closure = ReadAsObjects(json);
|
||||
s_objects.Add(fileName, closure);
|
||||
}
|
||||
return closure;
|
||||
}
|
||||
return closure;
|
||||
}
|
||||
|
||||
private static async Task<string> ReadJson(string fullName)
|
||||
private static string ReadJson(string fullName)
|
||||
{
|
||||
await using var stream = _assembly.GetManifestResourceStream(fullName).NotNull();
|
||||
using var stream = s_assembly.GetManifestResourceStream(fullName).NotNull();
|
||||
if (fullName.EndsWith(".gz"))
|
||||
{
|
||||
await using var z = new GZipStream(stream, CompressionMode.Decompress);
|
||||
using var z = new GZipStream(stream, CompressionMode.Decompress);
|
||||
using var reader2 = new StreamReader(z);
|
||||
return await reader2.ReadToEndAsync();
|
||||
return reader2.ReadToEnd();
|
||||
}
|
||||
using var reader = new StreamReader(stream);
|
||||
return await reader.ReadToEndAsync();
|
||||
return reader.ReadToEnd();
|
||||
}
|
||||
|
||||
private static Dictionary<string, string> ReadAsObjects(string json)
|
||||
private static ConcurrentDictionary<string, string> ReadAsObjects(string json)
|
||||
{
|
||||
var jsonObjects = new Dictionary<string, string>();
|
||||
var jsonObjects = new ConcurrentDictionary<string, string>();
|
||||
var array = JArray.Parse(json);
|
||||
foreach (var obj in array)
|
||||
{
|
||||
if (obj is JObject jobj)
|
||||
{
|
||||
jsonObjects.Add(jobj["id"].NotNull().Value<string>().NotNull(), jobj.ToString());
|
||||
jsonObjects.TryAdd(jobj["id"].NotNull().Value<string>().NotNull(), jobj.ToString());
|
||||
}
|
||||
}
|
||||
return jsonObjects;
|
||||
|
||||
@@ -1,13 +1,16 @@
|
||||
using System.Collections.Concurrent;
|
||||
using FluentAssertions;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Microsoft.Extensions.Logging.Abstractions;
|
||||
using Speckle.Newtonsoft.Json;
|
||||
using Speckle.Newtonsoft.Json.Linq;
|
||||
using Speckle.Objects.Geometry;
|
||||
using Speckle.Sdk.Common;
|
||||
using Speckle.Sdk.Host;
|
||||
using Speckle.Sdk.Models;
|
||||
using Speckle.Sdk.Serialisation;
|
||||
using Speckle.Sdk.Serialisation.Utilities;
|
||||
using Speckle.Sdk.Serialisation.V2;
|
||||
using Speckle.Sdk.Serialisation.V2.Receive;
|
||||
using Speckle.Sdk.Serialisation.V2.Send;
|
||||
using Speckle.Sdk.Serialization.Tests.Framework;
|
||||
@@ -17,32 +20,17 @@ namespace Speckle.Sdk.Serialization.Tests;
|
||||
|
||||
public class SerializationTests
|
||||
{
|
||||
private class TestLoader(string json) : IObjectLoader
|
||||
private readonly ISerializeProcessFactory _factory;
|
||||
|
||||
public SerializationTests()
|
||||
{
|
||||
public Task<(Json, IReadOnlyCollection<Id>)> GetAndCache(string rootId, DeserializeProcessOptions? options)
|
||||
{
|
||||
var childrenIds = ClosureParser.GetChildrenIds(new(json), default).Select(x => new Id(x)).ToList();
|
||||
return Task.FromResult<(Json, IReadOnlyCollection<Id>)>((new(json), childrenIds));
|
||||
}
|
||||
var serviceCollection = new ServiceCollection();
|
||||
serviceCollection.AddSpeckleSdk(new("Tests", "test"), "v3", typeof(TestClass).Assembly, typeof(Polyline).Assembly);
|
||||
var serviceProvider = serviceCollection.BuildServiceProvider();
|
||||
|
||||
public string? LoadId(string id) => null;
|
||||
|
||||
public void Dispose() { }
|
||||
_factory = serviceProvider.GetRequiredService<ISerializeProcessFactory>();
|
||||
}
|
||||
|
||||
/*
|
||||
[Test]
|
||||
[TestCase("RevitObject.json")]
|
||||
public async Task RunTest2(string fileName)
|
||||
{
|
||||
var fullName = _assembly.GetManifestResourceNames().Single(x => x.EndsWith(fileName));
|
||||
var json = await ReadJson(fullName);
|
||||
var closure = await ReadAsObjects(json);
|
||||
using DeserializeProcess sut = new(null, new TestLoader(json), new TestTransport(closure));
|
||||
var @base = await sut.Deserialize("551513ff4f3596024547fc818f1f3f70");
|
||||
@base.Should().NotBeNull();
|
||||
}*/
|
||||
|
||||
public class TestObjectLoader(IReadOnlyDictionary<string, string> idToObject) : IObjectLoader
|
||||
{
|
||||
public Task<(Json, IReadOnlyCollection<Id>)> GetAndCache(string rootId, DeserializeProcessOptions? options)
|
||||
@@ -66,7 +54,7 @@ public class SerializationTests
|
||||
[InlineData("RevitObject.json.gz")]
|
||||
public async Task Basic_Namespace_Validation(string fileName)
|
||||
{
|
||||
var closures = await TestFileManager.GetFileAsClosures(fileName);
|
||||
var closures = TestFileManager.GetFileAsClosures(fileName);
|
||||
var deserializer = new SpeckleObjectDeserializer
|
||||
{
|
||||
ReadTransport = new TestTransport(closures),
|
||||
@@ -106,7 +94,7 @@ public class SerializationTests
|
||||
[InlineData("RevitObject.json.gz")]
|
||||
public async Task Basic_Namespace_Validation_New(string fileName)
|
||||
{
|
||||
var closures = await TestFileManager.GetFileAsClosures(fileName);
|
||||
var closures = TestFileManager.GetFileAsClosures(fileName);
|
||||
await using var process = new DeserializeProcess(
|
||||
new TestObjectLoader(closures),
|
||||
null,
|
||||
@@ -165,7 +153,7 @@ public class SerializationTests
|
||||
[InlineData("RevitObject.json.gz", "3416d3fe01c9196115514c4a2f41617b", 7818)]
|
||||
public async Task Roundtrip_Test_Old(string fileName, string _, int count)
|
||||
{
|
||||
var closures = await TestFileManager.GetFileAsClosures(fileName);
|
||||
var closures = TestFileManager.GetFileAsClosures(fileName);
|
||||
var deserializer = new SpeckleObjectDeserializer
|
||||
{
|
||||
ReadTransport = new TestTransport(closures),
|
||||
@@ -199,7 +187,7 @@ public class SerializationTests
|
||||
[InlineData("RevitObject.json.gz", "3416d3fe01c9196115514c4a2f41617b", 7818, 4674)]
|
||||
public async Task Roundtrip_Test_New(string fileName, string rootId, int oldCount, int newCount)
|
||||
{
|
||||
var closures = await TestFileManager.GetFileAsClosures(fileName);
|
||||
var closures = TestFileManager.GetFileAsClosures(fileName);
|
||||
closures.Count.Should().Be(oldCount);
|
||||
|
||||
Base root;
|
||||
@@ -226,14 +214,12 @@ public class SerializationTests
|
||||
}
|
||||
|
||||
var newIdToJson = new ConcurrentDictionary<string, string>();
|
||||
|
||||
await using (
|
||||
var serializeProcess = new SerializeProcess(
|
||||
var serializeProcess = _factory.CreateSerializeProcess(
|
||||
new ConcurrentDictionary<Id, Json>(),
|
||||
newIdToJson,
|
||||
null,
|
||||
new DummySqLiteSendManager(),
|
||||
new DummySendServerObjectManager(newIdToJson),
|
||||
new BaseChildFinder(new BasePropertyGatherer()),
|
||||
new BaseSerializer(new DummySqLiteSendManager(), new ObjectSerializerFactory(new BasePropertyGatherer())),
|
||||
new NullLoggerFactory(),
|
||||
default,
|
||||
new SerializeProcessOptions(true, true, false, true)
|
||||
)
|
||||
|
||||
@@ -0,0 +1,36 @@
|
||||
using FluentAssertions;
|
||||
using Speckle.Sdk.Serialisation;
|
||||
using Speckle.Sdk.Serialisation.V2.Send;
|
||||
|
||||
namespace Speckle.Sdk.Serialization.Tests;
|
||||
|
||||
public class SerializationTypeTests
|
||||
{
|
||||
[Fact]
|
||||
public void Json()
|
||||
{
|
||||
var json = new Json("{}");
|
||||
json.ToString().Should().Be("{}");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Id()
|
||||
{
|
||||
var id = new Id("id");
|
||||
id.ToString().Should().Be("id");
|
||||
id.Equals(new Id("id")).Should().BeTrue();
|
||||
id.Equals(new Id("id2")).Should().BeFalse();
|
||||
id.GetHashCode().Should().Be("id".GetHashCode());
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void BaseItem()
|
||||
{
|
||||
var id = new Id("id");
|
||||
var json = new Json("{}");
|
||||
var baseItem = new BaseItem(id, json, false, new Dictionary<Id, int>());
|
||||
baseItem.Equals(new BaseItem(id, json, false, new Dictionary<Id, int>())).Should().BeTrue();
|
||||
baseItem.Equals(new BaseItem(new Id("id2"), json, false, new Dictionary<Id, int>())).Should().BeFalse();
|
||||
baseItem.GetHashCode().Should().Be(id.GetHashCode());
|
||||
}
|
||||
}
|
||||
+10
@@ -0,0 +1,10 @@
|
||||
{
|
||||
"6f422a35-6183-48b9-8021-d22ec97e8674": {
|
||||
"id": "6f422a35-6183-48b9-8021-d22ec97e8674",
|
||||
"value": true
|
||||
},
|
||||
"ef2f7ea0-495a-46af-a9ad-f18a8a298597": {
|
||||
"id": "ef2f7ea0-495a-46af-a9ad-f18a8a298597",
|
||||
"value": true
|
||||
}
|
||||
}
|
||||
+4
@@ -0,0 +1,4 @@
|
||||
{
|
||||
"id": "6f422a35-6183-48b9-8021-d22ec97e8674",
|
||||
"value": true
|
||||
}
|
||||
+4
@@ -0,0 +1,4 @@
|
||||
{
|
||||
"6f422a35-6183-48b9-8021-d22ec97e8674": true,
|
||||
"ef2f7ea0-495a-46af-a9ad-f18a8a298597": false
|
||||
}
|
||||
@@ -0,0 +1,216 @@
|
||||
using System.Net;
|
||||
using System.Text;
|
||||
using FluentAssertions;
|
||||
using HttpMultipartParser;
|
||||
using Moq;
|
||||
using RichardSzalay.MockHttp;
|
||||
using Speckle.Newtonsoft.Json;
|
||||
using Speckle.Newtonsoft.Json.Linq;
|
||||
using Speckle.Sdk.Common;
|
||||
using Speckle.Sdk.Helpers;
|
||||
using Speckle.Sdk.Logging;
|
||||
using Speckle.Sdk.Serialisation;
|
||||
using Speckle.Sdk.Serialisation.V2;
|
||||
using Speckle.Sdk.Serialisation.V2.Send;
|
||||
using Speckle.Sdk.Testing;
|
||||
|
||||
namespace Speckle.Sdk.Serialization.Tests;
|
||||
|
||||
public class ServerObjectManagerTests : MoqTest
|
||||
{
|
||||
[Fact]
|
||||
public async Task DownloadObjects()
|
||||
{
|
||||
var id = Guid.Parse("6f422a35-6183-48b9-8021-d22ec97e8674").ToString();
|
||||
var id2 = Guid.Parse("ef2f7ea0-495a-46af-a9ad-f18a8a298597").ToString();
|
||||
var ct = new CancellationToken();
|
||||
var token = "token";
|
||||
var timeout = 2;
|
||||
var uri = new Uri("http://localhost");
|
||||
var streamId = "streamId";
|
||||
var jObject = new JObject { { "id", id }, { "value", true } };
|
||||
var jObject2 = new JObject { { "id", id2 }, { "value", true } };
|
||||
var mockHttp = new MockHttpMessageHandler();
|
||||
Dictionary<string, string> postParameters = new()
|
||||
{
|
||||
{ "objects", JsonConvert.SerializeObject(new List<string> { id, id2 }) },
|
||||
};
|
||||
|
||||
string serializedPayload = JsonConvert.SerializeObject(postParameters);
|
||||
mockHttp
|
||||
.When(HttpMethod.Post, $"http://localhost/api/getobjects/{streamId}")
|
||||
.WithContent(serializedPayload)
|
||||
.Respond(
|
||||
"application/json",
|
||||
$"{id}\t{jObject.ToString(Formatting.None)}\n{id2}\t{jObject2.ToString(Formatting.None)}\n"
|
||||
);
|
||||
var httpClient = mockHttp.ToHttpClient();
|
||||
var http = Create<ISpeckleHttp>();
|
||||
http.Setup(x => x.CreateHttpClient(It.IsAny<HttpClientHandler>(), timeout, token)).Returns(httpClient);
|
||||
|
||||
var activityFactory = Create<ISdkActivityFactory>();
|
||||
activityFactory.Setup(x => x.Start(null, "DownloadObjects")).Returns((ISdkActivity?)null);
|
||||
|
||||
var serverObjectManager = new ServerObjectManager(
|
||||
http.Object,
|
||||
activityFactory.Object,
|
||||
uri,
|
||||
streamId,
|
||||
token,
|
||||
new(timeout: TimeSpan.FromSeconds(timeout))
|
||||
);
|
||||
var results = serverObjectManager.DownloadObjects(new List<string> { id, id2 }, null, ct);
|
||||
var objects = new JObject();
|
||||
await foreach (var (x, json) in results)
|
||||
{
|
||||
objects.Add(x, JToken.Parse(json));
|
||||
}
|
||||
|
||||
await VerifyJson(objects.ToString(Formatting.Indented));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task DownloadSingleObject()
|
||||
{
|
||||
var id = Guid.Parse("6f422a35-6183-48b9-8021-d22ec97e8674").ToString();
|
||||
var ct = new CancellationToken();
|
||||
var token = "token";
|
||||
var timeout = 2;
|
||||
var uri = new Uri("http://localhost");
|
||||
var streamId = "streamId";
|
||||
var jObject = new JObject { { "id", id }, { "value", true } };
|
||||
var mockHttp = new MockHttpMessageHandler();
|
||||
mockHttp
|
||||
.When(HttpMethod.Get, $"http://localhost/objects/{streamId}/{id}/single")
|
||||
.Respond("application/json", $"{jObject.ToString(Formatting.None)}\n");
|
||||
var httpClient = mockHttp.ToHttpClient();
|
||||
var http = Create<ISpeckleHttp>();
|
||||
http.Setup(x => x.CreateHttpClient(It.IsAny<HttpClientHandler>(), timeout, token)).Returns(httpClient);
|
||||
|
||||
var activityFactory = Create<ISdkActivityFactory>();
|
||||
activityFactory.Setup(x => x.Start(null, "DownloadSingleObject")).Returns((ISdkActivity?)null);
|
||||
|
||||
var serverObjectManager = new ServerObjectManager(
|
||||
http.Object,
|
||||
activityFactory.Object,
|
||||
uri,
|
||||
streamId,
|
||||
token,
|
||||
new(timeout: TimeSpan.FromSeconds(timeout))
|
||||
);
|
||||
var json = await serverObjectManager.DownloadSingleObject(id, null, ct);
|
||||
await VerifyJson(json);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task HasObjects()
|
||||
{
|
||||
var id = Guid.Parse("6f422a35-6183-48b9-8021-d22ec97e8674").ToString();
|
||||
var id2 = Guid.Parse("ef2f7ea0-495a-46af-a9ad-f18a8a298597").ToString();
|
||||
var ct = new CancellationToken();
|
||||
var token = "token";
|
||||
var timeout = 2;
|
||||
var uri = new Uri("http://localhost");
|
||||
var streamId = "streamId";
|
||||
var mockHttp = new MockHttpMessageHandler();
|
||||
Dictionary<string, string> postParameters = new()
|
||||
{
|
||||
{ "objects", JsonConvert.SerializeObject(new List<string> { id, id2 }) },
|
||||
};
|
||||
|
||||
Dictionary<string, bool> responseParameters = new() { { id, true }, { id2, false } };
|
||||
string serializedPayload = JsonConvert.SerializeObject(postParameters);
|
||||
mockHttp
|
||||
.When(HttpMethod.Post, $"http://localhost/api/diff/{streamId}")
|
||||
.WithContent(serializedPayload)
|
||||
.Respond("application/json", JsonConvert.SerializeObject(responseParameters));
|
||||
var httpClient = mockHttp.ToHttpClient();
|
||||
var http = Create<ISpeckleHttp>();
|
||||
http.Setup(x => x.CreateHttpClient(It.IsAny<HttpClientHandler>(), timeout, token)).Returns(httpClient);
|
||||
|
||||
var activityFactory = Create<ISdkActivityFactory>();
|
||||
activityFactory.Setup(x => x.Start(null, "HasObjects")).Returns((ISdkActivity?)null);
|
||||
|
||||
var serverObjectManager = new ServerObjectManager(
|
||||
http.Object,
|
||||
activityFactory.Object,
|
||||
uri,
|
||||
streamId,
|
||||
token,
|
||||
new(timeout: TimeSpan.FromSeconds(timeout))
|
||||
);
|
||||
var results = await serverObjectManager.HasObjects(new List<string> { id, id2 }, ct);
|
||||
|
||||
await Verify(results);
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData(true)]
|
||||
[InlineData(false)]
|
||||
public async Task UploadObjects(bool compressed)
|
||||
{
|
||||
var id = Guid.Parse("6f422a35-6183-48b9-8021-d22ec97e8674").ToString();
|
||||
var id2 = Guid.Parse("ef2f7ea0-495a-46af-a9ad-f18a8a298597").ToString();
|
||||
var ct = new CancellationToken();
|
||||
var token = "token";
|
||||
var timeout = 2;
|
||||
var uri = new Uri("http://localhost");
|
||||
var streamId = "streamId";
|
||||
var jObject = new JObject { { "id", id }, { "value", true } };
|
||||
var jObject2 = new JObject { { "id", id2 }, { "value", true } };
|
||||
|
||||
var mockHttp = new MockHttpMessageHandler();
|
||||
mockHttp
|
||||
.When(HttpMethod.Post, $"http://localhost/objects/{streamId}")
|
||||
.Respond(x => HandleUploadRequest(x, compressed, new List<JObject> { jObject, jObject2 }));
|
||||
var httpClient = mockHttp.ToHttpClient();
|
||||
var http = Create<ISpeckleHttp>();
|
||||
http.Setup(x => x.CreateHttpClient(It.IsAny<HttpClientHandler>(), timeout, token)).Returns(httpClient);
|
||||
|
||||
var activityFactory = Create<ISdkActivityFactory>();
|
||||
activityFactory.Setup(x => x.Start(null, "UploadObjects")).Returns((ISdkActivity?)null);
|
||||
|
||||
var serverObjectManager = new ServerObjectManager(
|
||||
http.Object,
|
||||
activityFactory.Object,
|
||||
uri,
|
||||
streamId,
|
||||
token,
|
||||
new(timeout: TimeSpan.FromSeconds(timeout), boundary: "boundary")
|
||||
);
|
||||
await serverObjectManager.UploadObjects(
|
||||
new List<BaseItem>
|
||||
{
|
||||
new(new(id), new Json(jObject.ToString()), true, null),
|
||||
new(new(id2), new Json(jObject2.ToString()), true, null),
|
||||
},
|
||||
compressed,
|
||||
null,
|
||||
ct
|
||||
);
|
||||
}
|
||||
|
||||
private async Task<HttpResponseMessage> HandleUploadRequest(
|
||||
HttpRequestMessage req,
|
||||
bool compressed,
|
||||
List<JObject> objects
|
||||
)
|
||||
{
|
||||
var content = await req.Content.NotNull().ReadAsStringAsync().ConfigureAwait(false);
|
||||
var stream = new MemoryStream(Encoding.Default.GetBytes(content));
|
||||
var formData = await MultipartFormDataParser.ParseAsync(stream, "boundary");
|
||||
formData.Files.Count.Should().Be(1);
|
||||
var file = formData.Files[0];
|
||||
file.FileName.Should().Be("batch-0");
|
||||
// file.ContentType.Should().Be("application/json");
|
||||
if (!compressed)
|
||||
{
|
||||
var dataStream = file.Data;
|
||||
using var reader = new StreamReader(dataStream);
|
||||
var s = await reader.ReadToEndAsync();
|
||||
JsonConvert.DeserializeObject<List<JObject>>(s).Should().BeEquivalentTo(objects);
|
||||
}
|
||||
|
||||
return new HttpResponseMessage(HttpStatusCode.OK);
|
||||
}
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net8.0</TargetFramework>
|
||||
@@ -9,7 +9,11 @@
|
||||
<ItemGroup>
|
||||
<PackageReference Include="altcover" />
|
||||
<PackageReference Include="AwesomeAssertions" />
|
||||
<PackageReference Include="HttpMultipartParser" />
|
||||
<PackageReference Include="Microsoft.Extensions.DependencyInjection" />
|
||||
<PackageReference Include="Microsoft.NET.Test.Sdk" />
|
||||
<PackageReference Include="Moq" />
|
||||
<PackageReference Include="RichardSzalay.MockHttp" />
|
||||
<PackageReference Include="xunit.assert" />
|
||||
<PackageReference Include="xunit.runner.visualstudio"/>
|
||||
</ItemGroup>
|
||||
|
||||
@@ -10,9 +10,29 @@
|
||||
},
|
||||
"AwesomeAssertions": {
|
||||
"type": "Direct",
|
||||
"requested": "[8.0.0, )",
|
||||
"resolved": "8.0.0",
|
||||
"contentHash": "6fWiV7mGZUzZXzeiW3hWF0nJokuuNm4hnzuqbM3IXHqGYkWnHl65+wNpuQ73xfJXClX0fmfKcTdQ2Ula719IDg=="
|
||||
"requested": "[8.1.0, )",
|
||||
"resolved": "8.1.0",
|
||||
"contentHash": "IfNC4cpXPi9tclWvuNO9lfkuIxJsUTLTS1NXto55jDrAUQJYl0zLI9ByISrfkbBE2Xtg+IWaAXQ6jnUx3anDuw=="
|
||||
},
|
||||
"HttpMultipartParser": {
|
||||
"type": "Direct",
|
||||
"requested": "[9.0.0, )",
|
||||
"resolved": "9.0.0",
|
||||
"contentHash": "WeGKDK62waagwo9nokRY62DrLukwVCNXOPVjrzi/qSS73D+B6zPOBkImsFqzhvRNweIobR74js9M2HTV+PTeIg==",
|
||||
"dependencies": {
|
||||
"Microsoft.CSharp": "4.7.0",
|
||||
"Microsoft.IO.RecyclableMemoryStream": "3.0.1",
|
||||
"System.Buffers": "4.6.0"
|
||||
}
|
||||
},
|
||||
"Microsoft.Extensions.DependencyInjection": {
|
||||
"type": "Direct",
|
||||
"requested": "[2.2.0, )",
|
||||
"resolved": "2.2.0",
|
||||
"contentHash": "MZtBIwfDFork5vfjpJdG5g8wuJFt7d/y3LOSVVtDK/76wlbtz6cjltfKHqLx2TKVqTj5/c41t77m1+h20zqtPA==",
|
||||
"dependencies": {
|
||||
"Microsoft.Extensions.DependencyInjection.Abstractions": "2.2.0"
|
||||
}
|
||||
},
|
||||
"Microsoft.NET.Test.Sdk": {
|
||||
"type": "Direct",
|
||||
@@ -34,12 +54,27 @@
|
||||
"Microsoft.SourceLink.Common": "8.0.0"
|
||||
}
|
||||
},
|
||||
"Moq": {
|
||||
"type": "Direct",
|
||||
"requested": "[4.20.72, )",
|
||||
"resolved": "4.20.72",
|
||||
"contentHash": "EA55cjyNn8eTNWrgrdZJH5QLFp2L43oxl1tlkoYUKIE9pRwL784OWiTXeCV5ApS+AMYEAlt7Fo03A2XfouvHmQ==",
|
||||
"dependencies": {
|
||||
"Castle.Core": "5.1.1"
|
||||
}
|
||||
},
|
||||
"PolySharp": {
|
||||
"type": "Direct",
|
||||
"requested": "[1.15.0, )",
|
||||
"resolved": "1.15.0",
|
||||
"contentHash": "FbU0El+EEjdpuIX4iDbeS7ki1uzpJPx8vbqOzEtqnl1GZeAGJfq+jCbxeJL2y0EPnUNk8dRnnqR2xnYXg9Tf+g=="
|
||||
},
|
||||
"RichardSzalay.MockHttp": {
|
||||
"type": "Direct",
|
||||
"requested": "[7.0.0, )",
|
||||
"resolved": "7.0.0",
|
||||
"contentHash": "QwnauYiaywp65QKFnP+wvgiQ2D8Pv888qB2dyfd7MSVDF06sIvxqASenk+RxsWybyyt+Hu1Y251wQxpHTv3UYg=="
|
||||
},
|
||||
"Speckle.InterfaceGenerator": {
|
||||
"type": "Direct",
|
||||
"requested": "[0.9.6, )",
|
||||
@@ -60,22 +95,30 @@
|
||||
},
|
||||
"Argon": {
|
||||
"type": "Transitive",
|
||||
"resolved": "0.26.0",
|
||||
"contentHash": "n7btGXdtRyprGnpLMpBs6rLScxlvPtVWwmTR8h7CtJvpZXBGhGvibEdZxRjeTZNrwf403jJ0ZPpt35Pz/NaNsw=="
|
||||
"resolved": "0.27.0",
|
||||
"contentHash": "LtZKATYeTwDyYq1AXrgVU/ly+nI6GvE0GK1isJYFPQOnb2uHUxvDA+yh40QYaITGTLViXK7rbWhNKpbZ5pb9XA=="
|
||||
},
|
||||
"Castle.Core": {
|
||||
"type": "Transitive",
|
||||
"resolved": "5.1.1",
|
||||
"contentHash": "rpYtIczkzGpf+EkZgDr9CClTdemhsrwA/W5hMoPjLkRFnXzH44zDLoovXeKtmxb1ykXK9aJVODSpiJml8CTw2g==",
|
||||
"dependencies": {
|
||||
"System.Diagnostics.EventLog": "6.0.0"
|
||||
}
|
||||
},
|
||||
"DiffEngine": {
|
||||
"type": "Transitive",
|
||||
"resolved": "15.9.0",
|
||||
"contentHash": "shE6+tO4w5BmQTX0z+WnUV4UfmPNn6oTqBINbkts6OP0Icyx5WROSDzjjb95EwVYC4IAS+PxxS4Vbapxz4hkdw==",
|
||||
"resolved": "16.1.0",
|
||||
"contentHash": "ImEFC6BN62paN0N7v8vrLY3x/LpfbJaJy5yDtL+/L2As6FI1npGJcFZwzz1A7pdDjIYPOXE91qv6BpgEUGjDkA==",
|
||||
"dependencies": {
|
||||
"EmptyFiles": "8.7.1",
|
||||
"System.Management": "9.0.1"
|
||||
"EmptyFiles": "8.8.0",
|
||||
"System.Management": "8.0.0"
|
||||
}
|
||||
},
|
||||
"EmptyFiles": {
|
||||
"type": "Transitive",
|
||||
"resolved": "8.7.1",
|
||||
"contentHash": "C8pvg0TvG2Mkn5LGNFGkFgFu8SUgYFwiu8U3y34qGQnnwKmGnlQTfTIUrtzfSjPxA4q7L/kRu09U5p32otZ2Aw=="
|
||||
"resolved": "8.8.0",
|
||||
"contentHash": "d0pgc/vMyKgQ9T3qiiJBn1uYUSZ1/OShh6tySnNSkELRSgM4A4IOrpdQhLqwCkPwYvdJqzKuxQ6wn3MQAd4GNA=="
|
||||
},
|
||||
"FSharp.Core": {
|
||||
"type": "Transitive",
|
||||
@@ -169,6 +212,11 @@
|
||||
"System.Runtime.CompilerServices.Unsafe": "4.5.1"
|
||||
}
|
||||
},
|
||||
"Microsoft.IO.RecyclableMemoryStream": {
|
||||
"type": "Transitive",
|
||||
"resolved": "3.0.1",
|
||||
"contentHash": "s/s20YTVY9r9TPfTrN5g8zPF1YhwxyqO6PxUkrYTGI2B+OGPe9AdajWZrLhFqXIvqIW23fnUE4+ztrUWNU1+9g=="
|
||||
},
|
||||
"Microsoft.SourceLink.Common": {
|
||||
"type": "Transitive",
|
||||
"resolved": "8.0.0",
|
||||
@@ -240,27 +288,37 @@
|
||||
"SQLitePCLRaw.core": "2.1.4"
|
||||
}
|
||||
},
|
||||
"System.Buffers": {
|
||||
"type": "Transitive",
|
||||
"resolved": "4.6.0",
|
||||
"contentHash": "lN6tZi7Q46zFzAbRYXTIvfXcyvQQgxnY7Xm6C6xQ9784dEL1amjM6S6Iw4ZpsvesAKnRVsM4scrDQaDqSClkjA=="
|
||||
},
|
||||
"System.CodeDom": {
|
||||
"type": "Transitive",
|
||||
"resolved": "9.0.1",
|
||||
"contentHash": "2J5uq+2smnj+u1jlyVJ6BGGqaK9fHcK/EwN7mbsuPqTI6dZr86br8Cg6o/5B+icQ9ANTvTDpJjnhDNtYYZijHQ=="
|
||||
"resolved": "8.0.0",
|
||||
"contentHash": "WTlRjL6KWIMr/pAaq3rYqh0TJlzpouaQ/W1eelssHgtlwHAH25jXTkUphTYx9HaIIf7XA6qs/0+YhtLEQRkJ+Q=="
|
||||
},
|
||||
"System.ComponentModel.Annotations": {
|
||||
"type": "Transitive",
|
||||
"resolved": "4.5.0",
|
||||
"contentHash": "UxYQ3FGUOtzJ7LfSdnYSFd7+oEv6M8NgUatatIN2HxNtDdlcvFAf+VIq4Of9cDMJEJC0aSRv/x898RYhB4Yppg=="
|
||||
},
|
||||
"System.Diagnostics.EventLog": {
|
||||
"type": "Transitive",
|
||||
"resolved": "6.0.0",
|
||||
"contentHash": "lcyUiXTsETK2ALsZrX+nWuHSIQeazhqPphLfaRxzdGaG93+0kELqpgEHtwWOlQe7+jSFnKwaCAgL4kjeZCQJnw=="
|
||||
},
|
||||
"System.IO.Hashing": {
|
||||
"type": "Transitive",
|
||||
"resolved": "9.0.1",
|
||||
"contentHash": "jY+E/PElNWQiazN0YHqZGvcSedcZ4Wt0Os1nnJ2SzR3gWZlhNRDkSXOhuHJcLuImD8SrJQQ8TfU0W4mVcit2hg=="
|
||||
"resolved": "9.0.3",
|
||||
"contentHash": "BrMGzDRLz410PE4qC8UeKeAc0hFRjBkiCUOLTwuod65NAjqg5tDNqYU7gP0A09taEXtecB+HJc1NNnnTjsKFAQ=="
|
||||
},
|
||||
"System.Management": {
|
||||
"type": "Transitive",
|
||||
"resolved": "9.0.1",
|
||||
"contentHash": "CLEo9O6FuO4GQ3ZQkGssg9CJ2w2TN7GMFf3wHTc7YVWJV4xoyJRPw+XIDQnCcSUJCrHhrAWOO60cAX29EV5LFQ==",
|
||||
"resolved": "8.0.0",
|
||||
"contentHash": "jrK22i5LRzxZCfGb+tGmke2VH7oE0DvcDlJ1HAKYU8cPmD8XnpUT0bYn2Gy98GEhGjtfbR/sxKTVb+dE770pfA==",
|
||||
"dependencies": {
|
||||
"System.CodeDom": "9.0.1"
|
||||
"System.CodeDom": "8.0.0"
|
||||
}
|
||||
},
|
||||
"System.Memory": {
|
||||
@@ -298,13 +356,13 @@
|
||||
},
|
||||
"Verify": {
|
||||
"type": "Transitive",
|
||||
"resolved": "28.10.1",
|
||||
"contentHash": "2B/VtFN5jtF5g28kaM4GdJZTwb3pisd4+wL2NEPi9ZYe2lghWsCzS30V6LF1ILApLBfAorAstkU/Vw3sDWRqrg==",
|
||||
"resolved": "29.2.0",
|
||||
"contentHash": "EhhwhXIeip9AJGWRPXh47NAUoiELnWzeBnAzFSl0+ryAfijTV1T+B4m6P6GbheWQ1CJ1cC1ZFLzgH276D5Bu3A==",
|
||||
"dependencies": {
|
||||
"Argon": "0.26.0",
|
||||
"DiffEngine": "15.9.0",
|
||||
"Argon": "0.27.0",
|
||||
"DiffEngine": "16.1.0",
|
||||
"SimpleInfoName": "3.1.0",
|
||||
"System.IO.Hashing": "9.0.1"
|
||||
"System.IO.Hashing": "9.0.3"
|
||||
}
|
||||
},
|
||||
"xunit.abstractions": {
|
||||
@@ -312,6 +370,20 @@
|
||||
"resolved": "2.0.3",
|
||||
"contentHash": "pot1I4YOxlWjIb5jmwvvQNbTrZ3lJQ+jUGkGjWE3hEFM0l5gOnBWS+H3qsex68s5cO52g+44vpGzhAt+42vwKg=="
|
||||
},
|
||||
"xunit.analyzers": {
|
||||
"type": "Transitive",
|
||||
"resolved": "1.18.0",
|
||||
"contentHash": "OtFMHN8yqIcYP9wcVIgJrq01AfTxijjAqVDy/WeQVSyrDC1RzBWeQPztL49DN2syXRah8TYnfvk035s7L95EZQ=="
|
||||
},
|
||||
"xunit.core": {
|
||||
"type": "Transitive",
|
||||
"resolved": "2.9.3",
|
||||
"contentHash": "BiAEvqGvyme19wE0wTKdADH+NloYqikiU0mcnmiNyXaF9HyHmE6sr/3DC5vnBkgsWaE6yPyWszKSPSApWdRVeQ==",
|
||||
"dependencies": {
|
||||
"xunit.extensibility.core": "[2.9.3]",
|
||||
"xunit.extensibility.execution": "[2.9.3]"
|
||||
}
|
||||
},
|
||||
"xunit.extensibility.core": {
|
||||
"type": "Transitive",
|
||||
"resolved": "2.9.3",
|
||||
@@ -354,9 +426,11 @@
|
||||
"type": "Project",
|
||||
"dependencies": {
|
||||
"Microsoft.NET.Test.Sdk": "[17.13.0, )",
|
||||
"Moq": "[4.20.72, )",
|
||||
"Speckle.Sdk": "[1.0.0, )",
|
||||
"Verify.Quibble": "[2.1.1, )",
|
||||
"Verify.Xunit": "[28.10.1, )",
|
||||
"Verify.Xunit": "[29.2.0, )",
|
||||
"xunit": "[2.9.3, )",
|
||||
"xunit.runner.visualstudio": "[3.0.2, )"
|
||||
}
|
||||
},
|
||||
@@ -430,18 +504,29 @@
|
||||
},
|
||||
"Verify.Xunit": {
|
||||
"type": "CentralTransitive",
|
||||
"requested": "[28.10.1, )",
|
||||
"resolved": "28.10.1",
|
||||
"contentHash": "mkG7agMlx8oAEGcHoRY72hyDyNTdLIrzbfmniXFQgQ3yKulAHSYvYc9quzhpg0Sy+jb3svbdLqnRSg0VRhet3A==",
|
||||
"requested": "[29.2.0, )",
|
||||
"resolved": "29.2.0",
|
||||
"contentHash": "MdcslVf40AzSA319ZHMzR+U4JqyquX28JFSrI9zA89yeZNaNcaSIb5PmE0XZ6p60Iy7eRYtnGEgSDimEUeXHZw==",
|
||||
"dependencies": {
|
||||
"Argon": "0.26.0",
|
||||
"DiffEngine": "15.9.0",
|
||||
"Argon": "0.27.0",
|
||||
"DiffEngine": "16.1.0",
|
||||
"SimpleInfoName": "3.1.0",
|
||||
"System.IO.Hashing": "9.0.1",
|
||||
"Verify": "28.10.1",
|
||||
"System.IO.Hashing": "9.0.3",
|
||||
"Verify": "29.2.0",
|
||||
"xunit.abstractions": "2.0.3",
|
||||
"xunit.extensibility.execution": "2.9.3"
|
||||
}
|
||||
},
|
||||
"xunit": {
|
||||
"type": "CentralTransitive",
|
||||
"requested": "[2.9.3, )",
|
||||
"resolved": "2.9.3",
|
||||
"contentHash": "TlXQBinK35LpOPKHAqbLY4xlEen9TBafjs0V5KnA4wZsoQLQJiirCR4CbIXvOH8NzkW4YeJKP5P/Bnrodm0h9Q==",
|
||||
"dependencies": {
|
||||
"xunit.analyzers": "1.18.0",
|
||||
"xunit.assert": "2.9.3",
|
||||
"xunit.core": "[2.9.3]"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,32 +0,0 @@
|
||||
using Speckle.Sdk.Common;
|
||||
|
||||
namespace Speckle.Sdk.Testing.Framework;
|
||||
|
||||
public class AggregationExceptionScrubber : WriteOnlyJsonConverter<AggregateException>
|
||||
{
|
||||
private static readonly ExceptionScrubber _innerScrubber = new();
|
||||
|
||||
public override void Write(VerifyJsonWriter writer, AggregateException exception)
|
||||
{
|
||||
writer.WriteStartObject();
|
||||
|
||||
writer.WriteMember(exception, exception.GetType().FullName, "Type");
|
||||
if (exception.InnerExceptions.Count == 1)
|
||||
{
|
||||
writer.WritePropertyName("InnerException");
|
||||
_innerScrubber.Write(writer, exception.InnerException.NotNull());
|
||||
}
|
||||
else
|
||||
{
|
||||
writer.WritePropertyName("InnerExceptions");
|
||||
writer.WriteStartArray();
|
||||
foreach (var innerException in exception.InnerExceptions)
|
||||
{
|
||||
_innerScrubber.Write(writer, innerException);
|
||||
}
|
||||
writer.WriteEndArray();
|
||||
}
|
||||
|
||||
writer.WriteEndObject();
|
||||
}
|
||||
}
|
||||
@@ -37,14 +37,14 @@ public class DummyReceiveServerObjectManager(IReadOnlyDictionary<string, string>
|
||||
) => throw new NotImplementedException();
|
||||
|
||||
public Task UploadObjects(
|
||||
IReadOnlyList<BaseItem> objects,
|
||||
IReadOnlyList<BaseItem> objectsToUpload,
|
||||
bool compressPayloads,
|
||||
IProgress<ProgressArgs>? progress,
|
||||
CancellationToken cancellationToken
|
||||
)
|
||||
{
|
||||
long totalBytes = 0;
|
||||
foreach (var item in objects)
|
||||
foreach (var item in objectsToUpload)
|
||||
{
|
||||
totalBytes += Encoding.Default.GetByteCount(item.Json.Value);
|
||||
}
|
||||
|
||||
@@ -22,10 +22,7 @@ public class DummySendServerObjectManager(ConcurrentDictionary<string, string> s
|
||||
public Task<Dictionary<string, bool>> HasObjects(
|
||||
IReadOnlyCollection<string> objectIds,
|
||||
CancellationToken cancellationToken
|
||||
)
|
||||
{
|
||||
return Task.FromResult(objectIds.Distinct().ToDictionary(x => x, savedObjects.ContainsKey));
|
||||
}
|
||||
) => Task.FromResult(objectIds.Distinct().ToDictionary(x => x, _ => false));
|
||||
|
||||
public Task UploadObjects(
|
||||
IReadOnlyList<BaseItem> objects,
|
||||
|
||||
@@ -1,18 +0,0 @@
|
||||
using Argon;
|
||||
|
||||
namespace Speckle.Sdk.Testing.Framework;
|
||||
|
||||
public class ExceptionScrubber : WriteOnlyJsonConverter<Exception>
|
||||
{
|
||||
public override void Write(VerifyJsonWriter writer, Exception value)
|
||||
{
|
||||
var ex = new JObject
|
||||
{
|
||||
["Type"] = value.GetType().FullName,
|
||||
["Message"] = value.Message,
|
||||
["Source"] = value.Source?.Trim(),
|
||||
};
|
||||
//intentionally removed stacktrace to avoid errors on different machines and line numbers
|
||||
writer.WriteRawValue(ex.ToString(Formatting.Indented));
|
||||
}
|
||||
}
|
||||
@@ -1,24 +0,0 @@
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using Argon;
|
||||
using Speckle.Sdk.Common;
|
||||
using Speckle.Sdk.Serialisation;
|
||||
|
||||
namespace Speckle.Sdk.Testing.Framework;
|
||||
|
||||
[SuppressMessage("Design", "CA1062:Validate arguments of public methods")]
|
||||
public class IdStringSerializer : JsonConverter
|
||||
{
|
||||
public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer)
|
||||
{
|
||||
var id = (Id)value;
|
||||
writer.WriteValue(id.Value);
|
||||
}
|
||||
|
||||
public override object? ReadJson(JsonReader reader, Type type, object? existingValue, JsonSerializer serializer)
|
||||
{
|
||||
var json = reader.ReadAsString();
|
||||
return new Id(json.NotNull());
|
||||
}
|
||||
|
||||
public override bool CanConvert(Type type) => typeof(Id) == type;
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using Moq;
|
||||
|
||||
namespace Speckle.Sdk.Testing;
|
||||
|
||||
[ExcludeFromCodeCoverage]
|
||||
public abstract class MoqTest : IDisposable
|
||||
{
|
||||
protected MoqTest() => Repository = new(MockBehavior.Strict);
|
||||
|
||||
public void Dispose() => Repository.VerifyAll();
|
||||
|
||||
protected MockRepository Repository { get; private set; } = new(MockBehavior.Strict);
|
||||
|
||||
protected Mock<T> Create<T>(MockBehavior behavior = MockBehavior.Strict)
|
||||
where T : class => Repository.Create<T>(behavior);
|
||||
}
|
||||
@@ -7,8 +7,10 @@
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Microsoft.NET.Test.Sdk" />
|
||||
<PackageReference Include="Moq" />
|
||||
<PackageReference Include="Verify.Quibble" />
|
||||
<PackageReference Include="Verify.Xunit" />
|
||||
<PackageReference Include="xunit" />
|
||||
<PackageReference Include="xunit.runner.visualstudio"/>
|
||||
</ItemGroup>
|
||||
|
||||
|
||||
@@ -25,13 +25,7 @@ public static class SpeckleVerify
|
||||
VerifierSettings.DontIgnoreEmptyCollections();
|
||||
VerifierSettings.SortPropertiesAlphabetically();
|
||||
VerifierSettings.SortJsonObjects();
|
||||
VerifierSettings.AddExtraSettings(x =>
|
||||
{
|
||||
var existing = x.Converters.OfType<WriteOnlyJsonConverter<AggregateException>>().First();
|
||||
x.Converters.Remove(existing);
|
||||
x.Converters.Add(new AggregationExceptionScrubber());
|
||||
x.Converters.Add(new ExceptionScrubber());
|
||||
});
|
||||
VerifierSettings.IgnoreStackTrace();
|
||||
VerifyQuibble.Initialize();
|
||||
}
|
||||
|
||||
@@ -42,16 +36,19 @@ public static class SpeckleVerify
|
||||
Converters = { new JsonStringSerializer() },
|
||||
};
|
||||
|
||||
private static async Task VerifyJsonObjects(IDictionary<string, Json> objects, string sourceFile) =>
|
||||
await VerifyJson(JObject.FromObject(objects, _jsonSerializer).ToString(), sourceFile: sourceFile);
|
||||
private static SettingsTask VerifyJsonObjects(IDictionary<string, Json> objects, string sourceFile) =>
|
||||
VerifyJson(JObject.FromObject(objects, _jsonSerializer).ToString(), sourceFile: sourceFile);
|
||||
|
||||
public static async Task VerifyJsonDictionary(
|
||||
public static SettingsTask VerifyJsonDictionary(
|
||||
IDictionary<string, string> objects,
|
||||
[CallerFilePath] string sourceFile = ""
|
||||
) => await VerifyJsonObjects(objects.ToDictionary(x => x.Key, x => new Json(x.Value)), sourceFile);
|
||||
) => VerifyJsonObjects(objects.ToDictionary(x => x.Key, x => new Json(x.Value)), sourceFile);
|
||||
|
||||
public static async Task VerifyJsonDictionary(
|
||||
public static SettingsTask VerifyJsonDictionary(
|
||||
IDictionary<Id, Json> objects,
|
||||
[CallerFilePath] string sourceFile = ""
|
||||
) => await VerifyJsonObjects(objects.ToDictionary(x => x.Key.Value, x => x.Value), sourceFile);
|
||||
) => VerifyJsonObjects(objects.ToDictionary(x => x.Key.Value, x => x.Value), sourceFile);
|
||||
|
||||
public static SettingsTask VerifyJsons(IReadOnlyCollection<Json> objects, [CallerFilePath] string sourceFile = "") =>
|
||||
VerifyJson(JArray.FromObject(objects, _jsonSerializer).ToString(), sourceFile: sourceFile);
|
||||
}
|
||||
|
||||
@@ -22,6 +22,15 @@
|
||||
"Microsoft.SourceLink.Common": "8.0.0"
|
||||
}
|
||||
},
|
||||
"Moq": {
|
||||
"type": "Direct",
|
||||
"requested": "[4.20.72, )",
|
||||
"resolved": "4.20.72",
|
||||
"contentHash": "EA55cjyNn8eTNWrgrdZJH5QLFp2L43oxl1tlkoYUKIE9pRwL784OWiTXeCV5ApS+AMYEAlt7Fo03A2XfouvHmQ==",
|
||||
"dependencies": {
|
||||
"Castle.Core": "5.1.1"
|
||||
}
|
||||
},
|
||||
"PolySharp": {
|
||||
"type": "Direct",
|
||||
"requested": "[1.15.0, )",
|
||||
@@ -47,19 +56,30 @@
|
||||
},
|
||||
"Verify.Xunit": {
|
||||
"type": "Direct",
|
||||
"requested": "[28.10.1, )",
|
||||
"resolved": "28.10.1",
|
||||
"contentHash": "mkG7agMlx8oAEGcHoRY72hyDyNTdLIrzbfmniXFQgQ3yKulAHSYvYc9quzhpg0Sy+jb3svbdLqnRSg0VRhet3A==",
|
||||
"requested": "[29.2.0, )",
|
||||
"resolved": "29.2.0",
|
||||
"contentHash": "MdcslVf40AzSA319ZHMzR+U4JqyquX28JFSrI9zA89yeZNaNcaSIb5PmE0XZ6p60Iy7eRYtnGEgSDimEUeXHZw==",
|
||||
"dependencies": {
|
||||
"Argon": "0.26.0",
|
||||
"DiffEngine": "15.9.0",
|
||||
"Argon": "0.27.0",
|
||||
"DiffEngine": "16.1.0",
|
||||
"SimpleInfoName": "3.1.0",
|
||||
"System.IO.Hashing": "9.0.1",
|
||||
"Verify": "28.10.1",
|
||||
"System.IO.Hashing": "9.0.3",
|
||||
"Verify": "29.2.0",
|
||||
"xunit.abstractions": "2.0.3",
|
||||
"xunit.extensibility.execution": "2.9.3"
|
||||
}
|
||||
},
|
||||
"xunit": {
|
||||
"type": "Direct",
|
||||
"requested": "[2.9.3, )",
|
||||
"resolved": "2.9.3",
|
||||
"contentHash": "TlXQBinK35LpOPKHAqbLY4xlEen9TBafjs0V5KnA4wZsoQLQJiirCR4CbIXvOH8NzkW4YeJKP5P/Bnrodm0h9Q==",
|
||||
"dependencies": {
|
||||
"xunit.analyzers": "1.18.0",
|
||||
"xunit.assert": "2.9.3",
|
||||
"xunit.core": "[2.9.3]"
|
||||
}
|
||||
},
|
||||
"xunit.runner.visualstudio": {
|
||||
"type": "Direct",
|
||||
"requested": "[3.0.2, )",
|
||||
@@ -68,22 +88,30 @@
|
||||
},
|
||||
"Argon": {
|
||||
"type": "Transitive",
|
||||
"resolved": "0.26.0",
|
||||
"contentHash": "n7btGXdtRyprGnpLMpBs6rLScxlvPtVWwmTR8h7CtJvpZXBGhGvibEdZxRjeTZNrwf403jJ0ZPpt35Pz/NaNsw=="
|
||||
"resolved": "0.27.0",
|
||||
"contentHash": "LtZKATYeTwDyYq1AXrgVU/ly+nI6GvE0GK1isJYFPQOnb2uHUxvDA+yh40QYaITGTLViXK7rbWhNKpbZ5pb9XA=="
|
||||
},
|
||||
"Castle.Core": {
|
||||
"type": "Transitive",
|
||||
"resolved": "5.1.1",
|
||||
"contentHash": "rpYtIczkzGpf+EkZgDr9CClTdemhsrwA/W5hMoPjLkRFnXzH44zDLoovXeKtmxb1ykXK9aJVODSpiJml8CTw2g==",
|
||||
"dependencies": {
|
||||
"System.Diagnostics.EventLog": "6.0.0"
|
||||
}
|
||||
},
|
||||
"DiffEngine": {
|
||||
"type": "Transitive",
|
||||
"resolved": "15.9.0",
|
||||
"contentHash": "shE6+tO4w5BmQTX0z+WnUV4UfmPNn6oTqBINbkts6OP0Icyx5WROSDzjjb95EwVYC4IAS+PxxS4Vbapxz4hkdw==",
|
||||
"resolved": "16.1.0",
|
||||
"contentHash": "ImEFC6BN62paN0N7v8vrLY3x/LpfbJaJy5yDtL+/L2As6FI1npGJcFZwzz1A7pdDjIYPOXE91qv6BpgEUGjDkA==",
|
||||
"dependencies": {
|
||||
"EmptyFiles": "8.7.1",
|
||||
"System.Management": "9.0.1"
|
||||
"EmptyFiles": "8.8.0",
|
||||
"System.Management": "8.0.0"
|
||||
}
|
||||
},
|
||||
"EmptyFiles": {
|
||||
"type": "Transitive",
|
||||
"resolved": "8.7.1",
|
||||
"contentHash": "C8pvg0TvG2Mkn5LGNFGkFgFu8SUgYFwiu8U3y34qGQnnwKmGnlQTfTIUrtzfSjPxA4q7L/kRu09U5p32otZ2Aw=="
|
||||
"resolved": "8.8.0",
|
||||
"contentHash": "d0pgc/vMyKgQ9T3qiiJBn1uYUSZ1/OShh6tySnNSkELRSgM4A4IOrpdQhLqwCkPwYvdJqzKuxQ6wn3MQAd4GNA=="
|
||||
},
|
||||
"FSharp.Core": {
|
||||
"type": "Transitive",
|
||||
@@ -250,25 +278,30 @@
|
||||
},
|
||||
"System.CodeDom": {
|
||||
"type": "Transitive",
|
||||
"resolved": "9.0.1",
|
||||
"contentHash": "2J5uq+2smnj+u1jlyVJ6BGGqaK9fHcK/EwN7mbsuPqTI6dZr86br8Cg6o/5B+icQ9ANTvTDpJjnhDNtYYZijHQ=="
|
||||
"resolved": "8.0.0",
|
||||
"contentHash": "WTlRjL6KWIMr/pAaq3rYqh0TJlzpouaQ/W1eelssHgtlwHAH25jXTkUphTYx9HaIIf7XA6qs/0+YhtLEQRkJ+Q=="
|
||||
},
|
||||
"System.ComponentModel.Annotations": {
|
||||
"type": "Transitive",
|
||||
"resolved": "4.5.0",
|
||||
"contentHash": "UxYQ3FGUOtzJ7LfSdnYSFd7+oEv6M8NgUatatIN2HxNtDdlcvFAf+VIq4Of9cDMJEJC0aSRv/x898RYhB4Yppg=="
|
||||
},
|
||||
"System.Diagnostics.EventLog": {
|
||||
"type": "Transitive",
|
||||
"resolved": "6.0.0",
|
||||
"contentHash": "lcyUiXTsETK2ALsZrX+nWuHSIQeazhqPphLfaRxzdGaG93+0kELqpgEHtwWOlQe7+jSFnKwaCAgL4kjeZCQJnw=="
|
||||
},
|
||||
"System.IO.Hashing": {
|
||||
"type": "Transitive",
|
||||
"resolved": "9.0.1",
|
||||
"contentHash": "jY+E/PElNWQiazN0YHqZGvcSedcZ4Wt0Os1nnJ2SzR3gWZlhNRDkSXOhuHJcLuImD8SrJQQ8TfU0W4mVcit2hg=="
|
||||
"resolved": "9.0.3",
|
||||
"contentHash": "BrMGzDRLz410PE4qC8UeKeAc0hFRjBkiCUOLTwuod65NAjqg5tDNqYU7gP0A09taEXtecB+HJc1NNnnTjsKFAQ=="
|
||||
},
|
||||
"System.Management": {
|
||||
"type": "Transitive",
|
||||
"resolved": "9.0.1",
|
||||
"contentHash": "CLEo9O6FuO4GQ3ZQkGssg9CJ2w2TN7GMFf3wHTc7YVWJV4xoyJRPw+XIDQnCcSUJCrHhrAWOO60cAX29EV5LFQ==",
|
||||
"resolved": "8.0.0",
|
||||
"contentHash": "jrK22i5LRzxZCfGb+tGmke2VH7oE0DvcDlJ1HAKYU8cPmD8XnpUT0bYn2Gy98GEhGjtfbR/sxKTVb+dE770pfA==",
|
||||
"dependencies": {
|
||||
"System.CodeDom": "9.0.1"
|
||||
"System.CodeDom": "8.0.0"
|
||||
}
|
||||
},
|
||||
"System.Memory": {
|
||||
@@ -306,13 +339,13 @@
|
||||
},
|
||||
"Verify": {
|
||||
"type": "Transitive",
|
||||
"resolved": "28.10.1",
|
||||
"contentHash": "2B/VtFN5jtF5g28kaM4GdJZTwb3pisd4+wL2NEPi9ZYe2lghWsCzS30V6LF1ILApLBfAorAstkU/Vw3sDWRqrg==",
|
||||
"resolved": "29.2.0",
|
||||
"contentHash": "EhhwhXIeip9AJGWRPXh47NAUoiELnWzeBnAzFSl0+ryAfijTV1T+B4m6P6GbheWQ1CJ1cC1ZFLzgH276D5Bu3A==",
|
||||
"dependencies": {
|
||||
"Argon": "0.26.0",
|
||||
"DiffEngine": "15.9.0",
|
||||
"Argon": "0.27.0",
|
||||
"DiffEngine": "16.1.0",
|
||||
"SimpleInfoName": "3.1.0",
|
||||
"System.IO.Hashing": "9.0.1"
|
||||
"System.IO.Hashing": "9.0.3"
|
||||
}
|
||||
},
|
||||
"xunit.abstractions": {
|
||||
@@ -320,6 +353,20 @@
|
||||
"resolved": "2.0.3",
|
||||
"contentHash": "pot1I4YOxlWjIb5jmwvvQNbTrZ3lJQ+jUGkGjWE3hEFM0l5gOnBWS+H3qsex68s5cO52g+44vpGzhAt+42vwKg=="
|
||||
},
|
||||
"xunit.analyzers": {
|
||||
"type": "Transitive",
|
||||
"resolved": "1.18.0",
|
||||
"contentHash": "OtFMHN8yqIcYP9wcVIgJrq01AfTxijjAqVDy/WeQVSyrDC1RzBWeQPztL49DN2syXRah8TYnfvk035s7L95EZQ=="
|
||||
},
|
||||
"xunit.core": {
|
||||
"type": "Transitive",
|
||||
"resolved": "2.9.3",
|
||||
"contentHash": "BiAEvqGvyme19wE0wTKdADH+NloYqikiU0mcnmiNyXaF9HyHmE6sr/3DC5vnBkgsWaE6yPyWszKSPSApWdRVeQ==",
|
||||
"dependencies": {
|
||||
"xunit.extensibility.core": "[2.9.3]",
|
||||
"xunit.extensibility.execution": "[2.9.3]"
|
||||
}
|
||||
},
|
||||
"xunit.extensibility.core": {
|
||||
"type": "Transitive",
|
||||
"resolved": "2.9.3",
|
||||
@@ -408,6 +455,12 @@
|
||||
"requested": "[13.0.2, )",
|
||||
"resolved": "13.0.2",
|
||||
"contentHash": "g1BejUZwax5PRfL6xHgLEK23sqHWOgOj9hE7RvfRRlN00AGt8GnPYt8HedSK7UB3HiRW8zCA9Pn0iiYxCK24BA=="
|
||||
},
|
||||
"xunit.assert": {
|
||||
"type": "CentralTransitive",
|
||||
"requested": "[2.9.3, )",
|
||||
"resolved": "2.9.3",
|
||||
"contentHash": "/Kq28fCE7MjOV42YLVRAJzRF0WmEqsmflm0cfpMjGtzQ2lR5mYVj1/i0Y8uDAOLczkL3/jArrwehfMD0YogMAA=="
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,13 +5,12 @@ using GraphQL.Client.Http;
|
||||
using Speckle.Newtonsoft.Json;
|
||||
using Speckle.Sdk.Api;
|
||||
using Speckle.Sdk.Api.GraphQL.Inputs;
|
||||
using Xunit;
|
||||
|
||||
namespace Speckle.Sdk.Tests.Integration.Api.GraphQL;
|
||||
|
||||
public class GraphQLClientExceptionHandling : IAsyncLifetime
|
||||
{
|
||||
private Client _sut;
|
||||
private IClient _sut;
|
||||
|
||||
public Task DisposeAsync() => Task.CompletedTask;
|
||||
|
||||
|
||||
+1
-2
@@ -2,13 +2,12 @@
|
||||
using Speckle.Sdk.Api;
|
||||
using Speckle.Sdk.Api.GraphQL.Inputs;
|
||||
using Speckle.Sdk.Api.GraphQL.Resources;
|
||||
using Xunit;
|
||||
|
||||
namespace Speckle.Sdk.Tests.Integration.API.GraphQL.Resources;
|
||||
|
||||
public class ActiveUserResourceTests : IAsyncLifetime
|
||||
{
|
||||
private Client _testUser;
|
||||
private IClient _testUser;
|
||||
private ActiveUserResource Sut => _testUser.ActiveUser;
|
||||
|
||||
// Setup method for xUnit using IAsyncLifetime
|
||||
|
||||
@@ -4,14 +4,13 @@ using Speckle.Sdk.Api.GraphQL.Inputs;
|
||||
using Speckle.Sdk.Api.GraphQL.Models;
|
||||
using Speckle.Sdk.Api.GraphQL.Resources;
|
||||
using Speckle.Sdk.Common;
|
||||
using Xunit;
|
||||
using Version = Speckle.Sdk.Api.GraphQL.Models.Version;
|
||||
|
||||
namespace Speckle.Sdk.Tests.Integration.API.GraphQL.Resources;
|
||||
|
||||
public class CommentResourceTests : IAsyncLifetime
|
||||
{
|
||||
private Client _testUser;
|
||||
private IClient _testUser;
|
||||
private CommentResource Sut;
|
||||
private Project _project;
|
||||
private Model _model;
|
||||
|
||||
+1
-2
@@ -4,13 +4,12 @@ using Speckle.Sdk.Api.GraphQL.Enums;
|
||||
using Speckle.Sdk.Api.GraphQL.Inputs;
|
||||
using Speckle.Sdk.Api.GraphQL.Models;
|
||||
using Speckle.Sdk.Api.GraphQL.Resources;
|
||||
using Xunit;
|
||||
|
||||
namespace Speckle.Sdk.Tests.Integration.API.GraphQL.Resources;
|
||||
|
||||
public class ModelResourceExceptionalTests : IAsyncLifetime
|
||||
{
|
||||
private Client _testUser;
|
||||
private IClient _testUser;
|
||||
private ModelResource Sut => _testUser.Model;
|
||||
private Project _project;
|
||||
private Model _model;
|
||||
|
||||
@@ -3,13 +3,12 @@ using Speckle.Sdk.Api;
|
||||
using Speckle.Sdk.Api.GraphQL.Inputs;
|
||||
using Speckle.Sdk.Api.GraphQL.Models;
|
||||
using Speckle.Sdk.Api.GraphQL.Resources;
|
||||
using Xunit;
|
||||
|
||||
namespace Speckle.Sdk.Tests.Integration.API.GraphQL.Resources;
|
||||
|
||||
public class ModelResourceTests : IAsyncLifetime
|
||||
{
|
||||
private Client _testUser;
|
||||
private IClient _testUser;
|
||||
private ModelResource Sut => _testUser.Model;
|
||||
private Project _project;
|
||||
private Model _model;
|
||||
|
||||
@@ -2,13 +2,12 @@
|
||||
using Speckle.Sdk.Api;
|
||||
using Speckle.Sdk.Api.GraphQL.Resources;
|
||||
using Speckle.Sdk.Credentials;
|
||||
using Xunit;
|
||||
|
||||
namespace Speckle.Sdk.Tests.Integration.API.GraphQL.Resources;
|
||||
|
||||
public class OtherUserResourceTests
|
||||
{
|
||||
private readonly Client _testUser;
|
||||
private readonly IClient _testUser;
|
||||
private readonly Account _testData;
|
||||
private OtherUserResource Sut => _testUser.OtherUser;
|
||||
|
||||
|
||||
+1
-2
@@ -3,13 +3,12 @@ using Speckle.Sdk.Api;
|
||||
using Speckle.Sdk.Api.GraphQL.Inputs;
|
||||
using Speckle.Sdk.Api.GraphQL.Models;
|
||||
using Speckle.Sdk.Api.GraphQL.Resources;
|
||||
using Xunit;
|
||||
|
||||
namespace Speckle.Sdk.Tests.Integration.API.GraphQL.Resources;
|
||||
|
||||
public class ProjectInviteResourceExceptionalTests : IAsyncLifetime
|
||||
{
|
||||
private Client _testUser;
|
||||
private IClient _testUser;
|
||||
private Project _project;
|
||||
private ProjectInviteResource Sut => _testUser.ProjectInvite;
|
||||
|
||||
|
||||
+1
-2
@@ -4,13 +4,12 @@ using Speckle.Sdk.Api.GraphQL;
|
||||
using Speckle.Sdk.Api.GraphQL.Inputs;
|
||||
using Speckle.Sdk.Api.GraphQL.Models;
|
||||
using Speckle.Sdk.Common;
|
||||
using Xunit;
|
||||
|
||||
namespace Speckle.Sdk.Tests.Integration.API.GraphQL.Resources;
|
||||
|
||||
public class ProjectInviteResourceTests : IAsyncLifetime
|
||||
{
|
||||
private Client _inviter,
|
||||
private IClient _inviter,
|
||||
_invitee;
|
||||
private Project _project;
|
||||
private PendingStreamCollaborator _createdInvite;
|
||||
|
||||
+1
-2
@@ -6,13 +6,12 @@ using Speckle.Sdk.Api.GraphQL.Inputs;
|
||||
using Speckle.Sdk.Api.GraphQL.Models;
|
||||
using Speckle.Sdk.Api.GraphQL.Resources;
|
||||
using Speckle.Sdk.Common;
|
||||
using Xunit;
|
||||
|
||||
namespace Speckle.Sdk.Tests.Integration.API.GraphQL.Resources;
|
||||
|
||||
public class ProjectResourceExceptionalTests : IAsyncLifetime
|
||||
{
|
||||
private Client _testUser,
|
||||
private IClient _testUser,
|
||||
_secondUser,
|
||||
_unauthedUser;
|
||||
private Project _testProject;
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user