private void OnSecondaryRootScheduled(NativeActivityContext context, Bookmark bookmark, object value) { CompensationExtension compensationExtension = context.GetExtension <CompensationExtension>(); Fx.Assert(compensationExtension != null, "CompensationExtension must be valid"); long compensationId = (long)value; CompensationTokenData compensationToken = compensationExtension.Get(compensationId); Fx.Assert(compensationToken != null, "CompensationTokenData must be valid"); if (compensationToken.CompensationState == CompensationState.Canceling) { Fx.Assert(compensationToken.BookmarkTable[CompensationBookmarkName.Canceled] == null, "Bookmark should not be already initialized in the bookmark table."); compensationToken.BookmarkTable[CompensationBookmarkName.Canceled] = context.CreateBookmark(new BookmarkCallback(OnCanceledOrCompensated)); compensationExtension.NotifyMessage(context, compensationToken.CompensationId, CompensationBookmarkName.OnCancellation); } else if (compensationToken.CompensationState == CompensationState.Compensating) { Fx.Assert(compensationToken.BookmarkTable[CompensationBookmarkName.Compensated] == null, "Bookmark should not be already initialized in the bookmark table."); compensationToken.BookmarkTable[CompensationBookmarkName.Compensated] = context.CreateBookmark(new BookmarkCallback(OnCanceledOrCompensated)); compensationExtension.NotifyMessage(context, compensationToken.CompensationId, CompensationBookmarkName.OnCompensation); } }
private void OnConfirmationHandlerComplete(NativeActivityContext context, ActivityInstance completedInstance) { Fx.Assert(context != null, "context must be valid"); Fx.Assert(completedInstance != null, "completedInstance must be valid"); CompensationExtension compensationExtension = context.GetExtension <CompensationExtension>(); Fx.Assert(compensationExtension != null, "CompensationExtension must be valid"); CompensationTokenData compensationToken = compensationExtension.Get(_compensationId.Get(context)); Fx.Assert(compensationToken != null, "CompensationTokenData must be valid"); if (completedInstance.State == ActivityInstanceState.Closed) { Fx.Assert(compensationToken.CompensationState == CompensationState.Confirming, "CompensationParticipant should be in Confirming State"); _currentCompensationToken.Set(context, new CompensationToken(compensationToken)); if (compensationToken.ExecutionTracker.Count > 0) { context.ScheduleActivity(DefaultConfirmation, new CompletionCallback(this.OnConfirmationComplete)); } else { compensationExtension.NotifyMessage(context, compensationToken.CompensationId, CompensationBookmarkName.Confirmed); } } }
private void InternalOnCompensationComplete(NativeActivityContext context, CompensationExtension compensationExtension, CompensationTokenData compensationToken) { switch (compensationToken.CompensationState) { case CompensationState.Canceling: compensationExtension.NotifyMessage(context, compensationToken.CompensationId, CompensationBookmarkName.Canceled); break; case CompensationState.Compensating: compensationExtension.NotifyMessage(context, compensationToken.CompensationId, CompensationBookmarkName.Compensated); break; default: Fx.Assert(false, "CompensationState is in unexpected state!"); break; } }
private void OnConfirmationComplete(NativeActivityContext context, ActivityInstance completedInstance) { Fx.Assert(context != null, "context must be valid"); Fx.Assert(completedInstance != null, "completedInstance must be valid"); CompensationExtension compensationExtension = context.GetExtension <CompensationExtension>(); Fx.Assert(compensationExtension != null, "CompensationExtension must be valid"); CompensationTokenData compensationToken = compensationExtension.Get(_compensationId.Get(context)); Fx.Assert(compensationToken != null, "CompensationTokenData must be valid"); if (completedInstance.State == ActivityInstanceState.Closed) { compensationExtension.NotifyMessage(context, compensationToken.CompensationId, CompensationBookmarkName.Confirmed); } }
private void OnConfirmation(NativeActivityContext context, Bookmark bookmark, object value) { CompensationExtension compensationExtension = context.GetExtension <CompensationExtension>(); Fx.Assert(compensationExtension != null, "CompensationExtension must be valid"); long compensationId = (long)value; Fx.Assert(compensationId != CompensationToken.RootCompensationId, "CompensationId must be passed when resuming the Completed bookmark"); CompensationTokenData compensationToken = compensationExtension.Get(compensationId); Fx.Assert(compensationToken != null, "CompensationTokenData must be valid"); Fx.Assert(compensationToken.CompensationState == CompensationState.Confirming, "CompensationState should be in Confirming state"); if (TD.CompensationStateIsEnabled()) { TD.CompensationState(compensationToken.DisplayName, compensationToken.CompensationState.ToString()); } compensationToken.RemoveBookmark(context, CompensationBookmarkName.OnCancellation); compensationToken.RemoveBookmark(context, CompensationBookmarkName.OnCompensation); if (ConfirmationHandler != null) { context.ScheduleActivity(ConfirmationHandler, new CompletionCallback(OnConfirmationHandlerComplete), new FaultCallback(OnExceptionFromHandler)); } else { _currentCompensationToken.Set(context, new CompensationToken(compensationToken)); if (compensationToken.ExecutionTracker.Count > 0) { context.ScheduleActivity(DefaultConfirmation, new CompletionCallback(this.OnConfirmationComplete)); } else { compensationExtension.NotifyMessage(context, compensationToken.CompensationId, CompensationBookmarkName.Confirmed); } } }
protected override void Execute(NativeActivityContext context) { CompensationExtension compensationExtension = context.GetExtension <CompensationExtension>(); Fx.Assert(compensationExtension != null, "CompensationExtension must be valid"); CompensationToken compensationToken = Target.Get(context); Fx.Assert(compensationToken != null, "compensationToken must be valid"); // The compensationToken should be a valid one at this point. Ensure its validated in Confirm activity. CompensationTokenData tokenData = compensationExtension.Get(compensationToken.CompensationId); Fx.Assert(tokenData != null, "The compensationToken should be a valid one at this point. Ensure its validated in Confirm activity."); Fx.Assert(tokenData.BookmarkTable[CompensationBookmarkName.Confirmed] == null, "Bookmark should not be already initialized in the bookmark table."); tokenData.BookmarkTable[CompensationBookmarkName.Confirmed] = context.CreateBookmark(new BookmarkCallback(OnConfirmed)); tokenData.CompensationState = CompensationState.Confirming; compensationExtension.NotifyMessage(context, tokenData.CompensationId, CompensationBookmarkName.OnConfirmation); }