コード例 #1
0
        /// <summary>
        /// 通过工作流实体的id获得工作流实体
        /// </summary>
        /// <param name="wfe_id"></param>
        /// <returns></returns>
        public static UI_WFEntity_Info GetWorkFlowEntiy(int wfe_id, bool FullInfo = false)
        {
            UI_WFEntity_Info wfe  = new UI_WFEntity_Info();
            WorkFlows        wfs  = new WorkFlows();
            WorkFlow_Entity  wfe1 = wfs.GetWorkFlowEntity(wfe_id);

            if (FullInfo)
            {
                CWorkFlow   wf  = new CWorkFlow();
                XmlDocument doc = new XmlDocument();
                doc.LoadXml(Encoding.Default.GetString(wfe1.WE_Binary));
                XmlNode xml = doc.DocumentElement;
                wf.ParaseBaseInfo(xml);
                WorkFlow_Define wfd = wfs.GetWorkFlowDefine(wfe_id);
                //wfe.name = wfd.W_Name;
                //wfe.description = wfd.W_Attribution;
                wfe.Binary      = Encoding.Default.GetString(wfe1.WE_Binary);
                wfe.name        = wf.name;
                wfe.description = wf.description;
            }

            wfe.EntityID       = wfe1.WE_Id;
            wfe.serial         = wfe1.WE_Ser;
            wfe.Status         = wfe1.WE_Status;
            wfe.Last_TransTime = wfe1.Last_Trans_Time;
            return(wfe);
        }
コード例 #2
0
        //fhp添加方法结束-----

        /// <summary>
        /// 或的工作流的信息以及指定变量的值
        /// </summary>
        /// <param name="wfe_id">工作流实体ID</param>
        /// <param name="paras">变量列表
        /// 例如: 要获得工作流(ID 为 4)的Equip_GyCode的当前值,则:
        /// Dictionary paras = new Dictionary();
        /// paras["Equip_GyCode"] = null;
        /// UI_WFEntity_Info wfei = GetWorkFlowEntityWithParams(4, paras);
        ///
        /// 调用完成后, wfei返回了 name, description, EntityID, serial, Status
        /// 而paras["Equip_GyCode"] 将会被设置为正确值
        /// </param>
        /// <returns></returns>
        public static UI_WFEntity_Info GetWorkFlowEntityWithParams(int wfe_id, IDictionary <string, object> paras)
        {
            UI_WFEntity_Info wfe  = new UI_WFEntity_Info();
            WorkFlows        wfs  = new WorkFlows();
            WorkFlow_Entity  wfe1 = wfs.GetWorkFlowEntity(wfe_id);

            CWorkFlow   wf  = new CWorkFlow();
            XmlDocument doc = new XmlDocument();

            doc.LoadXml(Encoding.Default.GetString(wfe1.WE_Binary));
            XmlNode xml = doc.DocumentElement;

            wf.ParaseBaseInfo(xml);
            wf.ParseParams(xml.SelectSingleNode("paramtable"));

            Dictionary <string, object> _tmp = new Dictionary <string, object>(paras);

            foreach (var par in _tmp)
            {
                paras[par.Key] = wf.paramstable[par.Key].value;
            }


            wfe.name        = wf.name;
            wfe.description = wf.description;
            wfe.EntityID    = wf.EntityID;
            wfe.serial      = wf.EntitySerial;
            wfe.Status      = wfe1.WE_Status;
            return(wfe);
        }
コード例 #3
0
        //创建一个工作流
        public static UI_WorkFlow_Entity CreateAWFEntityByName(string wf_name, string Ser_Num = null)
        {
            CWorkFlow wf = new CWorkFlow();

            if (!wf.CreateEntity(wf_name, Ser_Num))
            {
                return(null);
            }

            return(wf);
        }
