예제 #1
0
 public InstanceHandle CreateInstanceHandle(InstanceOwner owner, Guid instanceId)
 {
     if (instanceId == Guid.Empty)
     {
         throw Fx.Exception.Argument("instanceId", SRCore.CannotCreateContextWithNullId);
     }
     return PrepareInstanceHandle(new InstanceHandle(this, owner, instanceId));
 }
예제 #2
0
        internal InstanceView(InstanceOwner owner, Guid instanceId)
            : this()
        {
            Fx.Assert(instanceId != Guid.Empty, "Null instanceId passed to InstanceView ctor.");

            InstanceOwner = owner;
            InstanceId = instanceId;
            IsBoundToInstance = true;
        }
 internal InstanceHandle(InstanceStore store, InstanceOwner owner)
 {
     this.thisLock = new object();
     this.Version = -1L;
     this.Store = store;
     this.Owner = owner;
     this.View = new InstanceView(owner);
     this.IsValid = true;
 }
 internal InstancePersistenceEvent AddHandleToEvent(InstanceHandle handle, InstancePersistenceEvent persistenceEvent, InstanceOwner owner)
 {
     lock (this.ThisLock)
     {
         InstanceNormalEvent ownerEventHelper = this.GetOwnerEventHelper(persistenceEvent, owner);
         ownerEventHelper.BoundHandles.Add(handle);
         ownerEventHelper.PendingHandles.Remove(handle);
         return (ownerEventHelper.IsSignaled ? ownerEventHelper : null);
     }
 }
예제 #5
0
        internal InstanceHandle(InstanceStore store, InstanceOwner owner)
        {
            Fx.Assert(store != null, "Shouldn't be possible.");

            Version = -1;
            Store = store;
            Owner = owner;
            View = new InstanceView(owner);
            IsValid = true;
        }
        internal PersistenceProviderDirectory(InstanceStore store, InstanceOwner owner, IDictionary<XName, InstanceValue> instanceMetadataChanges, WorkflowDefinitionProvider workflowDefinitionProvider, WorkflowServiceHost serviceHost,
            DurableConsistencyScope consistencyScope, int maxInstances)
            : this(workflowDefinitionProvider, serviceHost, consistencyScope, maxInstances)
        {
            Fx.Assert(store != null, "InstanceStore must be specified on PPD.");
            Fx.Assert(owner != null, "InstanceOwner must be specified on PPD.");

            this.store = store;
            this.owner = owner;
            this.InstanceMetadataChanges = instanceMetadataChanges;
        }
예제 #7
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.Trace.IsEtwProviderEnabled)
            {
                eventTraceActivity = new EventTraceActivity(instanceId);
            }
        }
 internal InstancePersistenceEvent FindEvent(InstancePersistenceEvent eventType, out InstanceOwner instanceOwner)
 {
     return this.FindEventHelper(eventType, out instanceOwner, false);
 }
예제 #9
0
        protected void SignalEvent(InstancePersistenceEvent persistenceEvent, InstanceOwner owner)
        {
            if (persistenceEvent == null)
            {
                throw Fx.Exception.ArgumentNull("persistenceEvent");
            }
            if (owner == null)
            {
                throw Fx.Exception.ArgumentNull("owner");
            }

            InstanceNormalEvent normal;
            InstanceHandle[] handlesToNotify = null;
            lock (ThisLock)
            {
                WeakReference ownerReference;
                if (!this.owners.TryGetValue(owner.InstanceOwnerId, out ownerReference) || !object.ReferenceEquals(ownerReference.Target, owner))
                {
                    throw Fx.Exception.Argument("owner", SRCore.OwnerBelongsToWrongStore);
                }

                normal = GetOwnerEventHelper(persistenceEvent, owner);
                if (!normal.IsSignaled)
                {
                    normal.IsSignaled = true;
                    if (normal.BoundHandles.Count > 0)
                    {
                        handlesToNotify = normal.BoundHandles.ToArray();
                    }
                }
            }
            if (handlesToNotify != null)
            {
                foreach (InstanceHandle handle in handlesToNotify)
                {
                    handle.EventReady(normal);
                }
            }
        }
