Exemplo n.º 1
2
        protected override IAsyncResult BeginTryCommand(InstancePersistenceContext context, InstancePersistenceCommand command, TimeSpan timeout, AsyncCallback callback, object state)
        {
            StructuredTracer.Correlate();

            try
            {
                if (command is SaveWorkflowCommand)
                {
                    return new TypedCompletedAsyncResult<bool>(SaveWorkflow(context, (SaveWorkflowCommand)command), callback, state);
                }
                else if (command is LoadWorkflowCommand)
                {
                    return new TypedCompletedAsyncResult<bool>(LoadWorkflow(context, (LoadWorkflowCommand)command), callback, state);
                }
                else if (command is CreateWorkflowOwnerCommand)
                {
                    return new TypedCompletedAsyncResult<bool>(CreateWorkflowOwner(context, (CreateWorkflowOwnerCommand)command), callback, state);
                }
                else if (command is DeleteWorkflowOwnerCommand)
                {
                    return new TypedCompletedAsyncResult<bool>(DeleteWorkflowOwner(context, (DeleteWorkflowOwnerCommand)command), callback, state);
                }
                return new TypedCompletedAsyncResult<bool>(false, callback, state);
            }
            catch (Exception e)
            {
                return new TypedCompletedAsyncResult<Exception>(e, callback, state);
            }
        }
Exemplo n.º 2
0
        //The persistence engine will send a variety of commands to the configured InstanceStore,
        //such as CreateWorkflowOwnerCommand, SaveWorkflowCommand, and LoadWorkflowCommand.
        //This method is where we will handle those commands
        protected override IAsyncResult BeginTryCommand(InstancePersistenceContext context, InstancePersistenceCommand command, TimeSpan timeout, AsyncCallback callback, object state)
        {
            IDictionary<XName, InstanceValue> data;

            //The CreateWorkflowOwner command instructs the instance store to create a new instance owner bound to the instanace handle
            if (command is CreateWorkflowOwnerCommand)
            {
                context.BindInstanceOwner(this.ownerInstanceId, Guid.NewGuid());
            }
            //The SaveWorkflow command instructs the instance store to modify the instance bound to the instance handle or an instance key
            else if (command is SaveWorkflowCommand)
            {
                var saveCommand = (SaveWorkflowCommand)command;
                data = saveCommand.InstanceData;

                this.Save(data);
            }
            //The LoadWorkflow command instructs the instance store to lock and load the instance bound to the identifier in the instance handle
            else if (command is LoadWorkflowCommand)
            {
                var fileName = IoHelper.GetFileName(this.ownerInstanceId);

                using (var inputStream = new FileStream(fileName, FileMode.Open))
                {
                    data = LoadInstanceDataFromFile(inputStream);
                    //load the data into the persistence Context
                    context.LoadedInstance(InstanceState.Initialized, data, null, null, null);
                }
            }

            return new CompletedAsyncResult<bool>(true, callback, state);
        }
 public IAsyncResult BeginExecute(InstancePersistenceCommand command, TimeSpan timeout, AsyncCallback callback, object state)
 {
     IAsyncResult result;
     if (command == null)
     {
         throw Fx.Exception.ArgumentNull("command");
     }
     this.ThrowIfNotActive("BeginExecute");
     try
     {
         this.ReconcileTransaction();
         result = new ExecuteAsyncResult(this, command, timeout, callback, state);
     }
     catch (TimeoutException)
     {
         this.InstanceHandle.Free();
         throw;
     }
     catch (OperationCanceledException)
     {
         this.InstanceHandle.Free();
         throw;
     }
     return result;
 }
        protected override IAsyncResult BeginTryCommand(InstancePersistenceContext context, InstancePersistenceCommand command, TimeSpan timeout, AsyncCallback callback, object state)
        {
            if(context == null) throw new ArgumentNullException("context");
            if(command == null) throw new ArgumentNullException("command");

            // Log which commands we are receiving
            Debug.WriteLine("InstanceStore::BeginTryCommand::{0} received", command.GetType().Name);

            IAsyncResult result = null;  
            
            // validate the store lock
                      
            if (command is CreateWorkflowOwnerCommand)
            {
                result = CreateWorkflowOwner(context, (CreateWorkflowOwnerCommand) command, timeout, callback, state);
            }
                        
            if (result == null)
            {
                // Log which commands we are not handling
                Debug.WriteLine("InstanceStore::BeginTryCommand::{0} was not implemented", command.GetType().Name);

                // The base.BeginTryCommand will return a false (unhandled) return value
                return base.BeginTryCommand(context, command, timeout, callback, state);
            }
            return result;
        }
 public TryLoadRunnableWorkflowAsyncResult(InstancePersistenceContext context, InstancePersistenceCommand command, SqlWorkflowInstanceStore store, SqlWorkflowInstanceStoreLock storeLock, Transaction currentTransaction, TimeSpan timeout, AsyncCallback callback, object state) : base(context, command, store, storeLock, currentTransaction, timeout, callback, state)
 {
     if (base.Store.WorkflowHostType == Guid.Empty)
     {
         throw FxTrace.Exception.AsError(new InstancePersistenceCommandException(command.Name, System.Activities.DurableInstancing.SR.TryLoadRequiresWorkflowType, null));
     }
 }
 public SaveWorkflowAsyncResult(InstancePersistenceContext context, InstancePersistenceCommand command, SqlWorkflowInstanceStore store, SqlWorkflowInstanceStoreLock storeLock, Transaction currentTransaction, TimeSpan timeout, AsyncCallback callback, object state) : base(context, command, store, storeLock, currentTransaction, timeout, callback, state)
 {
     if (((SaveWorkflowCommand) command).InstanceKeyMetadataChanges.Count > 0)
     {
         throw FxTrace.Exception.AsError(new InstancePersistenceCommandException(System.Activities.DurableInstancing.SR.InstanceKeyMetadataChangesNotSupported));
     }
 }
