public void StartWorkflow()
        {
            System.DateTime startTime = DateTime.Now;

            String originalQueryString = ((!String.IsNullOrWhiteSpace(UrlOriginal)) ? ((UrlOriginal.Split('?').Length > 0) ? UrlOriginal.Split('?')[1] : String.Empty) : String.Empty);


            // CREATE WORKFLOW START REQUEST

            Mercury.Server.Application.WorkflowStartRequest workflowStartRequest = new Server.Application.WorkflowStartRequest();

            workflowStartRequest.Arguments = new System.Collections.Generic.Dictionary <String, Object> ();

            workflowStartRequest.WorkflowId = WorkflowId;

            workflowStartRequest.WorkflowInstanceId = WorkflowInstanceId;

            workflowStartRequest.WorkflowName = WorkflowName;

            // LOAD ARGUMENTS FROM ORIGINAL QUERY STRING

            for (Int32 currentIndex = 0; currentIndex < originalQueryString.Split('&').Length; currentIndex++)
            {
                String parameter = originalQueryString.Split('&')[currentIndex];

                String parameterName = ((parameter.Contains("=")) ? parameter.Split('=')[0] : String.Empty);

                String parameterValue = ((parameter.Contains("=")) ? parameter.Split('=')[1] : String.Empty);

                if (!String.IsNullOrWhiteSpace(parameterName))
                {
                    workflowStartRequest.Arguments.Add(parameterName, parameterValue);
                }
            }


            // CALL WORKFLOW START ON MERCURY SERVER

            workflowResponse = MercuryApplication.WorkflowStart(workflowStartRequest);

            System.Diagnostics.Debug.WriteLine("WorkflowStart: " + DateTime.Now.Subtract(startTime).TotalMilliseconds.ToString());

            WorkflowInstanceId = workflowResponse.WorkflowInstanceId; // ASSIGN NEW WORKFLOW INSTANCE ID FOR FUTURE REFERENCE (CONTINUE AND RESUME)


            startTime = DateTime.Now;

            HandleWorkflowResponse();

            actionResultType = Models.ActionResultType.Control;

            System.Diagnostics.Debug.WriteLine("WorkflowStart_HandleResponse: " + DateTime.Now.Subtract(startTime).TotalMilliseconds.ToString());

            return;
        }
Exemple #2
0
        protected void WorkflowStart_OnClick(Object sender, EventArgs e)
        {
            if (MercuryApplication == null)
            {
                return;
            }


            System.DateTime startTime = DateTime.Now;

            Server.Application.WorkflowStartRequest startRequest = WorkflowStartRequest;

            startRequest.Arguments = new System.Collections.Generic.Dictionary <String, Object> ();

            foreach (String currentKey in Request.QueryString.Keys)
            {
                startRequest.Arguments.Add(currentKey, Request.QueryString[currentKey]);
            }

            startRequest.WorkflowId = CurrentWorkflow.Id;

            startRequest.WorkflowName = CurrentWorkflow.Name;

            WorkflowStartRequest = startRequest;


            WorkflowResponse = MercuryApplication.WorkflowStart(startRequest);

            System.Diagnostics.Debug.WriteLine("WorkflowStart: " + DateTime.Now.Subtract(startTime).TotalMilliseconds.ToString());

            WorkflowInstanceId = WorkflowResponse.WorkflowInstanceId;

            startTime = DateTime.Now;

            HandleWorkflowResponse();

            System.Diagnostics.Debug.WriteLine("WorkflowStart_HandleResponse: " + DateTime.Now.Subtract(startTime).TotalMilliseconds.ToString());

            return;
        }