コード例 #4
0
        public static CWorkFlow CreateWFEntityModifiedTimeOut(string wf_name, string event_name, CTimeOutProperty property, string Ser_Num = null /*2016/2/12--保证子工作流串号与父工作流相同*/)
        {
            CWorkFlow wf = new CWorkFlow();

            WorkFlows wfs = new WorkFlows();

            XmlDocument     doc    = new XmlDocument();
            WorkFlow_Define define = wfs.GetWorkFlowDefine(wf_name);

            doc.LoadXml(Encoding.Default.GetString(define.W_Xml));
            wf.InstFromXmlNode((XmlNode)doc.DocumentElement);

            //修改wf
            IEvent           ev_target   = wf.events[event_name];
            CTimeOutProperty timeout_pro = ev_target.GetTimeOutProperty();

            timeout_pro.ExactTime  = property.ExactTime;
            timeout_pro.StartTime  = property.StartTime;
            timeout_pro.TimeOffset = property.TimeOffset;

            WorkFlow_Entity wfe = new WorkFlow_Entity();

            wfe.WE_Status = WE_STATUS.CREATED;
            wfe.WE_Binary = Encoding.Default.GetBytes(wf.WriteToXmlNode().OuterXml);

            if (Ser_Num == null)
            {
                wfe.WE_Ser = "";
            }
            else
            {
                wfe.WE_Ser = Ser_Num;
            }

            if (!wfs.AddWorkEntity(wf_name, wfe))
            {
                return(null);
            }

            wf.EntityID     = wfe.WE_Id;
            wf.EntitySerial = wfe.WE_Ser;
            wf.DefineID     = define.W_ID;



            wf.RegEventsTimeOut(true);

            return(wf);
        }
コード例 #5
0
        /// <summary>
        /// 检查SubProcess的状态
        /// </summary>
        private void CheckSubEventStatus()
        {
            //如果当前状态是SubProcess, 则要检测子时间是否已经执行完毕,
            //若已经执行完毕,则需要将返回值从子事件中取回
            if (m_events[m_courrentEvent].GetType().Name == "CSubProcessEvent")
            {
                CSubProcessEvent subE = (CSubProcessEvent)(m_events[m_courrentEvent]);
                WorkFlows wfs = new WorkFlows();

                WorkFlow_Entity wfe = wfs.GetWorkFlowEntity(subE.WfEntityId);
                //自流程已执行完成
                if (wfe.WE_Status == WE_STATUS.DONE)
                {
                    CWorkFlow subWf = new CWorkFlow();
                    XmlDocument doc = new XmlDocument();
                    doc.LoadXml(Encoding.Default.GetString(wfs.GetWorkFlowEntity(subE.WfEntityId).WE_Binary));
                    subWf.InstFromXmlNode(doc.DocumentElement);
                    subWf.EntityID = subE.WfEntityId;

                    IEvent subEnd = subWf.GetCurrentEvent();
                    //将变量返回回来
                    foreach (var p in subE.m_paramsFrom)
                    {
                        subE.paramlist[p.Key].value = subEnd.paramlist[p.Value].value;
                    }
                    //若子工作流的工作方式为串行, 则父工作流在子流程完成后继续向下执行
                    if (subE.WorkingMode == "serial")
                    {
                        StateTransfer("");
                        if (m_events[m_courrentEvent].GetType().Name == "CEndEvent")
                        {
                            //将该工作流置为已完成(结束)
                            UpdateEntity(WE_STATUS.DONE);
                            //2016.1.3 添加子事件返回

                        }
                        else
                            //更新工作流到数据库,不改变状态
                            UpdateEntity(WE_STATUS.INVALID);
                    }
                }


            }
        }