Exemplo n.º 7
0
 public IAsyncResult BeginExecute(InstancePersistenceCommand command, TimeSpan timeout, AsyncCallback callback, object state)
 {
     if (execute_delegate == null)
     {
         execute_delegate = new Action <InstancePersistenceCommand, TimeSpan> (Execute);
     }
     return(execute_delegate.BeginInvoke(command, timeout, callback, state));
 }
Exemplo n.º 8
0
 public IAsyncResult BeginExecute(InstanceHandle handle, InstancePersistenceCommand command, TimeSpan timeout, AsyncCallback callback, object state)
 {
     if (execute_delegate == null)
     {
         execute_delegate = new Func <InstanceHandle, InstancePersistenceCommand, TimeSpan, InstanceView> (Execute);
     }
     return(execute_delegate.BeginInvoke(handle, command, timeout, callback, state));
 }
 internal IAsyncResult BeginTryCommandInternal(InstancePersistenceContext context, InstancePersistenceCommand command, TimeSpan timeout, AsyncCallback callback, object state)
 {
     SqlWorkflowInstanceStoreAsyncResult result = null;
     if (command is SaveWorkflowCommand)
     {
         result = new SaveWorkflowAsyncResult(context, command, this, this.storeLock, Transaction.Current, timeout, callback, state);
     }
     else if (command is TryLoadRunnableWorkflowCommand)
     {
         result = new TryLoadRunnableWorkflowAsyncResult(context, command, this, this.storeLock, Transaction.Current, timeout, callback, state);
     }
     else if (command is LoadWorkflowCommand)
     {
         result = new LoadWorkflowAsyncResult(context, command, this, this.storeLock, Transaction.Current, timeout, callback, state);
     }
     else if (command is LoadWorkflowByInstanceKeyCommand)
     {
         result = new LoadWorkflowByKeyAsyncResult(context, command, this, this.storeLock, Transaction.Current, timeout, callback, state);
     }
     else if (command is ExtendLockCommand)
     {
         result = new ExtendLockAsyncResult(null, command, this, this.storeLock, null, timeout, callback, state);
     }
     else if (command is DetectRunnableInstancesCommand)
     {
         result = new DetectRunnableInstancesAsyncResult(null, command, this, this.storeLock, null, timeout, callback, state);
     }
     else if (command is DetectActivatableWorkflowsCommand)
     {
         result = new DetectActivatableWorkflowsAsyncResult(null, command, this, this.storeLock, null, timeout, callback, state);
     }
     else if (command is RecoverInstanceLocksCommand)
     {
         result = new RecoverInstanceLocksAsyncResult(null, command, this, this.storeLock, null, timeout, callback, state);
     }
     else if (command is UnlockInstanceCommand)
     {
         result = new UnlockInstanceAsyncResult(null, command, this, this.storeLock, Transaction.Current, timeout, callback, state);
     }
     else if (command is CreateWorkflowOwnerCommand)
     {
         result = new CreateWorkflowOwnerAsyncResult(context, command, this, this.storeLock, Transaction.Current, timeout, callback, state);
     }
     else if (command is DeleteWorkflowOwnerCommand)
     {
         result = new DeleteWorkflowOwnerAsyncResult(context, command, this, this.storeLock, Transaction.Current, timeout, callback, state);
     }
     else if (command is QueryActivatableWorkflowsCommand)
     {
         result = new QueryActivatableWorkflowAsyncResult(context, command, this, this.storeLock, Transaction.Current, timeout, callback, state);
     }
     else
     {
         return base.BeginTryCommand(context, command, timeout, callback, state);
     }
     result.ScheduleCallback();
     return result;
 }
