void IActivityEventListener <CorrelationTokenEventArgs> .OnEvent(object sender, CorrelationTokenEventArgs dataChangeEventArgs)
        {
            if (sender == null)
            {
                throw new ArgumentException("sender");
            }
            if (dataChangeEventArgs == null)
            {
                throw new ArgumentException("dataChangeEventArgs");
            }

            ActivityExecutionContext context = sender as ActivityExecutionContext;
            Activity activity = context.Activity;

            ICollection <CorrelationProperty> correlationValues = dataChangeEventArgs.CorrelationToken.Properties;

            if (dataChangeEventArgs.IsInitializing)
            {
                CreateSubscription(this.instanceId, context, correlationValues);
                return;
            }

            if (queueName != null)
            {
                if (!CorrelationResolver.IsInitializingMember(queueName.InterfaceType, queueName.MethodName,
                                                              correlationValues == null ? null : new object[] { correlationValues }))
                {
                    DeleteSubscription(context);
                }
            }

            dataChangeEventArgs.CorrelationToken.UnsubscribeFromCorrelationTokenInitializedEvent(activity, this);
        }
Ejemplo n.º 2
0
        private static void CreateFollowerEntry(IServiceProvider context, Type interfaceType, string followermethodName, string initializermethodName)
        {
            if (!CorrelationResolver.IsInitializingMember(interfaceType, initializermethodName, null))
            {
                return;
            }

            WorkflowQueuingService queueSvcs = (WorkflowQueuingService)context.GetService(typeof(WorkflowQueuingService));
            FollowerQueueCreator   follower  = new FollowerQueueCreator(followermethodName);

            WorkflowActivityTrace.Activity.TraceEvent(TraceEventType.Information, 0, "Creating follower {0} on initializer {1}", interfaceType.Name + followermethodName, interfaceType.Name + initializermethodName);

            ICollection <CorrelationProperty> corrValues = CorrelationResolver.ResolveCorrelationValues(interfaceType, initializermethodName, null, true);
            EventQueueName key = new EventQueueName(interfaceType, initializermethodName, corrValues);
            WorkflowQueue  initializerQueue = null;

            if (queueSvcs.Exists(key))
            {
                initializerQueue = queueSvcs.GetWorkflowQueue(key);
            }
            else
            {
                // traversed follower before initializer
                initializerQueue         = queueSvcs.CreateWorkflowQueue(key, true);
                initializerQueue.Enabled = false;
            }

            initializerQueue.RegisterForQueueItemArrived(follower);
        }
Ejemplo n.º 3
0
        internal static void InvalidateCorrelationToken(Activity activity, Type interfaceType, string methodName, object[] messageArgs)
        {
            object correlationProvider = CorrelationResolver.GetCorrelationProvider(interfaceType);

            if (correlationProvider is NonCorrelatedProvider)
            {
                return;
            }

            CorrelationToken reference = GetCorrelationToken(activity);
            ICollection <CorrelationProperty> correlationvalues = CorrelationResolver.ResolveCorrelationValues(interfaceType, methodName, messageArgs, false);

            if (!CorrelationResolver.IsInitializingMember(interfaceType, methodName, messageArgs))
            {
                if (!reference.Initialized)
                {
                    throw new InvalidOperationException(SR.GetString(SR.Error_CorrelationNotInitialized, reference.Name, activity.QualifiedName));
                }
                ValidateCorrelation(reference.Properties, correlationvalues, reference.Name, activity);
                return;
            }

            // invalidate correlation token if methodName is an initializer
            reference.Initialize(activity, correlationvalues);
        }
        internal static IComparable ResolveQueueName(Activity activity, Type interfaceType, string methodName)
        {
            if (activity == null)
            {
                throw new ArgumentNullException("activity");
            }
            if (interfaceType == null)
            {
                throw new ArgumentNullException("interfaceType");
            }
            if (methodName == null)
            {
                throw new ArgumentNullException("methodName");
            }
            if (CorrelationResolver.IsInitializingMember(interfaceType, methodName, null))
            {
                return(new EventQueueName(interfaceType, methodName, CorrelationResolver.ResolveCorrelationValues(interfaceType, methodName, null, true)));
            }
            CorrelationToken correlationToken = GetCorrelationToken(activity);

            if (!correlationToken.Initialized)
            {
                return(null);
            }
            return(new EventQueueName(interfaceType, methodName, correlationToken.Properties));
        }
