コード例 #1
0
ファイル: WfRuntime.cs プロジェクト: jerryshi2007/AK47Source
        public static IWfProcess StartWorkflow(WfProcessStartupParams startupParams)
        {
            startupParams.NullCheck<WfRuntimeException>("startupParams");

            WfProcess process = new WfProcess(startupParams.ProcessDescriptor);

            FillProcessDescriptorProperties(startupParams, process.Descriptor);
            FillProcessInstanceProperties(startupParams, process);

            WfProcessContextCache.Instance.Add(process.ID, process);

            if (process.Creator == null && DeluxePrincipal.IsAuthenticated)
                process.Creator = DeluxeIdentity.CurrentUser;

            if (process.InitialActivity != null)
            {
                if (process.InitialActivity.Descriptor.Properties.GetValue("AutoGenerateCadidates", true))
                {
                    process.InitialActivity.GenerateCandidatesFromResources();

                    WfMatrix matrix = process.GetMatrix();

                    if (matrix != null)
                        ((WfActivityBase)process.InitialActivity).GenerateCandidatesFromMatrix(matrix);
                }

                if (startupParams.CheckStartProcessUserPermission)
                    CheckStartProcessUserPermission(process);

                if (startupParams.Assignees.Count == 0)
                {
                    startupParams.Assignees.CopyFrom(process.InitialActivity.Candidates);
                }

                if (process.InitialActivity.Descriptor.Resources.Count == 0)
                {
                    startupParams.Assignees.ToUsers().ForEach(u => process.InitialActivity.Descriptor.Resources.Add(new WfUserResourceDescriptor(u)));
                }

                WfSimulator.WriteSimulationInfo(process, WfSimulationOperationType.Startup);

                //如果自动启动第一个活动且存在活动点,则流转到第一个点
                if (startupParams.AutoStartInitialActivity)
                {
                    WfAssigneeCollection assignees = startupParams.Assignees;
                    process.InitialActivity.Candidates.Clear();
                    process.InitialActivity.Candidates.CopyFrom(startupParams.Assignees);

                    IWfActivity originalInitial = process.InitialActivity;

                    WfRuntime.DecorateProcess(process);

                    //修饰流程后,如果起始点发生了变化...
                    if (originalInitial != process.InitialActivity)
                        assignees = process.InitialActivity.Candidates;

                    WfTransferParams transferParams = new WfTransferParams(process.InitialActivity.Descriptor);

                    //设置初始节点子流程参数
                    process.InitialActivity.Descriptor.BranchProcessTemplates.ForEach(branchTemplate =>
                    {
                        transferParams.BranchTransferParams.Add(new WfBranchProcessTransferParams(branchTemplate));
                    });

                    transferParams.Operator = startupParams.Creator;
                    transferParams.Assignees.CopyFrom(assignees);
                    process.MoveTo(transferParams);

                    WfRuntime.ProcessContext.NormalizeTaskTitles();
                }
            }

            WfRuntime.ProcessContext.AffectedProcesses.AddOrReplace(process);

            return process;
        }
コード例 #2
0
ファイル: WfRuntime.cs プロジェクト: jerryshi2007/AK47Source
        private static void FillProcessInstanceProperties(WfProcessStartupParams startupParams, WfProcess process)
        {
            process.ResourceID = startupParams.ResourceID;
            process.RelativeParams.CopyFrom(startupParams.RelativeParams);
            process.RelativeID = startupParams.RelativeID;
            process.RelativeURL = startupParams.RelativeURL;
            process.BranchStartupParams = startupParams.BranchStartupParams;
            process.EntryInfo = startupParams.Group;
            process.OwnerActivityID = startupParams.OwnerActivityID;
            process.OwnerTemplateKey = startupParams.OwnerTemplateKey;
            process.Sequence = startupParams.Sequence;
            process.ApplicationRuntimeParameters.CopyFrom(startupParams.ApplicationRuntimeParameters);
            process.Committed = startupParams.AutoCommit;

            process.OwnerDepartment = startupParams.Department;
            process.Creator = startupParams.Creator;
        }