Example #1
0
 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;
 }
Example #2
0
        protected override ActivityExecutionStatus Execute(ActivityExecutionContext executionContext)
        {
            if (executionContext == null)
                throw new ArgumentNullException("executionContext");
           
            Type type = typeof(IInvokerLocalService);

            object obj = executionContext.GetService(type);
            if (obj == null)
                throw new InvalidOperationException("IInvokerLocalService not found");

            // pre-processing
            base.RaiseEvent(ReturnActivity.InvokingEvent, this, EventArgs.Empty);
            this.OnInvoking(EventArgs.Empty);

            // return object
            object returnValue = null;
            if (this.ConnectorActivityName != "(None)")
            {
                returnValue = this.Parameters.Contains("(ReturnValue)") ? this.Parameters["(ReturnValue)"].GetValue(WorkflowParameterBinding.ValueProperty) : null;
            }

            // fire and forget in sync manner
            object[] args = new object[2] { this.WorkflowInstanceId, returnValue };
            type.InvokeMember("RaiseResponseEvent", BindingFlags.InvokeMethod, null, obj, args);

            return ActivityExecutionStatus.Closed;
        }
Example #3
0
        protected override ActivityExecutionStatus Execute(ActivityExecutionContext context)
        {
            if (context == null)
            {
                throw new ArgumentNullException("context");
            }

            ExternalRuleSetService.ExternalRuleSetService ruleSetService = context.GetService<ExternalRuleSetService.ExternalRuleSetService>();

            if (ruleSetService != null)
            {
                RuleSet ruleSet = ruleSetService.GetRuleSet(new RuleSetInfo(this.RuleSetName, this.MajorVersion, this.MinorVersion));
                if (ruleSet != null)
                {
                    Activity targetActivity = this.GetRootWorkflow(this.Parent);
                    RuleValidation validation = new RuleValidation(targetActivity.GetType(), null);
                    RuleExecution execution = new RuleExecution(validation, targetActivity, context);
                    ruleSet.Execute(execution);
                }
            }
            else
            {
                throw new InvalidOperationException("A RuleSetService must be configured on the host to use the PolicyFromService activity.");
            }

            return ActivityExecutionStatus.Closed;
        }
 internal void DeleteQueue(ActivityExecutionContext context)
 {
     if (StateMachineHelpers.IsRootExecutionContext(context))
     {
         WorkflowQueuingService service = context.GetService<WorkflowQueuingService>();
         service.GetWorkflowQueue("SetStateQueue");
         service.DeleteWorkflowQueue("SetStateQueue");
     }
 }
 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;
     }
 }
 private void DeleteSubscription(ActivityExecutionContext context)
 {
     if (this.queueName != null)
     {
         WorkflowQueuingService service = context.GetService <WorkflowQueuingService>();
         if (this.queueCreator)
         {
             service.DeleteWorkflowQueue(this.queueName);
         }
         if (this.eventHandler == null)
         {
             WorkflowSubscriptionService service2 = context.GetService <WorkflowSubscriptionService>();
             if (service2 != null)
             {
                 service2.DeleteSubscription(this.subscriptionId);
             }
             WorkflowActivityTrace.Activity.TraceEvent(TraceEventType.Information, 0, "CorrelationTokenInvalidatedHandler subscription deleted SubId {0} QueueId {1}", new object[] { this.subscriptionId, this.queueName });
         }
     }
 }
Example #7
0
        internal static WorkflowQueue GetWorkflowQueue(ActivityExecutionContext context, IComparable queueName)
        {
            WorkflowQueuingService workflowQueuingService = context.GetService <WorkflowQueuingService>();

            if (workflowQueuingService.Exists(queueName))
            {
                WorkflowQueue workflowQueue = workflowQueuingService.GetWorkflowQueue(queueName);
                return(workflowQueue);
            }
            return(null);
        }
        private void CreateSubscription(Guid instanceId, ActivityExecutionContext context, ICollection <CorrelationProperty> correlationValues)
        {
            WorkflowQueuingService service       = context.GetService <WorkflowQueuingService>();
            EventQueueName         queueName     = new EventQueueName(this.interfaceType, this.followerOperation, correlationValues);
            WorkflowQueue          workflowQueue = null;

            if (!service.Exists(queueName))
            {
                WorkflowActivityTrace.Activity.TraceEvent(TraceEventType.Information, 0, "CorrelationTokenInvalidatedHandler: creating q {0} ", new object[] { queueName.GetHashCode() });
                workflowQueue     = service.CreateWorkflowQueue(queueName, true);
                this.queueCreator = true;
            }
            else
            {
                workflowQueue = service.GetWorkflowQueue(queueName);
            }
            if (this.eventHandler != null)
            {
                workflowQueue.RegisterForQueueItemAvailable(this.eventHandler);
            }
            WorkflowSubscriptionService service2     = (WorkflowSubscriptionService)context.GetService(typeof(WorkflowSubscriptionService));
            MessageEventSubscription    subscription = new MessageEventSubscription(queueName, instanceId);

            this.queueName             = queueName;
            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) && (service2 != null))
            {
                service2.CreateSubscription(subscription);
            }
        }
Example #9
0
        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));
        }