Ejemplo n.º 5
0
        internal static IComparable ResolveQueueName(Activity activity, Type interfaceType, string methodName)
        {
            if (activity == null)
            {
                throw new ArgumentNullException("activity");
            }
            if (interfaceType == null)
            {
                throw new ArgumentNullException("interfaceType");
            }
            if (methodName == null)
            {
                throw new ArgumentNullException("methodName");
            }

            // resolver will check for an explicit correlation provider,
            // if none present this will return an uncorrelated provider.
            // note, an uncorrelated methodName will always be an initializer
            if (CorrelationResolver.IsInitializingMember(interfaceType, methodName, null))
            {
                ICollection <CorrelationProperty> corrvalues = CorrelationResolver.ResolveCorrelationValues(interfaceType, methodName, null, true);
                return(new EventQueueName(interfaceType, methodName, corrvalues));
            }

            CorrelationToken reference = GetCorrelationToken(activity);

            if (!reference.Initialized)
            {
                return(null);
            }

            return(new EventQueueName(interfaceType, methodName, reference.Properties));
        }
Ejemplo n.º 6
0
        private EventQueueName GetKey(object[] eventArgs)
        {
            bool provideInitializerTokens = CorrelationResolver.IsInitializingMember(this.proxiedType, this.eventName, eventArgs);

            ICollection <CorrelationProperty> predicates = CorrelationResolver.ResolveCorrelationValues(this.proxiedType, this.eventName, eventArgs, provideInitializerTokens);

            return(new EventQueueName(this.proxiedType, this.eventName, predicates));
        }
 private static void InitializeFollowers(IServiceProvider context, Type interfaceType, string followermethodName)
 {
     if (!CorrelationResolver.IsInitializingMember(interfaceType, followermethodName, null))
     {
         foreach (EventInfo info in interfaceType.GetEvents())
         {
             CreateFollowerEntry(context, interfaceType, followermethodName, info.Name);
         }
     }
 }
Ejemplo n.º 8
0
        private static void InitializeFollowers(IServiceProvider context, Type interfaceType, string followermethodName)
        {
            if (CorrelationResolver.IsInitializingMember(interfaceType, followermethodName, null))
            {
                return;
            }

            EventInfo[] events = interfaceType.GetEvents();
            foreach (EventInfo e in events)
            {
                CreateFollowerEntry(context, interfaceType, followermethodName, e.Name);
            }
        }
 internal static void UninitializeFollowers(Type interfaceType, string initializer, WorkflowQueue initializerQueue)
 {
     if (CorrelationResolver.IsInitializingMember(interfaceType, initializer, null))
     {
         foreach (EventInfo info in interfaceType.GetEvents())
         {
             string name = info.Name;
             if (!CorrelationResolver.IsInitializingMember(interfaceType, info.Name, null))
             {
                 initializerQueue.UnregisterForQueueItemArrived(new FollowerQueueCreator(name));
             }
         }
     }
 }
