/// <summary> /// Insert instance state into the persistence store. /// </summary> /// <param name="workItem"></param> /// <param name="ownerId"></param> /// <param name="ownedUntil"></param> public void InsertInstanceState(PendingWorkItem workItem, Guid ownerId, DateTime ownedUntil) { using (DbCommand dbCommand = resourceProvider.CreateCommand(dbConnection, nameResolver.ResolveCommandName(CommandNames.InsertInstanceState), CommandType.StoredProcedure)) { string instanceParameter = nameResolver.ResolveParameterName( CommandNames.InsertInstanceState, ParameterNames.InstanceId); string resultParameter = nameResolver.ResolveParameterName( CommandNames.InsertInstanceState, ParameterNames.Result); resourceProvider.AddParameter(dbCommand, instanceParameter, workItem.InstanceId, AdoDbType.Guid); resourceProvider.AddParameter(dbCommand, nameResolver.ResolveParameterName(CommandNames.InsertInstanceState, ParameterNames.State), workItem.SerialisedActivity, AdoDbType.Binary); resourceProvider.AddParameter(dbCommand, nameResolver.ResolveParameterName(CommandNames.InsertInstanceState, ParameterNames.Status), workItem.Status, AdoDbType.Int32); resourceProvider.AddParameter(dbCommand, nameResolver.ResolveParameterName(CommandNames.InsertInstanceState, ParameterNames.Unlock), workItem.Unlock, AdoDbType.Boolean); resourceProvider.AddParameter(dbCommand, nameResolver.ResolveParameterName(CommandNames.InsertInstanceState, ParameterNames.IsBlocked), workItem.IsBlocked, AdoDbType.Boolean); resourceProvider.AddParameter(dbCommand, nameResolver.ResolveParameterName(CommandNames.InsertInstanceState, ParameterNames.Info), workItem.Info, AdoDbType.String); resourceProvider.AddParameter(dbCommand, nameResolver.ResolveParameterName(CommandNames.InsertInstanceState, ParameterNames.OwnerId), ownerId, AdoDbType.Guid); resourceProvider.AddParameter(dbCommand, nameResolver.ResolveParameterName(CommandNames.InsertInstanceState, ParameterNames.OwnedUntil), ownedUntil, AdoDbType.DateTime); resourceProvider.AddParameter(dbCommand, nameResolver.ResolveParameterName(CommandNames.InsertInstanceState, ParameterNames.NextTimer), workItem.NextTimer, AdoDbType.DateTime); resourceProvider.AddParameter(dbCommand, resultParameter, AdoDbType.Int32, ParameterDirection.Output); resourceProvider.AddParameter(dbCommand, nameResolver.ResolveParameterName(CommandNames.InsertInstanceState, ParameterNames.CurrentOwnerId), AdoDbType.Guid, ParameterDirection.Output); dbCommand.ExecuteNonQuery(); checkResult(dbCommand, resultParameter, instanceParameter); } }
/// <summary> /// Insert instance state into the persistence store. /// </summary> /// <param name="workItem"></param> /// <param name="ownerId"></param> /// <param name="ownedUntil"></param> public void InsertInstanceState(PendingWorkItem workItem, Guid ownerId, DateTime ownedUntil) { using (DbCommand dbCommand = CreateCommand(_nameResolver.ResolveCommandName(PersistenceCommandName.InsertInstanceState), CommandType.StoredProcedure)) { String instanceParameter = _nameResolver.ResolveParameterName( PersistenceCommandName.InsertInstanceState, PersistenceParameterName.InstanceId); String resultParameter = _nameResolver.ResolveParameterName( PersistenceCommandName.InsertInstanceState, PersistenceParameterName.Result); AddParameter(dbCommand, instanceParameter, workItem.InstanceId, AdoDbType.Guid); AddParameter(dbCommand, _nameResolver.ResolveParameterName( PersistenceCommandName.InsertInstanceState, PersistenceParameterName.State), workItem.SerialisedActivity, AdoDbType.Binary); AddParameter(dbCommand, _nameResolver.ResolveParameterName( PersistenceCommandName.InsertInstanceState, PersistenceParameterName.Status), workItem.Status, AdoDbType.Int32); AddParameter(dbCommand, _nameResolver.ResolveParameterName( PersistenceCommandName.InsertInstanceState, PersistenceParameterName.Unlock), workItem.Unlock, AdoDbType.Boolean); AddParameter(dbCommand, _nameResolver.ResolveParameterName( PersistenceCommandName.InsertInstanceState, PersistenceParameterName.IsBlocked), workItem.IsBlocked, AdoDbType.Boolean); AddParameter(dbCommand, _nameResolver.ResolveParameterName( PersistenceCommandName.InsertInstanceState, PersistenceParameterName.Info), workItem.Info, AdoDbType.Text); AddParameter(dbCommand, _nameResolver.ResolveParameterName( PersistenceCommandName.InsertInstanceState, PersistenceParameterName.OwnerId), ownerId, AdoDbType.Guid); AddParameter(dbCommand, _nameResolver.ResolveParameterName( PersistenceCommandName.InsertInstanceState, PersistenceParameterName.OwnedUntil), ownedUntil.ToUniversalTime(), AdoDbType.DateTime); AddParameter(dbCommand, _nameResolver.ResolveParameterName( PersistenceCommandName.InsertInstanceState, PersistenceParameterName.NextTimer), workItem.NextTimer, AdoDbType.DateTime); AddParameter(dbCommand, resultParameter, AdoDbType.Int32, ParameterDirection.Output); AddParameter(dbCommand, _nameResolver.ResolveParameterName( PersistenceCommandName.InsertInstanceState, PersistenceParameterName.CurrentOwnerId), AdoDbType.Guid, ParameterDirection.Output); dbCommand.ExecuteNonQuery(); CheckResult(dbCommand, resultParameter, instanceParameter); } }
/// <summary> /// Insert instance state into the persistence store. /// </summary> /// <param name="workItem"></param> /// <param name="ownerId"></param> /// <param name="ownedUntil"></param> public void InsertInstanceState(PendingWorkItem workItem, Guid ownerId, DateTime ownedUntil) { WfLogHelper.WriteLog("持久化InsertInstanceState InstanceId=" + workItem.InstanceId + ";ownerId=" + ownerId + ";时间=" + ownedUntil); using (DbCommand dbCommand = CreateCommand(nameResolver.ResolveCommandName(PersistenceCommandName.InsertInstanceState), CommandType.StoredProcedure)) { string instanceParameter = nameResolver.ResolveParameterName( PersistenceCommandName.InsertInstanceState, PersistenceParameterName.InstanceId); string resultParameter = nameResolver.ResolveParameterName( PersistenceCommandName.InsertInstanceState, PersistenceParameterName.Result); AddParameter(dbCommand, instanceParameter, workItem.InstanceId, AdoDbType.Guid); //DbParameter dp= AddParameter(dbCommand, nameResolver.ResolveParameterName( // PersistenceCommandName.InsertInstanceState, // PersistenceParameterName.State), workItem.SerialisedActivity, // AdoDbType.Binary); #region beyond OracleCommand cmd2 = (OracleCommand)dbCommand.Connection.CreateCommand(); //OracleTransaction tx; //tx = conn.BeginTransaction(); //cmd2.Transaction = tx; cmd2.CommandText = "declare xx blob; begin dbms_lob.createtemporary(xx, false, 0); :tempblob := xx; end;"; cmd2.Parameters.Add(new OracleParameter("tempblob", OracleType.Blob)); cmd2.Parameters["tempblob"].Direction = ParameterDirection.Output; cmd2.ExecuteNonQuery(); OracleLob tempLob; tempLob = (OracleLob)cmd2.Parameters["tempblob"].Value; tempLob.BeginBatch(OracleLobOpenMode.ReadWrite); tempLob.Write(workItem.SerialisedActivity, 0, workItem.SerialisedActivity.Length); tempLob.EndBatch(); //dbCommand.Parameters.Add(new OracleParameter("p_STATE", OracleType.Blob)); OracleParameter p_STATE = new OracleParameter("p_STATE", OracleType.Blob); p_STATE.Direction = ParameterDirection.Input; p_STATE.Value = tempLob; dbCommand.Parameters.Add(p_STATE); #endregion AddParameter(dbCommand, nameResolver.ResolveParameterName( PersistenceCommandName.InsertInstanceState, PersistenceParameterName.Status), workItem.Status, AdoDbType.Int32); AddParameter(dbCommand, nameResolver.ResolveParameterName( PersistenceCommandName.InsertInstanceState, PersistenceParameterName.Unlock), workItem.Unlock, AdoDbType.Boolean); AddParameter(dbCommand, nameResolver.ResolveParameterName( PersistenceCommandName.InsertInstanceState, PersistenceParameterName.IsBlocked), workItem.IsBlocked, AdoDbType.Boolean); AddParameter(dbCommand, nameResolver.ResolveParameterName( PersistenceCommandName.InsertInstanceState, PersistenceParameterName.Info), workItem.Info, AdoDbType.Text); AddParameter(dbCommand, nameResolver.ResolveParameterName( PersistenceCommandName.InsertInstanceState, PersistenceParameterName.OwnerId), ownerId, AdoDbType.Guid); AddParameter(dbCommand, nameResolver.ResolveParameterName( PersistenceCommandName.InsertInstanceState, PersistenceParameterName.OwnedUntil), ownedUntil.ToUniversalTime(), AdoDbType.DateTime); AddParameter(dbCommand, nameResolver.ResolveParameterName( PersistenceCommandName.InsertInstanceState, PersistenceParameterName.NextTimer), workItem.NextTimer, AdoDbType.DateTime); AddParameter(dbCommand, resultParameter, AdoDbType.Int32, ParameterDirection.Output); AddParameter(dbCommand, nameResolver.ResolveParameterName( PersistenceCommandName.InsertInstanceState, PersistenceParameterName.CurrentOwnerId), AdoDbType.Guid, ParameterDirection.Output); dbCommand.ExecuteNonQuery(); checkResult(dbCommand, resultParameter, instanceParameter); } }
/// <summary> /// Unlock a workflow instance. /// </summary> /// <param name="rootActivity"> /// The root activity of the workflow instance. /// </param> protected override void UnlockWorkflowInstanceState(Activity rootActivity) { TraceHelper.Trace(); try { PendingWorkItem workItem = new PendingWorkItem(); workItem.Type = PendingWorkItem.ItemType.ActivationComplete; workItem.InstanceId = WorkflowEnvironment.WorkflowInstanceId; WorkflowEnvironment.WorkBatch.Add(this, workItem); } catch (Exception e) { string errorMessage = RM.Get_Error_PersistenceServiceException(e.ToString()); TraceHelper.Trace(errorMessage); PersistenceException persistenceException = new PersistenceException(errorMessage, e); base.RaiseServicesExceptionNotHandledEvent( persistenceException, WorkflowEnvironment.WorkflowInstanceId); throw persistenceException; } }
/// <summary> /// Persist a workflow instance to the persistence store. /// </summary> /// <param name="rootActivity"> /// Root activity of the workflow instance. /// </param> /// <param name="unlock"> /// Indicates whether to unlock the instance when complete. /// </param> protected override void SaveWorkflowInstanceState(Activity rootActivity, bool unlock) { TraceHelper.Trace(); try { if (rootActivity == null) throw new ArgumentNullException("rootActivity"); PendingWorkItem workItem = new PendingWorkItem(); workItem.Status = GetWorkflowStatus(rootActivity); workItem.IsBlocked = GetIsBlocked(rootActivity); workItem.Info = GetSuspendOrTerminateInfo(rootActivity); workItem.StateId = (Guid) rootActivity.GetValue(Activity.ActivityContextGuidProperty); workItem.Type = PendingWorkItem.ItemType.Instance; workItem.InstanceId = WorkflowEnvironment.WorkflowInstanceId; workItem.Unlock = unlock; if (workItem.Status != WorkflowStatus.Completed && workItem.Status != WorkflowStatus.Terminated) workItem.SerialisedActivity = GetDefaultSerializedForm(rootActivity); else workItem.SerialisedActivity = new byte[0]; TimerEventSubscription timerEventSubscription = ((TimerEventSubscriptionCollection) rootActivity.GetValue( TimerEventSubscriptionCollection.TimerCollectionProperty)).Peek(); if (timerEventSubscription == null) workItem.NextTimer = null; else workItem.NextTimer = timerEventSubscription.ExpiresAt; WorkflowEnvironment.WorkBatch.Add(this, workItem); } catch (Exception e) { Tracer.Debug("�־û�SaveWorkflowInstanceState�����쳣:" + e.ToString()); string errorMessage = RM.Get_Error_PersistenceServiceException(e.ToString()); TraceHelper.Trace(errorMessage); PersistenceException persistenceException = new PersistenceException(errorMessage, e); base.RaiseServicesExceptionNotHandledEvent( persistenceException, WorkflowEnvironment.WorkflowInstanceId); throw persistenceException; } }
/// <summary> /// Persist a completed scope to the persistence store. /// </summary> /// <param name="activity"> /// The completed scope to pesist. /// </param> protected override void SaveCompletedContextActivity(Activity activity) { TraceHelper.Trace(); try { PendingWorkItem workItem = new PendingWorkItem(); workItem.Type = PendingWorkItem.ItemType.CompletedScope; workItem.SerialisedActivity = GetDefaultSerializedForm(activity); workItem.InstanceId = WorkflowEnvironment.WorkflowInstanceId; workItem.StateId = (Guid)activity.GetValue( Activity.ActivityContextGuidProperty); WorkflowEnvironment.WorkBatch.Add(this, workItem); } catch (Exception e) { string errorMessage = RM.Get_Error_PersistenceServiceException(e.ToString()); TraceHelper.Trace(errorMessage); PersistenceException persistenceException = new PersistenceException(errorMessage, e); base.RaiseServicesExceptionNotHandledEvent( persistenceException, WorkflowEnvironment.WorkflowInstanceId); throw persistenceException; } }