Exemplo n.º 10
0
        protected override IAsyncResult BeginTryCommand(
            InstancePersistenceContext context,
            InstancePersistenceCommand command,
            TimeSpan timeout, AsyncCallback callback, object state)
        {

            switch(command.GetType().Name)
            {
                case "CreateWorkflowOwnerCommand":

                    Func<Exception> createFunc = () => ProcessCreateWorkflowOwner(context,
                                                                                  command as CreateWorkflowOwnerCommand);

                    return createFunc.BeginInvoke(ar =>
                        {
                            Exception ex = createFunc.EndInvoke(ar);
                            callback(new InstanceStoreAsyncResult(ar, ex));
                        }, state);

                case "LoadWorkflowCommand":
                    Func<Exception> loadFunc = () => ProcessLoadWorkflow(context,
                                                                         command as LoadWorkflowCommand);

                    return loadFunc.BeginInvoke(ar =>
                        {
                            Exception ex = loadFunc.EndInvoke(ar);
                            callback(new InstanceStoreAsyncResult(ar, ex));
                        }, state);

                case "LoadWorkflowByInstanceKeyCommand":
                    Func<Exception> loadByKeyFunc = () => ProcessLoadWorkflowByInstanceKey(context,
                                                                                           command as LoadWorkflowByInstanceKeyCommand);

                    return loadByKeyFunc.BeginInvoke(ar =>
                        {
                            Exception ex = loadByKeyFunc.EndInvoke(ar);
                            callback(new InstanceStoreAsyncResult(ar, ex));
                        }, state);

                case "SaveWorkflowCommand":
                    Func<Exception> saveFunc = () => ProcessSaveWorkflow(context,
                                                                         command as SaveWorkflowCommand);

                    return saveFunc.BeginInvoke(ar =>
                        {
                            Exception ex = saveFunc.EndInvoke(ar);
                            callback(new InstanceStoreAsyncResult(ar, ex));
                        }, state);

                default:
                    return base.BeginTryCommand(
                        context, command, timeout, callback, state);
            }


        }
 public PersistenceTask(SqlWorkflowInstanceStore store, SqlWorkflowInstanceStoreLock storeLock, InstancePersistenceCommand instancePersistenceCommand, TimeSpan taskInterval, bool automaticallyResetTimer)
 {
     this.automaticallyResetTimer = automaticallyResetTimer;
     this.commandCompletedCallback = Fx.ThunkCallback(new AsyncCallback(this.CommandCompletedCallback));
     this.instancePersistenceCommand = instancePersistenceCommand;
     this.Store = store;
     this.StoreLock = storeLock;
     this.SurrogateLockOwnerId = this.StoreLock.SurrogateLockOwnerId;
     this.taskInterval = taskInterval;
     this.thisLock = new object();
 }
        public LoadRetryAsyncResult(SqlWorkflowInstanceStore store, InstancePersistenceContext context,
            InstancePersistenceCommand command, TimeSpan timeout, AsyncCallback callback, object state)
            : base(callback, state)
        {
            this.InstanceStore = store;
            this.InstancePersistenceContext = context;
            this.InstancePersistenceCommand = command;
            this.commandTimeout = new TimeoutHelper(timeout);

            InstanceStore.BeginTryCommandInternal(this.InstancePersistenceContext, this.InstancePersistenceCommand,
                this.commandTimeout.RemainingTime(), LoadRetryAsyncResult.onTryCommandCallback, this);
        }
 public ExtendLockAsyncResult
     (
     InstancePersistenceContext context,
     InstancePersistenceCommand command,
     SqlWorkflowInstanceStore store,
     SqlWorkflowInstanceStoreLock storeLock,
     Transaction currentTransaction,
     TimeSpan timeout, 
     AsyncCallback callback, 
     object state
     ) :
     base(context, command, store, storeLock, currentTransaction, timeout, int.MaxValue, callback, state)
 {
 }
 protected SqlWorkflowInstanceStoreAsyncResult
     (
     InstancePersistenceContext context,
     InstancePersistenceCommand command,
     SqlWorkflowInstanceStore store,
     SqlWorkflowInstanceStoreLock storeLock,
     Transaction currentTransaction,
     TimeSpan timeout,
     AsyncCallback callback,
     object state
     ) 
     : this(context, command, store, storeLock, currentTransaction, timeout, store.MaxConnectionRetries, callback, state)
 {
 }
 public DetectActivatableWorkflowsAsyncResult
     (
     InstancePersistenceContext context,
     InstancePersistenceCommand command,
     SqlWorkflowInstanceStore store,
     SqlWorkflowInstanceStoreLock storeLock,
     Transaction currentTransaction,
     TimeSpan timeout,
     AsyncCallback callback,
     object state
     ) :
     base(context, command, store, storeLock, currentTransaction, timeout, callback, state)
 {
 }
 public TestDatabaseVersionAndRunAsyncResult(
     InstancePersistenceContext context,
     InstancePersistenceCommand command,
     SqlWorkflowInstanceStore store,
     SqlWorkflowInstanceStoreLock storeLock,
     Transaction currentTransaction,
     TimeSpan timeout,
     Version targetVersion,
     AsyncCallback callback,
     object state) :
     base(context, command, store, storeLock, currentTransaction, timeout, callback, state)
 {
     this.currentTransaction = currentTransaction;
     this.targetVersion = targetVersion;
 }
 public LoadWorkflowAsyncResult
     (
     InstancePersistenceContext context, 
     InstancePersistenceCommand command, 
     SqlWorkflowInstanceStore store,
     SqlWorkflowInstanceStoreLock storeLock,
     Transaction currentTransaction,
     TimeSpan timeout, 
     AsyncCallback callback, 
     object state
     ) :
     base(context, command, store, storeLock, currentTransaction, timeout, callback, state)
 {
     this.associatedInstanceKeys = new Dictionary<Guid, IDictionary<XName, InstanceValue>>();
     this.completedInstanceKeys = new Dictionary<Guid, IDictionary<XName, InstanceValue>>();
     this.objectSerializer = ObjectSerializerFactory.GetDefaultObjectSerializer();
 }
 public IAsyncResult BeginExecute(InstanceHandle handle, InstancePersistenceCommand command, TimeSpan timeout, AsyncCallback callback, object state)
 {
     if (command == null)
     {
         throw Fx.Exception.ArgumentNull("command");
     }
     if (handle == null)
     {
         throw Fx.Exception.ArgumentNull("handle");
     }
     if (!object.ReferenceEquals(this, handle.Store))
     {
         throw Fx.Exception.Argument("handle", SRCore.ContextNotFromThisStore);
     }
     TimeoutHelper.ThrowIfNegativeArgument(timeout);
     return(InstancePersistenceContext.BeginOuterExecute(handle, command, Transaction.Current, timeout, callback, state));
 }
 public IAsyncResult BeginExecute(InstanceHandle handle, InstancePersistenceCommand command, TimeSpan timeout, AsyncCallback callback, object state)
 {
     if (command == null)
     {
         throw Fx.Exception.ArgumentNull("command");
     }
     if (handle == null)
     {
         throw Fx.Exception.ArgumentNull("handle");
     }
     if (!object.ReferenceEquals(this, handle.Store))
     {
         throw Fx.Exception.Argument("handle", SRCore.ContextNotFromThisStore);
     }
     TimeoutHelper.ThrowIfNegativeArgument(timeout);
     return InstancePersistenceContext.BeginOuterExecute(handle, command, Transaction.Current, timeout, callback, state);
 }
 protected internal override IAsyncResult BeginTryCommand(InstancePersistenceContext context, InstancePersistenceCommand command, TimeSpan timeout, AsyncCallback callback, object state)
 {
     if (context == null)
     {
         throw FxTrace.Exception.ArgumentNull("context");
     }
     if (command == null)
     {
         throw FxTrace.Exception.ArgumentNull("command");
     }
     if (!this.storeLock.IsValid && !(command is CreateWorkflowOwnerCommand))
     {
         throw FxTrace.Exception.AsError(new InstanceOwnerException(command.Name, this.storeLock.LockOwnerId));
     }
     if (this.IsRetryCommand(command))
     {
         return new LoadRetryAsyncResult(this, context, command, timeout, callback, state);
     }
     return this.BeginTryCommandInternal(context, command, timeout, callback, state);
 }
 // ExtendLockAsyncResult and RecoverInstanceLocksAsyncResult directly call this ctor
 protected SqlWorkflowInstanceStoreAsyncResult
     (
     InstancePersistenceContext context,
     InstancePersistenceCommand command,
     SqlWorkflowInstanceStore store,
     SqlWorkflowInstanceStoreLock storeLock,
     Transaction currentTransaction,
     TimeSpan timeout,
     int maximumRetries,
     AsyncCallback callback,
     object state
     ) :
     base(callback, state)
 {
     this.DependentTransaction = (currentTransaction != null) ? currentTransaction.DependentClone(DependentCloneOption.BlockCommitUntilComplete) : null;
     this.InstancePersistenceContext = context;
     this.InstancePersistenceCommand = command;
     this.Store = store;
     this.StoreLock = storeLock;
     this.TimeoutHelper = new TimeoutHelper(timeout);
     this.OnCompleting += SqlWorkflowInstanceStoreAsyncResult.finallyCallback;
     this.maximumRetries = maximumRetries;
 }
        public void Execute(InstancePersistenceCommand command, TimeSpan timeout)
        {
            if (command == null)
            {
                throw Fx.Exception.ArgumentNull("command");
            }
            ThrowIfNotActive("Execute");

            try
            {
                ReconcileTransaction();
                ExecuteAsyncResult.End(new ExecuteAsyncResult(this, command, timeout));
            }
            catch (TimeoutException)
            {
                InstanceHandle.Free();
                throw;
            }
            catch (OperationCanceledException)
            {
                InstanceHandle.Free();
                throw;
            }
        }
