private static WfGlobalParameters LoadFromDB(string key) { string sql = string.Format("SELECT [PROPERTIES] FROM WF.GLOBAL_PARAMETERS WHERE {0}", GetWhereSqlClauseBuilder(key).ToSqlString(TSqlBuilder.Instance)); WfGlobalParameters result = null; string properties = (string)DbHelper.RunSqlReturnScalar(sql, WorkflowSettings.GetConfig().ConnectionName); if (properties.IsNotEmpty()) { XElementFormatter formatter = new XElementFormatter(); formatter.OutputShortType = WorkflowSettings.GetConfig().OutputShortType; XElement root = XElement.Parse(properties); object deserializedData = formatter.Deserialize(root); if (deserializedData is PropertyValueCollection) { result = new WfGlobalParameters(); result.Key = key; result._Properties = (PropertyValueCollection)deserializedData; } else { result = (WfGlobalParameters)deserializedData; } } return(result); }
internal static XElementFormatter CreateFormatter() { XElementFormatter formatter = new XElementFormatter(); formatter.OutputShortType = WorkflowSettings.GetConfig().OutputShortType; return(formatter); }
public static IWfProcessDescriptor LoadDescriptor(string processKey) { IWfProcessDescriptor processDesp = GetDefaultProcessDescriptor(processKey); processDesp = processDesp ?? WorkflowSettings.GetConfig().GetDescriptorManager().LoadDescriptor(processKey); return(processDesp); }
public static WfProcessDescriptorInfo FromProcessDescriptor(IWfProcessDescriptor processDesp) { XElementFormatter formatter = new XElementFormatter(); formatter.OutputShortType = WorkflowSettings.GetConfig().OutputShortType; XElement root = formatter.Serialize(processDesp); return(FromProcessDescriptor(processDesp, root)); }
public IWfProcessDescriptor Clone() { XElementFormatter formatter = new XElementFormatter(); formatter.OutputShortType = WorkflowSettings.GetConfig().OutputShortType; formatter.FieldCanXElementSerialize += new FieldCanXElementSerializeHandler(formatter_FieldCanXElementSerialize); XElement root = formatter.Serialize(this); return((IWfProcessDescriptor)formatter.Deserialize(root)); }
public static IWfProcessDescriptor GetDescriptor(string processKey) { IWfProcessDescriptor processDesp = WfRuntime.ProcessContext.FireGetProcessDescriptor(processKey); processDesp = processDesp ?? GetDefaultProcessDescriptor(processKey); processDesp = processDesp ?? WorkflowSettings.GetConfig().GetDescriptorManager().GetDescriptor(processKey); return(processDesp); }
/// <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); }
/// <summary> /// 从流程对象生成入库的对象 /// </summary> /// <param name="process"></param> /// <returns></returns> public static WfProcessInstanceData FromProcess(IWfProcess process) { process.NullCheck("process"); WfProcessInstanceData instanceData = new WfProcessInstanceData(); instanceData.InstanceID = process.ID; instanceData.ResourceID = process.ResourceID; instanceData.Status = process.Status; instanceData.StartTime = process.StartTime; instanceData.EndTime = process.EndTime; instanceData.ApplicationName = process.Descriptor.ApplicationName; instanceData.ProcessName = GetRuntimeProcessName(process); process.RuntimeProcessName = instanceData.ProcessName; instanceData.DescriptorKey = process.Descriptor.Key; instanceData.ProgramName = process.Descriptor.ProgramName; instanceData._Creator = process.Creator; instanceData._Department = process.OwnerDepartment; instanceData.Sequence = process.Sequence; instanceData.OwnerActivityID = ((WfProcess)process).OwnerActivityID; instanceData.OwnerTemplateKey = ((WfProcess)process).OwnerTemplateKey; instanceData.Committed = process.Committed; instanceData.ExtData = process.Context.GetValue("SerilizationExtData", GetDefaultExtData(process)); XElementFormatter formatter = new XElementFormatter(); formatter.OutputShortType = WorkflowSettings.GetConfig().OutputShortType; instanceData.Data = formatter.Serialize(process).ToString(); if (process.CurrentActivity != null) { instanceData.CurrentActivityID = process.CurrentActivity.ID; } return(instanceData); }
public void Update() { XElementFormatter formatter = new XElementFormatter(); formatter.OutputShortType = WorkflowSettings.GetConfig().OutputShortType; string properties = formatter.Serialize(this).ToString(); string updateSQL = string.Format("UPDATE WF.GLOBAL_PARAMETERS SET [PROPERTIES] = {0} WHERE {1}", TSqlBuilder.Instance.CheckQuotationMark(properties, true), GetWhereSqlClauseBuilder(this.Key).ToSqlString(TSqlBuilder.Instance)); using (DbContext context = DbContext.GetContext(WorkflowSettings.GetConfig().ConnectionName)) { using (TransactionScope scope = TransactionScopeFactory.Create()) { if (DbHelper.RunSql(updateSQL, WorkflowSettings.GetConfig().ConnectionName) == 0) { InsertSqlClauseBuilder iBuilder = new InsertSqlClauseBuilder(); iBuilder.AppendItem("[KEY]", this.Key); iBuilder.AppendItem("[PROPERTIES]", properties); iBuilder.AppendTenantCode(typeof(WfGlobalParameters)); string insertSQL = string.Format("INSERT INTO WF.GLOBAL_PARAMETERS {0}", iBuilder.ToSqlString(TSqlBuilder.Instance)); DbHelper.RunSql(insertSQL, WorkflowSettings.GetConfig().ConnectionName); } scope.Complete(); } } CacheNotifyData notifyData = new CacheNotifyData(typeof(WfGlobalParametersCache), CalculateCacheKey(this.Key), CacheNotifyType.Invalid); UdpCacheNotifier.Instance.SendNotifyAsync(notifyData); MmfCacheNotifier.Instance.SendNotify(notifyData); }
private static string GetConnectionName() { return(WfRuntime.ProcessContext.SimulationContext.GetConnectionName(WorkflowSettings.GetConfig().ConnectionName)); }
private static WfProcessCollection DataTableToProcessCollection(DataTable table) { WfProcessCollection result = new WfProcessCollection(); XElementFormatter formatter = new XElementFormatter(); formatter.OutputShortType = WorkflowSettings.GetConfig().OutputShortType; foreach (DataRow row in table.Rows) { WfProcessInstanceData instanceData = new WfProcessInstanceData(); ORMapping.DataRowToObject(row, instanceData); XElement extData = GetExtData(instanceData.ExtData); Encoding originalEncoding = GetEncodingFromExtData(extData); Encoding preferedEncoding = originalEncoding; byte[] decompressedData = null; if (null != instanceData.BinaryData) { PerformanceMonitorHelper.GetDefaultMonitor().WriteExecutionDuration(string.Format("Extra Process Data:{0}", instanceData.InstanceID), () => decompressedData = CompressManager.ExtractBytes(instanceData.BinaryData)); PerformanceMonitorHelper.GetDefaultMonitor().WriteExecutionDuration("EncodeProcessString", () => { preferedEncoding = GetPreferedEncoding(decompressedData, originalEncoding); instanceData.Data = BytesToProcessData(decompressedData, preferedEncoding); } ); } else { (instanceData.Data != null).FalseThrow <ArgumentException>(Translator.Translate(Define.DefaultCulture, "流程实例表的Data和BinaryData都为空")); } XElement root = null; try { root = XElement.Parse(instanceData.Data); } catch (System.Xml.XmlException) { if (decompressedData != null) { instanceData.Data = ChangeEncoding(decompressedData, preferedEncoding); root = XElement.Parse(instanceData.Data); } else { throw; } } extData.SetAttributeValue("encoding", originalEncoding.BodyName); WfProcess process = null; PerformanceMonitorHelper.GetDefaultMonitor().WriteExecutionDuration(string.Format("Deserialize Process:{0}", instanceData.InstanceID), () => process = (WfProcess)formatter.Deserialize(root)); process.LoadingType = DataLoadingType.External; process.Activities.ForEach(a => { ((WfActivityBase)a).LoadingType = DataLoadingType.External; WfActivityBuilderBase.LoadActions(a); }); process.UpdateTag = instanceData.UpdateTag; process.Context["SerilizationExtData"] = extData.ToString(); result.Add(process); } return(result); }
public void SaveProcess(IWfProcess process) { WfProcessInstanceData instanceData = WfProcessInstanceData.FromProcess(process); if (instanceData.Data.IsNotEmpty()) { if (WorkflowSettings.GetConfig().Compressed) { XElement extData = GetExtData(instanceData.ExtData); PerformanceMonitorHelper.GetDefaultMonitor().WriteExecutionDuration("CompressProcess", () => { instanceData.BinaryData = GetCompressedStream(instanceData.Data, Encoding.GetEncoding(extData.Attribute("encoding", "utf-8"))); instanceData.Data = string.Empty; }); } } string sql = string.Empty; ORMappingItemCollection mapping = ORMapping.GetMappingInfo <WfProcessInstanceData>(); if (process.LoadingType == DataLoadingType.External) { UpdateSqlClauseBuilder uBuilder = ORMapping.GetUpdateSqlClauseBuilder(instanceData, mapping); uBuilder.AppendItem("UPDATE_TAG", "UPDATE_TAG + 1", "=", true); uBuilder.AppendTenantCode(); WhereSqlClauseBuilder whereBuilder = ORMapping.GetWhereSqlClauseBuilderByPrimaryKey(instanceData, mapping); whereBuilder.AppendItem("UPDATE_TAG", process.UpdateTag); sql = string.Format("UPDATE {0} SET {1} WHERE {2}", mapping.TableName, uBuilder.ToSqlString(TSqlBuilder.Instance), whereBuilder.ToSqlString(TSqlBuilder.Instance)); } else { InsertSqlClauseBuilder iBuilder = ORMapping.GetInsertSqlClauseBuilder(instanceData, mapping); iBuilder.AppendTenantCode(); sql = string.Format("INSERT INTO {0} {1}", mapping.TableName, iBuilder.ToSqlString(TSqlBuilder.Instance)); } Dictionary <object, object> context = new Dictionary <object, object>(); using (TransactionScope scope = TransactionScopeFactory.Create()) { PerformanceMonitorHelper.GetDefaultMonitor().WriteExecutionDuration("WriteProcessToDB", () => (DbHelper.RunSql(sql, GetConnectionName()) > 0).FalseThrow <WfRuntimeException>( Translator.Translate(Define.DefaultCulture, "更新流程{0}失败,流程状态已经改变", process.ID)) ); PerformanceMonitorHelper.GetDefaultMonitor().WriteExecutionDuration("WriteProcessActivitiesToDB", () => WfProcessCurrentActivityAdapter.Instance.UpdateProcessActivities(process)); PerformanceMonitorHelper.GetDefaultMonitor().WriteExecutionDuration("WriteRelativeProcessInfoToDB", () => { WfRelativeProcessAdapter.Instance.Delete(new WfRelativeProcess() { ProcessID = process.ID }); if (process.RelativeID.IsNotEmpty()) { WfRelativeProcessAdapter.Instance.Update(new WfRelativeProcess() { Description = string.IsNullOrEmpty(process.Descriptor.Description) ? process.Descriptor.Name : process.Descriptor.Description, ProcessID = process.ID, RelativeID = process.RelativeID, RelativeURL = process.RelativeURL }); } }); if (WorkflowSettings.GetConfig().SaveRelativeData) { PerformanceMonitorHelper.GetDefaultMonitor().WriteExecutionDuration("WriteRelativeDataToDB", () => WfExtraPersistenceSettings.GetConfig().GetPersisters().SaveData(process, context)); } scope.Complete(); } }
/// <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(); }
/// <summary> /// 根据ResourceID删除流程 /// </summary> /// <param name="resourceID"></param> public static void DeleteProcessByResourceID(string resourceID) { WorkflowSettings.GetConfig().GetPersistManager().DeleteProcessByResourceID(resourceID); }
/// <summary> /// 根据ActivityID删除流程 /// </summary> /// <param name="activityID"></param> public static void DeleteProcessByActivityID(string activityID) { WorkflowSettings.GetConfig().GetPersistManager().DeleteProcessByActivityID(activityID); }
/// <summary> /// 根据流程ID删除流程 /// </summary> /// <param name="processID"></param> public static void DeleteProcessByProcessID(string processID) { WorkflowSettings.GetConfig().GetPersistManager().DeleteProcessByProcessID(processID); }
/// <summary> /// 根据ResourceID得到流程 /// </summary> /// <param name="resourceID"></param> /// <returns></returns> public static WfProcessCollection GetProcessByResourceID(string resourceID) { resourceID.NullCheck <WfRuntimeException>("resourceID"); WfProcessCollection processes = new WfProcessCollection(); foreach (KeyValuePair <string, IWfProcess> kp in WfProcessContextCache.Instance) { if (string.Compare(kp.Value.ResourceID, resourceID, true) == 0) { processes.Add(kp.Value); break; } } WfProcessCollection persistedProcesses = null; PerformanceMonitorHelper.GetDefaultMonitor().WriteExecutionDuration(string.Format("LoadProcessByResourceID({0})", resourceID), () => persistedProcesses = WorkflowSettings.GetConfig().GetPersistManager().LoadProcessByResourceID(resourceID) ); persistedProcesses.ForEach(p => { if (processes.ContainsKey(p.ID) == false) { processes.Add(p); } WfProcessContextCache.Instance[p.ID] = p; }); return(processes); }
/// <summary> /// 根据ActivityID得到流程 /// </summary> /// <param name="activityID"></param> /// <returns></returns> public static IWfProcess GetProcessByActivityID(string activityID) { activityID.NullCheck <WfRuntimeException>("activityID"); IWfProcess process = null; foreach (KeyValuePair <string, IWfProcess> kp in WfProcessContextCache.Instance) { if (kp.Value.Activities.ContainsKey(activityID)) { process = kp.Value; break; } } if (process == null) { PerformanceMonitorHelper.GetDefaultMonitor().WriteExecutionDuration(string.Format("LoadProcessByActivityID({0})", activityID), () => process = WorkflowSettings.GetConfig().GetPersistManager().LoadProcessByActivityID(activityID) ); WfProcessContextCache.Instance.Add(process.ID, process); } return(process); }
/// <summary> /// 得到某个活动的子流程的状态信息,没有流程实例,只是状态信息 /// </summary> /// <param name="activityID"></param> /// <param name="templateKey"></param> /// <param name="includeAborted">是否包含已经作废的流程</param> /// <returns></returns> public static WfProcessCurrentInfoCollection GetProcessStatusByOwnerActivityID(string activityID, string templateKey, bool includeAborted) { activityID.CheckStringIsNullOrEmpty("activityID"); WfProcessCurrentInfoCollection queryResult = null; PerformanceMonitorHelper.GetDefaultMonitor().WriteExecutionDuration(string.Format("LoadProcessByOwnerActivityID({0}-{1})", activityID, templateKey), () => queryResult = WorkflowSettings.GetConfig().GetPersistManager().LoadProcessInfoOwnerActivityID(activityID, templateKey, includeAborted) ); return(queryResult); }
protected override string GetConnectionName() { return(WfRuntime.ProcessContext.SimulationContext.GetConnectionName(WorkflowSettings.GetConfig().ConnectionName)); }
public static void ClearAll() { WorkflowSettings.GetConfig().GetDescriptorManager().ClearAll(); }
public static void DeleteDescriptor(string processKey) { WorkflowSettings.GetConfig().GetDescriptorManager().DeleteDescriptor(processKey); }
public static bool ExsitsProcessKey(string processKey) { return(WorkflowSettings.GetConfig().GetDescriptorManager().ExsitsProcessKey(processKey)); }
public static void SaveDescriptor(IWfProcessDescriptor processDesp) { WorkflowSettings.GetConfig().GetDescriptorManager().SaveDescriptor(processDesp); }
protected override string GetConnectionName() { return(WorkflowSettings.GetConfig().ConnectionName); }
/// <summary> /// 得到某个活动的子流程。如果缓存中存在,则使用缓存中的流程 /// </summary> /// <param name="activityID"></param> /// <param name="templateKey"></param> /// <returns></returns> public static WfProcessCollection GetProcessByOwnerActivityID(string activityID, string templateKey) { activityID.CheckStringIsNullOrEmpty("activityID"); templateKey.CheckStringIsNullOrEmpty("templateKey"); WfProcessCollection queryResult = null; PerformanceMonitorHelper.GetDefaultMonitor().WriteExecutionDuration(string.Format("LoadProcessByOwnerActivityID({0}-{1})", activityID, templateKey), () => queryResult = WorkflowSettings.GetConfig().GetPersistManager().LoadProcessByOwnerActivityID(activityID, templateKey) ); WfProcessCollection result = new WfProcessCollection(); foreach (IWfProcess process in queryResult) { //如果缓存中存在,则使用缓存的数据,如果缓存中不存在,则使用查询到的结果 IWfProcess processNeedToAdd = WfProcessContextCache.Instance.GetOrAddNewValue(process.ID, (cache, key) => { cache.Add(key, process); return(process); }); result.Add(processNeedToAdd); } return(result); }