Esempio n. 1
0
        /// <summary>
        /// 启动一个模版(组)下的一组分支流程,在服务模式下,可能返回多个流程。其它情况返回单个流程
        /// </summary>
        /// <param name="branchTransferParams"></param>
        /// <param name="group"></param>
        /// <param name="index"></param>
        /// <returns></returns>
        private WfProcessCollection StartupBranchProcess(WfBranchProcessTransferParams branchTransferParams, IWfBranchProcessGroup group, int index)
        {
            WfProcessCollection processes = null;

            if (branchTransferParams.Template.OperationDefinition == null)
            {
                WfProcessStartupParams startupParams = PrepareOneBranchProcessStartupParams(branchTransferParams, group, index);

                startupParams.CheckStartProcessUserPermission = false;

                processes = new WfProcessCollection();
                processes.Add(WfRuntime.StartWorkflow(startupParams));
            }
            else
            {
                if (WfRuntime.ProcessContext.EnableServiceCall)
                {
                    WfServiceStartupProcessParams startupParams = PrepareOneServiceStartupProcessParams(branchTransferParams, group, index);

                    processes = InvokeBranchProcess(startupParams, branchTransferParams.Template);
                }
                else
                {
                    processes = new WfProcessCollection();
                }
            }

            return(processes);
        }
Esempio n. 2
0
        public override object Deserialize(IDictionary <string, object> dictionary, Type type, JavaScriptSerializer serializer)
        {
            WfBranchProcessTransferParams data = new WfBranchProcessTransferParams();

            data.Template = JSONSerializerExecute.Deserialize <WfBranchProcessTemplateDescriptor>(dictionary["Template"]);
            data.BranchParams.CopyFrom(JSONSerializerExecute.Deserialize <WfBranchProcessStartupParamsCollection>(dictionary["BranchParams"]));

            return(data);
        }
Esempio n. 3
0
        protected override void OnModifyWorkflow(WfExecutorDataContext dataContext)
        {
            this.TargetActivity.Process.Committed = true;

            WfBranchProcessTransferParams bptp = new WfBranchProcessTransferParams(
                WfTemplateBuilder.CreateDefaultCirculationTemplate("Circulate", this.Circulators));

            WfRuntime.ProcessContext.AfterStartupBranchProcess += new WfAfterStartupBranchProcessHandler(WfActivityRelativeExecutorBase.AfterStartupBranchProcess);

            this.TargetActivity.StartupBranchProcesses(bptp);
        }
Esempio n. 4
0
        /// <summary>
        /// 内部启动分支流程
        /// </summary>
        /// <param name="branchTransferParams">分支流程启动参数</param>
        /// <param name="addToOwnerBranches"></param>
        /// <returns></returns>
        internal WfProcessCollection InternalStartupBranchProcesses(WfBranchProcessTransferParams branchTransferParams, bool addToOwnerBranches)
        {
            WfProcessCollection processes = null;

            if (CanStartBranchProcessFromTemplate(branchTransferParams.Template))
            {
                IWfBranchProcessGroup group = this.BranchProcessGroups[branchTransferParams.Template.Key];

                //以模版Key为分支流程实例的分组标准
                if (group == null)
                {
                    group = new WfBranchProcessGroup(this, branchTransferParams.Template);
                    this.BranchProcessGroups.Add(group);
                }

                WfRuntime.ProcessContext.FirePrepareBranchProcessParams(group, branchTransferParams.BranchParams);

                ProcessProgress.Current.MaxStep += branchTransferParams.BranchParams.Count;
                ProcessProgress.Current.Response();

                //根据模板内的分支流程参数,逐一启动具体流程
                for (int i = 0; i < branchTransferParams.BranchParams.Count; i++)
                {
                    //processes = StartupBranchProcess(branchTransferParams, group, group.BranchProcessStatistics.MaxSequence++);
                    processes = StartupBranchProcess(branchTransferParams, group, i);

                    processes.ForEach(p =>
                    {
                        if (addToOwnerBranches)
                        {
                            if (group.Branches.Contains(p) == false)
                            {
                                group.Branches.Add(p);
                            }
                        }

                        WfRuntime.ProcessContext.FireAfterStartupBranchProcess(p);
                    });

                    ProcessProgress.Current.MaxStep = Math.Max(ProcessProgress.Current.MaxStep, ProcessProgress.Current.CurrentStep + processes.Count);
                    ProcessProgress.Current.IncrementBy(processes.Count);
                    ProcessProgress.Current.Response();
                }

                WfRuntime.ProcessContext.AffectedProcesses.AddOrReplace(this.Process);
            }

            if (processes == null)
            {
                processes = new WfProcessCollection();
            }

            return(processes);
        }
