internal void Subscribe(ActivityExecutionContext context) { WorkflowQueuingService workflowQueuingService = context.GetService <WorkflowQueuingService>(); WorkflowQueue workflowQueue = workflowQueuingService.GetWorkflowQueue(StateMachineWorkflowActivity.SetStateQueueName); workflowQueue.RegisterForQueueItemAvailable(this); }
void IEventActivity.Subscribe(ActivityExecutionContext parentContext, IActivityEventListener <QueueEventArgs> parentEventHandler) { WorkflowQueuingService queueService = parentContext.GetService <WorkflowQueuingService>(); if (_queueName != null && queueService != null && parentEventHandler != null) { WorkflowQueue queue = queueService.GetWorkflowQueue(_queueName); queue.RegisterForQueueItemAvailable(parentEventHandler, this.QualifiedName); } }
private Boolean DoSubscribe(ActivityExecutionContext context, IActivityEventListener <QueueEventArgs> listener) { WorkflowQueue queue = CreateQueue(context); queue.RegisterForQueueItemAvailable(listener); FileWatcherService fileService = context.GetService <FileWatcherService>(); this.subscriptionId = fileService.RegisterListener(this.QueueName, this.Path, this.Filter, this.NotifyFilter, this.IncludeSubdirectories); return(subscriptionId != Guid.Empty); }
private void CreateSubscription(Guid instanceId, ActivityExecutionContext context, ICollection <CorrelationProperty> correlationValues) { WorkflowQueuingService queueSvcs = context.GetService <WorkflowQueuingService>(); EventQueueName queueId = new EventQueueName(this.interfaceType, this.followerOperation, correlationValues); WorkflowQueue workflowQueue = null; if (!queueSvcs.Exists(queueId)) { WorkflowActivityTrace.Activity.TraceEvent(TraceEventType.Information, 0, "CorrelationTokenInvalidatedHandler: creating q {0} ", queueId.GetHashCode()); workflowQueue = queueSvcs.CreateWorkflowQueue(queueId, true); queueCreator = true; } else { workflowQueue = queueSvcs.GetWorkflowQueue(queueId); } if (this.eventHandler != null) { workflowQueue.RegisterForQueueItemAvailable(this.eventHandler); } WorkflowSubscriptionService subscriptionService = (WorkflowSubscriptionService)context.GetService(typeof(WorkflowSubscriptionService)); MessageEventSubscription subscription = new MessageEventSubscription(queueId, instanceId); this.queueName = queueId; this.subscriptionId = subscription.SubscriptionId; subscription.InterfaceType = this.interfaceType; subscription.MethodName = this.followerOperation; this.interfaceType = null; this.followerOperation = null; if (correlationValues != null) { foreach (CorrelationProperty property in correlationValues) { subscription.CorrelationProperties.Add(property); } } if (this.eventHandler != null) { return; } if (subscriptionService == null) { return; } subscriptionService.CreateSubscription(subscription); }
internal static bool Subscribe(IServiceProvider context, Activity activity, Type interfaceType, string methodName, IActivityEventListener <QueueEventArgs> eventListener, Guid instanceId) { if (activity == null) { throw new ArgumentNullException("activity"); } if (interfaceType == null) { throw new ArgumentNullException("interfaceType"); } if (methodName == null) { throw new ArgumentNullException("methodName"); } WorkflowQueuingService queueService = (WorkflowQueuingService)context.GetService(typeof(WorkflowQueuingService)); IComparable queueName = ResolveQueueName(activity, interfaceType, methodName); if (queueName != null) { // initializer WorkflowQueue queue = null; if (queueService.Exists(queueName)) { queue = queueService.GetWorkflowQueue(queueName); queue.Enabled = true; } else { queue = queueService.CreateWorkflowQueue(queueName, true); } if (eventListener != null) { queue.RegisterForQueueItemAvailable(eventListener, activity.QualifiedName); WorkflowActivityTrace.Activity.TraceEvent(TraceEventType.Information, 0, "CorrelationService: activity '{0}' subscribing to QueueItemAvailable", activity.QualifiedName); return(true); } return(false); } SubscribeForCorrelationTokenInvalidation(activity, interfaceType, methodName, eventListener, instanceId); return(false); }
void IEventActivity.Subscribe(ActivityExecutionContext parentContext, IActivityEventListener <QueueEventArgs> parentEventHandler) { if (parentContext == null) { throw new ArgumentNullException("parentContext"); } if (parentEventHandler == null) { throw new ArgumentNullException("parentEventHandler"); } this.IsInEventActivityMode = true; base.RaiseEvent(DelayActivity.InitializeTimeoutDurationEvent, this, EventArgs.Empty); TimeSpan timeSpan = this.TimeoutDuration; DateTime timeOut = DateTime.UtcNow + timeSpan; WorkflowQueuingService qService = parentContext.GetService <WorkflowQueuingService>(); IComparable queueName = ((IEventActivity)this).QueueName; TimerEventSubscription timerSub = new TimerEventSubscription((Guid)queueName, this.WorkflowInstanceId, timeOut); WorkflowQueue queue = qService.CreateWorkflowQueue(queueName, false); queue.RegisterForQueueItemAvailable(parentEventHandler, this.QualifiedName); this.SubscriptionID = timerSub.SubscriptionId; Activity root = this; while (root.Parent != null) { root = root.Parent; } TimerEventSubscriptionCollection timers = (TimerEventSubscriptionCollection)root.GetValue(TimerEventSubscriptionCollection.TimerCollectionProperty); Debug.Assert(timers != null, "TimerEventSubscriptionCollection on root activity should never be null, but it was"); timers.Add(timerSub); }
protected sealed override ActivityExecutionStatus Execute(ActivityExecutionContext executionContext) { if (executionContext == null) { throw new ArgumentNullException("executionContext"); } WorkflowQueuingService queueService = executionContext.GetService <WorkflowQueuingService>(); WorkflowQueue queue = queueService.GetWorkflowQueue(_queueName); queue.RegisterForQueueItemAvailable(this, this.QualifiedName); if (queue.Count > 0) { object item = queue.Dequeue(); ProcessQueueItem(executionContext, item); queue.UnregisterForQueueItemAvailable(this); // run all Activities return(base.Execute(executionContext)); } return(ActivityExecutionStatus.Executing); }
/// <summary> /// Subscribes to item available. /// </summary> /// <param name="ctx">The CTX.</param> protected void SubscribeToQueueItemAvailable(ActivityExecutionContext ctx) { WorkflowQueue queue = GetQueue(ctx); queue.RegisterForQueueItemAvailable(this); }