Esempio n. 1
0
 static string ToMessage(InstanceKey instanceKey)
 {
     if (instanceKey != null && instanceKey.IsValid)
     {
         return(SRCore.KeyCompleteSpecific(instanceKey.Value));
     }
     return(SRCore.KeyCompleteDefault);
 }
 static string ToMessage(InstanceKey instanceKey)
 {
     if (instanceKey != null && instanceKey.IsValid)
     {
         return SRCore.KeyNotReadySpecific(instanceKey.Value);
     }
     return SRCore.KeyNotReadyDefault;
 }
 static string ToMessage(Guid instanceId, InstanceKey instanceKey, Guid conflictingInstanceId)
 {
     if (instanceKey != null && instanceKey.IsValid)
     {
         if (instanceId != Guid.Empty && conflictingInstanceId != Guid.Empty)
         {
             return SRCore.KeyCollisionSpecific(instanceId, instanceKey.Value, conflictingInstanceId);
         }
         return SRCore.KeyCollisionSpecificKeyOnly(instanceKey.Value);
     }
     return SRCore.KeyCollisionDefault;
 }
 static string ToMessage(Guid instanceId, InstanceKey instanceKey, Guid conflictingInstanceId)
 {
     if (instanceKey != null && instanceKey.IsValid)
     {
         if (instanceId != Guid.Empty && conflictingInstanceId != Guid.Empty)
         {
             return(SRCore.KeyCollisionSpecific(instanceId, instanceKey.Value, conflictingInstanceId));
         }
         return(SRCore.KeyCollisionSpecificKeyOnly(instanceKey.Value));
     }
     return(SRCore.KeyCollisionDefault);
 }
 public SerializableInstanceKey(InstanceKey instanceKey)
 {
     this.value = instanceKey.Value;
     if (instanceKey.Metadata != null)
     {
         this.metadata = new Dictionary<XName, SerializableInstanceValue>(instanceKey.Metadata.Count);
         foreach (KeyValuePair<XName, InstanceValue> pair in instanceKey.Metadata)
         {
             this.metadata.Add(pair.Key, new SerializableInstanceValue(pair.Value));
         }
     }
 }
        public CorrelationMessageProperty(InstanceKey correlationKey, IEnumerable<InstanceKey> additionalKeys, IEnumerable<InstanceKey> transientCorrelations)
        {
            if (correlationKey == null)
            {
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("correlationKey");
            }

            if (additionalKeys == null)
            {
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("additionalKeys");
            }

            this.correlationKey = correlationKey;

            ICollection<InstanceKey> additionalKeysCollection = additionalKeys as ICollection<InstanceKey>;
            if (additionalKeysCollection != null && additionalKeysCollection.Count == 0)
            {
                this.additionalKeys = emptyInstanceKeyList;
            }
            else
            {
                this.additionalKeys = additionalKeys as ReadOnlyCollection<InstanceKey>;
                if (this.additionalKeys == null)
                {
                    IList<InstanceKey> additionalKeysList = additionalKeys as IList<InstanceKey>;
                    if (additionalKeysList == null)
                    {
                        additionalKeysList = new List<InstanceKey>(additionalKeys);
                    }
                    this.additionalKeys = new ReadOnlyCollection<InstanceKey>(additionalKeysList);
                }
            }

            ICollection<InstanceKey> transientCorrelationsCollection = transientCorrelations as ICollection<InstanceKey>;
            if (transientCorrelations == null || (transientCorrelationsCollection != null && transientCorrelationsCollection.Count == 0))
            {
                this.transientCorrelations = emptyInstanceKeyList;
            }
            else
            {
                this.transientCorrelations = transientCorrelations as ReadOnlyCollection<InstanceKey>;
                if (this.transientCorrelations == null)
                {
                    IList<InstanceKey> transientCorrelationsList = transientCorrelations as IList<InstanceKey>;
                    if (transientCorrelationsList == null)
                    {
                        transientCorrelationsList = new List<InstanceKey>(transientCorrelations);
                    }
                    this.transientCorrelations = new ReadOnlyCollection<InstanceKey>(transientCorrelationsList);
                }
            }
        }
 public CorrelationMessageProperty(InstanceKey correlationKey, IEnumerable<InstanceKey> additionalKeys, IEnumerable<InstanceKey> transientCorrelations)
 {
     if (correlationKey == null)
     {
         throw System.ServiceModel.DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("correlationKey");
     }
     if (additionalKeys == null)
     {
         throw System.ServiceModel.DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("additionalKeys");
     }
     this.correlationKey = correlationKey;
     ICollection<InstanceKey> is2 = additionalKeys as ICollection<InstanceKey>;
     if ((is2 != null) && (is2.Count == 0))
     {
         this.additionalKeys = emptyInstanceKeyList;
     }
     else
     {
         this.additionalKeys = additionalKeys as ReadOnlyCollection<InstanceKey>;
         if (this.additionalKeys == null)
         {
             IList<InstanceKey> list = additionalKeys as IList<InstanceKey>;
             if (list == null)
             {
                 list = new List<InstanceKey>(additionalKeys);
             }
             this.additionalKeys = new ReadOnlyCollection<InstanceKey>(list);
         }
     }
     ICollection<InstanceKey> is3 = transientCorrelations as ICollection<InstanceKey>;
     if ((transientCorrelations == null) || ((is3 != null) && (is3.Count == 0)))
     {
         this.transientCorrelations = emptyInstanceKeyList;
     }
     else
     {
         this.transientCorrelations = transientCorrelations as ReadOnlyCollection<InstanceKey>;
         if (this.transientCorrelations == null)
         {
             IList<InstanceKey> list2 = transientCorrelations as IList<InstanceKey>;
             if (list2 == null)
             {
                 list2 = new List<InstanceKey>(transientCorrelations);
             }
             this.transientCorrelations = new ReadOnlyCollection<InstanceKey>(list2);
         }
     }
 }
 internal void InitializeBookmarkScope(NativeActivityContext context, InstanceKey instanceKey)
 {
     if (this.Scope == null)
     {
         this.bookmarkScopeHandle.CreateBookmarkScope(context, instanceKey.Value);
         this.Scope = this.bookmarkScopeHandle.BookmarkScope;
     }
     else if (this.Scope.IsInitialized)
     {
         if (this.Scope.Id != instanceKey.Value)
         {
             throw System.ServiceModel.Activities.FxTrace.Exception.AsError(new InvalidOperationException(System.ServiceModel.Activities.SR.CorrelationHandleInUse(this.Scope.Id, instanceKey.Value)));
         }
     }
     else
     {
         this.Scope.Initialize(context, instanceKey.Value);
     }
 }
