protected internal override Activity LoadCompletedContextActivity(Guid id, Activity outerActivity)
 {
     using (PersistenceDBAccessor accessor = new PersistenceDBAccessor(this._dbResourceAllocator, this._enableRetries))
     {
         return(WorkflowPersistenceService.RestoreFromDefaultSerializedForm(accessor.RetrieveCompletedScope(id), outerActivity));
     }
 }
 private IList <Guid> LoadExpiredTimerIds()
 {
     using (PersistenceDBAccessor accessor = new PersistenceDBAccessor(this._dbResourceAllocator, this._enableRetries))
     {
         return(accessor.RetrieveExpiredTimerIds(this._serviceInstanceId, this.OwnershipTimeout));
     }
 }
 protected internal override Activity LoadWorkflowInstanceState(Guid id)
 {
     using (PersistenceDBAccessor accessor = new PersistenceDBAccessor(this._dbResourceAllocator, this._enableRetries))
     {
         WorkflowTrace.Host.TraceEvent(TraceEventType.Information, 0, "SqlWorkflowPersistenceService({0}):Loading instance {1}", new object[] { this._serviceInstanceId.ToString(), id.ToString() });
         return(WorkflowPersistenceService.RestoreFromDefaultSerializedForm(accessor.RetrieveInstanceState(id, this._serviceInstanceId, this.OwnershipTimeout), null));
     }
 }
 public IEnumerable <SqlPersistenceWorkflowInstanceDescription> GetAllWorkflows()
 {
     if (base.State == WorkflowRuntimeServiceState.Started)
     {
         using (PersistenceDBAccessor accessor = new PersistenceDBAccessor(this._dbResourceAllocator, this._enableRetries))
         {
             return(accessor.RetrieveAllInstanceDescriptions());
         }
     }
     throw new InvalidOperationException(string.Format(CultureInfo.CurrentCulture, ExecutionStringManager.WorkflowRuntimeNotStarted, new object[0]));
 }
        void IPendingWork.Commit(Transaction transaction, ICollection items)
        {
            PersistenceDBAccessor accessor = null;

            try
            {
                accessor = new PersistenceDBAccessor(this._dbResourceAllocator, transaction, this._transactionService);
                foreach (PendingWorkItem item in items)
                {
                    switch (item.Type)
                    {
                    case PendingWorkItem.ItemType.Instance:
                        accessor.InsertInstanceState(item, this._serviceInstanceId, this.OwnershipTimeout);
                        break;

                    case PendingWorkItem.ItemType.CompletedScope:
                        accessor.InsertCompletedScope(item.InstanceId, item.StateId, item.SerializedActivity);
                        break;

                    case PendingWorkItem.ItemType.ActivationComplete:
                        accessor.ActivationComplete(item.InstanceId, this._serviceInstanceId);
                        break;
                    }
                }
            }
            catch (SqlException exception)
            {
                WorkflowTrace.Runtime.TraceEvent(TraceEventType.Error, 0, "SqlWorkflowPersistenceService({1})Exception thrown while persisting instance: {0}", new object[] { exception.Message, this._serviceInstanceId.ToString() });
                WorkflowTrace.Runtime.TraceEvent(TraceEventType.Error, 0, "stacktrace : {0}", new object[] { exception.StackTrace });
                if (exception.Number == _deadlock)
                {
                    PersistenceException exception2 = new PersistenceException(exception.Message, exception);
                    throw exception2;
                }
                throw;
            }
            catch (Exception exception3)
            {
                WorkflowTrace.Runtime.TraceEvent(TraceEventType.Error, 0, "SqlWorkflowPersistenceService({1}): Exception thrown while persisting instance: {0}", new object[] { exception3.Message, this._serviceInstanceId.ToString() });
                WorkflowTrace.Runtime.TraceEvent(TraceEventType.Error, 0, "stacktrace : {0}", new object[] { exception3.StackTrace });
                throw exception3;
            }
            finally
            {
                if (accessor != null)
                {
                    accessor.Dispose();
                }
            }
        }
 private void RecoverRunningWorkflowInstances()
 {
     if (Guid.Empty == this._serviceInstanceId)
     {
         IList <Guid> list = null;
         using (PersistenceDBAccessor accessor = new PersistenceDBAccessor(this._dbResourceAllocator, this._enableRetries))
         {
             list = accessor.RetrieveNonblockingInstanceStateIds(this._serviceInstanceId, this.OwnershipTimeout);
         }
         foreach (Guid guid in list)
         {
             try
             {
                 base.Runtime.GetWorkflow(guid).Load();
             }
             catch (Exception exception)
             {
                 base.RaiseServicesExceptionNotHandledEvent(exception, guid);
             }
         }
     }
     else
     {
         using (PersistenceDBAccessor accessor2 = new PersistenceDBAccessor(this._dbResourceAllocator, this._enableRetries))
         {
             Guid guid2;
             while (accessor2.TryRetrieveANonblockingInstanceStateId(this._serviceInstanceId, this.OwnershipTimeout, out guid2))
             {
                 try
                 {
                     base.Runtime.GetWorkflow(guid2).Load();
                     continue;
                 }
                 catch (Exception exception2)
                 {
                     base.RaiseServicesExceptionNotHandledEvent(exception2, guid2);
                     continue;
                 }
             }
         }
     }
 }
        void IPendingWork.Commit(Transaction transaction, ICollection items)
        {
            PersistenceDBAccessor accessor = null;
            try
            {
                accessor = new PersistenceDBAccessor(this._dbResourceAllocator, transaction, this._transactionService);
                foreach (PendingWorkItem item in items)
                {
                    switch (item.Type)
                    {
                        case PendingWorkItem.ItemType.Instance:
                            accessor.InsertInstanceState(item, this._serviceInstanceId, this.OwnershipTimeout);
                            break;

                        case PendingWorkItem.ItemType.CompletedScope:
                            accessor.InsertCompletedScope(item.InstanceId, item.StateId, item.SerializedActivity);
                            break;

                        case PendingWorkItem.ItemType.ActivationComplete:
                            accessor.ActivationComplete(item.InstanceId, this._serviceInstanceId);
                            break;
                    }
                }
            }
            catch (SqlException exception)
            {
                WorkflowTrace.Runtime.TraceEvent(TraceEventType.Error, 0, "SqlWorkflowPersistenceService({1})Exception thrown while persisting instance: {0}", new object[] { exception.Message, this._serviceInstanceId.ToString() });
                WorkflowTrace.Runtime.TraceEvent(TraceEventType.Error, 0, "stacktrace : {0}", new object[] { exception.StackTrace });
                if (exception.Number == _deadlock)
                {
                    PersistenceException exception2 = new PersistenceException(exception.Message, exception);
                    throw exception2;
                }
                throw;
            }
            catch (Exception exception3)
            {
                WorkflowTrace.Runtime.TraceEvent(TraceEventType.Error, 0, "SqlWorkflowPersistenceService({1}): Exception thrown while persisting instance: {0}", new object[] { exception3.Message, this._serviceInstanceId.ToString() });
                WorkflowTrace.Runtime.TraceEvent(TraceEventType.Error, 0, "stacktrace : {0}", new object[] { exception3.StackTrace });
                throw exception3;
            }
            finally
            {
                if (accessor != null)
                {
                    accessor.Dispose();
                }
            }
        }
 private void RecoverRunningWorkflowInstances()
 {
     if (Guid.Empty == this._serviceInstanceId)
     {
         IList<Guid> list = null;
         using (PersistenceDBAccessor accessor = new PersistenceDBAccessor(this._dbResourceAllocator, this._enableRetries))
         {
             list = accessor.RetrieveNonblockingInstanceStateIds(this._serviceInstanceId, this.OwnershipTimeout);
         }
         foreach (Guid guid in list)
         {
             try
             {
                 base.Runtime.GetWorkflow(guid).Load();
             }
             catch (Exception exception)
             {
                 base.RaiseServicesExceptionNotHandledEvent(exception, guid);
             }
         }
     }
     else
     {
         using (PersistenceDBAccessor accessor2 = new PersistenceDBAccessor(this._dbResourceAllocator, this._enableRetries))
         {
             Guid guid2;
             while (accessor2.TryRetrieveANonblockingInstanceStateId(this._serviceInstanceId, this.OwnershipTimeout, out guid2))
             {
                 try
                 {
                     base.Runtime.GetWorkflow(guid2).Load();
                     continue;
                 }
                 catch (Exception exception2)
                 {
                     base.RaiseServicesExceptionNotHandledEvent(exception2, guid2);
                     continue;
                 }
             }
         }
     }
 }
 protected internal override Activity LoadWorkflowInstanceState(Guid id)
 {
     using (PersistenceDBAccessor accessor = new PersistenceDBAccessor(this._dbResourceAllocator, this._enableRetries))
     {
         WorkflowTrace.Host.TraceEvent(TraceEventType.Information, 0, "SqlWorkflowPersistenceService({0}):Loading instance {1}", new object[] { this._serviceInstanceId.ToString(), id.ToString() });
         return WorkflowPersistenceService.RestoreFromDefaultSerializedForm(accessor.RetrieveInstanceState(id, this._serviceInstanceId, this.OwnershipTimeout), null);
     }
 }
 private IList<Guid> LoadExpiredTimerIds()
 {
     using (PersistenceDBAccessor accessor = new PersistenceDBAccessor(this._dbResourceAllocator, this._enableRetries))
     {
         return accessor.RetrieveExpiredTimerIds(this._serviceInstanceId, this.OwnershipTimeout);
     }
 }
 protected internal override Activity LoadCompletedContextActivity(Guid id, Activity outerActivity)
 {
     using (PersistenceDBAccessor accessor = new PersistenceDBAccessor(this._dbResourceAllocator, this._enableRetries))
     {
         return WorkflowPersistenceService.RestoreFromDefaultSerializedForm(accessor.RetrieveCompletedScope(id), outerActivity);
     }
 }
 public IEnumerable<SqlPersistenceWorkflowInstanceDescription> GetAllWorkflows()
 {
     if (base.State == WorkflowRuntimeServiceState.Started)
     {
         using (PersistenceDBAccessor accessor = new PersistenceDBAccessor(this._dbResourceAllocator, this._enableRetries))
         {
             return accessor.RetrieveAllInstanceDescriptions();
         }
     }
     throw new InvalidOperationException(string.Format(CultureInfo.CurrentCulture, ExecutionStringManager.WorkflowRuntimeNotStarted, new object[0]));
 }
 private void RecoverRunningWorkflowInstances()
 {
     if (Guid.Empty == _serviceInstanceId)
     {
         //
         // Only one host, get all the ids in one go
         IList<Guid> instanceIds = null;
         using (PersistenceDBAccessor persistenceDBAccessor = new PersistenceDBAccessor(_dbResourceAllocator, _enableRetries))
         {
             instanceIds = persistenceDBAccessor.RetrieveNonblockingInstanceStateIds(_serviceInstanceId, OwnershipTimeout);
         }
         foreach (Guid instanceId in instanceIds)
         {
             try
             {
                 WorkflowInstance instance = Runtime.GetWorkflow(instanceId);
                 instance.Load();
             }
             catch (Exception e)
             {
                 RaiseServicesExceptionNotHandledEvent(e, instanceId);
             }
         }
     }
     else
     {
         using (PersistenceDBAccessor persistenceDBAccessor = new PersistenceDBAccessor(_dbResourceAllocator, _enableRetries))
         {
             //
             // Load one at a time to avoid thrashing with other hosts
             Guid instanceId;
             while (persistenceDBAccessor.TryRetrieveANonblockingInstanceStateId(_serviceInstanceId, OwnershipTimeout, out instanceId))
             {
                 try
                 {
                     WorkflowInstance instance = Runtime.GetWorkflow(instanceId);
                     instance.Load();
                 }
                 catch (Exception e)
                 {
                     RaiseServicesExceptionNotHandledEvent(e, instanceId);
                 }
             }
         }
     }
 }
        /// <summary>
        /// Commmit the work items using the transaction
        /// </summary>
        /// <param name="transaction"></param>        
        /// <param name="items"></param>
        void IPendingWork.Commit(System.Transactions.Transaction transaction, ICollection items)
        {
            PersistenceDBAccessor persistenceDBAccessor = null;
            try
            {
                persistenceDBAccessor = new PersistenceDBAccessor(_dbResourceAllocator, transaction, _transactionService);
                foreach (PendingWorkItem item in items)
                {
                    switch (item.Type)
                    {
                        case PendingWorkItem.ItemType.Instance:
                            persistenceDBAccessor.InsertInstanceState(item, _serviceInstanceId, OwnershipTimeout);
                            break;

                        case PendingWorkItem.ItemType.CompletedScope:
                            persistenceDBAccessor.InsertCompletedScope(item.InstanceId, item.StateId, item.SerializedActivity);
                            break;

                        case PendingWorkItem.ItemType.ActivationComplete:
                            persistenceDBAccessor.ActivationComplete(item.InstanceId, _serviceInstanceId);
                            break;

                        default:
                            Debug.Assert(false, "Committing unknown pending work item type in SqlPersistenceService.Commit()");
                            break;
                    }

                }
            }
            catch (SqlException se)
            {
                WorkflowTrace.Runtime.TraceEvent(TraceEventType.Error, 0, "SqlWorkflowPersistenceService({1})Exception thrown while persisting instance: {0}", se.Message, _serviceInstanceId.ToString());
                WorkflowTrace.Runtime.TraceEvent(TraceEventType.Error, 0, "stacktrace : {0}", se.StackTrace);

                if (se.Number == _deadlock)
                {
                    PersistenceException pe = new PersistenceException(se.Message, se);
                    throw pe;
                }
                else
                {
                    throw;
                }

            }
            catch (Exception e)
            {
                WorkflowTrace.Runtime.TraceEvent(TraceEventType.Error, 0, "SqlWorkflowPersistenceService({1}): Exception thrown while persisting instance: {0}", e.Message, _serviceInstanceId.ToString());
                WorkflowTrace.Runtime.TraceEvent(TraceEventType.Error, 0, "stacktrace : {0}", e.StackTrace);
                throw e;
            }
            finally
            {
                if (persistenceDBAccessor != null)
                    persistenceDBAccessor.Dispose();
            }
        }
 internal protected override Activity LoadCompletedContextActivity(Guid id, Activity outerActivity)
 {
     using (PersistenceDBAccessor persistenceDBAccessor = new PersistenceDBAccessor(_dbResourceAllocator, _enableRetries))
     {
         byte[] state = persistenceDBAccessor.RetrieveCompletedScope(id);
         return WorkflowPersistenceService.RestoreFromDefaultSerializedForm(state, outerActivity);
     }
 }
        internal protected override Activity LoadWorkflowInstanceState(Guid id)
        {
            using (PersistenceDBAccessor persistenceDBAccessor = new PersistenceDBAccessor(_dbResourceAllocator, _enableRetries))
            {
                WorkflowTrace.Host.TraceEvent(TraceEventType.Information, 0, "SqlWorkflowPersistenceService({0}):Loading instance {1}", _serviceInstanceId.ToString(), id.ToString());
                byte[] state = persistenceDBAccessor.RetrieveInstanceState(id, _serviceInstanceId, OwnershipTimeout);
                return WorkflowPersistenceService.RestoreFromDefaultSerializedForm(state, null);
            }

        }