Example #10
0
        protected override ActivityExecutionStatus Execute(ActivityExecutionContext context)
        {
            if (context == null)
            {
                throw new ArgumentNullException("context");
            }
            this.RaiseEvent(PolicyFromService.BeforePolicyAppliedEvent, this, new EventArgs());
            ExternalRuleSetService ruleSetService = context.GetService <ExternalRuleSetService>();

            if (ruleSetService != null)
            {
                RuleSet ruleSet = Cache.Instance.Bag[this.RuleSetName + this.MajorVersion + this.MinorVersion] as RuleSet;
                if (ruleSet == null)
                {
                    ruleSet = ruleSetService.GetRuleSet(new RuleSetInfo(this.RuleSetName, this.MajorVersion, this.MinorVersion));
                    Cache.Instance.Bag.Add(this.RuleSetName + this.MajorVersion + this.MinorVersion, ruleSet);
                }

                if (ruleSet != null)
                {
                    Activity       targetActivity = this.GetRootWorkflow(this.Parent);
                    RuleValidation validation     = new RuleValidation(targetActivity.GetType(), null);
                    RuleExecution  execution      = new RuleExecution(validation, targetActivity, context);

                    try
                    {
                        Dictionary <string, object> param = new Dictionary <string, object>();
                        param.Add("rulesetname", string.Format("{0}.{1}.{2}", ruleSet.Name, this.MajorVersion, this.MinorVersion));
                        ruleSet.Execute(execution);
                    }
                    catch (Exception ex)
                    {
                        Trace.TraceError(ex.Message + Environment.NewLine + ex.StackTrace + Environment.NewLine + ex.InnerException);
                        if (!Information.IsSilientBusinessRuleError)
                        {
                            throw new Exception(ex.Message, ex.InnerException);
                        }
                        string mapId = Guid.NewGuid().ToString();
                        this.ErrorMessage = string.Format("A critical error occurred while executing rule {0}. MapId:{1}", ruleSet.Name, mapId);
                        PrintRuleSetTraceInformation(mapId, ruleSet, validation);
                    }

                    base.RaiseEvent(PolicyFromService.AfterPolicyAppliedEvent, this, EventArgs.Empty);
                }
            }
            else
            {
                throw new InvalidOperationException("A RuleSetService must be configured on the host to use the PolicyFromService activity.");
            }

            return(ActivityExecutionStatus.Closed);
        }
 internal override void ProcessEvent(ActivityExecutionContext context)
 {
     SetStateEventArgs args = context.GetService<WorkflowQueuingService>().GetWorkflowQueue("SetStateQueue").Dequeue() as SetStateEventArgs;
     StateActivity currentState = StateMachineHelpers.GetCurrentState(context);
     if (currentState == null)
     {
         throw new InvalidOperationException(SR.GetStateMachineWorkflowMustHaveACurrentState());
     }
     StateMachineExecutionState state = StateMachineExecutionState.Get(StateMachineHelpers.GetRootState((StateActivity) context.Activity));
     SetStateAction action = new SetStateAction(currentState.QualifiedName, args.TargetStateName);
     state.EnqueueAction(action);
     state.ProcessActions(context);
 }
Example #12
0
        // 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;
            }
        }
        protected override ActivityExecutionStatus HandleFault(ActivityExecutionContext executionContext, Exception exception)
        {
            SPSecurity.RunWithElevatedPrivileges(delegate()
            {
                string errorMessage = string.Format("Error querying XML. {0}", exception.Message);

                ISharePointService spService = (ISharePointService)executionContext.GetService(typeof(ISharePointService));
                spService.LogToHistoryList(this.WorkflowInstanceId, SPWorkflowHistoryEventType.WorkflowError, -1, TimeSpan.MinValue, "Error",
                                           errorMessage, String.Empty);
            });

            return(base.HandleFault(executionContext, exception));
        }
Example #14
0
        protected override sealed ActivityExecutionStatus Execute(ActivityExecutionContext context)
        {
            // Fire the Before Invoke Handler
            base.RaiseEvent(OnBeforeInvokeEvent, this, EventArgs.Empty);

            // Get reference to the transactional service from the context
            AbstractTransactionService service = context.GetService<AbstractTransactionService>();
            // Call a method on the service and pass the payload to it
            service.DebitAmount(this.Amount);

            // Return the status of the activity as closed
            return ActivityExecutionStatus.Closed;
        }
Example #15
0
        // 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);
        }
Example #16
0
    private void Compensate(ActivityExecutionContext activityExecutionContext)
    {
        var compensationService = activityExecutionContext.GetService <ICompensationService>();

        if (string.IsNullOrWhiteSpace(CompensableActivityId))
        {
            compensationService.Compensate(activityExecutionContext, Exception, Message);
        }
        else
        {
            compensationService.Compensate(activityExecutionContext, CompensableActivityId, Exception, Message);
        }
    }
Example #17
0
        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);
            }
        }
Example #18
0
        void IEventActivity.Unsubscribe(ActivityExecutionContext parentContext, IActivityEventListener <QueueEventArgs> parentEventHandler)
        {
            if (parentContext == null)
            {
                throw new ArgumentNullException("parentContext");
            }
            if (parentEventHandler == null)
            {
                throw new ArgumentNullException("parentEventHandler");
            }

            System.Diagnostics.Debug.Assert(this.SubscriptionID != Guid.Empty);
            WorkflowQueuingService qService = parentContext.GetService <WorkflowQueuingService>();
            WorkflowQueue          wfQueue  = null;

            try
            {
                wfQueue = qService.GetWorkflowQueue(this.SubscriptionID);
            }
            catch
            {
                // If the queue no longer exists, eat the exception, we clear the subscription id later.
            }

            if (wfQueue != null && wfQueue.Count != 0)
            {
                wfQueue.Dequeue();
            }

            // WinOE

            Activity root = parentContext.Activity;

            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.Remove(this.SubscriptionID);

            if (wfQueue != null)
            {
                wfQueue.UnregisterForQueueItemAvailable(parentEventHandler);
                qService.DeleteWorkflowQueue(this.SubscriptionID);
            }

            this.SubscriptionID = Guid.Empty;
        }
