Exemple #1
0
        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);
        }
 protected virtual void OnPersistWorkflow(WfExecutorDataContext dataContext)
 {
     WfRuntime.PersistWorkflows();
 }
Exemple #3
0
        /// <summary>
        /// 保存一个流程的数据,保存成功后,清除所有的缓存
        /// </summary>
        /// <param name="process"></param>
        public static void PersistWorkflows()
        {
            IWfProcessPersistManager persistManager = WorkflowSettings.GetConfig().GetPersistManager();

            WfActionParams actionParams = new WfActionParams(WfRuntime.ProcessContext);

            WfRuntime.ProcessContext.Acl.Distinct((a1, a2) => string.Compare(a1.ResourceID, a2.ResourceID, true) == 0 &&
                                                  string.Compare(a1.ObjectID, a2.ObjectID, true) == 0);

            PerformanceMonitorHelper.GetDefaultMonitor().WriteExecutionDuration("PersistWorkflows", () =>
            {
                CommonInfoMappingCollection cimItems = new CommonInfoMappingCollection();

                cimItems.FromProcesses(WfRuntime.ProcessContext.AffectedProcesses);

                using (TransactionScope scope = TransactionScopeFactory.Create())
                {
                    PerformanceMonitorHelper.GetDefaultMonitor().WriteExecutionDuration("DeletePendingActivities",
                                                                                        () => WfPendingActivityInfoAdapter.Instance.Delete(WfRuntime.ProcessContext.ReleasedPendingActivities));

                    PerformanceMonitorHelper.GetDefaultMonitor().WriteExecutionDuration("Update Acl",
                                                                                        () => WfAclAdapter.Instance.Update(WfRuntime.ProcessContext.Acl));

                    PerformanceMonitorHelper.GetDefaultMonitor().WriteExecutionDuration("Update CommonInfoMapping",
                                                                                        () => CommonInfoMappingAdapter.Instance.Update(cimItems));

                    //保存流程后再执行Actions
                    PerformanceMonitorHelper.GetDefaultMonitor().WriteExecutionDuration("PersistActions",
                                                                                        () => WfRuntime.ProcessContext.AffectedActions.PersistActions(actionParams));

                    ProcessProgress.Current.MaxStep += WfRuntime.ProcessContext.AffectedProcesses.Count;
                    ProcessProgress.Current.Response();

                    int i     = 0;
                    int total = WfRuntime.ProcessContext.AffectedProcesses.Count;

                    WfRuntime.ProcessContext.AffectedProcesses.ForEach(process =>
                    {
                        PerformanceMonitorHelper.GetDefaultMonitor().WriteExecutionDuration(
                            string.Format("PersistWorkflow: {0}", process.ID),
                            () => persistManager.SaveProcess(process));

                        i++;
                        ProcessProgress.Current.Increment();

                        ProcessProgress.Current.StatusText = Translator.Translate(Define.DefaultCulture, "保存了{0}/{1}条流程数据", i, total);
                        ProcessProgress.Current.Response();
                    });

                    //保存流程后再执行Actions
                    PerformanceMonitorHelper.GetDefaultMonitor().WriteExecutionDuration("AfterWorkflowPersistAction",
                                                                                        () => WfRuntime.ProcessContext.AffectedActions.AfterWorkflowPersistAction(actionParams));

                    ProcessProgress.Current.StatusText = string.Empty;
                    ProcessProgress.Current.Response();

                    scope.Complete();
                }
            });

            WfRuntime.ClearCache();
        }
Exemple #4
0
        private static IWfActivity LoadActivity(string ownerActID)
        {
            IWfProcess process = WfRuntime.GetProcessByActivityID(ownerActID);

            return(process.Activities[ownerActID]);
        }