Exemple #1
0
        public bool ChangeWorkflowStep(CodeTorch.Core.Workflow workflow, WorkflowNextStep nextStep, string entityIDValue, string comment)
        {
            bool success = false;


            //get current workflow step
            WorkflowStep currentStep = GetCurrentWorkflowStep(workflow, entityIDValue);

            //see if next workflowstep is in possible
            WorkflowNextStep validNextStep = currentStep.PossibleNextSteps.
                                             Where(s => s.Code.ToLower() == nextStep.Code.ToLower()).SingleOrDefault();

            if (validNextStep != null)
            {
                //check comments
                if ((validNextStep.RequireComment) && (String.IsNullOrEmpty(comment)))
                {
                    throw new ApplicationException("Comments are required to change to this step");
                }
                else
                {
                    WorkflowStep step = workflow.GetStepByCode(validNextStep.Code);


                    string userName;
                    userName = UserIdentityService.GetInstance().IdentityProvider.GetUserName();

                    using (TransactionScope rootScope = TransactionUtils.CreateTransactionScope())
                    {
                        foreach (BaseWorkflowAction action in step.Actions)
                        {
                            action.Execute(null, workflow.Code, currentStep.Code, validNextStep.Code, entityIDValue, comment, userName);
                        }

                        //update workflow step
                        SetStep(workflow, step, entityIDValue, comment);

                        if (step.UpdateEntityWithStatusCode)
                        {
                            //update existing table status
                            SetEntityStatus(workflow, step, entityIDValue);
                        }

                        success = true;

                        rootScope.Complete();
                    }
                }
            }
            else
            {
                //invalid - someone may have changed status
                throw new ApplicationException("Status cannot be changed at this time");
            }


            return(success);
        }
        protected override string GetDisplayText(object value)
        {
            WorkflowNextStep step = (WorkflowNextStep)value;

            string retVal = step.Name;


            return(base.GetDisplayText(retVal));
        }
Exemple #3
0
        protected void Save_Click(object sender, EventArgs e)
        {
            //perform validation
            try
            {
                if (String.IsNullOrEmpty(StatusList.SelectedValue))
                {
                    throw new ApplicationException("Status is required");
                }

                WorkflowNextStep nextstep =
                    step.PossibleNextSteps
                    .Where(s =>
                           (
                               (s.Code.ToLower() == StatusList.SelectedValue.ToLower())
                           )
                           )
                    .SingleOrDefault();

                if (nextstep != null)
                {
                    if (nextstep.RequireComment)
                    {
                        if (String.IsNullOrEmpty(Comments.Text))
                        {
                            throw new ApplicationException("Comments are required to change to this status");
                        }
                    }

                    //all is well execute workflow

                    bool Success = WorkflowService.GetInstance().GetProvider(workflow).ChangeWorkflowStep(workflow, nextstep, EntityID, Comments.Text);

                    if (Success)
                    {
                        this.ClientScript.RegisterStartupScript(this.GetType(), "OnLoad", BuildCloseWindowJavascript(nextstep.Name));
                    }
                }
            }
            catch (Exception ex)
            {
                string MessageFormat = "The following error(s) occurred:<br/>{0}";
                Message.Visible  = true;
                Message.Text     = String.Format(MessageFormat, ex.Message);
                Message.CssClass = "ErrorMessages";
            }
        }
Exemple #4
0
        protected override void Execute(NativeActivityContext context)
        {
            // RESET APPLICATION REFERENCE ON WORK QUEUE ITEM

            WorkQueueItem.Get(context).Application = WorkflowManager.Get(context).Application;


            // ENSURE THAT THE ITEM IS ASSIGNED TO USER

            WorkQueueItem.Get(context).SelfAssign("Workflow Suspend Work Queue Item", false);


            // ATTEMPT TO SUSPEND THE ITEM

            Success.Set(context, WorkQueueItem.Get(context).Suspend(

                            WorkflowLastStep.Get(context),

                            WorkflowNextStep.Get(context),

                            ConstraintDays.Get(context),

                            MilestoneDays.Get(context),

                            ReleaseItem.Get(context)

                            ));


            if (!Success.Get(context))    // THROW EXCEPTION IF UNABLE TO SUSPEND

            {
                CommonFunctions.RaiseActivityException(WorkflowManager.Get(context).Application,

                                                       1,

                                                       WorkQueueItem.Get(context).Id,

                                                       WorkflowSteps.Get(context),

                                                       WorkflowManager.Get(context).Application.LastException.Message

                                                       );
            }

            // RECORD WORKFLOW STEPS

            Workflows.Activities.CommonFunctions.WorkflowStepsAdd(

                WorkflowManager.Get(context).Application,

                1,

                WorkQueueItem.Get(context).Id,

                WorkflowSteps.Get(context),

                "Suspend for Next Step: " + WorkflowNextStep.Get(context) +

                "  |  Constraint Days: " + ConstraintDays.Get(context).ToString() +

                "  |  Milestone Days: " + MilestoneDays.Get(context).ToString()

                );


            // SAVE WORKFLOW STEPS

            WorkflowManager.Get(context).Application.WorkQueueItemWorkflowStepsSave(WorkQueueItem.Get(context).Id, WorkflowSteps.Get(context));


            // EVALUATE IF WE WANT TO SUSPEND THE WORKFLOW TOO, OR JUST THE WORKFLOW ITEM AND LET THE WORKFLOW CONTINUE

            if (SuspendWorkflow.Get(context))
            {
                // MARK WORKFLOW AS SUSPEND USING WORKFLOW MANAGER

                WorkflowManager.Get(context).WorkflowStatus = WorkflowStatus.Suspended;


                // CREATE A BOOKMARK SET TO THE WORKFLOW INSTANCE ID TO MAKE IT UNIQUE

                context.CreateBookmark(context.WorkflowInstanceId.ToString(), new BookmarkCallback(this.ResumeWorkflow));
            }

            return;
        }