Exemplo n.º 1
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);
        }
Exemplo n.º 2
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);
                    }
                }


            }
        }
Exemplo n.º 3
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);
                }
            }
        }