コード例 #1
0
        internal InstanceHandle(InstanceStore store, InstanceOwner owner, Guid instanceId)
        {
            Fx.Assert(store != null, "Shouldn't be possible here either.");
            Fx.Assert(instanceId != Guid.Empty, "Should be validating this.");

            Version = -1;
            Store   = store;
            Owner   = owner;
            Id      = instanceId;
            View    = new InstanceView(owner, instanceId);
            IsValid = true;
            if (Fx.IsEtwProviderEnabled)
            {
                _eventTraceActivity = new EventTraceActivity(instanceId);
            }
        }
コード例 #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 (_inProgressBind != null)
                    {
                        // If there's a Version, it should be committed.
                        if (Version != -1)
                        {
                            if (!Owner.TryCompleteBind(ref _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 _inProgressBind, ref handlesPendingResolution);
                        }
                    }

                    if (_pendingOwnerEvents != null && IsValid)
                    {
                        if (_boundOwnerEvents == null)
                        {
                            _boundOwnerEvents = new HashSet <XName>();
                        }

                        foreach (InstancePersistenceEvent persistenceEvent in _pendingOwnerEvents)
                        {
                            if (!_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>(_pendingOwnerEvents.Count);
                                }
                                normals.Add(normal);
                            }
                        }

                        _pendingOwnerEvents = null;

                        if (normals != null && _waitResult != null)
                        {
                            resultToComplete = _waitResult;
                            _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);
                }
            }
        }
コード例 #3
0
 internal virtual IEnumerable <InstancePersistenceCommand> Reduce(InstanceView view)
 {
     return(null);
 }
コード例 #4
0
 protected internal virtual void Validate(InstanceView view)
 {
 }