Esempio n. 9
0
        bool TryGetMessageVersion(InstanceKey instanceKey, out MessageVersion version)
        {
            Fx.Assert(instanceKey != null, "Expect a valid instanceKey here");
            version = MessageVersion.None;
            if (instanceKey != null)
            {
                InstanceValue messageVersionValue;
                if (instanceKey.Metadata.TryGetValue(WorkflowServiceNamespace.MessageVersionForReplies, out messageVersionValue))
                {
                    version = (MessageVersion)messageVersionValue.Value;
                    return true;
                }
            }

            return false;
        }
 public InstanceKeyCollisionException(XName commandName, Guid instanceId, InstanceKey instanceKey, Guid conflictingInstanceId, string message, Exception innerException)
     : base(commandName, instanceId, message, innerException)
 {
     ConflictingInstanceId = conflictingInstanceId;
     InstanceKey = instanceKey;
 }
 static void TryAddKeyToInstanceKeysCollection(IDictionary<Guid, IDictionary<XName, InstanceValue>> instanceKeysToAssociate, InstanceKey keyToAdd)
 {
     Fx.Assert(instanceKeysToAssociate != null, "instanceKeysToAssociate cannot be null");
     Fx.Assert(keyToAdd != null, "keyToAdd cannot be null");
     
     if (instanceKeysToAssociate.ContainsKey(keyToAdd.Value))
     {
         throw FxTrace.Exception.AsError(new InvalidOperationException(SR.DuplicateInstanceKeyExists(keyToAdd.Value)));
     }
     instanceKeysToAssociate.Add(keyToAdd.Value, keyToAdd.Metadata);
 }
 public CorrelationMessageProperty(InstanceKey correlationKey, IEnumerable<InstanceKey> additionalKeys)
     : this(correlationKey, additionalKeys, null)
 {
 }
 public InstanceKeyCompleteException(XName commandName, InstanceKey instanceKey)
     : this(commandName, instanceKey, null)
 {
 }
 public InstanceKeyCollisionException(XName commandName, Guid instanceId, InstanceKey instanceKey, Guid conflictingInstanceId, string message, Exception innerException)
     : base(commandName, instanceId, message, innerException)
 {
     ConflictingInstanceId = conflictingInstanceId;
     InstanceKey           = instanceKey;
 }
        internal void InitializeBookmarkScope(NativeActivityContext context, InstanceKey instanceKey)
        {
            Fx.Assert(context != null, "executionContext cannot be null");
            Fx.Assert(instanceKey != null, "instanceKey cannot be null");

            if (context.GetExtension<SendReceiveExtension>() != null)
            {
                if (this.InstanceKey != null && this.InstanceKey.Value != instanceKey.Value)
                {
                    throw FxTrace.Exception.AsError(
                        new InvalidOperationException(SR.CorrelationHandleInUse(this.InstanceKey.Value, instanceKey.Value)));
                }
                this.InstanceKey = instanceKey;
            }
            else
            {
                if (this.Scope == null)
                {
                    this.bookmarkScopeHandle.CreateBookmarkScope(context, instanceKey.Value);
                    this.Scope = this.bookmarkScopeHandle.BookmarkScope;
                }
                else
                {
                    if (this.Scope.IsInitialized)
                    {
                        if (this.Scope.Id != instanceKey.Value)
                        {
                            throw FxTrace.Exception.AsError(
                                new InvalidOperationException(SR.CorrelationHandleInUse(this.Scope.Id, instanceKey.Value)));
                        }
                    }
                    else
                    {
                        this.Scope.Initialize(context, instanceKey.Value);
                    }
                }
            }
        }
 public abstract void Send(MessageContext message, SendSettings settings, InstanceKey correlatesWith, Bookmark sendCompleteBookmark);
 public InstanceKeyNotReadyException(XName commandName, InstanceKey instanceKey)
     : this(commandName, instanceKey, null)
 {
 }
 public InstanceKeyNotReadyException(XName commandName, Guid instanceId, InstanceKey instanceKey, string message, Exception innerException)
     : base(commandName, instanceId, message, innerException)
 {
     InstanceKey = instanceKey;
 }
        void LoadInProgressFinished(InstanceKey key)
        {
            AsyncWaitHandle waitHandle = null;

            // This may be called with a null.
            if (key != null)
            {
                lock (ThisLock)
                {
                    this.loadsInProgress.TryGetValue(key, out waitHandle);
                    if (waitHandle != null)
                    {
                        // Before we start waking up waiters, we need to remove the entry from the loadsInProgress dictionary,
                        // otherwise they would just queue up again.
                        this.loadsInProgress.Remove(key);
                    }
                }

                // Wake up any waiters outside the lock.
                if (waitHandle != null)
                {
                    waitHandle.Set();
                }
            }
        }
 public InstanceKeyNotReadyException(XName commandName, InstanceKey instanceKey, Exception innerException)
     : this(commandName, Guid.Empty, instanceKey, ToMessage(instanceKey), innerException)
 {
 }
 public InstanceKeyNotReadyException(XName commandName, InstanceKey instanceKey)
     : this(commandName, instanceKey, null)
 {
 }
            public LoadOrCreateAsyncResult(PersistenceProviderDirectory ppd, InstanceKey key, Guid suggestedIdOrId,
                bool canCreateInstance, ICollection<InstanceKey> associatedKeys, Transaction transaction, bool loadAny, WorkflowIdentityKey updatedIdentity,
                TimeSpan timeout, AsyncCallback callback, object state)
                : base(callback, state)
            {
                Exception completionException = null;
                bool completeSelf = false;

                this.ppd = ppd;
                this.key = key;
                this.suggestedIdOrId = suggestedIdOrId;
                this.canCreateInstance = canCreateInstance;
                this.associatedKeys = associatedKeys;
                Fx.Assert(!ppd.serviceHost.IsLoadTransactionRequired || (transaction != null), "Transaction must exist!");
                this.transaction = transaction;
                this.loadAny = loadAny;
                this.updatedIdentity = updatedIdentity;
                this.timeoutHelper = new TimeoutHelper(timeout);

                if (this.associatedKeys != null && this.associatedKeys.Count == 0)
                {
                    this.associatedKeys = null;
                }

                OnCompleting = LoadOrCreateAsyncResult.onComplete;

                //
                if (this.transaction != null)
                {
                    LoadOrCreateAsyncResult.PromoteTransaction(this.transaction);
                }

                try
                {
                    if (this.LoadFromCache())
                    {
                        completeSelf = true;
                    }
                }
                catch (Exception exception)
                {
                    if (Fx.IsFatal(exception))
                    {
                        throw;
                    }
                    completionException = exception;
                    completeSelf = true;
                }

                if (completeSelf)
                {
                    this.Complete(true, completionException);
                }
            }
 public InstanceKeyCollisionException(XName commandName, Guid instanceId, InstanceKey instanceKey, Guid conflictingInstanceId)
     : this(commandName, instanceId, instanceKey, conflictingInstanceId, null)
 {
 }
 internal IAsyncResult BeginGetInstance(InstanceKey instanceKey, ICollection<InstanceKey> additionalKeys, WorkflowGetInstanceContext parameters, TimeSpan timeout, AsyncCallback callback, object state)
 {
     ThrowIfClosedOrAborted(this.state);
     return new GetInstanceAsyncResult(this, instanceKey, additionalKeys, parameters, timeout, callback, state);
 }
 public InstanceKeyCollisionException(XName commandName, Guid instanceId, InstanceKey instanceKey, Guid conflictingInstanceId, Exception innerException)
     : this(commandName, instanceId, instanceKey, conflictingInstanceId, ToMessage(instanceId, instanceKey, conflictingInstanceId), innerException)
 {
 }