Example #19
0
        protected override sealed ActivityExecutionStatus Execute(ActivityExecutionContext context)
        {
            // Fire the Before Invoke Handler
            base.RaiseEvent(OnBeforeInvokeEvent, this, EventArgs.Empty);

            // Get reference to the transactional service from the context
            AbstractTransactionService service = context.GetService <AbstractTransactionService>();

            // Call a method on the service and pass the payload to it
            service.CreditAmount(this.Amount);

            // Return the status of the activity as closed
            return(ActivityExecutionStatus.Closed);
        }
        protected override ActivityExecutionStatus HandleFault(ActivityExecutionContext executionContext, Exception exception)
        {
            string errorMessage = string.Format("Error Executing PowerShell Script. {0}", exception.Message);

            ISharePointService spService = (ISharePointService)executionContext.GetService(typeof(ISharePointService));

            spService.LogToHistoryList(this.WorkflowInstanceId, SPWorkflowHistoryEventType.WorkflowError, -1, TimeSpan.MinValue, "Error",
                                       errorMessage, String.Empty);

            EventLog.WriteEntry("PowerActivity", errorMessage, EventLogEntryType.Error);
            errorMessage += Environment.NewLine + exception.StackTrace;

            return(base.HandleFault(executionContext, exception));
        }
Example #21
0
        protected sealed override ActivityExecutionStatus Execute(ActivityExecutionContext executionContext)
        {
            if (executionContext == null)
            {
                throw new ArgumentNullException("executionContext");
            }
            if (this.InterfaceType == null)
            {
                throw new ArgumentException(
                          SR.GetString(SR.Error_MissingInterfaceType), "executionContext");
            }

            Type   type       = this.InterfaceType;
            string methodName = this.MethodName;

            object serviceValue = executionContext.GetService(type);

            if (serviceValue == null)
            {
                throw new InvalidOperationException(SR.GetString(SR.Error_ServiceNotFound, this.InterfaceType));
            }

            this.RaiseEvent(MethodInvokingEvent, this, EventArgs.Empty);
            OnMethodInvoking(EventArgs.Empty);

            MethodInfo methodInfo = type.GetMethod(methodName, BindingFlags.Instance | BindingFlags.Public);

            ParameterModifier[] parameterModifiers = null;
            object[]            actualParameters   = InvokeHelper.GetParameters(methodInfo, this.ParameterBindings, out parameterModifiers);

            WorkflowParameterBinding resultBinding = null;

            if (this.ParameterBindings.Contains("(ReturnValue)"))
            {
                resultBinding = this.ParameterBindings["(ReturnValue)"];
            }

            CorrelationService.InvalidateCorrelationToken(this, type, methodName, actualParameters);

            object result = type.InvokeMember(this.MethodName, BindingFlags.InvokeMethod, new ExternalDataExchangeBinder(), serviceValue, actualParameters, parameterModifiers, null, null);

            if (resultBinding != null)
            {
                resultBinding.Value = InvokeHelper.CloneOutboundValue(result, new BinaryFormatter(), "(ReturnValue)");
            }

            InvokeHelper.SaveOutRefParameters(actualParameters, methodInfo, this.ParameterBindings);
            OnMethodInvoked(EventArgs.Empty);
            return(ActivityExecutionStatus.Closed);
        }
        protected override ActivityExecutionStatus Execute(ActivityExecutionContext executionContext)
        {
            {
               List<string> ls = executionContext.GetService(typeof(List<string>)) as List<string>;
               if (ls != null)
               {
                   ls.Add("--------------------------归档-----------------------------------");
                   ls.Add("流程编号:" + Root().流程编号.ToString());
                   ls.Add("");
               }
            }

            return base.Execute(executionContext);
        }
Example #23
0
        protected override ActivityExecutionStatus Execute(ActivityExecutionContext executionContext)
        {
            {
                List <string> ls = executionContext.GetService(typeof(List <string>)) as List <string>;
                if (ls != null)
                {
                    ls.Add("--------------------------归档-----------------------------------");
                    ls.Add("流程编号:" + Root().流程编号.ToString());
                    ls.Add("");
                }
            }

            return(base.Execute(executionContext));
        }
Example #24
0
        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
                Exception ex = o as Exception;
                if (ex != null)
                {
                    throw ex;
                }
                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();

                ///
                SubWorkflowService ws = aec.GetService <SubWorkflowService>();
                ws.OnFinishCallworkflowActivity(this.WorkflowInstanceId);
            }
        }
Example #25
0
        internal override void ProcessEvent(ActivityExecutionContext context)
        {
            SetStateEventArgs args         = context.GetService <WorkflowQueuingService>().GetWorkflowQueue("SetStateQueue").Dequeue() as SetStateEventArgs;
            StateActivity     currentState = StateMachineHelpers.GetCurrentState(context);

            if (currentState == null)
            {
                throw new InvalidOperationException(SR.GetStateMachineWorkflowMustHaveACurrentState());
            }
            StateMachineExecutionState state  = StateMachineExecutionState.Get(StateMachineHelpers.GetRootState((StateActivity)context.Activity));
            SetStateAction             action = new SetStateAction(currentState.QualifiedName, args.TargetStateName);

            state.EnqueueAction(action);
            state.ProcessActions(context);
        }
        internal void DeleteQueue(ActivityExecutionContext context)
        {
            if (!StateMachineHelpers.IsRootExecutionContext(context))
            {
                // we only subscribe to the set state event if
                // we're at the root level. If this instance is
                // being called, it is not possible to set the
                // state from the host side directly
                return;
            }

            WorkflowQueuingService workflowQueuingService = context.GetService <WorkflowQueuingService>();
            WorkflowQueue          workflowQueue          = workflowQueuingService.GetWorkflowQueue(StateMachineWorkflowActivity.SetStateQueueName);

            workflowQueuingService.DeleteWorkflowQueue(StateMachineWorkflowActivity.SetStateQueueName);
        }
Example #27
0
        void IActivityEventListener <QueueEventArgs> .OnEvent(object sender, QueueEventArgs e)
        {
            ActivityExecutionContext executionContext = sender as ActivityExecutionContext;
            WorkflowQueuingService   queueService     = executionContext.GetService <WorkflowQueuingService>();
            WorkflowQueue            queue            = queueService.GetWorkflowQueue(e.QueueName);

            if (queue.Count > 0)
            {
                object item = queue.Dequeue();
                ProcessQueueItem(executionContext, item);
                queue.UnregisterForQueueItemAvailable(this);

                // run all Activities
                base.Execute(executionContext);
            }
        }
