/// <summary>
        /// Suspends the specified context.
        /// </summary>
        /// <param name="context">The context.</param>
        protected virtual void Suspend(BusinessContext context)
        {
            //string strPrimaryKeyId = "28ad9324-85a5-4dd2-96a2-ace25bd14be4";

            //BusinessManager.Execute<CompleteAssignmentRequest, Response>(new CompleteAssignmentRequest(PrimaryKeyId.Parse(strPrimaryKeyId)));

            // Load WorkflowInstanceEntity
            WorkflowInstanceEntity wf = (WorkflowInstanceEntity)BusinessManager.Load(WorkflowInstanceEntity.ClassName, context.GetTargetPrimaryKeyId().Value);

            // Check Wf State
            if (wf.State != (int)BusinessProcessState.Active)
            {
                throw new InvalidOperationException();
            }

            WorkflowInstance instance = GlobalWorkflowRuntime.WorkflowRuntime.GetWorkflow((Guid)wf.PrimaryKeyId.Value);

            instance.Suspend(string.Empty);
            GlobalWorkflowRuntime.RunWorkflow(instance);

            //wf.State = (int)BusinessProcessState.Suspended;
            //BusinessManager.Update(wf);

            // Susupend All Active Assignments
        }
Exemplo n.º 2
0
        /// <summary>
        /// Runs the workflow.
        /// </summary>
        /// <param name="entity">The entity.</param>
        /// <param name="executionResult">The execution result.</param>
        private static void RunWorkflow(AssignmentEntity entity)
        {
            Guid   wfInstanceId = (Guid)entity.WorkflowInstanceId;
            string queueName    = entity.WorkflowActivityName;

            WorkflowInstance instance = GlobalWorkflowRuntime.WorkflowRuntime.GetWorkflow(wfInstanceId);

            instance.EnqueueItem(queueName, entity, null, null);

            GlobalWorkflowRuntime.RunWorkflow(instance);
        }
        /// <summary>
        /// Resumes the specified context.
        /// </summary>
        /// <param name="context">The context.</param>
        protected virtual void Resume(BusinessContext context)
        {
            // Load WorkflowInstanceEntity
            WorkflowInstanceEntity wf = (WorkflowInstanceEntity)BusinessManager.Load(WorkflowInstanceEntity.ClassName, context.GetTargetPrimaryKeyId().Value);

            // Check Wf State
            if (wf.State != (int)BusinessProcessState.Suspended)
            {
                throw new InvalidOperationException();
            }

            WorkflowInstance instance = GlobalWorkflowRuntime.WorkflowRuntime.GetWorkflow((Guid)wf.PrimaryKeyId.Value);

            instance.Resume();
            GlobalWorkflowRuntime.RunWorkflow(instance);

            //wf.State = (int)BusinessProcessState.Active;
            //BusinessManager.Update(wf);
        }
        /// <summary>
        /// Terminates the specified context.
        /// </summary>
        /// <param name="context">The context.</param>
        protected virtual void Terminate(BusinessContext context)
        {
            // Load WorkflowInstanceEntity
            WorkflowInstanceEntity wf = (WorkflowInstanceEntity)BusinessManager.Load(WorkflowInstanceEntity.ClassName, context.GetTargetPrimaryKeyId().Value);

            // Check Wf State
            if (wf.State != (int)BusinessProcessState.Active)
            {
                throw new InvalidOperationException();
            }

            WorkflowInstance instance = GlobalWorkflowRuntime.WorkflowRuntime.GetWorkflow((Guid)wf.PrimaryKeyId.Value);

            instance.Terminate("Cancel by user");
            GlobalWorkflowRuntime.RunWorkflow(instance);

            //wf.State = (int)BusinessProcessState.Completed;
            //wf.ExecutionResult = (int)BusinessProcessExecutionResult.Canceled;

            //BusinessManager.Update(wf);
        }