예제 #10
0
 internal InstanceView(InstanceOwner owner)
     : this()
 {
     InstanceOwner = owner;
 }
예제 #11
0
 internal void BindOwner(InstanceOwner owner)
 {
     Fx.AssertAndThrow(!IsViewFrozen, "BindOwner called on read-only InstanceView.");
     Fx.Assert(owner != null, "Null owner passed to BindOwner.");
     if (IsBoundToInstanceOwner)
     {
         throw Fx.Exception.AsError(new InvalidOperationException(SRCore.ContextAlreadyBoundToOwner));
     }
     InstanceOwner = owner;
 }
예제 #12
0
        internal InstanceOwner GetOrCreateOwner(Guid instanceOwnerId, Guid lockToken)
        {
            lock (ThisLock)
            {
                WeakReference ownerRef;
                InstanceOwner owner;
                if (this.owners.TryGetValue(instanceOwnerId, out ownerRef))
                {
                    owner = (InstanceOwner)ownerRef.Target;
                    if (owner == null)
                    {
                        owner = new InstanceOwner(instanceOwnerId, lockToken);
                        ownerRef.Target = owner;
                    }
                    else if (owner.OwnerToken != lockToken)
                    {
                        throw Fx.Exception.AsError(new InvalidOperationException(SRCore.StoreReportedConflictingLockTokens));
                    }
                }
                else
                {
                    owner = new InstanceOwner(instanceOwnerId, lockToken);
                    this.owners.Add(instanceOwnerId, new WeakReference(owner));
                }

                while (true)
                {
                    if (this.ownerKeysToScan.Length == this.ownerKeysIndexToScan)
                    {
                        this.ownerKeysToScan = new Guid[this.owners.Count];
                        this.owners.Keys.CopyTo(this.ownerKeysToScan, 0);
                        this.ownerKeysIndexToScan = 0;
                        break;
                    }

                    Guid current = this.ownerKeysToScan[this.ownerKeysIndexToScan++];
                    if (this.owners.TryGetValue(current, out ownerRef))
                    {
                        if (ownerRef.Target == null)
                        {
                            this.owners.Remove(current);
                        }
                        else
                        {
                            break;
                        }
                    }
                }

                return owner;
            }
        }
 internal void BindOwner(InstanceOwner owner)
 {
     lock (this.ThisLock)
     {
         this.Owner = owner;
     }
 }
 private InstancePersistenceEvent FindEventHelper(InstancePersistenceEvent eventType, out InstanceOwner instanceOwner, bool withReset)
 {
     instanceOwner = null;
     InstanceOwner[] instanceOwners = base.GetInstanceOwners();
     if (instanceOwners.Length > 0)
     {
         foreach (InstanceOwner owner in instanceOwners)
         {
             if (owner.InstanceOwnerId == this.storeLock.LockOwnerId)
             {
                 instanceOwner = owner;
                 break;
             }
         }
         if (instanceOwner != null)
         {
             if (withReset)
             {
                 base.ResetEvent(eventType, instanceOwner);
             }
             foreach (InstancePersistenceEvent event2 in base.GetEvents(instanceOwner))
             {
                 if (event2 == eventType)
                 {
                     return event2;
                 }
             }
         }
     }
     return null;
 }
예제 #15
0
        internal void BindOwner(InstanceOwner owner)
        {
            Fx.Assert(owner != null, "Null owner passed to BindOwner.");

            lock (ThisLock)
            {
                Fx.Assert(this.inProgressBind == null, "How did we get a bind in progress without an owner?");

                Fx.Assert(Owner == null, "BindOwner called when we already have an owner.");
                Owner = owner;
            }
        }
예제 #16
0
 public InstanceHandle CreateInstanceHandle(InstanceOwner owner)
 {
     return PrepareInstanceHandle(new InstanceHandle(this, owner));
 }