Exemplo n.º 23
0
 public InstanceView Execute(InstanceHandle handle, InstancePersistenceCommand command, TimeSpan timeout)
 {
     throw new NotImplementedException();
 }
Exemplo n.º 24
0
 protected internal virtual IAsyncResult BeginTryCommand(InstancePersistenceContext context, InstancePersistenceCommand command, TimeSpan timeout, AsyncCallback callback, object state)
 {
     if (try_command_delegate == null)
     {
         try_command_delegate = new Func <InstancePersistenceContext, InstancePersistenceCommand, TimeSpan, bool> (TryCommand);
     }
     return(try_command_delegate.BeginInvoke(context, command, timeout, callback, state));
 }
Exemplo n.º 25
0
 protected internal virtual IAsyncResult BeginTryCommand(InstancePersistenceContext context, InstancePersistenceCommand command, TimeSpan timeout, AsyncCallback callback, object state)
 {
     return(new CompletedAsyncResult <bool>(false, callback, state));
 }
 private bool IsRetryCommand(InstancePersistenceCommand command)
 {
     if (!this.IsLockRetryEnabled())
     {
         return false;
     }
     return ((command is LoadWorkflowByInstanceKeyCommand) || (command is LoadWorkflowCommand));
 }
Exemplo n.º 27
0
		public IAsyncResult BeginExecute (InstanceHandle handle, InstancePersistenceCommand command, TimeSpan timeout, AsyncCallback callback, object state)
		{
			if (execute_delegate == null)
				execute_delegate = new Func<InstanceHandle, InstancePersistenceCommand, TimeSpan, InstanceView> (Execute);
			return execute_delegate.BeginInvoke (handle, command, timeout, callback, state);
		}