Example #28
0
        protected sealed override ActivityExecutionStatus Cancel(ActivityExecutionContext executionContext)
        {
            if (executionContext == null)
            {
                throw new ArgumentNullException("executionContext");
            }

            WorkflowQueuingService queueService = executionContext.GetService <WorkflowQueuingService>();

            if (_queueName != null && queueService != null)
            {
                WorkflowQueue queue = queueService.GetWorkflowQueue(_queueName);
                queue.UnregisterForQueueItemAvailable(this);
            }
            return(ActivityExecutionStatus.Closed);
        }
Example #29
0
        private ActivityExecutionStatus ExecuteForActivity(ActivityExecutionContext context, Type interfaceType, string operation)
        {
            WorkflowQueuingService queueSvcs = (WorkflowQueuingService)context.GetService(typeof(WorkflowQueuingService));
            IComparable            queueId   = new EventQueueName(interfaceType, operation);

            if (queueId != null)
            {
                WorkflowQueue queue;
                object        msg = InboundActivityHelper.DequeueMessage(queueId, queueSvcs, this, out queue);
                if (msg != null)
                {
                    this.ProcessMessage(context, msg, interfaceType, operation);
                    return(ActivityExecutionStatus.Closed);
                }
            }
            return(ActivityExecutionStatus.Executing);
        }
Example #30
0
        protected override ActivityExecutionStatus Execute(ActivityExecutionContext executionContext)
        {
            this.RaiseEvent(InvokeWorkflow.BeforeInvokedEvent, this, new EventArgs());

            if (this.TargetWorkflow == null)
            {
                throw new InvalidOperationException("TargetWorkflow property must be set to a valid Type that derives from Activity.");
            }

            IStartWorkflow startWorkflow = executionContext.GetService(typeof(IStartWorkflow)) as IStartWorkflow;

            this.InstanceId = startWorkflow.StartWorkflow(this.TargetWorkflow, this.Parameters);

            //base.SetValue(InstanceIdProperty, instanceId);
            this.RaiseEvent(InvokeWorkflow.AfterInvokedEvent, this, new EventArgs());

            return(ActivityExecutionStatus.Closed);
        }
Example #31
0
        protected override ActivityExecutionStatus Execute(
            ActivityExecutionContext executionContext)
        {
            IAccountServices accountServices =
                executionContext.GetService <IAccountServices>();

            if (accountServices == null)
            {
                //we have a big problem
                throw new InvalidOperationException(
                          "Unable to retrieve IAccountServices from runtime");
            }

            //apply the adjustment to the account
            Account = accountServices.AdjustBalance(Id, Adjustment);

            return(base.Execute(executionContext));
        }
 internal static ActivityExecutionStatus ExecuteForActivity(HandleExternalEventActivity activity, ActivityExecutionContext context, Type interfaceType, string operation, out object[] args)
 {
     WorkflowQueuingService queueSvcs = (WorkflowQueuingService) context.GetService(typeof(WorkflowQueuingService));
     args = null;
     IComparable queueId = CorrelationService.ResolveQueueName(activity, interfaceType, operation);
     if (queueId != null)
     {
         WorkflowQueue queue;
         object msg = DequeueMessage(queueId, queueSvcs, activity, out queue);
         CorrelationService.UninitializeFollowers(interfaceType, operation, queue);
         if (msg != null)
         {
             args = ProcessEvent(activity, context, msg, interfaceType, operation);
             return ActivityExecutionStatus.Closed;
         }
     }
     return ActivityExecutionStatus.Executing;
 }
        internal static ActivityExecutionStatus ExecuteForActivity(HandleExternalEventActivity activity, ActivityExecutionContext context, Type interfaceType, string operation, out object[] args)
        {
            WorkflowQueuingService queueSvcs = (WorkflowQueuingService)context.GetService(typeof(WorkflowQueuingService));

            args = null;
            IComparable queueId = CorrelationService.ResolveQueueName(activity, interfaceType, operation);

            if (queueId != null)
            {
                WorkflowQueue queue;
                object        msg = DequeueMessage(queueId, queueSvcs, activity, out queue);
                CorrelationService.UninitializeFollowers(interfaceType, operation, queue);
                if (msg != null)
                {
                    args = ProcessEvent(activity, context, msg, interfaceType, operation);
                    return(ActivityExecutionStatus.Closed);
                }
            }
            return(ActivityExecutionStatus.Executing);
        }
        internal override void ProcessEvent(ActivityExecutionContext context)
        {
            WorkflowQueuingService workflowQueuingService = context.GetService <WorkflowQueuingService>();
            WorkflowQueue          workflowQueue          = workflowQueuingService.GetWorkflowQueue(StateMachineWorkflowActivity.SetStateQueueName);
            SetStateEventArgs      eventArgs    = workflowQueue.Dequeue() as SetStateEventArgs;
            StateActivity          currentState = StateMachineHelpers.GetCurrentState(context);

            if (currentState == null)
            {
                throw new InvalidOperationException(SR.GetStateMachineWorkflowMustHaveACurrentState());
            }

            StateActivity rootState = StateMachineHelpers.GetRootState((StateActivity)context.Activity);
            StateMachineExecutionState executionState = StateMachineExecutionState.Get(rootState);
            SetStateAction             action         = new SetStateAction(currentState.QualifiedName, eventArgs.TargetStateName);

            Debug.Assert(!executionState.HasEnqueuedActions);
            executionState.EnqueueAction(action);
            executionState.ProcessActions(context);
        }
