/// <summary> /// 执行一项队列操作 /// </summary> /// <param name="pq"></param> public void DoQueueOperation(WfPersistQueue pq) { pq.NullCheck("pq"); Dictionary <object, object> context = new Dictionary <object, object>(); IWfProcess process = WfRuntime.GetProcessByProcessID(pq.ProcessID); try { WfQueuePersistenceSettings.GetConfig().GetPersisters().SaveData(process, context); } finally { WfRuntime.ClearCache(); } }
/// <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(); }