Пример #1
0
        // Returns null if an InstanceHandleConflictException should be thrown.
        internal InstanceView Commit(InstanceView newState)
        {
            Fx.Assert(newState != null, "Null view passed to Commit.");
            newState.MakeReadOnly();
            View = newState;

            List <InstanceHandleReference> handlesPendingResolution = null;
            InstanceHandle handleToFree                      = null;
            List <InstancePersistenceEvent> normals          = null;
            WaitForEventsAsyncResult        resultToComplete = null;

            try
            {
                lock (ThisLock)
                {
                    if (this.inProgressBind != null)
                    {
                        // If there's a Version, it should be committed.
                        if (Version != -1)
                        {
                            if (!Owner.TryCompleteBind(ref this.inProgressBind, ref handlesPendingResolution, out handleToFree))
                            {
                                return(null);
                            }
                        }
                        else
                        {
                            Fx.Assert(OperationPending, "Should have cancelled this bind in FinishOperation.");
                            Fx.Assert(AcquirePending == null, "Should not be in Commit during AcquirePending.");
                            Owner.CancelBind(ref this.inProgressBind, ref handlesPendingResolution);
                        }
                    }

                    if (this.pendingOwnerEvents != null && IsValid)
                    {
                        if (this.boundOwnerEvents == null)
                        {
                            this.boundOwnerEvents = new HashSet <XName>();
                        }

                        foreach (InstancePersistenceEvent persistenceEvent in this.pendingOwnerEvents)
                        {
                            if (!this.boundOwnerEvents.Add(persistenceEvent.Name))
                            {
                                Fx.Assert("Should not have conflicts between pending and bound events.");
                                continue;
                            }

                            InstancePersistenceEvent normal = Store.AddHandleToEvent(this, persistenceEvent, Owner);
                            if (normal != null)
                            {
                                if (normals == null)
                                {
                                    normals = new List <InstancePersistenceEvent>(this.pendingOwnerEvents.Count);
                                }
                                normals.Add(normal);
                            }
                        }

                        this.pendingOwnerEvents = null;

                        if (normals != null && this.waitResult != null)
                        {
                            resultToComplete = this.waitResult;
                            this.waitResult  = null;
                        }
                    }

                    return(View);
                }
            }
            finally
            {
                InstanceOwner.ResolveHandles(handlesPendingResolution);

                // This is a convenience, it is not required for correctness.
                if (handleToFree != null)
                {
                    Fx.Assert(!object.ReferenceEquals(handleToFree, this), "Shouldn't have been told to free ourselves.");
                    handleToFree.Free();
                }

                if (resultToComplete != null)
                {
                    resultToComplete.Signaled(normals);
                }
            }
        }
        public void Open(TimeSpan timeout)
        {
            Fx.Assert(Host != null, "Extension should have been attached in WorkflowServiceHost constructor.");

            lock (this.thisLock)
            {
                ThrowIfDisposedOrImmutable(this.state);
                this.state = States.Opened;
            }
            InitializeDefinitionProvider();

            CheckPersistenceProviderBehavior();

            SetDefaultOwnerMetadata();


            if (InstanceStore != null)
            {
                using (new TransactionScope(TransactionScopeOption.Suppress))
                {
                    TimeoutHelper timeoutHelper = new TimeoutHelper(timeout);
                    InstanceHandle handle = null;
                    try
                    {
                        handle = InstanceStore.CreateInstanceHandle(null);
                        this.owner = InstanceStore.Execute(handle, GetCreateOwnerCommand(), timeoutHelper.RemainingTime()).InstanceOwner;
                        this.handle = handle;
                        handle = null;
                    }
                    catch (InstancePersistenceException exception)
                    {
                        throw FxTrace.Exception.AsError(new CommunicationException(SR.UnableToOpenAndRegisterStore, exception));
                    }
                    finally
                    {
                        if (handle != null)
                        {
                            handle.Free();
                        }
                    }
                }
            }

            InitializePersistenceProviderDirectory();
        }
Пример #3
0
        internal InstanceView Commit(InstanceView newState)
        {
            InstanceView view;

            newState.MakeReadOnly();
            this.View = newState;
            List <InstanceHandleReference> handlesPendingResolution = null;
            InstanceHandle handleToFree = null;
            List <InstancePersistenceEvent> persistenceEvents = null;
            WaitForEventsAsyncResult        waitResult        = null;

            try
            {
                lock (this.ThisLock)
                {
                    if (this.inProgressBind != null)
                    {
                        if (this.Version != -1L)
                        {
                            if (!this.Owner.TryCompleteBind(ref this.inProgressBind, ref handlesPendingResolution, out handleToFree))
                            {
                                return(null);
                            }
                        }
                        else
                        {
                            this.Owner.CancelBind(ref this.inProgressBind, ref handlesPendingResolution);
                        }
                    }
                    if ((this.pendingOwnerEvents != null) && this.IsValid)
                    {
                        if (this.boundOwnerEvents == null)
                        {
                            this.boundOwnerEvents = new HashSet <XName>();
                        }
                        foreach (InstancePersistenceEvent event2 in this.pendingOwnerEvents)
                        {
                            if (this.boundOwnerEvents.Add(event2.Name))
                            {
                                InstancePersistenceEvent item = this.Store.AddHandleToEvent(this, event2, this.Owner);
                                if (item != null)
                                {
                                    if (persistenceEvents == null)
                                    {
                                        persistenceEvents = new List <InstancePersistenceEvent>(this.pendingOwnerEvents.Count);
                                    }
                                    persistenceEvents.Add(item);
                                }
                            }
                        }
                        this.pendingOwnerEvents = null;
                        if ((persistenceEvents != null) && (this.waitResult != null))
                        {
                            waitResult      = this.waitResult;
                            this.waitResult = null;
                        }
                    }
                    view = this.View;
                }
            }
            finally
            {
                InstanceOwner.ResolveHandles(handlesPendingResolution);
                if (handleToFree != null)
                {
                    handleToFree.Free();
                }
                if (waitResult != null)
                {
                    waitResult.Signaled(persistenceEvents);
                }
            }
            return(view);
        }
 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;
     }
 }
 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;
     }
 }
 public void Open(TimeSpan timeout)
 {
     lock (this.thisLock)
     {
         ThrowIfDisposedOrImmutable(this.state);
         this.state = 1;
     }
     this.CheckPersistenceProviderBehavior();
     this.SetDefaultOwnerMetadata();
     if (this.InstanceStore != null)
     {
         using (new TransactionScope(TransactionScopeOption.Suppress))
         {
             TimeoutHelper helper = new TimeoutHelper(timeout);
             InstanceHandle handle = null;
             try
             {
                 handle = this.InstanceStore.CreateInstanceHandle((InstanceOwner) null);
                 this.owner = this.InstanceStore.Execute(handle, this.createOwnerCommand, helper.RemainingTime()).InstanceOwner;
                 this.handle = handle;
                 handle = null;
             }
             catch (InstancePersistenceException exception)
             {
                 throw System.ServiceModel.Activities.FxTrace.Exception.AsError(new CommunicationException(System.ServiceModel.Activities.SR.UnableToOpenAndRegisterStore, exception));
             }
             finally
             {
                 if (handle != null)
                 {
                     handle.Free();
                 }
             }
         }
     }
     this.InitializePersistenceProviderDirectory();
 }