diff --git a/DUI3-DX/Connectors/ArcGIS/Speckle.Connectors.ArcGIS3/Bindings/ArcGISReceiveBinding.cs b/DUI3-DX/Connectors/ArcGIS/Speckle.Connectors.ArcGIS3/Bindings/ArcGISReceiveBinding.cs index fcccc93f25..489e7296bd 100644 --- a/DUI3-DX/Connectors/ArcGIS/Speckle.Connectors.ArcGIS3/Bindings/ArcGISReceiveBinding.cs +++ b/DUI3-DX/Connectors/ArcGIS/Speckle.Connectors.ArcGIS3/Bindings/ArcGISReceiveBinding.cs @@ -58,7 +58,8 @@ public async Task Receive(string modelCardId) modelCard.ModelName.NotNull(), modelCard.SelectedVersionId.NotNull(), cts.Token, - (status, progress) => OnSendOperationProgress(modelCardId, status, progress) + (status, progress) => + Commands.SetModelProgress(modelCardId, new ModelCardProgress(modelCardId, status, progress), cts) ) .ConfigureAwait(false); @@ -77,10 +78,5 @@ public async Task Receive(string modelCardId) } } - private void OnSendOperationProgress(string modelCardId, string status, double? progress) - { - Commands.SetModelProgress(modelCardId, new ModelCardProgress(modelCardId, status, progress)); - } - public void CancelReceive(string modelCardId) => _cancellationManager.CancelOperation(modelCardId); } diff --git a/DUI3-DX/Connectors/ArcGIS/Speckle.Connectors.ArcGIS3/Bindings/ArcGISSendBinding.cs b/DUI3-DX/Connectors/ArcGIS/Speckle.Connectors.ArcGIS3/Bindings/ArcGISSendBinding.cs index 4c0215694b..9ef113e74d 100644 --- a/DUI3-DX/Connectors/ArcGIS/Speckle.Connectors.ArcGIS3/Bindings/ArcGISSendBinding.cs +++ b/DUI3-DX/Connectors/ArcGIS/Speckle.Connectors.ArcGIS3/Bindings/ArcGISSendBinding.cs @@ -350,7 +350,8 @@ public async Task Send(string modelCardId) .Execute( mapMembers, sendInfo, - (status, progress) => OnSendOperationProgress(modelCardId, status, progress), + (status, progress) => + Commands.SetModelProgress(modelCardId, new ModelCardProgress(modelCardId, status, progress), cts), cts.Token ) .ConfigureAwait(false); @@ -407,9 +408,4 @@ private void RunExpirationChecks(bool idsDeleted) Commands.SetModelsExpired(expiredSenderIds); ChangedObjectIds = new HashSet(); } - - private void OnSendOperationProgress(string modelCardId, string status, double? progress) - { - Commands.SetModelProgress(modelCardId, new ModelCardProgress(modelCardId, status, progress)); - } } diff --git a/DUI3-DX/Connectors/Autocad/Speckle.Connectors.AutocadShared/Bindings/AutocadReceiveBinding.cs b/DUI3-DX/Connectors/Autocad/Speckle.Connectors.AutocadShared/Bindings/AutocadReceiveBinding.cs index 2faf89f7ad..b1973d331d 100644 --- a/DUI3-DX/Connectors/Autocad/Speckle.Connectors.AutocadShared/Bindings/AutocadReceiveBinding.cs +++ b/DUI3-DX/Connectors/Autocad/Speckle.Connectors.AutocadShared/Bindings/AutocadReceiveBinding.cs @@ -65,7 +65,8 @@ public async Task Receive(string modelCardId) modelCard.ModelName.NotNull(), modelCard.SelectedVersionId.NotNull(), cts.Token, - onOperationProgressed: (status, progress) => OnSendOperationProgress(modelCardId, status, progress) + (status, progress) => + Commands.SetModelProgress(modelCardId, new ModelCardProgress(modelCardId, status, progress), cts) ) .ConfigureAwait(false); @@ -83,9 +84,4 @@ public async Task Receive(string modelCardId) Application.DocumentManager.DocumentActivationEnabled = true; } } - - private void OnSendOperationProgress(string modelCardId, string status, double? progress) - { - Commands.SetModelProgress(modelCardId, new ModelCardProgress(modelCardId, status, progress)); - } } diff --git a/DUI3-DX/Connectors/Autocad/Speckle.Connectors.AutocadShared/Bindings/AutocadSendBinding.cs b/DUI3-DX/Connectors/Autocad/Speckle.Connectors.AutocadShared/Bindings/AutocadSendBinding.cs index 32cc40fbe7..820fb90097 100644 --- a/DUI3-DX/Connectors/Autocad/Speckle.Connectors.AutocadShared/Bindings/AutocadSendBinding.cs +++ b/DUI3-DX/Connectors/Autocad/Speckle.Connectors.AutocadShared/Bindings/AutocadSendBinding.cs @@ -167,7 +167,8 @@ private async Task SendInternal(string modelCardId) .Execute( autocadObjects, sendInfo, - (status, progress) => OnSendOperationProgress(modelCardId, status, progress), + (status, progress) => + Commands.SetModelProgress(modelCardId, new ModelCardProgress(modelCardId, status, progress), cts), cts.Token ) .ConfigureAwait(false); @@ -191,10 +192,5 @@ private async Task SendInternal(string modelCardId) } } - private void OnSendOperationProgress(string modelCardId, string status, double? progress) - { - Commands.SetModelProgress(modelCardId, new ModelCardProgress(modelCardId, status, progress)); - } - public void CancelSend(string modelCardId) => _cancellationManager.CancelOperation(modelCardId); } diff --git a/DUI3-DX/Connectors/Revit/Speckle.Connectors.RevitShared/Bindings/RevitSendBinding.cs b/DUI3-DX/Connectors/Revit/Speckle.Connectors.RevitShared/Bindings/RevitSendBinding.cs index 99e6492b79..ee437aeea2 100644 --- a/DUI3-DX/Connectors/Revit/Speckle.Connectors.RevitShared/Bindings/RevitSendBinding.cs +++ b/DUI3-DX/Connectors/Revit/Speckle.Connectors.RevitShared/Bindings/RevitSendBinding.cs @@ -112,7 +112,8 @@ public async Task Send(string modelCardId) .Execute( revitObjects, sendInfo, - (status, progress) => OnSendOperationProgress(modelCardId, status, progress), + (status, progress) => + Commands.SetModelProgress(modelCardId, new ModelCardProgress(modelCardId, status, progress), cts), cts.Token ) .ConfigureAwait(false); @@ -130,11 +131,6 @@ public async Task Send(string modelCardId) } } - private void OnSendOperationProgress(string modelCardId, string status, double? progress) - { - Commands.SetModelProgress(modelCardId, new ModelCardProgress(modelCardId, status, progress)); - } - /// /// Keeps track of the changed element ids as well as checks if any of them need to trigger /// a filter refresh (e.g., views being added). diff --git a/DUI3-DX/Connectors/Rhino/Speckle.Connectors.Rhino7/Bindings/RhinoReceiveBinding.cs b/DUI3-DX/Connectors/Rhino/Speckle.Connectors.Rhino7/Bindings/RhinoReceiveBinding.cs index 951ff40f6f..6c78f254df 100644 --- a/DUI3-DX/Connectors/Rhino/Speckle.Connectors.Rhino7/Bindings/RhinoReceiveBinding.cs +++ b/DUI3-DX/Connectors/Rhino/Speckle.Connectors.Rhino7/Bindings/RhinoReceiveBinding.cs @@ -60,7 +60,8 @@ public async Task Receive(string modelCardId) modelCard.ModelName.NotNull(), modelCard.SelectedVersionId.NotNull(), cts.Token, - (status, progress) => OnSendOperationProgress(modelCardId, status, progress) + (status, progress) => + Commands.SetModelProgress(modelCardId, new ModelCardProgress(modelCardId, status, progress), cts) ) .ConfigureAwait(false); @@ -79,10 +80,5 @@ public async Task Receive(string modelCardId) } } - private void OnSendOperationProgress(string modelCardId, string status, double? progress) - { - Commands.SetModelProgress(modelCardId, new ModelCardProgress(modelCardId, status, progress)); - } - public void CancelSend(string modelCardId) => _cancellationManager.CancelOperation(modelCardId); } diff --git a/DUI3-DX/Connectors/Rhino/Speckle.Connectors.Rhino7/Bindings/RhinoSendBinding.cs b/DUI3-DX/Connectors/Rhino/Speckle.Connectors.Rhino7/Bindings/RhinoSendBinding.cs index 7e4e6be8a3..9005692407 100644 --- a/DUI3-DX/Connectors/Rhino/Speckle.Connectors.Rhino7/Bindings/RhinoSendBinding.cs +++ b/DUI3-DX/Connectors/Rhino/Speckle.Connectors.Rhino7/Bindings/RhinoSendBinding.cs @@ -174,7 +174,8 @@ public async Task Send(string modelCardId) .Execute( rhinoObjects, sendInfo, - (status, progress) => OnSendOperationProgress(modelCardId, status, progress), + (status, progress) => + Commands.SetModelProgress(modelCardId, new ModelCardProgress(modelCardId, status, progress), cts), cts.Token ) .ConfigureAwait(false); @@ -193,11 +194,6 @@ public async Task Send(string modelCardId) } } - private void OnSendOperationProgress(string modelCardId, string status, double? progress) - { - Commands.SetModelProgress(modelCardId, new ModelCardProgress(modelCardId, status, progress)); - } - public void CancelSend(string modelCardId) => _cancellationManager.CancelOperation(modelCardId); /// diff --git a/DUI3-DX/DUI3/Speckle.Connectors.DUI/Bindings/IBasicConnectorBinding.cs b/DUI3-DX/DUI3/Speckle.Connectors.DUI/Bindings/IBasicConnectorBinding.cs index 7b38ee9fbd..c88da91a81 100644 --- a/DUI3-DX/DUI3/Speckle.Connectors.DUI/Bindings/IBasicConnectorBinding.cs +++ b/DUI3-DX/DUI3/Speckle.Connectors.DUI/Bindings/IBasicConnectorBinding.cs @@ -75,8 +75,16 @@ public void SetGlobalNotification(ToastNotificationType type, string title, stri } ); - public void SetModelProgress(string modelCardId, ModelCardProgress progress) => - Bridge.Send(SET_MODEL_PROGRESS_UI_COMMAND_NAME, new { modelCardId, progress }); + public void SetModelProgress(string modelCardId, ModelCardProgress progress, CancellationTokenSource cts) + { + // NOTE: To prevent potential race condition + // After cancelling operation some parts could still send last progress update which was set progress on UI + // after it forced to be undefined. This is the safest way to prevent any case like this. + if (!cts.IsCancellationRequested) + { + Bridge.Send(SET_MODEL_PROGRESS_UI_COMMAND_NAME, new { modelCardId, progress }); + } + } public void SetModelError(string modelCardId, Exception error) => Bridge.Send(SET_MODEL_ERROR_UI_COMMAND_NAME, new { modelCardId, error = error.Message });