Skip to content

Commit

Permalink
DUI3-173: adds send and receive cancellation on document switch (#3499)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
clairekuang authored Jun 20, 2024
1 parent a184d0c commit b58c348
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<AutocadRootObject> autocadObjects = Application.DocumentManager.CurrentDocument.GetObjects(
modelCard.SendFilter.NotNull().GetObjectIds()
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit b58c348

Please sign in to comment.