protected internal override void SaveCompletedContextActivity(Activity completedScopeActivity) { PendingWorkItem workItem = new PendingWorkItem { Type = PendingWorkItem.ItemType.CompletedScope, SerializedActivity = WorkflowPersistenceService.GetDefaultSerializedForm(completedScopeActivity), InstanceId = WorkflowEnvironment.WorkflowInstanceId, StateId = ((ActivityExecutionContextInfo)completedScopeActivity.GetValue(Activity.ActivityExecutionContextInfoProperty)).ContextGuid }; WorkflowEnvironment.WorkBatch.Add(this, workItem); }
protected internal override void SaveWorkflowInstanceState(Activity rootActivity, bool unlock) { if (rootActivity == null) { throw new ArgumentNullException("rootActivity"); } WorkflowStatus workflowStatus = WorkflowPersistenceService.GetWorkflowStatus(rootActivity); bool isBlocked = WorkflowPersistenceService.GetIsBlocked(rootActivity); string suspendOrTerminateInfo = WorkflowPersistenceService.GetSuspendOrTerminateInfo(rootActivity); Guid guid = (Guid)rootActivity.GetValue(Activity.ActivityContextGuidProperty); PendingWorkItem workItem = new PendingWorkItem { Type = PendingWorkItem.ItemType.Instance, InstanceId = WorkflowEnvironment.WorkflowInstanceId }; if ((workflowStatus != WorkflowStatus.Completed) && (workflowStatus != WorkflowStatus.Terminated)) { workItem.SerializedActivity = WorkflowPersistenceService.GetDefaultSerializedForm(rootActivity); } else { workItem.SerializedActivity = new byte[0]; } workItem.Status = (int)workflowStatus; workItem.Blocked = isBlocked ? 1 : 0; workItem.Info = suspendOrTerminateInfo; workItem.StateId = guid; workItem.Unlocked = unlock; TimerEventSubscription subscription = ((TimerEventSubscriptionCollection)rootActivity.GetValue(TimerEventSubscriptionCollection.TimerCollectionProperty)).Peek(); workItem.NextTimer = (subscription == null) ? SqlDateTime.MaxValue : subscription.ExpiresAt; if (workItem.Info == null) { workItem.Info = ""; } WorkflowTrace.Host.TraceEvent(TraceEventType.Information, 0, "SqlWorkflowPersistenceService({4}):Committing instance {0}, Blocked={1}, Unlocked={2}, NextTimer={3}", new object[] { guid.ToString(), workItem.Blocked, workItem.Unlocked, workItem.NextTimer.Value.ToLocalTime(), this._serviceInstanceId.ToString() }); WorkflowEnvironment.WorkBatch.Add(this, workItem); }