Exemple #3
0
        private void InitialPageLoadInitialization()
        {
            // SAVE REFERRER SO THAT THE APPLICATION CAN RETURN TO IT AFTER COMPLETING THE WORKFLOW

            if (String.IsNullOrWhiteSpace(ReferrerUrl))    // ONLY RELOAD IF CURRENT SAVE SESSION IS EMPTY REFERRER

            {
                if (Request.UrlReferrer != null)
                {
                    ReferrerUrl = Request.UrlReferrer.ToString();
                }

                else
                {
                    ReferrerUrl = "/Application/Workspace/Workspace.aspx";
                }
            }


            // INITIALIZE WORKFLOW

            String workflowName = (String)Request.QueryString["Workflow"];

            Int64 currentWorkflowId = 0;


            if (!String.IsNullOrWhiteSpace(workflowName))
            {
                CurrentWorkflow = MercuryApplication.WorkflowGet(workflowName, false);
            }

            else
            {
                if (Int64.TryParse((String)Request.QueryString["WorkflowId"], out currentWorkflowId))
                {
                    CurrentWorkflow = MercuryApplication.WorkflowGet(currentWorkflowId, true);

                    if (CurrentWorkflow != null)
                    {
                        workflowName = CurrentWorkflow.Name;
                    }
                }
            }


            if (!String.IsNullOrEmpty((String)Request.QueryString["WorkflowInstanceId"]))
            {
                // RESUME EXISTING WORKFLOW

                WorkflowInstanceId = new Guid((String)Request.QueryString["WorkflowInstanceId"]);

                CurrentWorkflow = MercuryApplication.WorkflowGet(workflowName, false);

                if (CurrentWorkflow == null)
                {
                    CurrentWorkflow = MercuryApplication.WorkflowGet(currentWorkflowId, true);
                }

                if (CurrentWorkflow != null)
                {
                    WorkflowTitleLabel.Text = "Workflow: " + CurrentWorkflow.Name + ((!String.IsNullOrEmpty(CurrentWorkflow.Description)) ? " [" + CurrentWorkflow.Description + "]" : String.Empty);

                    TelerikAjaxManager.ResponseScripts.Add(ResponseScriptWorkflowResume);
                }

                else
                {
                    WorkflowTitleLabel.Text = "Workflow Engine";

                    WorkflowExceptionMessageRow.Style.Clear();

                    WorkflowExceptionMessage.Text = "Workflow Exception: Unable to Load Workflow.";
                }
            }

            else
            {
                Boolean canWork = true;

                Int64 workQueueItemId;

                if (Int64.TryParse((String)Request.QueryString["WorkQueueItemId"], out workQueueItemId))
                {
                    canWork = false;

                    Client.Core.Work.WorkQueueItem workQueueItem = MercuryApplication.WorkQueueItemGet(workQueueItemId);

                    if (workQueueItem != null)
                    {
                        if ((workQueueItem.AssignedToSecurityAuthorityId == MercuryApplication.Session.SecurityAuthorityId)

                            && (workQueueItem.AssignedToUserAccountId == MercuryApplication.Session.UserAccountId))
                        {
                            canWork = true;
                        }

                        else if (workQueueItem.AssignTo(MercuryApplication.Session.SecurityAuthorityId, MercuryApplication.Session.UserAccountId, MercuryApplication.Session.UserAccountName, MercuryApplication.Session.UserDisplayName, "Member Profile - Work History"))
                        {
                            canWork = true;
                        }
                    }

                    if (canWork)
                    {
                        Server.Application.WorkflowStartRequest startRequest = WorkflowStartRequest;

                        startRequest.WorkQueueItemId = workQueueItemId;

                        WorkflowStartRequest = startRequest;
                    }
                }

                if ((canWork) && (CurrentWorkflow != null))
                {
                    WorkflowTitleLabel.Text = "Workflow: " + CurrentWorkflow.Name + ((!String.IsNullOrEmpty(CurrentWorkflow.Description)) ? " [" + CurrentWorkflow.Description + "]" : String.Empty);

                    Page.ClientScript.RegisterStartupScript(this.GetType(), "StartWorkflow", ResponseScriptWorkflowStart);
                }

                else if (!canWork)
                {
                    WorkflowTitleLabel.Text = "Workflow Engine";

                    WorkflowExceptionMessageRow.Style.Clear();

                    WorkflowExceptionMessage.Text = "Permission Denied: Unable to perform work on the selected Work Queue Item. This Item might already be owned. Please try again.";
                }

                else
                {
                    WorkflowTitleLabel.Text = "Workflow Engine";

                    WorkflowExceptionMessageRow.Style.Clear();

                    WorkflowExceptionMessage.Text = "Workflow Exception: " + MercuryApplication.LastException;
                }
            }

            return;
        }