public void InsertInstanceState(PendingWorkItem item, Guid ownerId, DateTime ownedUntil) { DbCommand command = this.NewStoredProcCommand("InsertInstanceState"); command.Parameters.Add(this.dbResourceAllocator.NewDbParameter("@uidInstanceID", item.InstanceId)); command.Parameters.Add(this.dbResourceAllocator.NewDbParameter("@state", item.SerializedActivity)); command.Parameters.Add(this.dbResourceAllocator.NewDbParameter("@status", item.Status)); command.Parameters.Add(this.dbResourceAllocator.NewDbParameter("@unlocked", item.Unlocked)); command.Parameters.Add(this.dbResourceAllocator.NewDbParameter("@blocked", item.Blocked)); command.Parameters.Add(this.dbResourceAllocator.NewDbParameter("@info", item.Info)); command.Parameters.Add(this.dbResourceAllocator.NewDbParameter("@ownedUntil", (ownedUntil == DateTime.MaxValue) ? SqlDateTime.MaxValue : ownedUntil)); command.Parameters.Add(this.dbResourceAllocator.NewDbParameter("@ownerID", this.DbOwnerId(ownerId))); command.Parameters.Add(this.dbResourceAllocator.NewDbParameter("@nextTimer", item.NextTimer)); DbParameter parameter = this.dbResourceAllocator.NewDbParameter(); parameter.ParameterName = "@result"; parameter.DbType = DbType.Int32; parameter.Value = 0; parameter.Direction = ParameterDirection.InputOutput; command.Parameters.Add(parameter); DbParameter parameter2 = this.dbResourceAllocator.NewDbParameter(); parameter2.ParameterName = "@currentOwnerID"; parameter2.DbType = DbType.Guid; parameter2.Value = Guid.Empty; parameter2.Direction = ParameterDirection.InputOutput; command.Parameters.Add(parameter2); WorkflowTrace.Host.TraceEvent(TraceEventType.Information, 0, "SqlWorkflowPersistenceService({0}): inserting instance: {1}, unlocking: {2} database: {3}", new object[] { ownerId.ToString(), item.InstanceId.ToString(), item.Unlocked.ToString(), this.connection.Database }); command.ExecuteNonQuery(); CheckOwnershipResult(command); }
protected internal override void UnlockWorkflowInstanceState(Activity rootActivity) { PendingWorkItem workItem = new PendingWorkItem { Type = PendingWorkItem.ItemType.ActivationComplete, InstanceId = WorkflowEnvironment.WorkflowInstanceId }; WorkflowEnvironment.WorkBatch.Add(this, workItem); WorkflowTrace.Host.TraceEvent(TraceEventType.Information, 0, "SqlWorkflowPersistenceService({0}):Unlocking instance {1}", new object[] { this._serviceInstanceId.ToString(), workItem.InstanceId.ToString() }); }
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); }
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); }
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); }
// uidInstanceID, status, blocked, info, nextTimer internal protected override void SaveWorkflowInstanceState(Activity rootActivity, bool unlock) { if (rootActivity == null) throw new ArgumentNullException("rootActivity"); WorkflowStatus workflowStatus = WorkflowPersistenceService.GetWorkflowStatus(rootActivity); bool isInstanceBlocked = WorkflowPersistenceService.GetIsBlocked(rootActivity); string instanceInfo = WorkflowPersistenceService.GetSuspendOrTerminateInfo(rootActivity); Guid contextGuid = (Guid)rootActivity.GetValue(Activity.ActivityContextGuidProperty); PendingWorkItem item = new PendingWorkItem(); item.Type = PendingWorkItem.ItemType.Instance; item.InstanceId = WorkflowEnvironment.WorkflowInstanceId; if (workflowStatus != WorkflowStatus.Completed && workflowStatus != WorkflowStatus.Terminated) item.SerializedActivity = WorkflowPersistenceService.GetDefaultSerializedForm(rootActivity); else item.SerializedActivity = new Byte[0]; item.Status = (int)workflowStatus; item.Blocked = isInstanceBlocked ? 1 : 0; item.Info = instanceInfo; item.StateId = contextGuid; item.Unlocked = unlock; TimerEventSubscriptionCollection timers = (TimerEventSubscriptionCollection)rootActivity.GetValue(TimerEventSubscriptionCollection.TimerCollectionProperty); Debug.Assert(timers != null, "TimerEventSubscriptionCollection should never be null, but it is"); TimerEventSubscription sub = timers.Peek(); item.NextTimer = sub == null ? SqlDateTime.MaxValue : sub.ExpiresAt; if (item.Info == null) item.Info = ""; WorkflowTrace.Host.TraceEvent(TraceEventType.Information, 0, "SqlWorkflowPersistenceService({4}):Committing instance {0}, Blocked={1}, Unlocked={2}, NextTimer={3}", contextGuid.ToString(), item.Blocked, item.Unlocked, item.NextTimer.Value.ToLocalTime(), _serviceInstanceId.ToString()); WorkflowEnvironment.WorkBatch.Add(this, item); }
public void InsertInstanceState(PendingWorkItem item, Guid ownerId, DateTime ownedUntil) { /* sproc params @uidInstanceID uniqueidentifier, @state image, @status int, @artifacts image, @queueingState image, @unlocked int, @blocked int, @info ntext, @ownerId uniqueidentifier, @ownedUntil datetime @nextTimer datetime */ DbCommand command = NewStoredProcCommand("InsertInstanceState"); command.Parameters.Add(this.dbResourceAllocator.NewDbParameter("@uidInstanceID", item.InstanceId)); command.Parameters.Add(this.dbResourceAllocator.NewDbParameter("@state", item.SerializedActivity)); command.Parameters.Add(this.dbResourceAllocator.NewDbParameter("@status", item.Status)); command.Parameters.Add(this.dbResourceAllocator.NewDbParameter("@unlocked", item.Unlocked)); command.Parameters.Add(this.dbResourceAllocator.NewDbParameter("@blocked", item.Blocked)); command.Parameters.Add(this.dbResourceAllocator.NewDbParameter("@info", item.Info)); command.Parameters.Add(this.dbResourceAllocator.NewDbParameter("@ownedUntil", ownedUntil == DateTime.MaxValue ? SqlDateTime.MaxValue : ownedUntil)); command.Parameters.Add(this.dbResourceAllocator.NewDbParameter("@ownerID", DbOwnerId(ownerId))); command.Parameters.Add(this.dbResourceAllocator.NewDbParameter("@nextTimer", item.NextTimer)); DbParameter p1 = this.dbResourceAllocator.NewDbParameter(); p1.ParameterName = "@result"; p1.DbType = DbType.Int32; p1.Value = 0; p1.Direction = ParameterDirection.InputOutput; command.Parameters.Add(p1); //command.Parameters.Add(this.dbResourceAllocator.NewDbParameter("@result", DbType.Int32, ParameterDirection.Output)); DbParameter p2 = this.dbResourceAllocator.NewDbParameter(); p2.ParameterName = "@currentOwnerID"; p2.DbType = DbType.Guid; p2.Value = Guid.Empty; p2.Direction = ParameterDirection.InputOutput; command.Parameters.Add(p2); //command.Parameters.Add(new DbParameter(this.dbResourceAllocator.NewDbParameter("@currentOwnerID", DbType.Guid, ParameterDirection.InputOutput)); #if DEBUG InsertToDbMap(ownerId, connection.Database); #endif WorkflowTrace.Host.TraceEvent(TraceEventType.Information, 0, "SqlWorkflowPersistenceService({0}): inserting instance: {1}, unlocking: {2} database: {3}", ownerId.ToString(), item.InstanceId.ToString(), item.Unlocked.ToString(), connection.Database); // // Cannot retry locally here as we don't own the tx // Rely on external retries at the batch commit or workflow level (for tx scopes) command.ExecuteNonQuery(); CheckOwnershipResult(command); }
internal protected override void UnlockWorkflowInstanceState(Activity rootActivity) { PendingWorkItem item = new PendingWorkItem(); item.Type = PendingWorkItem.ItemType.ActivationComplete; item.InstanceId = WorkflowEnvironment.WorkflowInstanceId; WorkflowEnvironment.WorkBatch.Add(this, item); WorkflowTrace.Host.TraceEvent(TraceEventType.Information, 0, "SqlWorkflowPersistenceService({0}):Unlocking instance {1}", _serviceInstanceId.ToString(), item.InstanceId.ToString()); }