Skip to content

Commit

Permalink
DUI3-448 both model card types need 2 clicks to actually cancel 1 to …
Browse files Browse the repository at this point in the history
…stop operation and 1 to refresh progress bar (#3538)

* Do not send any progress update if cancelled

* Use cts instead ct

---------

Co-authored-by: KatKatKateryna <[email protected]>
  • Loading branch information
oguzhankoral and KatKatKateryna authored Jun 28, 2024
1 parent 0568a29 commit cbe19c7
Show file tree
Hide file tree
Showing 8 changed files with 24 additions and 44 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand All @@ -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);
}
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -407,9 +408,4 @@ private void RunExpirationChecks(bool idsDeleted)
Commands.SetModelsExpired(expiredSenderIds);
ChangedObjectIds = new HashSet<string>();
}

private void OnSendOperationProgress(string modelCardId, string status, double? progress)
{
Commands.SetModelProgress(modelCardId, new ModelCardProgress(modelCardId, status, progress));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand All @@ -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));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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);
}
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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));
}

/// <summary>
/// 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).
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand All @@ -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);
}
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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);

/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 });
Expand Down

0 comments on commit cbe19c7

Please sign in to comment.