Exemplo n.º 28
0
 protected internal virtual bool TryCommand(InstancePersistenceContext context, InstancePersistenceCommand command, TimeSpan timeout)
 {
     return(EndTryCommand(BeginTryCommand(context, command, timeout, null, null)));
 }
            public ExecuteAsyncResult(InstanceHandle initialInstanceHandle, InstancePersistenceCommand command, Transaction transaction, TimeSpan timeout, AsyncCallback callback, object state)
                : this(command, timeout, callback, state)
            {
                this.initialInstanceHandle = initialInstanceHandle;

                OnCompleting = new Action<AsyncResult, Exception>(SimpleCleanup);

                IAsyncResult result = this.initialInstanceHandle.BeginAcquireExecutionContext(transaction, this.timeoutHelper.RemainingTime(), PrepareAsyncCompletion(ExecuteAsyncResult.onAcquireContext), this);
                if (result.CompletedSynchronously)
                {
                    // After this stage, must complete explicitly in order to get Cleanup to run correctly.
                    bool completeSelf = false;
                    Exception completionException = null;
                    try
                    {
                        completeSelf = OnAcquireContext(result);
                    }
                    catch (Exception exception)
                    {
                        if (Fx.IsFatal(exception))
                        {
                            throw;
                        }
                        completeSelf = true;
                        completionException = exception;
                    }
                    if (completeSelf)
                    {
                        Complete(true, completionException);
                    }
                }
            }
            public ExecuteAsyncResult(InstancePersistenceContext context, InstancePersistenceCommand command, TimeSpan timeout, AsyncCallback callback, object state)
                : this(command, timeout, callback, state)
            {
                this.context = context;

                this.priorAsyncResult = this.context.LastAsyncResult;
                Fx.Assert(this.priorAsyncResult != null, "The LastAsyncResult should already have been checked.");
                this.priorAsyncResult.executeCalledByCurrentCommand = true;

                OnCompleting = new Action<AsyncResult, Exception>(SimpleCleanup);

                bool completeSelf = false;
                bool success = false;
                try
                {
                    this.context.LastAsyncResult = this;
                    if (RunLoop())
                    {
                        completeSelf = true;
                    }
                    success = true;
                }
                finally
                {
                    if (!success)
                    {
                        this.context.LastAsyncResult = this.priorAsyncResult;
                    }
                }
                if (completeSelf)
                {
                    Complete(true);
                }
            }
 protected SqlWorkflowInstanceStoreAsyncResult(System.Runtime.DurableInstancing.InstancePersistenceContext context, System.Runtime.DurableInstancing.InstancePersistenceCommand command, SqlWorkflowInstanceStore store, SqlWorkflowInstanceStoreLock storeLock, Transaction currentTransaction, TimeSpan timeout, AsyncCallback callback, object state) : base(callback, state)
 {
     this.DependentTransaction       = (currentTransaction != null) ? currentTransaction.DependentClone(DependentCloneOption.BlockCommitUntilComplete) : null;
     this.InstancePersistenceContext = context;
     this.InstancePersistenceCommand = command;
     this.Store         = store;
     this.StoreLock     = storeLock;
     this.TimeoutHelper = new System.Runtime.TimeoutHelper(timeout);
     base.OnCompleting  = (Action <AsyncResult, Exception>)Delegate.Combine(base.OnCompleting, finallyCallback);
 }