예제 #17
0
        protected void ResetEvent(InstancePersistenceEvent persistenceEvent, InstanceOwner owner)
        {
            if (persistenceEvent == null)
            {
                throw Fx.Exception.ArgumentNull("persistenceEvent");
            }
            if (owner == null)
            {
                throw Fx.Exception.ArgumentNull("owner");
            }

            InstanceNormalEvent normal;
            lock (ThisLock)
            {
                WeakReference ownerReference;
                if (!this.owners.TryGetValue(owner.InstanceOwnerId, out ownerReference) || !object.ReferenceEquals(ownerReference.Target, owner))
                {
                    throw Fx.Exception.Argument("owner", SRCore.OwnerBelongsToWrongStore);
                }

                if (!owner.Events.TryGetValue(persistenceEvent.Name, out normal))
                {
                    return;
                }

                if (normal.IsSignaled)
                {
                    normal.IsSignaled = false;
                    if (normal.BoundHandles.Count == 0 && normal.PendingHandles.Count == 0)
                    {
                        owner.Events.Remove(persistenceEvent.Name);
                    }
                }
            }
        }
예제 #18
0
 // Must be called under ThisLock.  Doesn't validate the InstanceOwner.
 InstanceNormalEvent GetOwnerEventHelper(InstancePersistenceEvent persistenceEvent, InstanceOwner owner)
 {
     InstanceNormalEvent normal;
     if (!owner.Events.TryGetValue(persistenceEvent.Name, out normal))
     {
         normal = new InstanceNormalEvent(persistenceEvent);
         owner.Events.Add(persistenceEvent.Name, normal);
     }
     return normal;
 }
예제 #19
0
        internal void RemoveHandleFromEvents(InstanceHandle handle, IEnumerable<XName> eventNames, InstanceOwner owner)
        {
            lock (ThisLock)
            {
                Fx.Assert(this.owners.ContainsKey(owner.InstanceOwnerId), "InstanceHandle called RemoveHandleFromEvents on wrong InstanceStore!!");
                Fx.Assert(object.ReferenceEquals(this.owners[owner.InstanceOwnerId].Target, owner), "How did multiple instances of the same owner become simultaneously active in RemoveHandleFromEvents?");

                // Entry must exist since it is still registered by the handle.
                foreach (InstanceNormalEvent normal in eventNames.Select(name => owner.Events[name]))
                {
                    Fx.Assert(normal.BoundHandles.Contains(handle) || normal.PendingHandles.Contains(handle), "Event should still have handle registration.");

                    normal.PendingHandles.Remove(handle);
                    normal.BoundHandles.Remove(handle);
                    if (!normal.IsSignaled && normal.BoundHandles.Count == 0 && normal.PendingHandles.Count == 0)
                    {
                        owner.Events.Remove(normal.Name);
                    }
                }
            }
        }
예제 #20
0
        internal List<InstancePersistenceEvent> SelectSignaledEvents(IEnumerable<XName> eventNames, InstanceOwner owner)
        {
            List<InstancePersistenceEvent> readyEvents = null;
            lock (ThisLock)
            {
                Fx.Assert(this.owners.ContainsKey(owner.InstanceOwnerId), "InstanceHandle called SelectSignaledEvents on wrong InstanceStore!!");
                Fx.Assert(object.ReferenceEquals(this.owners[owner.InstanceOwnerId].Target, owner), "How did multiple instances of the same owner become simultaneously active?");

                // Entry must exist since it is still registered by the handle.
                foreach (InstanceNormalEvent normal in eventNames.Select(name => owner.Events[name]))
                {
                    if (normal.IsSignaled)
                    {
                        if (readyEvents == null)
                        {
                            readyEvents = new List<InstancePersistenceEvent>(1);
                        }
                        readyEvents.Add(normal);
                    }
                }
            }
            return readyEvents;
        }