コード例 #6
0
        /// <summary>
        /// 获取某一工作流实体的历史任务
        /// </summary>
        /// <param name="entity_id">工作流实体ID</param>
        /// <returns></returns>
        public static List <UI_MISSION> GetHistoryMissions(int entity_id)
        {
            List <UI_MISSION> his_miss = new List <UI_MISSION>();

            WorkFlows      wfs     = new WorkFlows();
            List <Mission> db_miss = wfs.GetWFEntityMissions(entity_id);

            WorkFlow_Entity wfe = wfs.GetWorkFlowEntity(entity_id);
            //恢复工作流实体
            CWorkFlow   wf  = new CWorkFlow();
            XmlDocument doc = new XmlDocument();

            doc.LoadXml(Encoding.Default.GetString(wfe.WE_Binary));
            wf.EntityID = wfe.WE_Id;
            wf.InstFromXmlNode(doc.DocumentElement);


            foreach (var mi in db_miss)
            {
                UI_MISSION ui_mi = new UI_MISSION();
                ui_mi.WE_Entity_Id  = entity_id;
                ui_mi.WE_Entity_Ser = wfe.WE_Ser;
                ui_mi.WE_Event_Desc = mi.Miss_Desc;
                ui_mi.WE_Event_Name = mi.Event_Name;
                ui_mi.WE_Name       = mi.Miss_Name;
                ui_mi.Mission_Url   = ""; //历史任务的页面至空
                ui_mi.Miss_Id       = mi.Miss_Id;

                List <Mission_Param> mis_pars = wfs.GetMissParams(mi.Miss_Id);
                foreach (var par in mis_pars)
                {
                    CParam cp = new CParam();
                    cp.type                          = par.Param_Type;
                    cp.name                          = par.Param_Name;
                    cp.value                         = par.Param_Value;
                    cp.description                   = par.Param_Desc;
                    ui_mi.Miss_Params[cp.name]       = cp.value;
                    ui_mi.Miss_ParamsAppRes[cp.name] = wf.paramstable[cp.name].linkEventsApp_res[ui_mi.WE_Event_Name];
                    ui_mi.Miss_ParamsDesc[cp.name]   = cp.description;//xwm modified
                }
                his_miss.Add(ui_mi);
            }
            return(his_miss);
        }
コード例 #7
0
        //fhp添加方法开始----

        public static UI_WFEntity_Info GetMainWorkFlowEntity(string wfe_ser)
        {
            UI_WFEntity_Info wfe  = new UI_WFEntity_Info();
            WorkFlows        wfs  = new WorkFlows();
            WorkFlow_Entity  wfe1 = wfs.GetMainWorkFlowEntity(wfe_ser);

            CWorkFlow   wf  = new CWorkFlow();
            XmlDocument doc = new XmlDocument();

            doc.LoadXml(Encoding.Default.GetString(wfe1.WE_Binary));
            wf.InstFromXmlNode(doc.DocumentElement);
            wfe.description = wf.description;
            wfe.name        = wf.name;

            wfe.EntityID = wfe1.WE_Id;
            wfe.serial   = wfe1.WE_Ser;
            wfe.Status   = wfe1.WE_Status;
            return(wfe);
        }
コード例 #8
0
        //获得工作流实体的当前任务
        public static UI_MISSION GetActiveMission <T>(int entity_id, ObjectContext oc, bool bAuthCheck = true)
        {
            UI_MISSION miss = new UI_MISSION();

            WorkFlows wfs = new WorkFlows();

            WorkFlow_Entity wfe = wfs.GetWorkFlowEntity(entity_id);

            miss.WE_Entity_Id  = wfe.WE_Id;
            miss.WE_Name       = wfs.GetWorkFlowEntityName(wfe.WE_Id);
            miss.WE_Entity_Ser = wfe.WE_Ser;

            //恢复工作流实体
            CWorkFlow   wf  = new CWorkFlow();
            XmlDocument doc = new XmlDocument();

            doc.LoadXml(Encoding.Default.GetString(wfe.WE_Binary));
            wf.InstFromXmlNode(doc.DocumentElement);
            wf.EntityID = wfe.WE_Id;
            //权限验证
            if (bAuthCheck)
            {
                IEvent ev = wf.GetCurrentEvent();
                if (!ev.CheckAuthority <T>((Dictionary <string, object>)HttpContext.Current.Session[authority_params], oc))
                {
                    return(null);
                }
            }

            miss.WE_Event_Name = wf.GetCurrentEvent().name;
            miss.WE_Event_Desc = wf.GetCurrentEvent().description;
            miss.Mission_Url   = wf.CurrentEventLink();
            //读取参数的值
            foreach (var pa in wf.GetCurrentEvent().paramlist)
            {
                miss.Miss_Params[pa.Key]       = pa.Value.value;
                miss.Miss_ParamsAppRes[pa.Key] = wf.GetCurrentEvent().paramsApp_res[pa.Key];
            }

            return(miss);
        }
