Пример #1
0
 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));
     }
 }
Пример #2
0
        protected override IAsyncResult BeginTryCommand(
            InstancePersistenceContext context,
            InstancePersistenceCommand command,
            TimeSpan timeout, AsyncCallback callback,
            object state)
        {
            try
            {
                switch (command)
                {
                case SaveWorkflowCommand saveWorkflowCommand:
                    return(new TypedCompletedAsyncResult <bool>(SaveWorkflow(context, saveWorkflowCommand), callback,
                                                                state));

                case LoadWorkflowCommand loadWorkflowCommand:
                    return(new TypedCompletedAsyncResult <bool>(LoadWorkflow(context, loadWorkflowCommand), callback,
                                                                state));

                case CreateWorkflowOwnerCommand createWorkflowOwnerCommand:
                    return(new TypedCompletedAsyncResult <bool>(
                               CreateWorkflowOwner(context, createWorkflowOwnerCommand), callback, state));

                case DeleteWorkflowOwnerCommand deleteWorkflowOwnerCommand:
                    return(new TypedCompletedAsyncResult <bool>(
                               DeleteWorkflowOwner(context, deleteWorkflowOwnerCommand), callback, state));

                default:
                    return(new TypedCompletedAsyncResult <bool>(false, callback, state));
                }
            }
            catch (Exception e)
            {
                return(new TypedCompletedAsyncResult <Exception>(e, callback, state));
            }
        }
 /// <summary>
 /// The try command.
 /// </summary>
 /// <param name="context">The context.</param>
 /// <param name="command">The command.</param>
 /// <param name="timeout">The timeout.</param>
 /// <returns>The <see cref="bool" />.</returns>
 protected override bool TryCommand(
     InstancePersistenceContext context,
     InstancePersistenceCommand command,
     TimeSpan timeout)
 {
     return(this.EndTryCommand(this.BeginTryCommand(context, command, timeout, null, null)));
 }
            public InstanceCommandWithTemporaryHandleAsyncResult(InstanceStore instanceStore, InstancePersistenceCommand command,
                                                                 TimeSpan timeout, AsyncCallback callback, object state)
                : base(callback, state)
            {
                this.instanceStore   = instanceStore;
                this.command         = command;
                this.temporaryHandle = instanceStore.CreateInstanceHandle();

                var currentTransaction = Transaction.Current;

                if (currentTransaction != null)
                {
                    this.dependentTransaction = currentTransaction.DependentClone(DependentCloneOption.BlockCommitUntilComplete);
                }

                this.OnCompleting = completeCallback;

                IAsyncResult result;

                using (this.PrepareTransactionalCall(this.dependentTransaction))
                {
                    result = instanceStore.BeginExecute(this.temporaryHandle, command, timeout, this.PrepareAsyncCompletion(commandCompletedCallback), this);
                }

                if (this.SyncContinue(result))
                {
                    this.Complete(true);
                }
            }
Пример #5
0
 /// <summary>
 /// Handles a <see cref="InstancePersistenceCommand"/>.
 /// </summary>
 /// <param name="context"></param>
 /// <param name="command"></param>
 /// <returns></returns>
 Task <bool> CommandAsync(InstancePersistenceContext context, InstancePersistenceCommand command)
 {
     if (command is CreateWorkflowOwnerCommand)
     {
         return(CreateWorkflowOwnerCommand(context, (CreateWorkflowOwnerCommand)command));
     }
     else if (command is QueryActivatableWorkflowsCommand)
     {
         return(QueryActivatableWorkflowsCommand(context, (QueryActivatableWorkflowsCommand)command));
     }
     else if (command is SaveWorkflowCommand)
     {
         return(SaveWorkflowCommand(context, (SaveWorkflowCommand)command));
     }
     else if (command is LoadWorkflowCommand)
     {
         return(LoadWorkflowCommand(context, (LoadWorkflowCommand)command));
     }
     else if (command is TryLoadRunnableWorkflowCommand)
     {
         return(TryLoadRunnableWorkflowCommand(context, (TryLoadRunnableWorkflowCommand)command));
     }
     else if (command is DeleteWorkflowOwnerCommand)
     {
         return(DeleteWorkflowOwnerCommand(context, (DeleteWorkflowOwnerCommand)command));
     }
     else
     {
         return(Task.FromResult(true));
     }
 }
