From db0d360c7584061d6d1aebeac38d31092f1d5941 Mon Sep 17 00:00:00 2001 From: oguzhankoral Date: Thu, 27 Jun 2024 12:07:13 +0300 Subject: [PATCH 1/2] Do not send any progress update if cancelled --- .../Bindings/ArcGISReceiveBinding.cs | 8 ++------ .../Bindings/ArcGISSendBinding.cs | 8 ++------ .../Bindings/AutocadReceiveBinding.cs | 8 ++------ .../Bindings/AutocadSendBinding.cs | 8 ++------ .../Bindings/RevitSendBinding.cs | 8 ++------ .../Bindings/RhinoReceiveBinding.cs | 8 ++------ .../Bindings/RhinoSendBinding.cs | 8 ++------ .../Bindings/IBasicConnectorBinding.cs | 12 ++++++++++-- 8 files changed, 24 insertions(+), 44 deletions(-) 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..e7eb76f99d 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.Token) ) .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..2c4671aab5 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.Token), 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..517cdfcc6c 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.Token) ) .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..74b41450e6 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.Token), 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 8bd3033442..bc6d65fead 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.Token), 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..3c3d7e9e37 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.Token) ) .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 f0fd3a63d3..a4525dd3f8 100644 --- a/DUI3-DX/Connectors/Rhino/Speckle.Connectors.Rhino7/Bindings/RhinoSendBinding.cs +++ b/DUI3-DX/Connectors/Rhino/Speckle.Connectors.Rhino7/Bindings/RhinoSendBinding.cs @@ -159,7 +159,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.Token), cts.Token ) .ConfigureAwait(false); @@ -178,11 +179,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..71abda99dc 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, CancellationToken ct) + { + // 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 (!ct.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 }); From a587062d1b2806719dc8ae883771b96642f3ed10 Mon Sep 17 00:00:00 2001 From: oguzhankoral Date: Fri, 28 Jun 2024 16:57:30 +0300 Subject: [PATCH 2/2] Use cts instead ct --- .../Bindings/ArcGISReceiveBinding.cs | 2 +- .../Speckle.Connectors.ArcGIS3/Bindings/ArcGISSendBinding.cs | 2 +- .../Bindings/AutocadReceiveBinding.cs | 2 +- .../Bindings/AutocadSendBinding.cs | 2 +- .../Bindings/RevitSendBinding.cs | 2 +- .../Speckle.Connectors.Rhino7/Bindings/RhinoReceiveBinding.cs | 2 +- .../Speckle.Connectors.Rhino7/Bindings/RhinoSendBinding.cs | 2 +- .../Speckle.Connectors.DUI/Bindings/IBasicConnectorBinding.cs | 4 ++-- 8 files changed, 9 insertions(+), 9 deletions(-) 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 e7eb76f99d..489e7296bd 100644 --- a/DUI3-DX/Connectors/ArcGIS/Speckle.Connectors.ArcGIS3/Bindings/ArcGISReceiveBinding.cs +++ b/DUI3-DX/Connectors/ArcGIS/Speckle.Connectors.ArcGIS3/Bindings/ArcGISReceiveBinding.cs @@ -59,7 +59,7 @@ public async Task Receive(string modelCardId) modelCard.SelectedVersionId.NotNull(), cts.Token, (status, progress) => - Commands.SetModelProgress(modelCardId, new ModelCardProgress(modelCardId, status, progress), cts.Token) + Commands.SetModelProgress(modelCardId, new ModelCardProgress(modelCardId, status, progress), cts) ) .ConfigureAwait(false); 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 2c4671aab5..9ef113e74d 100644 --- a/DUI3-DX/Connectors/ArcGIS/Speckle.Connectors.ArcGIS3/Bindings/ArcGISSendBinding.cs +++ b/DUI3-DX/Connectors/ArcGIS/Speckle.Connectors.ArcGIS3/Bindings/ArcGISSendBinding.cs @@ -351,7 +351,7 @@ public async Task Send(string modelCardId) mapMembers, sendInfo, (status, progress) => - Commands.SetModelProgress(modelCardId, new ModelCardProgress(modelCardId, status, progress), cts.Token), + Commands.SetModelProgress(modelCardId, new ModelCardProgress(modelCardId, status, progress), cts), cts.Token ) .ConfigureAwait(false); 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 517cdfcc6c..b1973d331d 100644 --- a/DUI3-DX/Connectors/Autocad/Speckle.Connectors.AutocadShared/Bindings/AutocadReceiveBinding.cs +++ b/DUI3-DX/Connectors/Autocad/Speckle.Connectors.AutocadShared/Bindings/AutocadReceiveBinding.cs @@ -66,7 +66,7 @@ public async Task Receive(string modelCardId) modelCard.SelectedVersionId.NotNull(), cts.Token, (status, progress) => - Commands.SetModelProgress(modelCardId, new ModelCardProgress(modelCardId, status, progress), cts.Token) + Commands.SetModelProgress(modelCardId, new ModelCardProgress(modelCardId, status, progress), cts) ) .ConfigureAwait(false); 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 74b41450e6..820fb90097 100644 --- a/DUI3-DX/Connectors/Autocad/Speckle.Connectors.AutocadShared/Bindings/AutocadSendBinding.cs +++ b/DUI3-DX/Connectors/Autocad/Speckle.Connectors.AutocadShared/Bindings/AutocadSendBinding.cs @@ -168,7 +168,7 @@ private async Task SendInternal(string modelCardId) autocadObjects, sendInfo, (status, progress) => - Commands.SetModelProgress(modelCardId, new ModelCardProgress(modelCardId, status, progress), cts.Token), + Commands.SetModelProgress(modelCardId, new ModelCardProgress(modelCardId, status, progress), cts), cts.Token ) .ConfigureAwait(false); 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 a9b20172b1..ee437aeea2 100644 --- a/DUI3-DX/Connectors/Revit/Speckle.Connectors.RevitShared/Bindings/RevitSendBinding.cs +++ b/DUI3-DX/Connectors/Revit/Speckle.Connectors.RevitShared/Bindings/RevitSendBinding.cs @@ -113,7 +113,7 @@ public async Task Send(string modelCardId) revitObjects, sendInfo, (status, progress) => - Commands.SetModelProgress(modelCardId, new ModelCardProgress(modelCardId, status, progress), cts.Token), + Commands.SetModelProgress(modelCardId, new ModelCardProgress(modelCardId, status, progress), cts), cts.Token ) .ConfigureAwait(false); 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 3c3d7e9e37..6c78f254df 100644 --- a/DUI3-DX/Connectors/Rhino/Speckle.Connectors.Rhino7/Bindings/RhinoReceiveBinding.cs +++ b/DUI3-DX/Connectors/Rhino/Speckle.Connectors.Rhino7/Bindings/RhinoReceiveBinding.cs @@ -61,7 +61,7 @@ public async Task Receive(string modelCardId) modelCard.SelectedVersionId.NotNull(), cts.Token, (status, progress) => - Commands.SetModelProgress(modelCardId, new ModelCardProgress(modelCardId, status, progress), cts.Token) + Commands.SetModelProgress(modelCardId, new ModelCardProgress(modelCardId, status, progress), cts) ) .ConfigureAwait(false); 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 adf90f3df0..9005692407 100644 --- a/DUI3-DX/Connectors/Rhino/Speckle.Connectors.Rhino7/Bindings/RhinoSendBinding.cs +++ b/DUI3-DX/Connectors/Rhino/Speckle.Connectors.Rhino7/Bindings/RhinoSendBinding.cs @@ -175,7 +175,7 @@ public async Task Send(string modelCardId) rhinoObjects, sendInfo, (status, progress) => - Commands.SetModelProgress(modelCardId, new ModelCardProgress(modelCardId, status, progress), cts.Token), + Commands.SetModelProgress(modelCardId, new ModelCardProgress(modelCardId, status, progress), cts), cts.Token ) .ConfigureAwait(false); diff --git a/DUI3-DX/DUI3/Speckle.Connectors.DUI/Bindings/IBasicConnectorBinding.cs b/DUI3-DX/DUI3/Speckle.Connectors.DUI/Bindings/IBasicConnectorBinding.cs index 71abda99dc..c88da91a81 100644 --- a/DUI3-DX/DUI3/Speckle.Connectors.DUI/Bindings/IBasicConnectorBinding.cs +++ b/DUI3-DX/DUI3/Speckle.Connectors.DUI/Bindings/IBasicConnectorBinding.cs @@ -75,12 +75,12 @@ public void SetGlobalNotification(ToastNotificationType type, string title, stri } ); - public void SetModelProgress(string modelCardId, ModelCardProgress progress, CancellationToken ct) + 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 (!ct.IsCancellationRequested) + if (!cts.IsCancellationRequested) { Bridge.Send(SET_MODEL_PROGRESS_UI_COMMAND_NAME, new { modelCardId, progress }); }