Example #35
0
        protected sealed override ActivityExecutionStatus Execute(ActivityExecutionContext executionContext)
        {
            ActivityExecutionStatus         status;
            ActivityExecutionContextManager manager = executionContext.ExecutionContextManager;
            ReadOnlyCollection <ActivityExecutionContext> contexts = manager.ExecutionContexts;

            Console.WriteLine("***ourCodeActivity.Execute {0}", contexts.Count);

            IComparable queue_name = "our_queue";

            WorkflowQueuingService qService = executionContext.GetService <WorkflowQueuingService> ();

            if (!qService.Exists(queue_name))
            {
                Console.WriteLine("CreatingQue");
                qService.CreateWorkflowQueue(queue_name, true);
            }

            status = base.Execute(executionContext);
            return(status);
        }
Example #36
0
        private void ProcessParameters(ActivityExecutionContext context, IMethodMessage message, Type interfaceType, string operation)
        {
            WorkflowParameterBindingCollection parameterBindings = this.ParameterBindings;

            if (parameterBindings != null)
            {
                MethodInfo method = interfaceType.GetMethod(operation);
                if (method != null)
                {
                    int  num  = 0;
                    bool flag = false;
                    foreach (ParameterInfo info2 in method.GetParameters())
                    {
                        if (!info2.ParameterType.IsByRef && (!info2.IsIn || !info2.IsOut))
                        {
                            if (parameterBindings.Contains(info2.Name))
                            {
                                WorkflowParameterBinding binding = parameterBindings[info2.Name];
                                binding.Value = message.Args[num++];
                            }
                        }
                        else
                        {
                            flag = true;
                        }
                    }
                    if ((method.ReturnType != typeof(void)) || flag)
                    {
                        IComparable            queueName = new EventQueueName(interfaceType, operation, base.QualifiedName);
                        WorkflowQueuingService service   = (WorkflowQueuingService)context.GetService(typeof(WorkflowQueuingService));
                        if (!service.Exists(queueName))
                        {
                            service.CreateWorkflowQueue(queueName, true);
                        }
                        service.GetWorkflowQueue(queueName).Enqueue(message);
                    }
                }
            }
        }
Example #37
0
        protected override ActivityExecutionStatus Execute(ActivityExecutionContext context)
        {
            //WorkflowQueuingService is a component that allows access to queue items
            //enqueued to a particular workflow instance
            // Items are submitted to a workflow instance from the host using the
            // EnqueueItem method call on the workflowinstance
            WorkflowQueuingService qService = context.GetService <WorkflowQueuingService>() as WorkflowQueuingService;

            // The Queue name is in the activity context and specified in the Enqueue item call
            IComparable qName = this.Queue;


            //Try to dequeue if there are any items available
            // Register the handler OnQueueItemAvailable when a item is queued
            if (!TryDequeueAndComplete(context, qName))
            {
                qService.GetWorkflowQueue(qName).QueueItemAvailable += this.OnQueueItemAvailable;
                return(ActivityExecutionStatus.Executing);
            }

            return(ActivityExecutionStatus.Closed);
        }
Example #38
0
        void IEventActivity.Unsubscribe(ActivityExecutionContext parentContext, IActivityEventListener <QueueEventArgs> parentEventHandler)
        {
            if (parentContext == null)
            {
                throw new ArgumentNullException("parentContext");
            }
            if (parentEventHandler == null)
            {
                throw new ArgumentNullException("parentEventHandler");
            }
            WorkflowQueuingService service       = parentContext.GetService <WorkflowQueuingService>();
            WorkflowQueue          workflowQueue = null;

            try
            {
                workflowQueue = service.GetWorkflowQueue(this.SubscriptionID);
            }
            catch
            {
            }
            if ((workflowQueue != null) && (workflowQueue.Count != 0))
            {
                workflowQueue.Dequeue();
            }
            Activity parent = parentContext.Activity;

            while (parent.Parent != null)
            {
                parent = parent.Parent;
            }
            ((TimerEventSubscriptionCollection)parent.GetValue(TimerEventSubscriptionCollection.TimerCollectionProperty)).Remove(this.SubscriptionID);
            if (workflowQueue != null)
            {
                workflowQueue.UnregisterForQueueItemAvailable(parentEventHandler);
                service.DeleteWorkflowQueue(this.SubscriptionID);
            }
            this.SubscriptionID = Guid.Empty;
        }