Пример #6
0
 private bool IsRetryCommand(InstancePersistenceCommand command)
 {
     if (!this.IsLockRetryEnabled())
     {
         return(false);
     }
     return((command is LoadWorkflowByInstanceKeyCommand) || (command is LoadWorkflowCommand));
 }
Пример #7
0
 bool IsRetryCommand(InstancePersistenceCommand command)
 {
     return
         (
         this.IsLockRetryEnabled() &&
         (
             command is LoadWorkflowByInstanceKeyCommand ||
             command is LoadWorkflowCommand
         )
         );
 }
        protected override bool TryCommand(
            InstancePersistenceContext context,
            InstancePersistenceCommand command, TimeSpan timeout)
        {
            ManualResetEvent waitEvent   = new ManualResetEvent(false);
            IAsyncResult     asyncResult = BeginTryCommand(
                context, command, timeout, ar => waitEvent.Set(), null);

            waitEvent.WaitOne(timeout);
            return(EndTryCommand(asyncResult));
        }
 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();
 }
Пример #10
0
        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);
        }
        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));
            }
        }
Пример #12
0
 public LoadWorkflowByKeyAsyncResult
 (
     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)
 {
 }
 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 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;
 }
Пример #15
0
 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 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, SR.TryLoadRequiresWorkflowType, null));
     }
 }
            private bool Load()
            {
                IAsyncResult result;

                if (this.ppd.store == null)
                {
                    this.isInstanceInitialized = false;
                    this.context = new PersistenceContext(this.ppd, (this.suggestedIdOrId == Guid.Empty) ? Guid.NewGuid() : this.suggestedIdOrId, this.key, this.associatedKeys);
                    return(this.Finish());
                }
                if (this.canCreateInstance && !this.lockInstance)
                {
                    if (this.suggestedIdOrId == Guid.Empty)
                    {
                        this.suggestedIdOrId = Guid.NewGuid();
                    }
                    this.handle = this.ppd.store.CreateInstanceHandle(this.ppd.owner, this.suggestedIdOrId);
                    this.isInstanceInitialized = false;
                    return(this.AfterLoad());
                }
                InstancePersistenceCommand command = this.ppd.CreateLoadCommandHelper(this.key, out this.handle, this.canCreateInstance, this.suggestedIdOrId, this.associatedKeys, this.loadAny);

                try
                {
                    using (base.PrepareTransactionalCall(this.transaction))
                    {
                        result = this.ppd.store.BeginExecute(this.handle, command, this.timeoutHelper.RemainingTime(), base.PrepareAsyncCompletion(new AsyncResult.AsyncCompletion(PersistenceProviderDirectory.LoadOrCreateAsyncResult.HandleExecute)), this);
                    }
                }
                catch (InstanceHandleConflictException)
                {
                    result = null;
                }
                catch (InstanceLockLostException)
                {
                    result = null;
                }
                if (result == null)
                {
                    return(this.ResolveHandleConflict());
                }
                return(base.SyncContinue(result));
            }
        /// <summary>
        /// The begin try command.
        /// </summary>
        /// <param name="context">The context.</param>
        /// <param name="command">The command.</param>
        /// <param name="timeout">The timeout.</param>
        /// <param name="callback">The callback.</param>
        /// <param name="state">The state.</param>
        /// <returns>The <see cref="IAsyncResult" />.</returns>
        /// <exception cref="SystemFailureException">Error processing message.</exception>
        protected override IAsyncResult BeginTryCommand(
            InstancePersistenceContext context,
            InstancePersistenceCommand command,
            TimeSpan timeout,
            AsyncCallback callback,
            object state)
        {
            lock (LocalLock)
            {
                if (command is CreateWorkflowOwnerCommand)
                {
                    context.BindInstanceOwner(this.ownerInstanceId, Guid.NewGuid());
                }
                else
                {
                    var saveWorkflowCommand = command as SaveWorkflowCommand;
                    if (saveWorkflowCommand != null)
                    {
                        this.SaveInstanceData(saveWorkflowCommand.InstanceData);
                    }
                    else if (command is LoadWorkflowCommand)
                    {
                        try
                        {
                            var instanceData = this.unstructuredStorageRepository.GetById(
                                "WorkflowInstanceStoreData",
                                this.ownerInstanceId.ToString());
                            var deserializedData = DeserializeData(instanceData.Payload.Combine());
                            context.LoadedInstance(InstanceState.Initialized, deserializedData, null, null, null);
                        }
                        catch (Exception exception)
                        {
                            throw;
                        }
                    }
                }

                return(new CompletedAsyncResult <bool>(true, 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;
 }
Пример #20
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> instanceStateData = null;
            WorkflowInstance instance   = null;
            Guid             InstanceId = Guid.Empty;

            if (context != null && context.InstanceView != null)
            {
                InstanceId = context.InstanceView.InstanceId;
                instance   = WorkflowInstance.Instances.Where(x => x.InstanceId == InstanceId.ToString()).FirstOrDefault();
            }

            //The CreateWorkflowOwner command instructs the instance store to create a new instance owner bound to the instanace handle
            if (command is CreateWorkflowOwnerCommand)
            {
                context.BindInstanceOwner(_storeId, 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)
            {
                if (instance != null && instance.Workflow != null && instance.Workflow.Serializable == true)
                {
                    SaveWorkflowCommand saveCommand = (SaveWorkflowCommand)command;
                    try
                    {
                        instanceStateData = saveCommand.InstanceData;
                        var instanceStateXml = DictionaryToXml(instanceStateData);
                        Save(context.InstanceView.InstanceId, this._storeId, instanceStateXml);
                    }
                    catch (Exception)
                    {
                        instance.Workflow.Serializable = false;
                    }
                }
            }
            //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 xml = Load(InstanceId, _storeId);
                // if (xml == null) throw new ArgumentNullException("Failed locating instance data for " + context.InstanceView.InstanceId.ToString());
                // if (xml == null) return new CompletedAsyncResult<bool>(false, callback, state);
                if (xml == null)
                {
                    return(new CompletedAsyncResult <bool>(true, callback, state));
                }
                instanceStateData = XmlToDictionary(xml);
                //load the data into the persistence Context
                context.LoadedInstance(InstanceState.Initialized, instanceStateData, null, null, null);
            }
            return(new CompletedAsyncResult <bool>(true, callback, state));
        }
        //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 = null;

            //The CreateWorkflowOwner command instructs the instance store to create a new instance owner bound to the instanace handle
            if (command is CreateWorkflowOwnerCommand)
            {
                context.BindInstanceOwner(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)
            {
                SaveWorkflowCommand saveCommand = (SaveWorkflowCommand)command;
                data = saveCommand.InstanceData;

                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)
            {
                string fileName = this.ownerInstanceID.ToString();

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

            return(new CompletedAsyncResult <bool>(true, callback, state));
        }
Пример #22
0
        protected override IAsyncResult BeginTryCommand(InstancePersistenceContext context, InstancePersistenceCommand command, TimeSpan timeout, AsyncCallback callback, object state)
        {
            SaveWorkflowCommand save = command as SaveWorkflowCommand;

            if (save != null)
            {
                lock (FileStore.s_thisLock)
                {
                    ProcessSaveCommand(context, save);
                }
            }

            LoadWorkflowCommand load = command as LoadWorkflowCommand;

            if (load != null)
            {
                lock (FileStore.s_thisLock)
                {
                    ProcessLoadCommand(context, load);
                }
            }

            LoadWorkflowByInstanceKeyCommand loadByKey = command as LoadWorkflowByInstanceKeyCommand;

            if (loadByKey != null)
            {
                lock (FileStore.s_thisLock)
                {
                    ProcessLoadByKeyCommand(context, loadByKey);
                }
            }

            if (save != null || load != null || loadByKey != null)
            {
                return(new CompletedAsyncResult(callback, state));
            }

            if (command is CreateWorkflowOwnerCommand createOwner)
            {
                Guid  ownerId = Guid.NewGuid();
                Owner owner   = new Owner();
                lock (s_thisLock)
                {
                    owner.Id        = ownerId;
                    owner.LockToken = Guid.NewGuid();
                    owner.Metadata  = new PropertyBag(createOwner.InstanceOwnerMetadata);
                    PersistenceItemManager.SaveToFile <Owner>(owner);
                }

                context.BindInstanceOwner(ownerId, owner.LockToken);
                context.BindEvent(HasRunnableWorkflowEvent.Value);
                return(new CompletedAsyncResult(callback, state));
            }

            if (command is DeleteWorkflowOwnerCommand deleteOwner)
            {
                Guid ownerId = context.InstanceView.InstanceOwner.InstanceOwnerId;

                lock (FileStore.s_thisLock)
                {
                    Owner owner = PersistenceItemManager.Load <Owner>(ownerId);
                    if (owner != null && owner.LockToken == context.LockToken)
                    {
                        PersistenceItemManager.Remove <Owner>(ownerId);
                    }
                }

                context.InstanceHandle.Free();
                return(new CompletedAsyncResult(callback, state));
            }

            return(base.BeginTryCommand(context, command, timeout, callback, state));
        }
Пример #23
0
 protected override IAsyncResult BeginTryCommand(InstancePersistenceContext context, InstancePersistenceCommand command, TimeSpan timeout, AsyncCallback callback, object state)
 {
     try
     {
         return(base.BeginTryCommand(context, command, timeout, callback, state));
     }
     catch (Exception e)
     {
         return(new TypedCompletedAsyncResult <Exception>(e, callback, state));
     }
 }
Пример #24
0
        protected override IAsyncResult BeginTryCommand(InstancePersistenceContext context, InstancePersistenceCommand command, TimeSpan timeout, AsyncCallback callback, object state)
        {
            if (command is CreateWorkflowOwnerCommand)
            {
                context.BindInstanceOwner(OwnerInstanceId, Guid.NewGuid());
            }
            else if (command is SaveWorkflowCommand)
            {
                var saveCommand = (SaveWorkflowCommand)command;
                Save(context.InstanceView.InstanceId, saveCommand.InstanceData);
            }
            else if (command is LoadWorkflowCommand)
            {
                context.LoadedInstance(InstanceState.Initialized, Load(context.InstanceView.InstanceId), null, null, null);
            }
            else if (command is DeleteWorkflowOwnerCommand)
            {
            }

            return(new CompletedAsyncResult <bool>(true, callback, state));
        }
Пример #25
0
        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);
        }
Пример #26
0
 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));
 }