예제 #21
0
        internal InstancePersistenceEvent AddHandleToEvent(InstanceHandle handle, InstancePersistenceEvent persistenceEvent, InstanceOwner owner)
        {
            lock (ThisLock)
            {
                Fx.Assert(this.owners.ContainsKey(owner.InstanceOwnerId), "InstanceHandle called AddHandleToEvent on wrong InstanceStore!!");
                Fx.Assert(object.ReferenceEquals(this.owners[owner.InstanceOwnerId].Target, owner), "How did multiple instances of the same owner become simultaneously active?");

                InstanceNormalEvent normal = GetOwnerEventHelper(persistenceEvent, owner);
                Fx.Assert(normal.PendingHandles.Contains(handle), "Should have already pended the handle.");
                Fx.Assert(!normal.BoundHandles.Contains(handle), "Should not be able to add a handle to an event twice.");
                normal.BoundHandles.Add(handle);
                normal.PendingHandles.Remove(handle);
                return normal.IsSignaled ? normal : null;
            }
        }
예제 #22
0
        internal void PendHandleToEvent(InstanceHandle handle, InstancePersistenceEvent persistenceEvent, InstanceOwner owner)
        {
            lock (ThisLock)
            {
                Fx.Assert(this.owners.ContainsKey(owner.InstanceOwnerId), "InstanceHandle called PendHandleToEvent on wrong InstanceStore!!");
                Fx.Assert(object.ReferenceEquals(this.owners[owner.InstanceOwnerId].Target, owner), "How did multiple of the same owner become simultaneously active?");

                InstanceNormalEvent normal = GetOwnerEventHelper(persistenceEvent, owner);
                Fx.Assert(!normal.PendingHandles.Contains(handle), "Should not have already pended the handle.");
                Fx.Assert(!normal.BoundHandles.Contains(handle), "Should not be able to pend an already-bound handle.");
                normal.PendingHandles.Add(handle);
            }
        }
 internal InstancePersistenceEvent FindEventWithReset(InstancePersistenceEvent eventType, out InstanceOwner instanceOwner)
 {
     return this.FindEventHelper(eventType, out instanceOwner, true);
 }
예제 #24
0
		protected void SignalEvent (InstancePersistenceEvent persistenceEvent, InstanceOwner owner)
		{
			throw new NotImplementedException ();
		}
        InstancePersistenceEvent FindEventHelper(InstancePersistenceEvent eventType, out InstanceOwner instanceOwner, bool withReset)
        {
            instanceOwner = null;
            InstanceOwner[] instanceOwners = GetInstanceOwners();

            if (instanceOwners.Length > 0)
            {
                foreach (InstanceOwner owner in instanceOwners)
                {
                    if (owner.InstanceOwnerId == this.storeLock.LockOwnerId)
                    {
                        instanceOwner = owner;
                        break;
                    }
                }

                if (instanceOwner != null)
                {
                    // Reset first.  That will allow the event to be cleaned up, so GetEvents won't return it (it will always return signalled events).
                    if (withReset)
                    {
                        base.ResetEvent(eventType, instanceOwner);
                    }
                    InstancePersistenceEvent[] registeredEvents = base.GetEvents(instanceOwner);

                    foreach (InstancePersistenceEvent persistenceEvent in registeredEvents)
                    {
                        if (persistenceEvent == eventType)
                        {
                            return persistenceEvent;
                        }
                    }
                }
            }

            return null;
        }
예제 #26
0
		protected InstancePersistenceEvent [] GetEvents (InstanceOwner owner)
		{
			throw new NotImplementedException ();
		}
        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();
        }
 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();
 }
예제 #29
0
		public InstanceHandle CreateInstanceHandle (InstanceOwner owner, Guid instanceId)
		{
			throw new NotImplementedException ();
		}
예제 #30
0
        protected InstancePersistenceEvent[] GetEvents(InstanceOwner owner)
        {
            if (owner == null)
            {
                throw Fx.Exception.ArgumentNull("owner");
            }

            lock (ThisLock)
            {
                WeakReference ownerReference;
                if (!this.owners.TryGetValue(owner.InstanceOwnerId, out ownerReference) || !object.ReferenceEquals(ownerReference.Target, owner))
                {
                    throw Fx.Exception.Argument("owner", SRCore.OwnerBelongsToWrongStore);
                }

                return owner.Events.Values.ToArray();
            }
        }