コード例 #9
0
        private static void UpdateEntity(CWorkFlow wf, WE_STATUS status)
        {
            try
            {
                WorkFlow_Entity wfe = new WorkFlow_Entity
                {
                    WE_Id     = wf.EntityID,
                    WE_Status = status
                };
                wfe.WE_Binary = Encoding.Default.GetBytes(wf.WriteToXmlNode().OuterXml);

                WorkFlows wfs = new WorkFlows();
                if (!wfs.SaveWorkFlowEntity(wfe))
                {
                    throw new Exception("Save WorkFlow Entity failed!");
                }
            }
            catch (Exception e)
            {
                return;
            }
        }
コード例 #10
0
        //发送消息到工作流
        public static void SubmitSignal(int wfe_id, IDictionary <string, string> signal, IDictionary <string, string> record = null)
        {
            WorkFlows       wfs = new WorkFlows();
            WorkFlow_Entity wfe = wfs.GetWorkFlowEntity(wfe_id);

            //如果该工作流处于非激活状态,则不能向其发送信息
            if (wfe.WE_Status != WE_STATUS.ACTIVE)
            {
                return;
            }

            CWorkFlow   wf  = new CWorkFlow();
            XmlDocument doc = new XmlDocument();

            doc.LoadXml(Encoding.Default.GetString(wfe.WE_Binary));
            wf.InstFromXmlNode(doc.DocumentElement);
            wf.EntityID = wfe.WE_Id;

            string preState = wf.GetCurrentState();

            JArray ja = new JArray();

            foreach (var s in signal)
            {
                JObject jo = new JObject();
                jo.Add("name", s.Key);
                jo.Add("value", s.Value);
                ja.Add(jo);
            }
            wf.SubmitSignal(JsonConvert.SerializeObject(ja));
            //如果preEvent为subprocess
            IEvent preEvent = wf.GetCurrentEvent();

            if (preEvent.GetType().Name == "CSubProcessEvent")
            {
                Post_processSubprocess(preEvent, record);
                //wf.SubmitSignal("[]");
            }


            //状态发生了迁移
            if (wf.GetCurrentState() != preState)
            {
                if (record != null)
                {
                    Mission ms = wfs.GetWFEntityLastMission(wf.EntityID);

                    List <Process_Record> res = new List <Process_Record>();
                    foreach (var re in record)
                    {
                        //如果record中包含事件定义的需要记录的record item则记录到数据库中
                        if (wf.GetRecordItems().ContainsKey(re.Key))
                        {
                            Process_Record pre = new Process_Record();
                            pre.Re_Name  = re.Key;
                            pre.Re_Value = re.Value;
                            res.Add(pre);
                        }
                    }
                    wfs.LinkRecordInfoToMiss(ms.Miss_Id, res);
                }
                //如果当前工作流是子流程,且已执行到End
                if (wf.GetCurrentEvent().GetType().Name == "CEndEvent" && wf.ParentEntityID != -1)
                {
                    WorkFlow_Entity P_wfe = wfs.GetWorkFlowEntity(wf.ParentEntityID);

                    CWorkFlow   P_wf  = new CWorkFlow();
                    XmlDocument P_doc = new XmlDocument();
                    P_doc.LoadXml(Encoding.Default.GetString(P_wfe.WE_Binary));
                    P_wf.InstFromXmlNode(P_doc.DocumentElement);
                    P_wf.EntityID = P_wfe.WE_Id;
                    P_wf.GetCurrentState();
                }
            }

            //如果当前时间为subprocess
            if (preEvent.GetType().Name == "CSubProcessEvent")
            {
                //如果该子事件的工作模式为并行的, 则需要发送一个信号,激励其自动运行一次
                if (((CSubProcessEvent)preEvent).WorkingMode == "parallel")
                {
                    SubmitSignal(wfe_id, new Dictionary <string, string>(), record);
                }
            }
        }