Пример #1
0
        static CorrelationQuery CreateCorrelationQueryCore(MessageQuerySet select, Collection <CorrelationInitializer> correlationInitializers)
        {
            CorrelationQuery correlationQuery = null;

            if (select != null)
            {
                Fx.Assert(select.Count != 0, "Empty MessageQuerySet is not allowed!");

                correlationQuery = new CorrelationQuery
                {
                    Select = select
                };
            }

            if (correlationInitializers != null && correlationInitializers.Count > 0)
            {
                foreach (CorrelationInitializer correlation in correlationInitializers)
                {
                    QueryCorrelationInitializer queryCorrelation = correlation as QueryCorrelationInitializer;
                    if (queryCorrelation != null)
                    {
                        Fx.Assert(queryCorrelation.MessageQuerySet.Count != 0, "Empty MessageQuerySet is not allowed!");

                        correlationQuery = correlationQuery ?? new CorrelationQuery();
                        correlationQuery.SelectAdditional.Add(queryCorrelation.MessageQuerySet);
                    }
                }
            }

            return(correlationQuery);
        }
        private static void InitializeCorrelationHandles(NativeActivityContext context, CorrelationHandle selectHandle, CorrelationHandle ambientHandle, Collection <CorrelationInitializer> additionalCorrelations, InstanceKey instanceKey, ICollection <InstanceKey> additionalKeys)
        {
            bool flag = false;

            if ((instanceKey != null) && instanceKey.IsValid)
            {
                if (selectHandle != null)
                {
                    selectHandle.InitializeBookmarkScope(context, instanceKey);
                }
                else if (ambientHandle != null)
                {
                    ambientHandle.InitializeBookmarkScope(context, instanceKey);
                    flag = true;
                }
                else if (context.DefaultBookmarkScope.IsInitialized)
                {
                    if (context.DefaultBookmarkScope.Id != instanceKey.Value)
                    {
                        throw System.ServiceModel.Activities.FxTrace.Exception.AsError(new InvalidOperationException(System.ServiceModel.Activities.SR.CorrelationHandleInUse(context.DefaultBookmarkScope.Id, instanceKey.Value)));
                    }
                }
                else
                {
                    context.DefaultBookmarkScope.Initialize(context, instanceKey.Value);
                }
            }
            if ((additionalKeys != null) && (additionalCorrelations != null))
            {
                IEnumerator <CorrelationInitializer> enumerator = additionalCorrelations.GetEnumerator();
                foreach (InstanceKey key in additionalKeys)
                {
                    while (enumerator.MoveNext())
                    {
                        QueryCorrelationInitializer current = enumerator.Current as QueryCorrelationInitializer;
                        if (current != null)
                        {
                            CorrelationHandle handle = (current.CorrelationHandle != null) ? current.CorrelationHandle.Get(context) : null;
                            if (handle == null)
                            {
                                if ((ambientHandle == null) || flag)
                                {
                                    throw System.ServiceModel.Activities.FxTrace.Exception.AsError(new InvalidOperationException(System.ServiceModel.Activities.SR.QueryCorrelationInitializerCannotBeInitialized));
                                }
                                handle = ambientHandle;
                                flag   = true;
                            }
                            handle.InitializeBookmarkScope(context, key);
                            break;
                        }
                    }
                }
            }
        }
