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;
 }
Beispiel #2
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);
                }
            }
        }
Beispiel #3
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);
                }
            }
        }
Beispiel #4
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);
        }