Пример #27
0
 protected override IAsyncResult BeginTryCommand(InstancePersistenceContext context, InstancePersistenceCommand command, TimeSpan timeout, AsyncCallback callback, object state)
 {
     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 CreateWorkflowOwnerWithIdentityCommand)
         {
             return(new TypedCompletedAsyncResult <bool>(CreateWorkflowOwnerWithIdentity(context, (CreateWorkflowOwnerWithIdentityCommand)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));
     }
 }
Пример #28
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> instanceStateData = null;

            //The CreateWorkflowOwner command instructs the instance store to create a new instance owner bound to the instanace handle
            if (command is CreateWorkflowOwnerCommand)
            {
                context.BindInstanceOwner(_storeId, 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)
            {
                SaveWorkflowCommand saveCommand = (SaveWorkflowCommand)command;
                instanceStateData = saveCommand.InstanceData;

                var instanceStateXml = DictionaryToXml(instanceStateData);
                Save(context.InstanceView.InstanceId, this._storeId, instanceStateXml);
            }
            //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 xml = Load(context.InstanceView.InstanceId, this._storeId);
                instanceStateData = XmlToDictionary(xml);
                //load the data into the persistence Context
                context.LoadedInstance(InstanceState.Initialized, instanceStateData, null, null, null);
            }

            return(new CompletedAsyncResult <bool>(true, callback, state));
        }
Пример #29
0
 internal IAsyncResult BeginTryCommandInternal(InstancePersistenceContext context, InstancePersistenceCommand command, TimeSpan timeout, AsyncCallback callback, object state)
 {
     return(BeginTryCommandInternal(context, command, Transaction.Current, timeout, callback, state));
 }
Пример #30
0
        internal IAsyncResult BeginTryCommandInternalWithVersionCheck(InstancePersistenceContext context, InstancePersistenceCommand command, TimeSpan timeout, AsyncCallback callback, object state, Version targetVersion)
        {
            SqlWorkflowInstanceStoreAsyncResult sqlWorkflowInstanceStoreAsyncResult = new TestDatabaseVersionAndRunAsyncResult(context, command, this, this.storeLock, Transaction.Current, timeout, targetVersion, callback, state);

            sqlWorkflowInstanceStoreAsyncResult.ScheduleCallback();
            return(sqlWorkflowInstanceStoreAsyncResult);
        }