Пример #3
0
        public static void ValidateCorrelationInitializer(ActivityMetadata metadata, Collection <CorrelationInitializer> correlationInitializers, bool isReply, string displayName, string operationName)
        {
            Fx.Assert(metadata != null, "cannot be null");

            if (correlationInitializers != null && correlationInitializers.Count > 0)
            {
                bool queryInitializerWithEmptyHandle = false;
                foreach (CorrelationInitializer correlation in correlationInitializers)
                {
                    if (correlation is RequestReplyCorrelationInitializer && isReply)
                    {
                        // This is a reply, so additional correlations should not have a request reply handle
                        metadata.AddValidationError(SR.ReplyShouldNotIncludeRequestReplyHandle(displayName, operationName));
                    }

                    QueryCorrelationInitializer queryCorrelation = correlation as QueryCorrelationInitializer;
                    if (queryCorrelation != null)
                    {
                        if (queryCorrelation.MessageQuerySet.Count == 0)
                        {
                            metadata.AddValidationError(SR.QueryCorrelationInitializerWithEmptyMessageQuerySet(displayName, operationName));
                        }
                    }

                    if (correlation.CorrelationHandle == null)
                    {
                        if (correlation is QueryCorrelationInitializer)
                        {
                            if (!queryInitializerWithEmptyHandle)
                            {
                                queryInitializerWithEmptyHandle = true;
                            }
                            else
                            {
                                // more than one queryInitializer present, in this case we don't permit null handle
                                metadata.AddValidationError(SR.NullCorrelationHandleInMultipleQueryCorrelation);
                            }
                        }
                        else
                        {
                            metadata.AddValidationError(SR.NullCorrelationHandleInInitializeCorrelation(correlation.GetType().Name));
                        }
                    }
                }
            }
        }
 public static void ValidateCorrelationInitializer(ActivityMetadata metadata, Collection <CorrelationInitializer> correlationInitializers, bool isReply, string displayName, string operationName)
 {
     if ((correlationInitializers != null) && (correlationInitializers.Count > 0))
     {
         bool flag = false;
         foreach (CorrelationInitializer initializer in correlationInitializers)
         {
             if ((initializer is RequestReplyCorrelationInitializer) && isReply)
             {
                 metadata.AddValidationError(System.ServiceModel.Activities.SR.ReplyShouldNotIncludeRequestReplyHandle(displayName, operationName));
             }
             QueryCorrelationInitializer initializer2 = initializer as QueryCorrelationInitializer;
             if ((initializer2 != null) && (initializer2.MessageQuerySet.Count == 0))
             {
                 metadata.AddValidationError(System.ServiceModel.Activities.SR.QueryCorrelationInitializerWithEmptyMessageQuerySet(displayName, operationName));
             }
             if (initializer.CorrelationHandle == null)
             {
                 if (initializer is QueryCorrelationInitializer)
                 {
                     if (!flag)
                     {
                         flag = true;
                     }
                     else
                     {
                         metadata.AddValidationError(System.ServiceModel.Activities.SR.NullCorrelationHandleInMultipleQueryCorrelation);
                     }
                 }
                 else
                 {
                     metadata.AddValidationError(System.ServiceModel.Activities.SR.NullCorrelationHandleInInitializeCorrelation(initializer.GetType().Name));
                 }
             }
         }
     }
 }
        private static CorrelationQuery CreateCorrelationQueryCore(MessageQuerySet select, Collection <CorrelationInitializer> correlationInitializers)
        {
            CorrelationQuery query = null;

            if (select != null)
            {
                query = new CorrelationQuery {
                    Select = select
                };
            }
            if ((correlationInitializers != null) && (correlationInitializers.Count > 0))
            {
                foreach (CorrelationInitializer initializer in correlationInitializers)
                {
                    QueryCorrelationInitializer initializer2 = initializer as QueryCorrelationInitializer;
                    if (initializer2 != null)
                    {
                        query = query ?? new CorrelationQuery();
                        query.SelectAdditional.Add(initializer2.MessageQuerySet);
                    }
                }
            }
            return(query);
        }
Пример #6
0
        // both receive and send initialize correlations using this method
        // if selectHandle is not null, we first try to initalize instanceKey with it , else we try to initalize the ambient handle
        // if ambient handle is not used for initializing instance key , we might use it for initalizing  queryCorrelationsInitalizer.

        // SelectHandle usage:
        // Receive: selectHandle is the correlatesWith handle
        // SendReply: in case of context based correlation, this is the context handle
        // Send: in case of context based correlation, this will be the callback handle
        // ReceiveReply: selectHandle will be always null
        // Note that only Receive can initialize a content based correlation with a selectHandle (parallel convoy)
        internal static void InitializeCorrelationHandles(NativeActivityContext context,
                                                          CorrelationHandle selectHandle, CorrelationHandle ambientHandle, Collection <CorrelationInitializer> additionalCorrelations,
                                                          InstanceKey instanceKey, ICollection <InstanceKey> additionalKeys)
        {
            bool isAmbientHandleUsed = false;

            if (instanceKey != null && instanceKey.IsValid)
            {
                if (selectHandle != null)
                {
                    selectHandle.InitializeBookmarkScope(context, instanceKey);
                }
                else if (ambientHandle != null)
                {
                    ambientHandle.InitializeBookmarkScope(context, instanceKey);
                    isAmbientHandleUsed = true;
                }
                else if (context.DefaultBookmarkScope.IsInitialized)
                {
                    if (context.DefaultBookmarkScope.Id != instanceKey.Value)
                    {
                        throw FxTrace.Exception.AsError(
                                  new InvalidOperationException(SR2.CorrelationHandleInUse(context.DefaultBookmarkScope.Id, instanceKey.Value)));
                    }
                }
                else
                {
                    context.DefaultBookmarkScope.Initialize(context, instanceKey.Value);
                }
            }

            if (additionalKeys != null && additionalCorrelations != null)
            {
                // The ordering of items in SelectAdditional and additional correlations are the same
                // Therefore, we assign keys iteratively

                IEnumerator <CorrelationInitializer> enumerator = additionalCorrelations.GetEnumerator();

                foreach (InstanceKey key in additionalKeys)
                {
                    Fx.Assert(key != null && key.IsValid, "only valid keys should be passed into InitializeCorrelationHandles");

                    while (enumerator.MoveNext())
                    {
                        QueryCorrelationInitializer queryCorrelation = enumerator.Current as QueryCorrelationInitializer;
                        if (queryCorrelation != null)
                        {
                            CorrelationHandle handle = (queryCorrelation.CorrelationHandle != null ? queryCorrelation.CorrelationHandle.Get(context) : null);
                            if (handle == null)
                            {
                                if (ambientHandle != null && !isAmbientHandleUsed)
                                {
                                    handle = ambientHandle;
                                    isAmbientHandleUsed = true;
                                }
                                else
                                {
                                    throw FxTrace.Exception.AsError(
                                              new InvalidOperationException(SR2.QueryCorrelationInitializerCannotBeInitialized));
                                }
                            }
                            handle.InitializeBookmarkScope(context, key);
                            break;
                        }
                    }
                }
            }
        }