From b58c348b831c8bdef6e2fa352c93964fa35a5e62 Mon Sep 17 00:00:00 2001 From: Claire Kuang Date: Thu, 20 Jun 2024 13:11:29 +0100 Subject: [PATCH] DUI3-173: adds send and receive cancellation on document switch (#3499) * adds send and receive cancellation on document switch * op in progress cancellation event with global toast notification * Update AutocadSendBinding.cs * disables document activation during send and receive operation * removes todo * reverts send to run on main thread --- .../Bindings/AutocadReceiveBinding.cs | 10 ++++++++++ .../Bindings/AutocadSendBinding.cs | 10 ++++++++++ 2 files changed, 20 insertions(+) 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 da2e5b34c0..2faf89f7ad 100644 --- a/DUI3-DX/Connectors/Autocad/Speckle.Connectors.AutocadShared/Bindings/AutocadReceiveBinding.cs +++ b/DUI3-DX/Connectors/Autocad/Speckle.Connectors.AutocadShared/Bindings/AutocadReceiveBinding.cs @@ -51,6 +51,11 @@ public async Task Receive(string modelCardId) // Init cancellation token source -> Manager also cancel it if exist before CancellationTokenSource cts = _cancellationManager.InitCancellationTokenSource(modelCardId); + // Disable document activation (document creation and document switch) + // Not disabling results in DUI model card being out of sync with the active document + // The DocumentActivated event isn't usable probably because it is pushed to back of main thread queue + Application.DocumentManager.DocumentActivationEnabled = false; + // Receive host objects var operationResults = await unitOfWork.Service .Execute( @@ -72,6 +77,11 @@ public async Task Receive(string modelCardId) // SWALLOW -> UI handles it immediately, so we do not need to handle anything return; } + finally + { + // renable document activation + Application.DocumentManager.DocumentActivationEnabled = true; + } } private void OnSendOperationProgress(string modelCardId, string status, double? 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 8ebb187279..4d580c6aed 100644 --- a/DUI3-DX/Connectors/Autocad/Speckle.Connectors.AutocadShared/Bindings/AutocadSendBinding.cs +++ b/DUI3-DX/Connectors/Autocad/Speckle.Connectors.AutocadShared/Bindings/AutocadSendBinding.cs @@ -130,6 +130,11 @@ private async Task SendInternal(string modelCardId) // Init cancellation token source -> Manager also cancel it if exist before CancellationTokenSource cts = _cancellationManager.InitCancellationTokenSource(modelCardId); + // Disable document activation (document creation and document switch) + // Not disabling results in DUI model card being out of sync with the active document + // The DocumentActivated event isn't usable probably because it is pushed to back of main thread queue + Application.DocumentManager.DocumentActivationEnabled = false; + // Get elements to convert List autocadObjects = Application.DocumentManager.CurrentDocument.GetObjects( modelCard.SendFilter.NotNull().GetObjectIds() @@ -169,6 +174,11 @@ private async Task SendInternal(string modelCardId) { Commands.SetModelError(modelCardId, e); } + finally + { + // renable document activation + Application.DocumentManager.DocumentActivationEnabled = true; + } } private void OnSendOperationProgress(string modelCardId, string status, double? progress)