protected override void UpdateInstance(NativeActivityUpdateContext updateContext) { PickState pickState = updateContext.GetValue(this.pickStateVariable); Fx.Assert(pickState != null, "Pick's Execute must have run by now."); if (updateContext.IsCancellationRequested || pickState.TriggerCompletionBookmark == null) { // do not schedule newly added Branches once a Trigger has successfully completed. return; } CompletionCallback onBranchCompleteCallback = new CompletionCallback(OnBranchComplete); foreach (PickBranchBody body in this.branchBodies) { if (updateContext.IsNewlyAdded(body)) { updateContext.ScheduleActivity(body, onBranchCompleteCallback, null); } } }
protected override void UpdateInstance(NativeActivityUpdateContext updateContext) { if (updateContext.IsCancellationRequested || this.branches == null) { return; } if (this.CompletionCondition != null && updateContext.GetValue(this.hasCompleted)) { // when CompletionCondition exists, schedule newly added branches only if "hasCompleted" variable evaluates to false return; } CompletionCallback onBranchComplete = new CompletionCallback(OnBranchComplete); foreach (Activity branch in this.branches) { if (updateContext.IsNewlyAdded(branch)) { updateContext.ScheduleActivity(branch, onBranchComplete); } } }
protected virtual void UpdateInstance(NativeActivityUpdateContext updateContext) { // note that this may be called multiple times on this same activity but with different instances // Override this only if you need to update runtime state as part of a dynamic update. }
void IInstanceUpdatable.InternalUpdateInstance(NativeActivityUpdateContext updateContext) { this.UpdateInstance(updateContext); }
protected override void UpdateInstance(NativeActivityUpdateContext updateContext) { // we only care about the server-side Receive since the client-side Receive is not persistable. // only valid instance update condition is when a bookmark with OperationBookmarkName is found. CorrelationHandle followingCorrelation = (this.CorrelatesWith == null) ? null : (CorrelationHandle)updateContext.GetValue(this.CorrelatesWith); if (followingCorrelation == null) { followingCorrelation = updateContext.FindExecutionProperty(CorrelationHandle.StaticExecutionPropertyName) as CorrelationHandle; } BookmarkScope bookmarkScope; if (followingCorrelation != null && followingCorrelation.Scope != null) { bookmarkScope = followingCorrelation.Scope; } else { bookmarkScope = updateContext.DefaultBookmarkScope; } string savedOriginalOperationName = (string)updateContext.GetSavedOriginalValue(OperationNamePropertyName); XName savedOriginalServiceContractName = (XName)updateContext.GetSavedOriginalValue(ServiceContractNamePropertyName); if ((savedOriginalOperationName == null && savedOriginalServiceContractName == null) || (savedOriginalOperationName == this.OperationName && savedOriginalServiceContractName == this.ServiceContractName)) { // neither ServiceContractName nor OperationName have changed // nothing to do, so exit early. return; } string originalOperationBookmarkName = BookmarkNameHelper.CreateBookmarkName(savedOriginalOperationName ?? this.OperationName, savedOriginalServiceContractName ?? this.ServiceContractName); if (updateContext.RemoveBookmark(originalOperationBookmarkName, bookmarkScope)) { // if we are here, it means Receive is on the server-side and waiting for a request message to arrive updateContext.CreateBookmark(this.OperationBookmarkName, new BookmarkCallback(this.OnMessage), bookmarkScope); } else { // this means Receive is in a state DU is not allowed. updateContext.DisallowUpdate(SR.InvalidReceiveStateForDU); } }
protected virtual void UpdateInstance(NativeActivityUpdateContext updateContext) { // note that this may be called multiple times on this same activity but with different instances // Override this only if you need to update runtime state as part of a dynamic update. }
void IInstanceUpdatable.InternalUpdateInstance(NativeActivityUpdateContext updateContext) { this.UpdateInstance(updateContext); }
/// <summary> /// Used for Dynamic Update: after the instance is updated, if the statemachine is already transitioning, the index of the to-be-scheduled state /// would need to be updated. /// </summary> /// <param name="updateContext">Dynamic Update context</param> /// <param name="eventManager">Internal StateMachineEventManager</param> /// <returns>True, 1. if update is successful and the instanced is updated with the new indexes, and 2 all the trigger ID in the queue are updated; /// false otherwise and the update should fail.</returns> private bool UpdateEventManager( NativeActivityUpdateContext updateContext, StateMachineEventManager eventManager) { Fx.Assert(null != eventManager.CurrentBeingProcessedEvent, "The eventManager must have some info that needs to be updated during transition."); int updatedEventsInQueue = 0; int originalTriggerId = int.MinValue; int originalConditionIndex = int.MinValue; bool updateCurrentEventSucceed = null == eventManager.CurrentBeingProcessedEvent ? true : false; foreach (InternalTransition transition in this.internalTransitions) { object savedTriggerIndex = updateContext.GetSavedOriginalValue(transition.Trigger); if (savedTriggerIndex != null) { Fx.Assert(!updateContext.IsNewlyAdded(transition.Trigger), "the trigger in transition already exist."); if (null != eventManager.CurrentBeingProcessedEvent && eventManager.CurrentBeingProcessedEvent.TriggedId == (int)savedTriggerIndex) { // found a match of the running trigger update the current processed event // Don't match the trigger ID, match only when the Condition is also matched. if (eventManager.CurrentConditionIndex == -1) { if (transition.IsUnconditional) { // executing transition before persist is unconditional originalTriggerId = eventManager.CurrentBeingProcessedEvent.TriggedId; originalConditionIndex = 0; eventManager.CurrentBeingProcessedEvent.TriggedId = transition.InternalTransitionIndex; if (updateContext.GetValue(this.isExiting)) { Fx.Assert(eventManager.OnTransition, "The state is transitioning."); updateContext.SetValue(this.Result, GetTo(transition.InternalTransitionIndex)); } updateCurrentEventSucceed = true; } else { updateContext.DisallowUpdate(SR.ChangeTransitionTypeDuringTransitioningBlockDU); return(false); } } else if (eventManager.CurrentConditionIndex >= 0) { Fx.Assert(!transition.IsUnconditional, "Cannot update a running conditional transition with a unconditional one."); if (!transition.IsUnconditional) { // executing transition before and after are conditional for (int updatedIndex = 0; updatedIndex < transition.TransitionDataList.Count; updatedIndex++) { Activity condition = transition.TransitionDataList[updatedIndex].Condition; Fx.Assert(null != condition, "Conditional transition must have Condition activity."); int?savedCondIndex = updateContext.GetSavedOriginalValue(condition) as int?; if (eventManager.CurrentConditionIndex == savedCondIndex) { originalTriggerId = eventManager.CurrentBeingProcessedEvent.TriggedId; originalConditionIndex = eventManager.CurrentConditionIndex; eventManager.CurrentBeingProcessedEvent.TriggedId = transition.InternalTransitionIndex; eventManager.CurrentConditionIndex = updatedIndex; if (updateContext.GetValue(this.isExiting)) { Fx.Assert(eventManager.OnTransition, "The state is transitioning."); updateContext.SetValue(this.Result, this.GetTo(transition.InternalTransitionIndex, (int)updatedIndex)); } updateCurrentEventSucceed = true; break; } } } } } foreach (TriggerCompletedEvent completedEvent in eventManager.Queue) { if ((int)savedTriggerIndex == completedEvent.TriggedId) { completedEvent.TriggedId = transition.InternalTransitionIndex; updatedEventsInQueue++; } } } } return(eventManager.Queue.Count() == updatedEventsInQueue ? updateCurrentEventSucceed : false); }