Esempio n. 26
0
 public InstanceKeyCompleteException(XName commandName, InstanceKey instanceKey, Exception innerException)
     : this(commandName, Guid.Empty, instanceKey, ToMessage(instanceKey), innerException)
 {
 }
        InstancePersistenceCommand CreateLoadCommandHelper(InstanceKey key, out InstanceHandle handle, bool canCreateInstance, Guid suggestedIdOrId, ICollection<InstanceKey> associatedKeys, bool loadAny)
        {
            if (loadAny)
            {
                handle = this.store.CreateInstanceHandle(this.owner);
                return new TryLoadRunnableWorkflowCommand();
            }
            else if (key != null)
            {
                LoadWorkflowByInstanceKeyCommand loadByKeyCommand;
                handle = this.store.CreateInstanceHandle(this.owner);
                if (canCreateInstance)
                {
                    loadByKeyCommand = new LoadWorkflowByInstanceKeyCommand()
                    {
                        LookupInstanceKey = key.Value,
                        AssociateInstanceKeyToInstanceId = suggestedIdOrId == Guid.Empty ? Guid.NewGuid() : suggestedIdOrId,
                        AcceptUninitializedInstance = true,
                    };
                }
                else
                {
                    loadByKeyCommand = new LoadWorkflowByInstanceKeyCommand()
                    {
                        LookupInstanceKey = key.Value,
                    };
                }
                InstanceKey lookupKeyToAdd = (canCreateInstance && key.Metadata != null && key.Metadata.Count > 0) ? key : null;
                if (associatedKeys != null)
                {
                    foreach (InstanceKey keyToAssociate in associatedKeys)
                    {
                        if (keyToAssociate == key)
                        {
                            if (!canCreateInstance)
                            {
                                continue;
                            }
                            lookupKeyToAdd = null;
                        }
                        TryAddKeyToInstanceKeysCollection(loadByKeyCommand.InstanceKeysToAssociate, keyToAssociate);
                    }
                }
                if (lookupKeyToAdd != null)
                {
                    TryAddKeyToInstanceKeysCollection(loadByKeyCommand.InstanceKeysToAssociate, lookupKeyToAdd);
                }
                return loadByKeyCommand;
            }
            else
            {
                if (associatedKeys != null)
                {
                    throw FxTrace.Exception.AsError(new InvalidOperationException(SR.NoAdditionalKeysOnInstanceIdLoad));
                }

                handle = this.store.CreateInstanceHandle(this.owner, suggestedIdOrId == Guid.Empty ? Guid.NewGuid() : suggestedIdOrId);
                return new LoadWorkflowCommand()
                {
                    AcceptUninitializedInstance = canCreateInstance,
                };
            }
        }
        AsyncWaitHandle LoadInProgressWaitHandle(InstanceKey key)
        {
            AsyncWaitHandle waitHandle = null;

            if (key != null)
            {
                lock (ThisLock)
                {
                    this.loadsInProgress.TryGetValue(key, out waitHandle);
                    if (waitHandle == null)
                    {
                        AsyncWaitHandle newWaitHandle = new AsyncWaitHandle(EventResetMode.ManualReset);
                        this.loadsInProgress.Add(key, newWaitHandle);
                    }
                }
            }

            return waitHandle;
        }
        // See if the instance exists in our cache
        PersistenceContext LoadFromCache(InstanceKey key, Guid suggestedIdOrId, bool canCreateInstance)
        {
            PersistenceContext foundContext = null;
            if (key != null || suggestedIdOrId != Guid.Empty)
            {
                lock (ThisLock)
                {
                    ThrowIfClosedOrAborted();

                    if (key == null)
                    {
                        this.instanceCache.TryGetValue(suggestedIdOrId, out foundContext);
                    }
                    else
                    {
                        this.keyMap.TryGetValue(key.Value, out foundContext);
                    }

                    // Done here to take advantage of the lock.
                    Fx.Assert(this.instanceCache.Count <= MaxInstances, "Too many instances in PPD.");
                }
            }
            else
            {
                Fx.Assert(canCreateInstance, "Must be able to create an instance if not addressable.");
            }

            return foundContext;
        }
        internal ReadOnlyCollection<BookmarkInfo> GetBookmarksForInstance(InstanceKey instanceKey)
        {
            ReadOnlyCollection<BookmarkInfo> result = null;
            PersistenceContext context;

            lock (ThisLock)
            {
                // It's okay if the instance doesn't exist. We will just return null.
                if (this.keyMap.TryGetValue(instanceKey.Value, out context))
                {
                    result = context.Bookmarks;
                }
            }

            return result;
        }
 public abstract void OnUninitializeCorrelation(InstanceKey correlationKey);