Exemplo n.º 32
0
		protected internal virtual IAsyncResult BeginTryCommand (InstancePersistenceContext context, InstancePersistenceCommand command, TimeSpan timeout, AsyncCallback callback, object state)
		{
			if (try_command_delegate == null)
				try_command_delegate = new Func<InstancePersistenceContext, InstancePersistenceCommand, TimeSpan, bool> (TryCommand);
			return try_command_delegate.BeginInvoke (context, command, timeout, callback, state);
		}
Exemplo n.º 33
0
		public InstanceView Execute (InstanceHandle handle, InstancePersistenceCommand command, TimeSpan timeout)
		{
			throw new NotImplementedException ();
		}
            ExecuteAsyncResult(InstancePersistenceCommand command, TimeSpan timeout, AsyncCallback callback, object state)
                : base(callback, state)
            {
                this.executionStack = new Stack<IEnumerator<InstancePersistenceCommand>>(2);
                this.timeoutHelper = new TimeoutHelper(timeout);

                this.currentExecution = (new List<InstancePersistenceCommand> { command }).GetEnumerator();
            }
            public ExecuteAsyncResult(InstancePersistenceContext context, InstancePersistenceCommand command, TimeSpan timeout)
                : this(command, timeout, null, null)
            {
                this.context = context;

                this.priorAsyncResult = this.context.LastAsyncResult;
                Fx.Assert(this.priorAsyncResult != null, "The LastAsyncResult should already have been checked.");
                this.priorAsyncResult.executeCalledByCurrentCommand = true;

                bool success = false;
                try
                {
                    this.context.LastAsyncResult = this;
                    RunLoopCore(true);
                    success = true;
                }
                finally
                {
                    this.context.LastAsyncResult = this.priorAsyncResult;
                    if (!success && this.context.IsHandleDoomedByRollback)
                    {
                        this.context.InstanceHandle.Free();
                    }
                }
                Complete(true);
            }
