CreateWorkflowInstance() private method

private CreateWorkflowInstance ( ) : System.Activities.Activity
return System.Activities.Activity
Exemplo n.º 1
0
        private static WorkflowApplication CreateWorkflowApplication(WorkflowHandlerBase workflowInstance, WorkflowApplicationCreationPurpose purpose, IDictionary <string, object> parameters)
        {
            try
            {
                string version;
                WorkflowApplication wfApp = null;
                var workflow = workflowInstance.CreateWorkflowInstance(out version);
                switch (purpose)
                {
                case WorkflowApplicationCreationPurpose.StartNew:
                    Dictionary <string, object> arguments = workflowInstance.CreateParameters();
                    arguments.Add(STATECONTENT, new WfContent(workflowInstance));
                    if (parameters != null)
                    {
                        foreach (var item in parameters)
                        {
                            arguments.Add(item.Key, item.Value);
                        }
                    }
                    wfApp = new WorkflowApplication(workflow, arguments);
                    workflowInstance.WorkflowDefinitionVersion = version;
                    workflowInstance.WorkflowInstanceGuid      = wfApp.Id.ToString();
                    break;

                default:
                    wfApp = new WorkflowApplication(workflow);
                    break;
                }

                WriteDebug("CreateWorkflowApplication: NodeId: " + workflowInstance.Id + ", instanceId: " + workflowInstance.WorkflowInstanceGuid + ", Purpose: " + purpose);

                InstanceHandle             ownerHandle;
                var                        store   = CreateInstanceStore(workflowInstance, out ownerHandle);
                Dictionary <XName, object> wfScope = new Dictionary <XName, object> {
                    { GetWorkflowHostTypePropertyName(), GetWorkflowHostTypeName(workflowInstance) }
                };

                wfApp.InstanceStore = store;
                wfApp.AddInitialInstanceValues(wfScope);

                wfApp.PersistableIdle      = a => { WriteDebug("PersistableIdle " + wfApp.Id); DestroyInstanceOwner(wfApp, ownerHandle); return(PersistableIdleAction.Unload); };
                wfApp.Unloaded             = b => { WriteDebug("Unloaded " + wfApp.Id); DestroyInstanceOwner(wfApp, ownerHandle); };
                wfApp.Completed            = c => { WriteDebug("Completed " + wfApp.Id); OnWorkflowCompleted(c); DestroyInstanceOwner(wfApp, ownerHandle); };
                wfApp.Aborted              = d => { WriteDebug("Aborted " + wfApp.Id); OnWorkflowAborted(d); DestroyInstanceOwner(wfApp, ownerHandle); };
                wfApp.OnUnhandledException = e => { WriteDebug("OnUnhandledException " + wfApp.Id); return(HandleError(e)); };

                wfApp.Extensions.Add(new ContentWorkflowExtension()
                {
                    WorkflowInstancePath = workflowInstance.Path
                });
                return(wfApp);
            }
            catch (Exception e)
            {
                WriteError("CreateWorkflowApplication", e);
                throw;
            }
        }
Exemplo n.º 2
0
        private static WorkflowApplication CreateWorkflowApplication(WorkflowHandlerBase workflowInstance, WorkflowApplicationCreationPurpose purpose,
                                                                     IDictionary <string, object> parameters)
        {
            string version;
            WorkflowApplication wfApp = null;
            var workflow = workflowInstance.CreateWorkflowInstance(out version);

            switch (purpose)
            {
            case WorkflowApplicationCreationPurpose.StartNew:
                Dictionary <string, object> arguments = workflowInstance.CreateParameters();
                arguments.Add(STATECONTENT, new WfContent(workflowInstance));
                if (parameters != null)
                {
                    foreach (var item in parameters)
                    {
                        arguments.Add(item.Key, item.Value);
                    }
                }
                wfApp = new WorkflowApplication(workflow, arguments);
                workflowInstance.WorkflowDefinitionVersion = version;
                workflowInstance.WorkflowInstanceGuid      = wfApp.Id.ToString();
                break;

            default:
                wfApp = new WorkflowApplication(workflow);
                break;
            }

            var store = CreateInstanceStore(workflowInstance);
            Dictionary <XName, object> wfScope = new Dictionary <XName, object>
            {
                { GetWorkflowHostTypePropertyName(), GetWorkflowHostTypeName(workflowInstance) }
            };

            wfApp.InstanceStore = store;
            wfApp.AddInitialInstanceValues(wfScope);

            wfApp.PersistableIdle      = a => { Debug.WriteLine("##WF> Pidle"); return(PersistableIdleAction.Unload); };
            wfApp.Unloaded             = b => { Debug.WriteLine("##WF> Unload"); };
            wfApp.Completed            = OnWorkflowCompleted;
            wfApp.Aborted              = OnWorkflowAborted;
            wfApp.OnUnhandledException = HandleError;

            wfApp.Extensions.Add(new ContentWorkflowExtension()
            {
                WorkflowInstancePath = workflowInstance.Path
            });
            return(wfApp);
        }
Exemplo n.º 3
0
        private static WorkflowApplication CreateWorkflowApplication(WorkflowHandlerBase workflowInstance, WorkflowApplicationCreationPurpose purpose,
            IDictionary<string, object> parameters)
        {
            string version;
            WorkflowApplication wfApp = null;
            var workflow = workflowInstance.CreateWorkflowInstance(out version);
            switch (purpose)
            {
                case WorkflowApplicationCreationPurpose.StartNew:
                    Dictionary<string, object> arguments = workflowInstance.CreateParameters();
                    arguments.Add(STATECONTENT, new WfContent(workflowInstance));
                    if (parameters != null)
                        foreach (var item in parameters)
                            arguments.Add(item.Key, item.Value);
                    wfApp = new WorkflowApplication(workflow, arguments);
                    workflowInstance.WorkflowDefinitionVersion = version;
                    workflowInstance.WorkflowInstanceGuid = wfApp.Id.ToString();
                    break;
                default:
                    wfApp = new WorkflowApplication(workflow);
                    break;
            }

            var store = CreateInstanceStore(workflowInstance);
            Dictionary<XName, object> wfScope = new Dictionary<XName, object>
            {
                { GetWorkflowHostTypePropertyName(), GetWorkflowHostTypeName(workflowInstance) }
            };
            wfApp.InstanceStore = store;
            wfApp.AddInitialInstanceValues(wfScope);

            wfApp.PersistableIdle = a => { Debug.WriteLine("##WF> Pidle"); return PersistableIdleAction.Unload; };
            wfApp.Unloaded = b => { Debug.WriteLine("##WF> Unload"); };
            wfApp.Completed = OnWorkflowCompleted;
            wfApp.Aborted = OnWorkflowAborted;
            wfApp.OnUnhandledException = HandleError;

            wfApp.Extensions.Add(new ContentWorkflowExtension() { WorkflowInstancePath = workflowInstance.Path });
            return wfApp;

        }