Exemple #1
0
        private WfProcessCollection LoadProcesses(Action <WhereSqlClauseBuilder> action)
        {
            action.NullCheck("action");

            var whereBuilder = new WhereSqlClauseBuilder();

            action(whereBuilder);

            var mapping = ORMapping.GetMappingInfo <WfProcessInstanceData>();

            string[] fields = ORMapping.GetSelectFieldsName(mapping, "Data");

            var sql = string.Format("SELECT {0},{1} FROM {2} WHERE {3}",
                                    string.Join(",", fields),
                                    BINARYDATA,
                                    mapping.TableName,
                                    whereBuilder.ToSqlString(TSqlBuilder.Instance));

            var table = DbHelper.RunSqlReturnDS(sql, GetConnectionName()).Tables[0];

            WfProcessCollection result = null;

            PerformanceMonitorHelper.GetDefaultMonitor().WriteExecutionDuration("DataTableToProcessCollection",
                                                                                () => result = DataTableToProcessCollection(table)
                                                                                );

            return(result);
        }
Exemple #2
0
        /// <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);
        }
Exemple #3
0
        /// <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);
        }
Exemple #4
0
        /// <summary>
        /// 调用外部服务。对方会返回一个或一组流程ID。本函数返回这组ID对应的流程。
        /// </summary>
        /// <param name="startupParams"></param>
        /// <param name="template"></param>
        /// <returns></returns>
        private WfProcessCollection InvokeBranchProcess(WfServiceStartupProcessParams startupParams, IWfBranchProcessTemplateDescriptor template)
        {
            this.Process.ApplicationRuntimeParameters["serviceOP_Paramas"] = startupParams;

            WfServiceInvoker svcInvoker = new WfServiceInvoker(template.OperationDefinition);

            object obj = svcInvoker.Invoke();

            WfProcessCollection processes          = new WfProcessCollection();
            WfBranchProcessTemplateDescriptor temp = template as WfBranchProcessTemplateDescriptor;

            IList array = obj as IList;

            if (array != null)
            {
                IWfProcess process = null;
                foreach (string processID in array)
                {
                    process = WfRuntime.GetProcessByProcessID(processID);
                    processes.Add(process);
                }

                temp.BranchProcessKey = process.Descriptor.Key;
            }
            else
            {
                IWfProcess process = WfRuntime.GetProcessByProcessID(obj.ToString());
                processes.Add(process);
                temp.BranchProcessKey = process.Descriptor.Key;
            }

            return(processes);
        }
Exemple #5
0
        /// <summary>
        /// 按照用户的相关性进行排序
        /// </summary>
        /// <param name="user"></param>
        /// <returns></returns>
        public WfProcessCollection SortByUserRelativity(IUser user)
        {
            List <WfProcessAndWeight> pws = new List <WfProcessAndWeight>();

            foreach (IWfProcess process in this)
            {
                int nWeight = 0;

                if (process.HasParentProcess == false)
                {
                    nWeight++;
                }

                if (user != null && process.CurrentActivity != null && process.CurrentActivity.Assignees.Contains(user))
                {
                    nWeight += 2;
                }

                pws.Add(new WfProcessAndWeight(nWeight, process));
            }

            pws.Sort((p1, p2) => p2.Weight - p1.Weight);

            WfProcessCollection result = new WfProcessCollection();

            pws.ForEach(pw => result.Add(pw.Process));

            return(result);
        }
Exemple #6
0
        /// <summary>
        /// 启动一个模版(组)下的一组分支流程,在服务模式下,可能返回多个流程。其它情况返回单个流程
        /// </summary>
        /// <param name="branchTransferParams"></param>
        /// <param name="group"></param>
        /// <param name="index"></param>
        /// <returns></returns>
        private WfProcessCollection StartupBranchProcess(WfBranchProcessTransferParams branchTransferParams, IWfBranchProcessGroup group, int index)
        {
            WfProcessCollection processes = null;

            if (branchTransferParams.Template.OperationDefinition == null)
            {
                WfProcessStartupParams startupParams = PrepareOneBranchProcessStartupParams(branchTransferParams, group, index);

                startupParams.CheckStartProcessUserPermission = false;

                processes = new WfProcessCollection();
                processes.Add(WfRuntime.StartWorkflow(startupParams));
            }
            else
            {
                if (WfRuntime.ProcessContext.EnableServiceCall)
                {
                    WfServiceStartupProcessParams startupParams = PrepareOneServiceStartupProcessParams(branchTransferParams, group, index);

                    processes = InvokeBranchProcess(startupParams, branchTransferParams.Template);
                }
                else
                {
                    processes = new WfProcessCollection();
                }
            }

            return(processes);
        }
Exemple #7
0
        public IWfProcess LoadProcessByActivityID(string activityID)
        {
            activityID.CheckStringIsNullOrEmpty("activityID");

            WfProcessCollection processes = LoadProcessesByActivityID(activityID);

            (processes.Count > 0).FalseThrow <WfRuntimeException>(Translator.Translate(Define.DefaultCulture, "不能找到ActivityID为{0}的流程", activityID));

            return(processes[0]);
        }