Esempio n. 5
0
        public override IDictionary <string, object> Serialize(object obj, JavaScriptSerializer serializer)
        {
            WfBranchProcessTransferParams data = (WfBranchProcessTransferParams)obj;

            IDictionary <string, object> dictionary = new Dictionary <string, object>();

            dictionary["Template"]     = data.Template;
            dictionary["BranchParams"] = data.BranchParams;

            return(dictionary);
        }
Esempio n. 6
0
        private WfServiceStartupProcessParams PrepareOneServiceStartupProcessParams(WfBranchProcessTransferParams branchParams, IWfBranchProcessGroup group, int index)
        {
            IWfBranchProcessTemplateDescriptor template            = branchParams.Template;
            WfBranchProcessStartupParams       branchStartupParams = branchParams.BranchParams[index];

            WfServiceStartupProcessParams startupParams = new WfServiceStartupProcessParams();

            startupParams.Creator = this.Process.Creator;

            if (branchStartupParams.Department == null)
            {
                startupParams.Department = this.Process.OwnerDepartment;
            }
            else
            {
                startupParams.Department = branchStartupParams.Department;
            }

            startupParams.Assignees = branchStartupParams.Assignees.ToUsers();

            if (branchStartupParams.DefaultTaskTitle.IsNullOrEmpty())
            {
                if (startupParams.DefaultTaskTitle.IsNullOrEmpty())
                {
                    startupParams.DefaultTaskTitle = this.Process.Descriptor.DefaultTaskTitle;
                }
                else
                {
                    startupParams.DefaultTaskTitle = this.Descriptor.TaskTitle;
                }
            }
            else
            {
                startupParams.DefaultTaskTitle = branchStartupParams.DefaultTaskTitle;
            }

            if (branchStartupParams.ResourceID.IsNullOrEmpty())
            {
                WfSubProcessResourceMode mode = template.Properties.GetValue("CreateResourceMode", WfSubProcessResourceMode.DependsOnProcess);
                switch (mode)
                {
                //这里的规则是什么?
                case WfSubProcessResourceMode.DependsOnProcess:
                    startupParams.ResourceID = this.Process.ResourceID;
                    break;

                case WfSubProcessResourceMode.SameWithRoot:
                    startupParams.ResourceID = this.Process.ResourceID;
                    break;

                case WfSubProcessResourceMode.NewCreate:
                    startupParams.ResourceID = UuidHelper.NewUuidString();
                    break;
                }
            }
            else
            {
                startupParams.ResourceID = branchStartupParams.ResourceID;
            }

            startupParams.OwnerActivityID  = this.ID;
            startupParams.OwnerTemplateKey = template.Key;
            startupParams.Sequence         = index;
            startupParams.RelativeParams   = new Dictionary <object, object>();

            foreach (var strpar in branchStartupParams.RelativeParams.AllKeys)
            {
                startupParams.RelativeParams.Add(strpar, this.Process.ApplicationRuntimeParameters[branchStartupParams.RelativeParams[strpar]]);
            }

            if (!string.IsNullOrEmpty(template.DefaultUrl))
            {
                startupParams.DefaultURL = template.DefaultUrl;
            }
            else if (!string.IsNullOrEmpty(this.Descriptor.Url))
            {
                startupParams.DefaultURL = this.Descriptor.Url;
            }
            else
            {
                startupParams.DefaultURL = this.Process.Descriptor.Url;
            }

            //如果是串行执行,且不是第一个流程,则不启动第一个活动,子流程处于未启动状态
            if (template.ExecuteSequence == WfBranchProcessExecuteSequence.Serial && index > 0)
            {
                startupParams.AutoStartInitialActivity = false;
            }

            return(startupParams);
        }
