Skip to content

Commit

Permalink
chore(core): Cleanup base object serializer v2 (specklesystems#3065)
Browse files Browse the repository at this point in the history
chore!(core): Cleanup base object serializer v2
  • Loading branch information
JR-Morgan authored Nov 30, 2023
1 parent b12c001 commit bac754c
Show file tree
Hide file tree
Showing 3 changed files with 179 additions and 240 deletions.
29 changes: 5 additions & 24 deletions Core/Core/Api/Operations/Operations.Send.cs
Original file line number Diff line number Diff line change
Expand Up @@ -97,49 +97,30 @@ public static async Task<string> Send(
var sendTimer = Stopwatch.StartNew();
SpeckleLog.Logger.Information("Starting send operation");

var localProgressDict = new ConcurrentDictionary<string, int>();
var internalProgressAction = GetInternalProgressAction(localProgressDict, onProgressAction);

BaseObjectSerializer? serializer = null;
JsonSerializerSettings? settings = null;
BaseObjectSerializerV2? serializerV2 = null;
if (serializerVersion == SerializerVersion.V1)
{
(serializer, settings) = GetSerializerInstance();
}
else
{
serializerV2 = new BaseObjectSerializerV2();
}

var localProgressDict = new ConcurrentDictionary<string, int>();
var internalProgressAction = GetInternalProgressAction(localProgressDict, onProgressAction);

if (serializerVersion == SerializerVersion.V1)
{
serializer.WriteTransports = transports;
serializer!.OnProgressAction = internalProgressAction;
serializer.CancellationToken = cancellationToken;
serializer.OnErrorAction = onErrorAction;
}
else
{
serializerV2!.OnProgressAction = internalProgressAction;
serializerV2.CancellationToken = cancellationToken;
serializerV2.OnErrorAction = onErrorAction;
serializerV2 = new BaseObjectSerializerV2(transports, internalProgressAction, cancellationToken);
}

foreach (var t in transports)
{
t.OnProgressAction = internalProgressAction;
t.CancellationToken = cancellationToken;
t.OnErrorAction = onErrorAction;
t.BeginWrite();

if (serializerVersion == SerializerVersion.V1)
{
serializer!.WriteTransports.Add(t);
}
else
{
serializerV2!.WriteTransports.Add(t);
}
}

string obj;
Expand Down
12 changes: 5 additions & 7 deletions Core/Core/Models/Base.cs
Original file line number Diff line number Diff line change
Expand Up @@ -108,14 +108,12 @@ public string GetId(bool decompose = false, SerializerVersion serializerVersion
}
else
{
var s = new BaseObjectSerializerV2();
if (decompose)
{
s.WriteTransports = new List<ITransport> { new MemoryTransport() };
}
var serializer = decompose
? new BaseObjectSerializerV2(new[] { new MemoryTransport() })
: new BaseObjectSerializerV2();

var obj = s.Serialize(this);
return JObject.Parse(obj).GetValue(nameof(id)).ToString();
string obj = serializer.Serialize(this);
return JObject.Parse(obj).GetValue(nameof(id))!.ToString();
}
}

Expand Down
Loading

0 comments on commit bac754c

Please sign in to comment.