Example #39
0
        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 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 sealed override ActivityExecutionStatus Execute(ActivityExecutionContext executionContext)
 {
     if (executionContext == null)
     {
         throw new ArgumentNullException("executionContext");
     }
     if (this.InterfaceType == null)
     {
         throw new ArgumentException(SR.GetString("Error_MissingInterfaceType"), "executionContext");
     }
     Type interfaceType = this.InterfaceType;
     string methodName = this.MethodName;
     object service = executionContext.GetService(interfaceType);
     if (service == null)
     {
         throw new InvalidOperationException(SR.GetString("Error_ServiceNotFound", new object[] { this.InterfaceType }));
     }
     base.RaiseEvent(MethodInvokingEvent, this, EventArgs.Empty);
     this.OnMethodInvoking(EventArgs.Empty);
     MethodInfo method = interfaceType.GetMethod(methodName, BindingFlags.Public | BindingFlags.Instance);
     ParameterModifier[] parameterModifiers = null;
     object[] messageArgs = InvokeHelper.GetParameters(method, this.ParameterBindings, out parameterModifiers);
     WorkflowParameterBinding binding = null;
     if (this.ParameterBindings.Contains("(ReturnValue)"))
     {
         binding = this.ParameterBindings["(ReturnValue)"];
     }
     CorrelationService.InvalidateCorrelationToken(this, interfaceType, methodName, messageArgs);
     object source = interfaceType.InvokeMember(this.MethodName, BindingFlags.InvokeMethod, new ExternalDataExchangeBinder(), service, messageArgs, parameterModifiers, null, null);
     if (binding != null)
     {
         binding.Value = InvokeHelper.CloneOutboundValue(source, new BinaryFormatter(), "(ReturnValue)");
     }
     InvokeHelper.SaveOutRefParameters(messageArgs, method, this.ParameterBindings);
     this.OnMethodInvoked(EventArgs.Empty);
     return ActivityExecutionStatus.Closed;
 }
        protected override ActivityExecutionStatus Execute(ActivityExecutionContext executionContext)
        {
            if (executionContext == null)
                throw new ArgumentNullException("executionContext");

            WorkflowQueuingService queueService = executionContext.GetService<WorkflowQueuingService>();

            // fire event
            this.RaiseEvent(WebServiceOutputActivity.SendingOutputEvent, this, EventArgs.Empty);

            WebServiceInputActivity webservicereceive = this.GetActivityByName(this.InputActivityName) as WebServiceInputActivity;
            if (webservicereceive == null)
            {
                Activity parent = this.Parent;
                while (parent != null)
                {
                    //typically if defined inside a custom activity
                    string qualifiedName = parent.QualifiedName + "." + this.InputActivityName;
                    webservicereceive = this.GetActivityByName(qualifiedName) as WebServiceInputActivity;
                    if (webservicereceive != null)
                        break;
                    parent = this.Parent;
                }
            }
            if (webservicereceive == null)
                throw new InvalidOperationException(SR.GetString(SR.Error_CannotResolveWebServiceInput, this.QualifiedName, this.InputActivityName));

            IComparable queueId = new EventQueueName(webservicereceive.InterfaceType, webservicereceive.MethodName, webservicereceive.QualifiedName);

            MethodInfo mInfo = webservicereceive.InterfaceType.GetMethod(webservicereceive.MethodName);
            if (!queueService.Exists(queueId))
            {
                // determine if no response is required,
                // compiler did not catch it, do the runtime check and return
                if (mInfo.ReturnType == typeof(void))
                {
                    return ActivityExecutionStatus.Closed;
                }

                bool isresponseRequired = false;
                foreach (ParameterInfo formalParameter in mInfo.GetParameters())
                {
                    if (formalParameter.ParameterType.IsByRef || (formalParameter.IsIn && formalParameter.IsOut))
                    {
                        isresponseRequired = true;
                    }
                }

                if (isresponseRequired)
                {
                    return ActivityExecutionStatus.Closed;
                }
            }

            if (!queueService.Exists(queueId))
                throw new InvalidOperationException(SR.GetString(SR.Error_WebServiceInputNotProcessed, webservicereceive.QualifiedName));

            IMethodResponseMessage responseMessage = null;
            WorkflowQueue queue = queueService.GetWorkflowQueue(queueId);

            if (queue.Count != 0)
                responseMessage = queue.Dequeue() as IMethodResponseMessage;

            IMethodMessage message = responseMessage as IMethodMessage;

            WorkflowParameterBindingCollection parameterBindings = this.ParameterBindings;
            ArrayList outArgs = new ArrayList();
            // populate result
            if (this.ParameterBindings.Contains("(ReturnValue)"))
            {
                WorkflowParameterBinding retBind = this.ParameterBindings["(ReturnValue)"];
                if (retBind != null)
                {
                    outArgs.Add(retBind.Value);
                }
            }

            foreach (ParameterInfo formalParameter in mInfo.GetParameters())
            {
                // update out and byref values
                if (formalParameter.ParameterType.IsByRef || (formalParameter.IsIn && formalParameter.IsOut))
                {
                    WorkflowParameterBinding binding = parameterBindings[formalParameter.Name];
                    outArgs.Add(binding.Value);
                }
            }

            // reset the waiting thread
            responseMessage.SendResponse(outArgs);

            return ActivityExecutionStatus.Closed;
        }
 internal static WorkflowQueue GetWorkflowQueue(ActivityExecutionContext context, IComparable queueName)
 {
     WorkflowQueuingService workflowQueuingService = context.GetService<WorkflowQueuingService>();
     if (workflowQueuingService.Exists(queueName))
     {
         WorkflowQueue workflowQueue = workflowQueuingService.GetWorkflowQueue(queueName);
         return workflowQueue;
     }
     return null;
 }
        protected override ActivityExecutionStatus Execute(ActivityExecutionContext executionContext)
        {
            if (executionContext == null)
                throw new ArgumentNullException("executionContext");

            // raise event
            base.RaiseEvent(InvokeWorkflowActivity.InvokingEvent, this, EventArgs.Empty);

            // collect the [in] parameters
            Dictionary<string, object> namedArgumentValues = new Dictionary<string, object>();
            foreach (WorkflowParameterBinding paramBinding in this.ParameterBindings)
                namedArgumentValues.Add(paramBinding.ParameterName, paramBinding.Value);

            IStartWorkflow workflowInvoker = executionContext.GetService(typeof(IStartWorkflow)) as IStartWorkflow;
            if (workflowInvoker == null)
                throw new InvalidOperationException(SR.GetString(SR.General_MissingService, typeof(IStartWorkflow).FullName));

            Guid instanceId = workflowInvoker.StartWorkflow(this.TargetWorkflow, namedArgumentValues);
            if (instanceId == Guid.Empty)
                throw new InvalidOperationException(SR.GetString(SR.Error_FailedToStartTheWorkflow));

            this.SetInstanceId(instanceId);

            return ActivityExecutionStatus.Closed;
        }
 protected override ActivityExecutionStatus Execute(ActivityExecutionContext executionContext)
 {
     if (executionContext == null)
     {
         throw new ArgumentNullException("executionContext");
     }
     WorkflowQueuingService service = executionContext.GetService<WorkflowQueuingService>();
     base.RaiseEvent(SendingOutputEvent, this, EventArgs.Empty);
     WebServiceInputActivity activityByName = base.GetActivityByName(this.InputActivityName) as WebServiceInputActivity;
     if (activityByName == null)
     {
         for (Activity activity2 = base.Parent; activity2 != null; activity2 = base.Parent)
         {
             string activityQualifiedName = activity2.QualifiedName + "." + this.InputActivityName;
             activityByName = base.GetActivityByName(activityQualifiedName) as WebServiceInputActivity;
             if (activityByName != null)
             {
                 break;
             }
         }
     }
     if (activityByName == null)
     {
         throw new InvalidOperationException(SR.GetString("Error_CannotResolveWebServiceInput", new object[] { base.QualifiedName, this.InputActivityName }));
     }
     IComparable queueName = new EventQueueName(activityByName.InterfaceType, activityByName.MethodName, activityByName.QualifiedName);
     MethodInfo method = activityByName.InterfaceType.GetMethod(activityByName.MethodName);
     if (!service.Exists(queueName))
     {
         if (method.ReturnType == typeof(void))
         {
             return ActivityExecutionStatus.Closed;
         }
         bool flag = false;
         foreach (ParameterInfo info2 in method.GetParameters())
         {
             if (info2.ParameterType.IsByRef || (info2.IsIn && info2.IsOut))
             {
                 flag = true;
             }
         }
         if (flag)
         {
             return ActivityExecutionStatus.Closed;
         }
     }
     if (!service.Exists(queueName))
     {
         throw new InvalidOperationException(SR.GetString("Error_WebServiceInputNotProcessed", new object[] { activityByName.QualifiedName }));
     }
     IMethodResponseMessage message = null;
     WorkflowQueue workflowQueue = service.GetWorkflowQueue(queueName);
     if (workflowQueue.Count != 0)
     {
         message = workflowQueue.Dequeue() as IMethodResponseMessage;
     }
     WorkflowParameterBindingCollection parameterBindings = this.ParameterBindings;
     ArrayList outArgs = new ArrayList();
     if (this.ParameterBindings.Contains("(ReturnValue)"))
     {
         WorkflowParameterBinding binding = this.ParameterBindings["(ReturnValue)"];
         if (binding != null)
         {
             outArgs.Add(binding.Value);
         }
     }
     foreach (ParameterInfo info3 in method.GetParameters())
     {
         if (info3.ParameterType.IsByRef || (info3.IsIn && info3.IsOut))
         {
             WorkflowParameterBinding binding2 = parameterBindings[info3.Name];
             outArgs.Add(binding2.Value);
         }
     }
     message.SendResponse(outArgs);
     return ActivityExecutionStatus.Closed;
 }
		protected sealed override ActivityExecutionStatus Execute (ActivityExecutionContext executionContext)
		{
			object[] parameters;
			object data = executionContext.GetService (InterfaceType);
			MethodInfo invoke = InterfaceType.GetMethod (MethodName);
			ParameterInfo[] pars = invoke.GetParameters ();

			parameters = new object [pars.Length];
			for (int i = 0; i < pars.Length; i++) {
				ParameterBindings.Add (new WorkflowParameterBinding (pars[i].Name));
			}

			// User may set the ParameterBindings
			OnMethodInvoking (new EventArgs ());

			for (int i = 0; i < pars.Length; i++) {
				parameters[i] = (ParameterBindings [pars[i].Name]).Value;
			}

			InterfaceType.InvokeMember (MethodName,
				BindingFlags.InvokeMethod,
				null, data,
				parameters);

			OnMethodInvoked (new EventArgs ());

			NeedsExecution = false;
			return ActivityExecutionStatus.Closed;
		}
