Beispiel #1
0
        protected void RunFlow(object sender, CommandEventArgs e)
        {
            var dto = new EmailDto()
            {
                Subject = txtEmailTitle.Text,
                Content = txtEmailContent.Text,
                From = "",
                To = txtEmailAddress.Text
            };

            var validator = ServiceLocator.Current.GetInstance<IValidator<EmailDto>>();
            var result = validator.Validate(dto);

            // need to output something there

            var flowInput = new WorkFlowInput()
            {
                Email = dto,
                IsNewRequest = true
            };

            var workflow = new FlowHost();
            workflow.OnWfCompleted += workflow_OnWfCompleted;
            workflow.OnWfError += workflow_OnWfError;
            workflow.OnIdle += workflow_OnIdle;
            var workflowId = workflow.CreateOrResume(flowInput);
            if (workflowId.HasValue)
                instanceId.Value = workflowId.Value.ToString();
        }
        public Guid? InitEmailFlow(EmailDto dto)
        {
            var flowInput = new WorkFlowInput()
            {
                Email = dto,
                IsNewRequest = true
            };

            var workflow = new FlowHost();
            workflow.OnWfCompleted += workflow_OnWfCompleted;
            workflow.OnWfError += workflow_OnWfError;
            workflow.OnIdle += workflow_OnIdle;
            var workflowId = workflow.CreateOrResume(flowInput);
            return workflowId;
        }
        public void ResumeEmailFlow(string bookmarkName, string instanceId)
        {
            var workflow = new FlowHost();
            workflow.OnWfCompleted += workflow_OnWfCompleted;
            workflow.OnWfError += workflow_OnWfError;
            var flowInput = new WorkFlowInput()
            {
                Email = null,
                IsNewRequest = false,
                BookmarkName = bookmarkName,
                InstanceId = Guid.Parse(instanceId)
            };

            workflow.CreateOrResume(flowInput);
        }
Beispiel #4
0
        protected void ResumeFlow(object sender, CommandEventArgs e)
        {
            var guidStr = instanceId.Value;

            var workflow = new FlowHost();
            workflow.OnWfCompleted += workflow_OnWfCompleted;
            workflow.OnWfError += workflow_OnWfError;
            var flowInput = new WorkFlowInput()
            {
                Email = null,
                IsNewRequest = false,
                BookmarkName = Constant.Bookmark.WaitforConfirmation,
                InstanceId = Guid.Parse(guidStr)
            };

            workflow.CreateOrResume(flowInput);
        }
Beispiel #5
0
        // creates a workflow application, binds parameters, links extensions and run it
        public Guid? CreateOrResume(WorkFlowInput request)
        {
            // input parameters for the WF program
            IDictionary<string, object> inputs = new Dictionary<string, object>();
            inputs.Add("Request", request);

            var connectionString = System.Configuration.ConfigurationManager.ConnectionStrings["WorkflowPrototype"];
            var persistStore = new SqlWorkflowInstanceStore(connectionString.ConnectionString)
            {
                InstanceCompletionAction = InstanceCompletionAction.DeleteNothing,
                InstanceLockedExceptionAction = InstanceLockedExceptionAction.AggressiveRetry,
                RunnableInstancesDetectionPeriod = new TimeSpan(0, 0, 0, 5),
                HostLockRenewalPeriod = new TimeSpan(0, 0, 0, 30),
                InstanceEncodingOption = InstanceEncodingOption.GZip
            };

            Activity wf = new CreditTransferFlow();

            Guid? instanceId = null;

            WorkflowApplication instance;
            if (!request.IsNewRequest && request.InstanceId.HasValue && !string.IsNullOrWhiteSpace(request.BookmarkName))
            {
                instance = new WorkflowApplication(wf);
            }
            else
            {
                instance = new WorkflowApplication(wf, inputs);
                instanceId = instance.Id;
            }

            instance.InstanceStore = persistStore;
            instance.PersistableIdle = e =>
            {
                if (OnIdle != null)
                {
                    OnIdle(e);
                }
                return PersistableIdleAction.Unload;
            };
            instance.Unloaded = (workflowApplicationEventArgs) =>
            {
                // Console.WriteLine("WorkflowApplication has Unloaded\n");
                _syncEvent.Set();
            };
            instance.Completed = (e) =>
            {
                if (OnWfCompleted != null)
                {
                    OnWfCompleted(e);
                }
                _syncEvent.Set();
            };
            instance.OnUnhandledException = (e) =>
            {
                if (OnWfError != null)
                {
                    OnWfError(e);
                }
                _syncEvent.Set();
                return UnhandledExceptionAction.Abort;
            };

            if (!request.IsNewRequest && request.InstanceId.HasValue && !string.IsNullOrWhiteSpace(request.BookmarkName))
            {
                instance.Load(request.InstanceId.Value);
                instance.ResumeBookmark(new Bookmark(request.BookmarkName), 1);
            }

            // add a tracking participant
            //instance.Extensions.Add(new SaveAllEventsToTestFileTrackingParticipant());

            // continue executing this instance
            instance.Run();

            _syncEvent.WaitOne();

            return instanceId;
        }