Esempio n. 32
0
 static InstanceKey()
 {
     InvalidKey = new InstanceKey();
 }
            public GetInstanceAsyncResult(DurableInstanceManager instanceManager, InstanceKey instanceKey, ICollection<InstanceKey> additionalKeys, WorkflowGetInstanceContext parameters,
                TimeSpan timeout, AsyncCallback callback, object state)
                : this(instanceManager, parameters, timeout, callback, state)
            {
                Fx.Assert(instanceKey != null, "Instance key must be set.");

                this.instanceKey = instanceKey;
                this.additionalKeys = additionalKeys;

                if (this.GetInstance())
                {
                    this.Complete(true);
                }
            }
 public void RegisterReceive(ReceiveSettings settings, InstanceKey correlatesWith, Bookmark receiveBookmark)
 {
     this.OnRegisterReceive(settings, correlatesWith, receiveBookmark);
 }
Esempio n. 35
0
 public InstanceKeyCompleteException(XName commandName, InstanceKey instanceKey)
     : this(commandName, instanceKey, null)
 {
 }
 protected abstract void OnRegisterReceive(ReceiveSettings settings, InstanceKey correlatesWith, Bookmark receiveBookmark);
Esempio n. 37
0
 public InstanceKeyCompleteException(XName commandName, Guid instanceId, InstanceKey instanceKey, string message, Exception innerException)
     : base(commandName, instanceId, message, innerException)
 {
     InstanceKey = instanceKey;
 }
 public InstanceKeyCollisionException(XName commandName, Guid instanceId, InstanceKey instanceKey, Guid conflictingInstanceId)
     : this(commandName, instanceId, instanceKey, conflictingInstanceId, null)
 {
 }
        // pass OperationContext.Current if you don't already have an OperationContext.
        protected void GetInstanceKeys(OperationContext operationContext, out InstanceKey instanceKey, out ICollection<InstanceKey> additionalKeys)
        {
            CorrelationMessageProperty correlationMessageProperty = null;
            InstanceKey localInstanceKey;
            ICollection<InstanceKey> localAdditionalKeys;

            instanceKey = InstanceKey.InvalidKey;
            additionalKeys = new ReadOnlyCollection<InstanceKey>(new InstanceKey[] { });

            if (!CorrelationMessageProperty.TryGet(operationContext.IncomingMessageProperties,
                out correlationMessageProperty))
            {
                if (this.keyCalculator != null)
                {
                    MessageBuffer requestMessageBuffer;
                    bool success;

                    if (operationContext.IncomingMessageProperties.TryGetValue(ChannelHandler.MessageBufferPropertyName, out requestMessageBuffer))
                    {
                        success = this.keyCalculator.CalculateKeys(requestMessageBuffer, operationContext.IncomingMessage, out localInstanceKey, out localAdditionalKeys);
                    }
                    else
                    {
                        // Message is not preserved.(DispatchRuntime.PreserveMessage is false.)
                        // this could be a case where we only have context queries, in this case we don't preserve the message
                        success = this.keyCalculator.CalculateKeys(operationContext.IncomingMessage, out localInstanceKey, out localAdditionalKeys);
                    }
                    if (success)
                    {
                        if (localInstanceKey != null)
                        {
                            instanceKey = localInstanceKey;
                        }
                        if (localAdditionalKeys != null)
                        {
                            additionalKeys = localAdditionalKeys;
                        }

                        correlationMessageProperty = new CorrelationMessageProperty(instanceKey, additionalKeys);

                        operationContext.IncomingMessageProperties.Add(CorrelationMessageProperty.Name, correlationMessageProperty);
                    }
                }
            }
            else
            {
                instanceKey = correlationMessageProperty.CorrelationKey;
                additionalKeys = correlationMessageProperty.AdditionalKeys;
            }

            //If InstanceKey is still not resolved do the activation operation validation.
            if (instanceKey == null || !instanceKey.IsValid)
            {
                if (!this.CanCreateInstance)
                {
                    this.host.RaiseUnknownMessageReceived(operationContext.IncomingMessage);

                    throw FxTrace.Exception.AsError(
                        new FaultException(
                        new DurableDispatcherAddressingFault()));
                }
            }
        }
 public InstanceKeyCollisionException(XName commandName, Guid instanceId, InstanceKey instanceKey, Guid conflictingInstanceId, Exception innerException)
     : this(commandName, instanceId, instanceKey, conflictingInstanceId, ToMessage(instanceId, instanceKey, conflictingInstanceId), innerException)
 {
 }