コード例 #1
0
        private static WorkflowApplication GetWorkFlowApplication(Dictionary <string, object> inputs, AutoResetEvent syncEvent)
        {
            InstanceStore store = new SqlWorkflowInstanceStore(ConfigurationManager.ConnectionStrings["WFDB"].ConnectionString);

            var accountFlowIdentity = new WorkflowIdentity {
                Name = "test", Version = new Version(1, 0, 0, 1)
            };

            WorkflowApplication.DeleteDefaultInstanceOwner(store);
            WorkflowApplication.CreateDefaultInstanceOwner(store, null, WorkflowIdentityFilter.Any, new TimeSpan(0, 0, 0, 10));

            WorkflowApplication wfApp = new WorkflowApplication(new FindApproverFlow(), inputs, accountFlowIdentity);

            wfApp.InstanceStore = store;

            wfApp.PersistableIdle = (e) =>
            {
                //a thread becomes in signaled state by calling Set on AutoResetEvent
                return(PersistableIdleAction.Unload);
            };
            wfApp.Unloaded = (workflowApplicationEventArgs) =>
            {
                syncEvent.Set();
                //InstanceUnloaded.Set();
            };

            wfApp.Completed = (e) =>
            {
                FindApproverResult      = (FindApproverResult)e.Outputs["Result"];
                WaitingApprovals        = (List <WorkFlowApproval>)e.Outputs["ApprovalList"];
                QuoteMasterWithGPStatus = (QuotationMaster)e.Outputs["QuotationMaster"];
                //syncEvent.Set();
            };

            wfApp.Aborted = (e) =>
            {
                string test = Convert.ToString(e.Reason.Message);
            };

            wfApp.OnUnhandledException = (e) =>
            {
                return(UnhandledExceptionAction.Terminate);
            };
            return(wfApp);
        }
コード例 #2
0
        private static WorkflowApplication GetWorkFlowApplication(Dictionary <string, object> inputs, AutoResetEvent syncEvent)
        {
            AutoResetEvent InstanceUnloaded = new AutoResetEvent(false);
            InstanceStore  store            = new SqlWorkflowInstanceStore(ConfigurationManager.ConnectionStrings["WFDB"].ConnectionString);

            var accountFlowIdentity = new WorkflowIdentity {
                Name = "test", Version = new Version(1, 0, 0, 1)
            };

            WorkflowApplication.DeleteDefaultInstanceOwner(store);
            WorkflowApplication.CreateDefaultInstanceOwner(store, null, WorkflowIdentityFilter.Any, new TimeSpan(0, 0, 0, 10));

            WorkflowApplication wfApp = null;

            if (inputs == null)
            {
                wfApp = new WorkflowApplication(new QuoteApprovalFlow(), accountFlowIdentity);
            }
            else
            {
                wfApp = new WorkflowApplication(new QuoteApprovalFlow(), inputs, accountFlowIdentity);
            }

            wfApp.InstanceStore = store;

            wfApp.PersistableIdle = (e) =>
            {
                ApprovalResult = ApprovalResult.WaitingForApproval;

                return(PersistableIdleAction.Unload);
            };


            wfApp.Unloaded = (workflowApplicationEventArgs) =>
            {
                syncEvent.Set();
                /*InstanceUnloaded.Set();*/  //a thread becomes in signaled state by calling Set on AutoResetEvent
            };

            //wfApp.OnUnhandledException = (e) =>
            //{
            //    var test = e.ToString();
            //    return UnhandledExceptionAction.Terminate;
            //};

            wfApp.Completed = (e) =>
            {
                if (e.CompletionState == ActivityInstanceState.Faulted)
                {
                    ApprovalResult = ApprovalResult.Exception;
                }
                else if (e.CompletionState == ActivityInstanceState.Canceled)
                {
                }
                else
                {
                    ApprovalResult = (ApprovalResult)e.Outputs["Result"];
                }

                syncEvent.Set();
            };

            wfApp.Aborted = (e) =>
            {
                syncEvent.Set();
            };

            wfApp.OnUnhandledException = (e) =>
            {
                ApprovalResult = ApprovalResult.Exception;
                //string subject = String.Format("eQ3.0 Workflow exception, quote Id: {0}", relatedQuoteId);
                //string strContent = String.Format("<p> eQ3.0 Workflow exception in {0}</p>", DateTime.Now.ToString());
                //strContent += String.Format("<p>Quote Id: {0}</p>", relatedQuoteId);
                //strContent += String.Format("<p>Workflow Id: {0}</p>", e.InstanceId);
                //strContent += String.Format("<p>Error message: {0}</p>", e.UnhandledException.Message);

                //MailHelper.SendMail("*****@*****.**", subject, strContent);
                var message = String.Format("<p>Workflow ID: {0}</p>", e.InstanceId);
                message += String.Format("<p>Error message: {0}</p>", e.UnhandledException.Message);
                SendErrorMail(message);
                return(UnhandledExceptionAction.Terminate);
            };
            return(wfApp);
        }