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)); }
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); }
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); }
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); }
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)); }
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); } } }
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)); } } } }
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)); } } }
void IActivityEventListener <QueueEventArgs> .OnEvent(object sender, QueueEventArgs args) { lock (this.sync) { WorkflowQueue queue = (WorkflowQueue)sender; EventQueueName queueName = (EventQueueName)queue.QueueName; WorkflowActivityTrace.Activity.TraceEvent(TraceEventType.Information, 0, "FollowerQueueCreator: initialized on operation {0} for follower {1}", new object[] { queueName.InterfaceType.Name + queueName.MethodName, this.followerOperation }); IMethodMessage message = queue.Peek() as IMethodMessage; ICollection <CorrelationProperty> propertyValues = CorrelationResolver.ResolveCorrelationValues(queueName.InterfaceType, queueName.MethodName, message.Args, false); EventQueueName name2 = new EventQueueName(queueName.InterfaceType, this.followerOperation, propertyValues); if (!queue.QueuingService.Exists(name2)) { WorkflowActivityTrace.Activity.TraceEvent(TraceEventType.Information, 0, "FollowerQueueCreator::CreateQueue creating q {0}", new object[] { name2.GetHashCode() }); queue.QueuingService.CreateWorkflowQueue(name2, true); } } }
internal static ICollection <CorrelationProperty> ResolveCorrelationValues(Type interfaceType, string eventName, object[] eventArgs, bool provideInitializerTokens) { if (interfaceType == null) { throw new ArgumentNullException("interfaceType"); } if (eventName == null) { throw new ArgumentNullException("eventName"); } if (eventName.Length == 0) { throw new ArgumentException(SR.GetString(SR.Error_EventNameMissing)); } ICorrelationProvider correlationProvider = CorrelationResolver.GetCorrelationProvider(interfaceType); return(correlationProvider.ResolveCorrelationPropertyValues(interfaceType, eventName, eventArgs, provideInitializerTokens)); }
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 bool IsInitializingMember(Type interfaceType, string memberName, object[] methodArgs) { if (interfaceType == null) { throw new ArgumentNullException("interfaceType"); } if (memberName == null) { throw new ArgumentNullException("memberName"); } if (memberName.Length == 0) { throw new ArgumentException(SR.GetString(SR.Error_EventNameMissing)); } ICorrelationProvider correlationProvider = CorrelationResolver.GetCorrelationProvider(interfaceType); return(correlationProvider.IsInitializingMember(interfaceType, memberName, methodArgs)); }
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); } } }
void IActivityEventListener <QueueEventArgs> .OnEvent(object sender, QueueEventArgs args) { lock (sync) { WorkflowQueue queue = (WorkflowQueue)sender; // create the queue after extracting the correlation values from the message EventQueueName staticId = (EventQueueName)queue.QueueName; WorkflowActivityTrace.Activity.TraceEvent(TraceEventType.Information, 0, "FollowerQueueCreator: initialized on operation {0} for follower {1}", staticId.InterfaceType.Name + staticId.MethodName, this.followerOperation); IMethodMessage message = queue.Peek() as IMethodMessage; ICollection <CorrelationProperty> corrValues = CorrelationResolver.ResolveCorrelationValues(staticId.InterfaceType, staticId.MethodName, message.Args, false); EventQueueName queueName = new EventQueueName(staticId.InterfaceType, this.followerOperation, corrValues); if (!queue.QueuingService.Exists(queueName)) { WorkflowActivityTrace.Activity.TraceEvent(TraceEventType.Information, 0, "FollowerQueueCreator::CreateQueue creating q {0}", queueName.GetHashCode()); queue.QueuingService.CreateWorkflowQueue(queueName, true); } } }
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); } }
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); } }