Exemple #8
0
        public IWfProcess LoadProcessByProcessID(string processID)
        {
            processID.CheckStringIsNullOrEmpty("processID");

            WfProcessCollection processes = LoadProcesses(builder => builder.AppendItem("INSTANCE_ID", processID));

            (processes.Count > 0).FalseThrow <WfRuntimeException>(Translator.Translate(Define.DefaultCulture, "不能找到ProcessID为{0}的流程", processID));

            return(processes[0]);
        }
Exemple #9
0
        /// <summary>
        /// 内部启动分支流程
        /// </summary>
        /// <param name="branchTransferParams">分支流程启动参数</param>
        /// <param name="addToOwnerBranches"></param>
        /// <returns></returns>
        internal WfProcessCollection InternalStartupBranchProcesses(WfBranchProcessTransferParams branchTransferParams, bool addToOwnerBranches)
        {
            WfProcessCollection processes = null;

            if (CanStartBranchProcessFromTemplate(branchTransferParams.Template))
            {
                IWfBranchProcessGroup group = this.BranchProcessGroups[branchTransferParams.Template.Key];

                //以模版Key为分支流程实例的分组标准
                if (group == null)
                {
                    group = new WfBranchProcessGroup(this, branchTransferParams.Template);
                    this.BranchProcessGroups.Add(group);
                }

                WfRuntime.ProcessContext.FirePrepareBranchProcessParams(group, branchTransferParams.BranchParams);

                ProcessProgress.Current.MaxStep += branchTransferParams.BranchParams.Count;
                ProcessProgress.Current.Response();

                //根据模板内的分支流程参数,逐一启动具体流程
                for (int i = 0; i < branchTransferParams.BranchParams.Count; i++)
                {
                    //processes = StartupBranchProcess(branchTransferParams, group, group.BranchProcessStatistics.MaxSequence++);
                    processes = StartupBranchProcess(branchTransferParams, group, i);

                    processes.ForEach(p =>
                    {
                        if (addToOwnerBranches)
                        {
                            if (group.Branches.Contains(p) == false)
                            {
                                group.Branches.Add(p);
                            }
                        }

                        WfRuntime.ProcessContext.FireAfterStartupBranchProcess(p);
                    });

                    ProcessProgress.Current.MaxStep = Math.Max(ProcessProgress.Current.MaxStep, ProcessProgress.Current.CurrentStep + processes.Count);
                    ProcessProgress.Current.IncrementBy(processes.Count);
                    ProcessProgress.Current.Response();
                }

                WfRuntime.ProcessContext.AffectedProcesses.AddOrReplace(this.Process);
            }

            if (processes == null)
            {
                processes = new WfProcessCollection();
            }

            return(processes);
        }
Exemple #10
0
        /// <summary>
        /// 根据流程实例,初始化统计值。主要用于分支流程的初始化
        /// </summary>
        /// <param name="processes"></param>
        internal void SyncProcessesStatus(WfProcessCollection processes)
        {
            this.Total += processes.Count;

            foreach (IWfProcess process in processes)
            {
                IncreaseByStatus(process.Status);
            }

            this.MaxSequence = processes.GetMaxSequence();
        }
Exemple #11
0
        /// <summary>
        /// 检查分支流程信息是否存在,且检查分支流程中是否有AllProcessesStatus
        /// </summary>
        internal void CheckProcessesStatusInBranches()
        {
            if (this.LoadingType == DataLoadingType.External)
            {
                if (this._Branches == null)
                {
                    this._Branches = new WfProcessCollection();

                    this._Branches.AllProcessesStatus = WfRuntime.GetProcessStatusByOwnerActivityID(this._OwnerActivity.ID, this.ProcessTemplate.Key, true);
                }
            }
        }
Exemple #12
0
        private static WfProcessCollection LoadBranches(string ownerActID, string templateKey, IWfBranchProcessGroup group)
        {
            WfProcessCollection branches = WfRuntime.GetProcessByOwnerActivityID(ownerActID, templateKey);

            foreach (WfProcess process in branches)
            {
                process.EntryInfo = group;
            }

            branches.Sort((p1, p2) => p1.Sequence - p2.Sequence);

            return(branches);
        }
Exemple #13
0
        /// <summary>
        /// 检查流程实例信息是否在Branches中
        /// </summary>
        private void CheckProcessInstancesInBranches()
        {
            if (this._Branches == null)
            {
                this._Branches = LoadBranches(this._OwnerActivity.ID, this.ProcessTemplate.Key, this);
            }
            else
            {
                if (this._Branches.AllProcessesStatus != null)
                {
                    if (this._Branches.AllProcessesStatus.Count > 0 && this._Branches.Count == 0)
                    {
                        WfProcessCollection processLoaded = LoadBranches(this._OwnerActivity.ID, this.ProcessTemplate.Key, this);

                        this._Branches.CopyFrom(processLoaded);
                    }
                }
            }
        }
Exemple #14
0
        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);
        }
Exemple #15
0
 protected override void OnModifyWorkflow(WfExecutorDataContext dataContext)
 {
     this.StartedProcesses = ((WfActivityBase)this.OwnerActivity).InternalStartupBranchProcesses(this.BranchTransferParams, false);
 }