void IActivityEventListener <QueueEventArgs> .OnEvent(object sender, QueueEventArgs e) { if (sender == null) { throw new ArgumentNullException("sender"); } if (e == null) { throw new ArgumentNullException("e"); } ActivityExecutionContext context = sender as ActivityExecutionContext; if (context == null) { throw new ArgumentException(SR.Error_SenderMustBeActivityExecutionContext, "sender"); } if (this.ExecutionStatus != ActivityExecutionStatus.Closed) { System.Diagnostics.Debug.Assert(this.SubscriptionID != Guid.Empty); WorkflowQueuingService qService = context.GetService <WorkflowQueuingService>(); qService.GetWorkflowQueue(e.QueueName).Dequeue(); qService.DeleteWorkflowQueue(e.QueueName); context.CloseActivity(); } }
private void DeleteSubscription(ActivityExecutionContext context) { if (this.queueName == null) { return; } WorkflowQueuingService queueSvcs = context.GetService <WorkflowQueuingService>(); if (queueCreator) { queueSvcs.DeleteWorkflowQueue(this.queueName); } if (this.eventHandler != null) { return; } WorkflowSubscriptionService subscriptionService = context.GetService <WorkflowSubscriptionService>(); if (subscriptionService != null) { subscriptionService.DeleteSubscription(this.subscriptionId); } WorkflowActivityTrace.Activity.TraceEvent(TraceEventType.Information, 0, "CorrelationTokenInvalidatedHandler subscription deleted SubId {0} QueueId {1}", this.subscriptionId, this.queueName); }
internal static bool Unsubscribe(IServiceProvider context, Activity activity, Type interfaceType, string methodName, IActivityEventListener <QueueEventArgs> eventListener) { if (activity == null) { throw new ArgumentException("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) { if (queueService.Exists(queueName)) { queueService.GetWorkflowQueue(queueName).UnregisterForQueueItemAvailable(eventListener); return(true); } } return(false); }
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); }
internal void Unsubscribe(ActivityExecutionContext context) { WorkflowQueuingService workflowQueuingService = context.GetService <WorkflowQueuingService>(); WorkflowQueue workflowQueue = workflowQueuingService.GetWorkflowQueue(StateMachineWorkflowActivity.SetStateQueueName); workflowQueue.UnregisterForQueueItemAvailable(this); }
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(InitializeTimeoutDurationEvent, this, EventArgs.Empty); TimeSpan timeoutDuration = this.TimeoutDuration; DateTime expiresAt = DateTime.UtcNow + timeoutDuration; WorkflowQueuingService service = parentContext.GetService <WorkflowQueuingService>(); IComparable queueName = ((IEventActivity)this).QueueName; TimerEventSubscription item = new TimerEventSubscription((Guid)queueName, base.WorkflowInstanceId, expiresAt); service.CreateWorkflowQueue(queueName, false).RegisterForQueueItemAvailable(parentEventHandler, base.QualifiedName); this.SubscriptionID = item.SubscriptionId; Activity parent = this; while (parent.Parent != null) { parent = parent.Parent; } ((TimerEventSubscriptionCollection)parent.GetValue(TimerEventSubscriptionCollection.TimerCollectionProperty)).Add(item); }
protected override void OnActivityExecutionContextLoad(IServiceProvider provider) { Logger.Instance.WriteMethodEntry(EventIdentifier.AsyncUpdateResourceOnActivityExecutionContextLoad); try { Logger.SetContextItem(this, this.WorkflowInstanceId); base.OnActivityExecutionContextLoad(provider); // Load the data access service via reflection Assembly assembly = Assembly.GetAssembly(typeof(UpdateResourceActivity)); const string TypeName = "Microsoft.ResourceManagement.Workflow.Runtime.DataAccessService"; this.dataAccessServiceType = assembly.GetType(TypeName); if (this.dataAccessServiceType == null) { throw Logger.Instance.ReportError(new WorkflowActivityLibraryException(Messages.DefinitionsConverter_NullOrEmptyDefinitionsTableError, TypeName)); } this.dataAccessService = provider.GetService(this.dataAccessServiceType); this.queuingService = (WorkflowQueuingService)provider.GetService(typeof(WorkflowQueuingService)); } finally { Logger.Instance.WriteMethodExit(EventIdentifier.AsyncUpdateResourceOnActivityExecutionContextLoad); } }
private void DeleteQueue(ActivityExecutionContext context) { Console.WriteLine("DeleteQueue"); WorkflowQueuingService qService = context.GetService <WorkflowQueuingService>(); qService.DeleteWorkflowQueue(this.QueueName); }
private bool ProcessQueueItem(ActivityExecutionContext context) { WorkflowQueuingService qService = context.GetService <WorkflowQueuingService>(); if (!qService.Exists(this.QueueName)) { return(false); } WorkflowQueue queue = qService.GetWorkflowQueue(this.QueueName); // If the queue has messages, then process the first one if (queue.Count == 0) { return(false); } FileWatcherEventArgs e = (FileWatcherEventArgs)queue.Dequeue(); // Raise the FileSystemEvent base.RaiseGenericEvent <FileWatcherEventArgs>(FileSystemEvent.FileWatcherEventHandlerEvent, this, e); DoUnsubscribe(context, this); DeleteQueue(context); return(true); }
protected override void OnActivityExecutionContextLoad(IServiceProvider provider) { Logger.Instance.WriteMethodEntry(EventIdentifier.AsyncCreateResourceOnActivityExecutionContextLoad); try { // Ideally we would set CallContext in OnActivityExecutionContextLoad instead here in Execute // as OnActivityExecutionContextLoad gets called on each hydration and rehydration of the workflow instance // but looks like it's invoked on a different thread context than the rest of the workflow instance execution. // To minimize the loss of the CallContext on rehydration, we'll set it in the Execute of every WAL child activities. // It will still get lost (momentarily) when the workflow is persisted in the middle of the execution of a replicator activity, for example. Logger.SetContextItem(this, this.WorkflowInstanceId); base.OnActivityExecutionContextLoad(provider); // Load the data access service via reflection Assembly assembly = Assembly.GetAssembly(typeof(UpdateResourceActivity)); const string TypeName = "Microsoft.ResourceManagement.Workflow.Runtime.DataAccessService"; this.dataAccessServiceType = assembly.GetType(TypeName); if (this.dataAccessServiceType == null) { throw Logger.Instance.ReportError(new WorkflowActivityLibraryException(Messages.DataAccessService_TypeLoadingFailedError, TypeName)); } this.dataAccessService = provider.GetService(this.dataAccessServiceType); this.queuingService = (WorkflowQueuingService)provider.GetService(typeof(WorkflowQueuingService)); } finally { Logger.Instance.WriteMethodExit(EventIdentifier.AsyncCreateResourceOnActivityExecutionContextLoad); } }
protected override ActivityExecutionStatus Execute(ActivityExecutionContext executionContext) { if (executionContext == null) { throw new ArgumentNullException("executionContext"); } if (this.Fault == null) { throw new InvalidOperationException(SR.GetString(CultureInfo.CurrentCulture, "Error_PropertyNotSet", new object[] { FaultProperty.Name })); } WorkflowQueuingService service = executionContext.GetService <WorkflowQueuingService>(); base.RaiseEvent(SendingFaultEvent, this, EventArgs.Empty); WebServiceInputActivity activityByName = base.GetActivityByName(this.InputActivityName) as WebServiceInputActivity; IComparable queueName = new EventQueueName(activityByName.InterfaceType, activityByName.MethodName, activityByName.QualifiedName); IMethodResponseMessage message = null; WorkflowQueue workflowQueue = service.GetWorkflowQueue(queueName); if (workflowQueue.Count != 0) { message = workflowQueue.Dequeue() as IMethodResponseMessage; } message.SendException(this.Fault); return(ActivityExecutionStatus.Closed); }
protected override void Initialize(IServiceProvider provider) { if (provider == null) { throw new ArgumentNullException("provider"); } if (this.Parent != null) { throw new InvalidOperationException("This is a root Activity"); } _queueName = new EventQueueName(this.Type, this.MethodName); WorkflowQueuingService queueService = (WorkflowQueuingService)provider.GetService(typeof(WorkflowQueuingService)); if (queueService != null) { WorkflowQueue queue = null; if (queueService.Exists(_queueName)) { queue = queueService.GetWorkflowQueue(_queueName); queue.Enabled = true; } else { queue = queueService.CreateWorkflowQueue(_queueName, true); } } base.Initialize(provider); }
protected override ActivityExecutionStatus Execute(ActivityExecutionContext aec) { //get the services needed //custom service to run the workflow CallWorkflowService ws = aec.GetService <CallWorkflowService>(); //Queuing service to setup the queue so the service can "callback" WorkflowQueuingService qs = aec.GetService <WorkflowQueuingService>(); //create the queue the service can call back on when the child workflow is done //you might want the queuename to be something different string qn = String.Format("{0}:{1}:{2}", this.WorkflowInstanceId.ToString(), Type.Name, this.Name); WorkflowQueue q = qs.CreateWorkflowQueue(qn, false); q.QueueItemAvailable += new EventHandler <QueueEventArgs>(q_QueueItemAvailable); //copy the params to a new collection Dictionary <string, object> inparams = new Dictionary <string, object>(); foreach (WorkflowParameterBinding bp in this.Parameters) { PropertyInfo pi = Type.GetProperty(bp.ParameterName); if (pi.CanWrite) { inparams.Add(bp.ParameterName, bp.Value); } } //ask the service to start the workflow ws.StartWorkflow(Type, inparams, this.WorkflowInstanceId, qn); return(ActivityExecutionStatus.Executing); }
void q_QueueItemAvailable(object sender, QueueEventArgs e) { ActivityExecutionContext aec = sender as ActivityExecutionContext; if (aec != null) { WorkflowQueuingService qs = aec.GetService <WorkflowQueuingService>(); WorkflowQueue q = qs.GetWorkflowQueue(e.QueueName); //get the outparameters from the workflow object o = q.Dequeue(); //delete the queue qs.DeleteWorkflowQueue(e.QueueName); Dictionary <string, object> outparams = o as Dictionary <string, object>; if (outparams != null) { foreach (KeyValuePair <string, object> item in outparams) { if (this.Parameters.Contains(item.Key)) { //modify the value this.Parameters[item.Key].SetValue(WorkflowParameterBinding.ValueProperty, item.Value); } } } aec.CloseActivity(); } }
internal void DeleteQueue(ActivityExecutionContext context) { if (StateMachineHelpers.IsRootExecutionContext(context)) { WorkflowQueuingService service = context.GetService <WorkflowQueuingService>(); service.GetWorkflowQueue("SetStateQueue"); service.DeleteWorkflowQueue("SetStateQueue"); } }
protected override void Initialize(IServiceProvider provider) { ThreadMonitor.WriteToConsole(Thread.CurrentThread, "WaitForMessageActivity", "WaitForMessageActivity: Processed Initialization"); WorkflowQueuingService queuingService = (WorkflowQueuingService)provider.GetService(typeof(WorkflowQueuingService)); this.workflowQueue = queuingService.CreateWorkflowQueue("WaitForMessageActivityQueue", false); this.workflowQueue.QueueItemAvailable += this.HandleExternalEvent; }
protected override void OnClosed(IServiceProvider provider) { base.OnClosed(provider); WorkflowQueuingService queueService = (WorkflowQueuingService)provider.GetService(typeof(WorkflowQueuingService)); if (_queueName != null && queueService != null) { queueService.DeleteWorkflowQueue(_queueName); } }
void IEventActivity.Unsubscribe(ActivityExecutionContext parentContext, IActivityEventListener <QueueEventArgs> parentEventHandler) { WorkflowQueuingService queueService = parentContext.GetService <WorkflowQueuingService>(); if (_queueName != null && queueService != null && parentEventHandler != null) { WorkflowQueue queue = queueService.GetWorkflowQueue(_queueName); queue.UnregisterForQueueItemAvailable(parentEventHandler); } }
internal void CreateQueue(ActivityExecutionContext context) { if (StateMachineHelpers.IsRootExecutionContext(context)) { WorkflowQueuingService service = context.GetService <WorkflowQueuingService>(); MessageEventSubscription subscription = new MessageEventSubscription("SetStateQueue", this._instanceId); service.CreateWorkflowQueue("SetStateQueue", true); base.SubscriptionId = subscription.SubscriptionId; } }
internal static WorkflowQueue GetWorkflowQueue(ActivityExecutionContext context, IComparable queueName) { WorkflowQueuingService service = context.GetService <WorkflowQueuingService>(); if (service.Exists(queueName)) { return(service.GetWorkflowQueue(queueName)); } return(null); }
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); }
/// <summary> /// Gets the queue. /// </summary> /// <param name="ctx">The CTX.</param> /// <returns></returns> protected WorkflowQueue GetQueue(ActivityExecutionContext ctx) { WorkflowQueuingService svc = ctx.GetService <WorkflowQueuingService>(); if (!svc.Exists(this.Name)) { return(svc.CreateWorkflowQueue(this.Name, false)); } return(svc.GetWorkflowQueue(this.Name)); }
private WorkflowQueue CreateQueue(ActivityExecutionContext context) { Console.WriteLine("CreateQueue"); WorkflowQueuingService qService = context.GetService <WorkflowQueuingService>(); if (!qService.Exists(this.QueueName)) { qService.CreateWorkflowQueue(this.QueueName, true); } return(qService.GetWorkflowQueue(this.QueueName)); }
private void PrivateInitialize(System.Workflow.ComponentModel.Activity rootActivity, Guid instanceId, IList <PropertyInfo> outputProperties, System.Workflow.ComponentModel.Activity workflowDefinition) { this.instanceId = instanceId; this.rootActivity = rootActivity; this.contextActivityMap = new Dictionary <int, System.Workflow.ComponentModel.Activity>(); this.scheduler = new Scheduler(this); this.workflowQueuingService = new WorkflowQueuingService(this); this.outputProperties = outputProperties; this.resourceManager = new VolatileResourceManager(); this.rootActivity.SetValue(System.Workflow.ComponentModel.Activity.WorkflowDefinitionProperty, workflowDefinition); this.rootActivity.SetValue(WorkflowExecutor.WorkflowExecutorProperty, this); }
protected override void Uninitialize(IServiceProvider provider) { WorkflowQueuingService qService = provider.GetService(typeof(WorkflowQueuingService)) as WorkflowQueuingService; IComparable qName = this.Queue; if (qService.Exists(qName) && qService.GetWorkflowQueue(qName).Count == 0) { qService.DeleteWorkflowQueue(qName); } base.Uninitialize(provider); }
protected override void Initialize(IServiceProvider provider) { WorkflowQueuingService qService = provider.GetService(typeof(WorkflowQueuingService)) as WorkflowQueuingService; IComparable qName = this.Queue; if (!qService.Exists(qName)) { bool transactional = true; qService.CreateWorkflowQueue(qName, transactional); } }
// Dequeue the item and then process the item private bool TryDequeueAndComplete(ActivityExecutionContext context, IComparable queueName) { WorkflowQueuingService qService = context.GetService <WorkflowQueuingService>() as WorkflowQueuingService; IComparable qName = this.Queue; if (qService.GetWorkflowQueue(qName).Count > 0) { this.Data = qService.GetWorkflowQueue(qName).Dequeue(); return(true); } return(false); }
// Handler when a queue item is available private void OnQueueItemAvailable(object sender, QueueEventArgs args) { ActivityExecutionContext context = sender as ActivityExecutionContext; WorkflowQueuingService qService = context.GetService <WorkflowQueuingService>() as WorkflowQueuingService; IComparable qName = this.Queue; // Dequeue the item and remove the handler if (TryDequeueAndComplete(context, qName)) { qService.GetWorkflowQueue(qName).QueueItemAvailable -= this.OnQueueItemAvailable; } }
private void ProcessParameters(ActivityExecutionContext context, IMethodMessage message, Type interfaceType, string operation) { WorkflowParameterBindingCollection parameters = ParameterBindings; if (parameters == null) { return; } //cache mInfo todo MethodInfo mInfo = interfaceType.GetMethod(operation); if (mInfo == null) { return; } int index = 0; bool responseRequired = false; foreach (ParameterInfo formalParameter in mInfo.GetParameters()) { // populate in params, checking on IsIn alone is not sufficient if (!(formalParameter.ParameterType.IsByRef || (formalParameter.IsIn && formalParameter.IsOut))) { if (parameters.Contains(formalParameter.Name)) { WorkflowParameterBinding binding = parameters[formalParameter.Name]; binding.Value = message.Args[index++]; } } else { responseRequired = true; } } if (mInfo.ReturnType != typeof(void) || responseRequired) { // create queue entry {interface, operation and receive activity Id} IComparable queueId = new EventQueueName(interfaceType, operation, QualifiedName); // enqueue the message for sendresponse reply context WorkflowQueuingService queuingService = (WorkflowQueuingService)context.GetService(typeof(WorkflowQueuingService)); if (!queuingService.Exists(queueId)) { queuingService.CreateWorkflowQueue(queueId, true); } queuingService.GetWorkflowQueue(queueId).Enqueue(message); } }
private void DoUnsubscribe(ActivityExecutionContext context, IActivityEventListener <QueueEventArgs> listener) { if (!this.subscriptionId.Equals(Guid.Empty)) { FileWatcherService fileService = context.GetService <FileWatcherService>(); fileService.UnregisterListener(this.subscriptionId); this.subscriptionId = Guid.Empty; } WorkflowQueuingService qService = context.GetService <WorkflowQueuingService>(); WorkflowQueue queue = qService.GetWorkflowQueue(this.QueueName); queue.UnregisterForQueueItemAvailable(listener); }