Ejemplo n.º 10
0
        internal static void UninitializeFollowers(Type interfaceType, string initializer, WorkflowQueue initializerQueue)
        {
            if (!CorrelationResolver.IsInitializingMember(interfaceType, initializer, null))
            {
                return;
            }

            EventInfo[] events = interfaceType.GetEvents();
            foreach (EventInfo e in events)
            {
                string follower = e.Name;
                if (!CorrelationResolver.IsInitializingMember(interfaceType, e.Name, null))
                {
                    initializerQueue.UnregisterForQueueItemArrived(new FollowerQueueCreator(follower));
                }
            }
        }
 protected sealed override void Initialize(IServiceProvider provider)
 {
     if (provider == null)
     {
         throw new ArgumentNullException("provider");
     }
     if ((!base.IsDynamicActivity && !this.IsNestedUnderMultiInstanceContainer) || this.IsInitializingUnderMultiInstanceContainer)
     {
         Type        interfaceType = this.InterfaceType;
         string      eventName     = this.EventName;
         IComparable comparable    = null;
         if (CorrelationResolver.IsInitializingMember(interfaceType, eventName, null))
         {
             comparable = new EventQueueName(interfaceType, eventName);
         }
         base.SetValue(QueueNameProperty, comparable);
         CorrelationService.Initialize(provider, this, interfaceType, eventName, base.WorkflowInstanceId);
     }
 }
 internal static void InvalidateCorrelationToken(Activity activity, Type interfaceType, string methodName, object[] messageArgs)
 {
     if (!(CorrelationResolver.GetCorrelationProvider(interfaceType) is NonCorrelatedProvider))
     {
         CorrelationToken correlationToken = GetCorrelationToken(activity);
         ICollection <CorrelationProperty> followerProperties = CorrelationResolver.ResolveCorrelationValues(interfaceType, methodName, messageArgs, false);
         if (!CorrelationResolver.IsInitializingMember(interfaceType, methodName, messageArgs))
         {
             if (!correlationToken.Initialized)
             {
                 throw new InvalidOperationException(SR.GetString("Error_CorrelationNotInitialized", new object[] { correlationToken.Name, activity.QualifiedName }));
             }
             ValidateCorrelation(correlationToken.Properties, followerProperties, correlationToken.Name, activity);
         }
         else
         {
             correlationToken.Initialize(activity, followerProperties);
         }
     }
 }
 private static void CreateFollowerEntry(IServiceProvider context, Type interfaceType, string followermethodName, string initializermethodName)
 {
     if (CorrelationResolver.IsInitializingMember(interfaceType, initializermethodName, null))
     {
         WorkflowQueuingService service       = (WorkflowQueuingService)context.GetService(typeof(WorkflowQueuingService));
         FollowerQueueCreator   eventListener = new FollowerQueueCreator(followermethodName);
         WorkflowActivityTrace.Activity.TraceEvent(TraceEventType.Information, 0, "Creating follower {0} on initializer {1}", new object[] { interfaceType.Name + followermethodName, interfaceType.Name + initializermethodName });
         ICollection <CorrelationProperty> propertyValues = CorrelationResolver.ResolveCorrelationValues(interfaceType, initializermethodName, null, true);
         EventQueueName queueName     = new EventQueueName(interfaceType, initializermethodName, propertyValues);
         WorkflowQueue  workflowQueue = null;
         if (service.Exists(queueName))
         {
             workflowQueue = service.GetWorkflowQueue(queueName);
         }
         else
         {
             workflowQueue         = service.CreateWorkflowQueue(queueName, true);
             workflowQueue.Enabled = false;
         }
         workflowQueue.RegisterForQueueItemArrived(eventListener);
     }
 }
Ejemplo n.º 14
0
        protected sealed override void Initialize(IServiceProvider provider)
        {
            if (provider == null)
            {
                throw new ArgumentNullException("provider");
            }

            //When activity is dropped inside multi instance container(replicator)
            //We delay CorrelationService initialization to template initialization time.
            if ((!this.IsDynamicActivity && !IsNestedUnderMultiInstanceContainer) || IsInitializingUnderMultiInstanceContainer)
            {
                Type        type      = this.InterfaceType;
                string      eventName = this.EventName;
                IComparable queueName = null;
                if (CorrelationResolver.IsInitializingMember(type, eventName, null))
                {
                    queueName = new EventQueueName(type, eventName);
                }
                this.SetValue(QueueNameProperty, queueName);

                CorrelationService.Initialize(provider, this, type, eventName, this.WorkflowInstanceId);
            }
        }