Esempio n. 7
0
        private WfProcessStartupParams PrepareOneBranchProcessStartupParams(WfBranchProcessTransferParams branchTransferParams, IWfBranchProcessGroup group, int index)
        {
            IWfBranchProcessTemplateDescriptor template            = branchTransferParams.Template;
            WfBranchProcessStartupParams       branchStartupParams = branchTransferParams.BranchParams[index];

            //准备启动子流程的参数
            //先检查有没有预定义好的分支流程
            IWfProcessDescriptor subProcessDesp = null;

            using (WfApplicationParametersContext apContext = WfApplicationParametersContext.CreateContext(branchStartupParams.ApplicationRuntimeParameters))
            {
                subProcessDesp = template.GetBranchProcessDescriptor();
            }

            if (template.DefaultProcessName.IsNotEmpty())
            {
                string runtimeProcessName = this.Process.ApplicationRuntimeParameters.GetMatchedString(template.DefaultProcessName);

                if (runtimeProcessName.IsNullOrEmpty())
                {
                    runtimeProcessName = template.DefaultProcessName;
                }

                if (runtimeProcessName.IsNullOrEmpty())
                {
                    ((WfProcessDescriptor)subProcessDesp).Name = runtimeProcessName;
                }

                if (subProcessDesp.InitialActivity != null && subProcessDesp.InitialActivity.Name.IsNullOrEmpty())
                {
                    ((WfActivityDescriptor)subProcessDesp.InitialActivity).Name = runtimeProcessName;
                }
            }

            if (template.DefaultTaskTitle.IsNotEmpty())
            {
                subProcessDesp.DefaultTaskTitle = template.DefaultTaskTitle;
            }

            if (template.DefaultUrl.IsNotEmpty())
            {
                subProcessDesp.Url = template.DefaultUrl;
            }

            if (subProcessDesp.Url.IsNullOrEmpty())
            {
                subProcessDesp.Url = this.Descriptor.Url.IsNotEmpty() ? this.Descriptor.Url : this.Descriptor.Process.Url;
            }

            WfProcessStartupParams startupParams = new WfProcessStartupParams();

            startupParams.Creator = this.Operator;

            if (branchStartupParams.Department == null)
            {
                startupParams.Department = this.Process.OwnerDepartment;
            }
            else
            {
                startupParams.Department = branchStartupParams.Department;
            }

            startupParams.Assignees.CopyFrom(branchStartupParams.Assignees);
            startupParams.ProcessDescriptor = subProcessDesp;

            if (branchStartupParams.DefaultTaskTitle.IsNullOrEmpty())
            {
                if (startupParams.DefaultTaskTitle.IsNullOrEmpty())
                {
                    if (subProcessDesp.DefaultTaskTitle.IsNotEmpty())
                    {
                        startupParams.DefaultTaskTitle = subProcessDesp.DefaultTaskTitle;
                    }
                    else
                    {
                        startupParams.DefaultTaskTitle = this.Process.Descriptor.DefaultTaskTitle;
                    }
                }
                else
                {
                    startupParams.DefaultTaskTitle = this.Descriptor.TaskTitle;
                }
            }
            else
            {
                startupParams.DefaultTaskTitle = branchStartupParams.DefaultTaskTitle;
            }

            if (branchStartupParams.ResourceID.IsNullOrEmpty())
            {
                WfSubProcessResourceMode mode = template.Properties.GetValue("CreateResourceMode", WfSubProcessResourceMode.DependsOnProcess);
                switch (mode)
                {
                case WfSubProcessResourceMode.DependsOnProcess:
                    if (subProcessDesp.Properties.GetValue("Independent", false))
                    {
                        startupParams.ResourceID = UuidHelper.NewUuidString();
                    }
                    else
                    {
                        startupParams.ResourceID = this.Process.ResourceID;
                    }
                    break;

                case WfSubProcessResourceMode.SameWithRoot:
                    startupParams.ResourceID = this.Process.ResourceID;
                    break;

                case WfSubProcessResourceMode.NewCreate:
                    startupParams.ResourceID = UuidHelper.NewUuidString();
                    break;
                }
            }
            else
            {
                startupParams.ResourceID = branchStartupParams.ResourceID;
            }

            if (branchStartupParams.RelativeParams.Count == 0)
            {
                startupParams.RelativeParams.CopyFrom(this.Process.RelativeParams);
            }
            else
            {
                startupParams.RelativeParams.CopyFrom(branchStartupParams.RelativeParams);
            }

            startupParams.BranchStartupParams = branchStartupParams;
            startupParams.Group            = group;
            startupParams.OwnerActivityID  = this.ID;
            startupParams.OwnerTemplateKey = template.Key;
            startupParams.Sequence         = index;
            startupParams.AutoCommit       = this.Process.Committed; //子流程的提交属性默认等于主流程的

            branchStartupParams.ApplicationRuntimeParameters.ForEach(kp => startupParams.ApplicationRuntimeParameters.Add(kp.Key, kp.Value));

            //如果是串行执行,且不是第一个流程,则不启动第一个活动,子流程处于未启动状态
            if (template.ExecuteSequence == WfBranchProcessExecuteSequence.Serial && index > 0)
            {
                startupParams.AutoStartInitialActivity = false;
            }

            return(startupParams);
        }
Esempio n. 8
0
 /// <summary>
 /// 启动分支流程
 /// </summary>
 /// <param name="branchTransferParams">启动分支流程的参数,里面包括一个分支流程模板</param>
 public void StartupBranchProcesses(WfBranchProcessTransferParams branchTransferParams)
 {
     InternalStartupBranchProcesses(branchTransferParams, true);
 }
Esempio n. 9
0
        public WfStartBranchProcessExecutor(IWfActivity operatorActivity, IWfActivity ownerActivity, WfBranchProcessTransferParams branchTransferParams)
            : base(operatorActivity, WfControlOperationType.StartBranchProcess)
        {
            ownerActivity.NullCheck("ownerActivity");
            branchTransferParams.NullCheck("branchTransferParams");

            this.OwnerActivity        = ownerActivity;
            this.BranchTransferParams = branchTransferParams;

            if (this.OperatorActivity == null)
            {
                this.OperatorActivity = ownerActivity;
            }
        }