Example #47
0
        internal static void AddCommentWorkflowHistory(string message, ActivityExecutionContext context, Guid wrkflowInstanceID)
        {
            ISharePointService service = (ISharePointService)context.GetService(typeof(ISharePointService));

            if (service == null)
            {
                throw new InvalidOperationException();
            }

            service.LogToHistoryList(wrkflowInstanceID, SPWorkflowHistoryEventType.None, 0, TimeSpan.MinValue, "", message, message);
        }
 internal void Unsubscribe(ActivityExecutionContext context)
 {
     context.GetService<WorkflowQueuingService>().GetWorkflowQueue("SetStateQueue").UnregisterForQueueItemAvailable(this);
 }
Example #49
0
        public WorkflowHistoryTraceListener(ActivityExecutionContext context, Guid workflowInstanceID)
        {
            service = (ISharePointService)context.GetService(typeof(ISharePointService));

            if (service == null)
            {
                throw new InvalidOperationException();
            }

            this.workflowInstanceID = workflowInstanceID;
        }
Example #50
0
        /// <summary>
        /// logs exceptions to sharepoint's workflow history log
        /// </summary>
        /// <param name="e"></param>
        /// <param name="context"></param>
        internal static void LogExceptionToWorkflowHistory(Exception e, ActivityExecutionContext context, Guid wrkflowInstanceID)
        {
            ISharePointService service = (ISharePointService)context.GetService(typeof(ISharePointService));

            if (service == null)
            {
                throw new InvalidOperationException();
            }

            service.LogToHistoryList(wrkflowInstanceID, SPWorkflowHistoryEventType.WorkflowError, 0, TimeSpan.MinValue, "Error", e.ToString(), "");
        }