Exemplo n.º 36
0
 public void Execute(InstancePersistenceCommand command, TimeSpan timeout)
 {
     throw new NotImplementedException();
 }
 internal static InstanceView OuterExecute(InstanceHandle initialInstanceHandle, InstancePersistenceCommand command, Transaction transaction, TimeSpan timeout)
 {
     try
     {
         return ExecuteAsyncResult.End(new ExecuteAsyncResult(initialInstanceHandle, command, transaction, timeout));
     }
     catch (TimeoutException)
     {
         initialInstanceHandle.Free();
         throw;
     }
     catch (OperationCanceledException)
     {
         initialInstanceHandle.Free();
         throw;
     }
 }
 internal static IAsyncResult BeginOuterExecute(InstanceHandle initialInstanceHandle, InstancePersistenceCommand command, Transaction transaction, TimeSpan timeout, AsyncCallback callback, object state)
 {
     try
     {
         return new ExecuteAsyncResult(initialInstanceHandle, command, transaction, timeout, callback, state);
     }
     catch (TimeoutException)
     {
         initialInstanceHandle.Free();
         throw;
     }
     catch (OperationCanceledException)
     {
         initialInstanceHandle.Free();
         throw;
     }
 }
Exemplo n.º 39
0
 protected internal virtual bool TryCommand(InstancePersistenceContext context, InstancePersistenceCommand command, TimeSpan timeout)
 {
     throw new NotImplementedException();
 }
Exemplo n.º 40
0
 public LoadRetryAsyncResult(SqlWorkflowInstanceStore store, System.Runtime.DurableInstancing.InstancePersistenceContext context, System.Runtime.DurableInstancing.InstancePersistenceCommand command, TimeSpan timeout, AsyncCallback callback, object state) : base(callback, state)
 {
     this.InstanceStore = store;
     this.InstancePersistenceContext = context;
     this.InstancePersistenceCommand = command;
     this.commandTimeout             = new TimeoutHelper(timeout);
     this.InstanceStore.BeginTryCommandInternal(this.InstancePersistenceContext, this.InstancePersistenceCommand, this.commandTimeout.RemainingTime(), onTryCommandCallback, this);
 }
            public ExecuteAsyncResult(InstanceHandle initialInstanceHandle, InstancePersistenceCommand command, Transaction transaction, TimeSpan timeout)
                : this(command, timeout, null, null)
            {
                this.initialInstanceHandle = initialInstanceHandle;
                this.context = this.initialInstanceHandle.AcquireExecutionContext(transaction, this.timeoutHelper.RemainingTime());

                Exception completionException = null;
                try
                {
                    // After this stage, must complete explicitly in order to get Cleanup to run correctly.
                    this.context.RootAsyncResult = this;
                    this.context.LastAsyncResult = this;
                    OnCompleting = new Action<AsyncResult, Exception>(Cleanup);

                    RunLoopCore(true);

                    if (this.transactionToCommit != null)
                    {
                        try
                        {
                            this.transactionToCommit.Commit();
                        }
                        catch (TransactionException)
                        {
                            // Since we are enlisted in this transaction, we can ignore exceptions from Commit.
                        }
                        this.transactionToCommit = null;
                    }

                    DoWaitForTransaction(true);
                }
                catch (Exception exception)
                {
                    if (Fx.IsFatal(exception))
                    {
                        throw;
                    }
                    completionException = exception;
                }
                Complete(true, completionException);
            }