Esempio n. 1
0
        private bool CreateWorkflowOwner(InstancePersistenceContext context, CreateWorkflowOwnerCommand command)
        {
            Guid instanceOwnerId = Guid.NewGuid();

            context.BindInstanceOwner(instanceOwnerId, instanceOwnerId);
            context.BindEvent(HasRunnableWorkflowEvent.Value);
            return(true);
        }
Esempio n. 2
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));
        }