Example #51
0
        protected override ActivityExecutionStatus Execute(ActivityExecutionContext context)
        {
            //WorkflowQueuingService is a component that allows access to queue items
            //enqueued to a particular workflow instance
            // Items are submitted to a workflow instance from the host using the 
            // EnqueueItem method call on the workflowinstance
            WorkflowQueuingService qService = context.GetService<WorkflowQueuingService>() as WorkflowQueuingService;

            // The Queue name is in the activity context and specified in the Enqueue item call
            IComparable qName = this.Queue;


            //Try to dequeue if there are any items available
            // Register the handler OnQueueItemAvailable when a item is queued
            if (!TryDequeueAndComplete(context, qName))
            {
                qService.GetWorkflowQueue(qName).QueueItemAvailable += this.OnQueueItemAvailable;
                return ActivityExecutionStatus.Executing;
            }

            return ActivityExecutionStatus.Closed;
        }
        internal static ChannelTicket Take(ActivityExecutionContext executionContext, Guid workflowId, LogicalChannel logicalChannel)
        {
            if (executionContext == null)
            {
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("executionContext");
            }

            if (workflowId == Guid.Empty)
            {
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgument("workflowId",
                    SR2.GetString(SR2.Error_Cache_InvalidWorkflowId));
            }

            if (logicalChannel == null)
            {
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("logicalChannel");
            }

            ChannelManagerService channelManager = executionContext.GetService<ChannelManagerService>();

            ChannelTicket channel;
            if (channelManager != null)
            {
                channel = channelManager.TakeChannel(workflowId, logicalChannel);
            }
            else
            {
                channel = ChannelManagerService.CreateTransientChannel(logicalChannel);
            }

            return channel;
        }
Example #53
0
		protected IComparable SetTimer (ActivityExecutionContext executionContext, DateTime expiresAt)
		{
		#if RUNTIME_DEP
			TimerEventSubscription te;
			WorkflowQueue queue;

			te = new TimerEventSubscription (executionContext.ExecutionContextManager.Workflow.InstanceId,
				expiresAt);

			WorkflowQueuingService qService = executionContext.GetService <WorkflowQueuingService> ();
		    	queue = qService.CreateWorkflowQueue (te.QueueName, true);
		    	queue.QueueItemArrived += OnQueueTimerItemArrived;
			executionContext.ExecutionContextManager.Workflow.TimerEventSubscriptionCollection.Add (te);
			return te.QueueName;
		#else
			return null;
		#endif

		}
        protected override ActivityExecutionStatus Execute(ActivityExecutionContext executionContext)
        {
            if (executionContext == null)
                throw new ArgumentNullException("executionContext");

            if (this.Fault == null)
            {
                throw new InvalidOperationException(SR.GetString(CultureInfo.CurrentCulture, SR.Error_PropertyNotSet, FaultProperty.Name));
            }

            WorkflowQueuingService queueService = executionContext.GetService<WorkflowQueuingService>();

            // fire event
            this.RaiseEvent(WebServiceFaultActivity.SendingFaultEvent, this, EventArgs.Empty);

            WebServiceInputActivity webservicereceive = this.GetActivityByName(this.InputActivityName) as WebServiceInputActivity;
            IComparable queueId = new EventQueueName(webservicereceive.InterfaceType, webservicereceive.MethodName, webservicereceive.QualifiedName);
            Debug.Assert(queueService.Exists(queueId));
            IMethodResponseMessage responseMessage = null;
            WorkflowQueue queue = queueService.GetWorkflowQueue(queueId);

            if (queue.Count != 0)
                responseMessage = queue.Dequeue() as IMethodResponseMessage;

            System.Diagnostics.Debug.Assert(responseMessage != null);

            // populate exception & reset the waiting thread
            responseMessage.SendException(this.Fault);

            return ActivityExecutionStatus.Closed;
        }
Example #55
0
        // 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;
        }
Example #56
0
		protected sealed override ActivityExecutionStatus Execute (ActivityExecutionContext executionContext)
		{
			ActivityExecutionStatus status;
			ActivityExecutionContextManager manager = executionContext.ExecutionContextManager;
			ReadOnlyCollection <ActivityExecutionContext> contexts = manager.ExecutionContexts;

			Console.WriteLine ("***ourCodeActivity.Execute {0}", contexts.Count);

			IComparable queue_name = "our_queue";

			WorkflowQueuingService qService = executionContext.GetService<WorkflowQueuingService> ();

		    	if (!qService.Exists (queue_name)) {
		    		Console.WriteLine ("CreatingQue");
			        qService.CreateWorkflowQueue (queue_name, true);
			}

			status = base.Execute (executionContext);
			return status;
		}
        protected sealed override ActivityExecutionStatus Execute(ActivityExecutionContext executionContext)
        {
            if (executionContext == null)
                throw new ArgumentNullException("executionContext");
            if (this.InterfaceType == null)
                throw new ArgumentException(
                    SR.GetString(SR.Error_MissingInterfaceType), "executionContext");

            Type type = this.InterfaceType;
            string methodName = this.MethodName;

            object serviceValue = executionContext.GetService(type);
            if (serviceValue == null)
                throw new InvalidOperationException(SR.GetString(SR.Error_ServiceNotFound, this.InterfaceType));

            this.RaiseEvent(MethodInvokingEvent, this, EventArgs.Empty);
            OnMethodInvoking(EventArgs.Empty);

            MethodInfo methodInfo = type.GetMethod(methodName, BindingFlags.Instance | BindingFlags.Public);
            ParameterModifier[] parameterModifiers = null;
            object[] actualParameters = InvokeHelper.GetParameters(methodInfo, this.ParameterBindings, out parameterModifiers);

            WorkflowParameterBinding resultBinding = null;
            if (this.ParameterBindings.Contains("(ReturnValue)"))
                resultBinding = this.ParameterBindings["(ReturnValue)"];

            CorrelationService.InvalidateCorrelationToken(this, type, methodName, actualParameters);

            object result = type.InvokeMember(this.MethodName, BindingFlags.InvokeMethod, new ExternalDataExchangeBinder(), serviceValue, actualParameters, parameterModifiers, null, null);
            if (resultBinding != null)
                resultBinding.Value = InvokeHelper.CloneOutboundValue(result, new BinaryFormatter(), "(ReturnValue)");

            InvokeHelper.SaveOutRefParameters(actualParameters, methodInfo, this.ParameterBindings);
            OnMethodInvoked(EventArgs.Empty);
            return ActivityExecutionStatus.Closed;
        }