Ejemplo n.º 1
0
        public IWfProcessPersistManager GetPersistManager()
        {
            if (this._PersistManager == null)
            {
                lock (this._PersistManagerSyncObj)
                {
                    if (this._PersistManager == null)
                    {
                        this._PersistManager = GetTypeInstance <IWfProcessPersistManager>("processPersistManager");
                    }
                }
            }

            return(this._PersistManager);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// 根据流程ID得到流程
        /// </summary>
        /// <param name="processID"></param>
        /// <returns></returns>
        public static IWfProcess GetProcessByProcessID(string processID)
        {
            processID.NullCheck <WfRuntimeException>("processID");

            IWfProcess result = WfProcessContextCache.Instance.GetOrAddNewValue(processID, (cache, key) =>
            {
                IWfProcess process = null;

                PerformanceMonitorHelper.GetDefaultMonitor().WriteExecutionDuration(string.Format("Load Process({0})", processID), () =>
                {
                    IWfProcessPersistManager persistManager = WorkflowSettings.GetConfig().GetPersistManager();

                    process = persistManager.LoadProcessByProcessID(key);

                    cache.Add(key, process);
                });

                return(process);
            });

            return(result);
        }
Ejemplo n.º 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();
        }