Ejemplo n.º 1
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);
        }
Ejemplo n.º 2
0
        public bool CreateEntity(string wf_name, string Ser_Num = null/*2016/2/12--保证子工作流串号与父工作流相同*/)
        {
            WorkFlows wfs = new WorkFlows();

            XmlDocument doc = new XmlDocument();
            WorkFlow_Define define = wfs.GetWorkFlowDefine(wf_name);
            doc.LoadXml(Encoding.Default.GetString(define.W_Xml));
            InstFromXmlNode((XmlNode)doc.DocumentElement);

           

            WorkFlow_Entity wfe = new WorkFlow_Entity();
            wfe.WE_Status = WE_STATUS.CREATED;
            wfe.WE_Binary = Encoding.Default.GetBytes(WriteToXmlNode().OuterXml);
            
                //wfe.Create_Info = SaveCreateRecord();
            //2016/2/12 --保证子工作流串号与父工作流相同
            if (Ser_Num == null)
                wfe.WE_Ser = "";
            else
                wfe.WE_Ser = Ser_Num;            

            if (!wfs.AddWorkEntity(wf_name, wfe))
                return false;

            m_entityID = wfe.WE_Id;
            m_entitySerial = wfe.WE_Ser;
            m_defineID = define.W_ID;

            RegEventsTimeOut(true);   
            return true;

        }
Ejemplo n.º 3
0
        /// <summary>
        /// 添加一条任务记录到数据库
        /// </summary>
        /// <param name="wfEntityId">工作流实体的ID</param>
        /// <param name="miss">新任务</param>        
        /// <returns>操作成功返回true,否则返回false</returns>
        public bool AddMissionRecord(int wfEntityId, Mission miss)
        {
            using (var db = base.NewDB())
            {
                //查找wfEntityId的工作流实体
                WorkFlow_Entity wfe = db.workflow_entities.Where(s => s.WE_Id == wfEntityId).First();
                if (wfe == null)
                    return false;

                if (wfe.Process_Info.Count == 0)
                {
                    miss.next_Mission = null;
                    miss.pre_Mission = null;
                    wfe.Process_Info.Add(miss);
                }
                else
                {
                    Mission last = wfe.Process_Info.Where(s => s.next_Mission.Count == 0).First();
                    miss.pre_Mission = last;
                    miss.Miss_WFentity = wfe;
                    last.next_Mission.Add(miss);
                }
                return (db.SaveChanges() != 0);
            }
        }
Ejemplo n.º 4
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);
        }
Ejemplo n.º 5
0
        /// <summary>
        /// 获得任务实体的所有已执行完的任务,以任务的顺序排列
        /// </summary>
        /// <param name="wfEntityId"></param>
        /// <returns></returns>
        public List<Mission> GetWFEntityMissions(int wfEntityId)
        {
            using (var db = base.NewDB())
            {
                List<Mission> missions = new List<Mission>();

                WorkFlow_Entity wfe = db.workflow_entities.Where(s => s.WE_Id == wfEntityId).First();

                if (wfe != null)
                {
                    Mission miss = wfe.Process_Info.Where(s => s.pre_Mission == null).First();
                    if (miss != null)
                    {
                        missions.Add(miss);

                        while (miss.next_Mission.Count != 0)
                        {
                            missions.Add(miss.next_Mission.First());
                            miss = (Mission)miss.next_Mission.First();
                        }
                    }
                }

                return missions;
            }
        }
Ejemplo n.º 6
0
        /// <summary>
        /// 获得任务实体的最后一个任务
        /// </summary>
        /// <param name="wfEntityId"></param>
        /// <returns></returns>
        public Mission GetWFEntityLastMission(int wfEntityId)
        {
            using (var db = base.NewDB())
            {
                WorkFlow_Entity wfe = db.workflow_entities.Where(s => s.WE_Id == wfEntityId).First();
                if (wfe == null)
                    return null;

                return wfe.Process_Info.Where(s => s.next_Mission.Count == 0).First();
            }
        }
Ejemplo n.º 7
0
        /// <summary>
        /// 获得工作流实体的描述信息
        /// </summary>
        /// <param name="wfe_id"></param>
        /// <returns></returns>
        public string GetWorkFlowEntityDesc(int wfe_id)
        {
            using (var db = base.NewDB())
            {
                WorkFlow_Entity we = db.workflow_entities.Where(a => a.WE_Id == wfe_id).First();
                if (we == null)
                    return "";

                return we.WE_Wref.W_Attribution;
            }
        }
Ejemplo n.º 8
0
        public string get_equip_info(string wfe_id)
        {
            WorkFlows wfsd    = new WorkFlows();
            Mission   db_miss = wfsd.GetWFEntityMissions(Convert.ToInt16(wfe_id)).Last();//获取该实体最后一个任务


            WorkFlow_Entity wfe = wfsd.GetWorkFlowEntity(Convert.ToInt16(wfe_id));
            //CWorkFlow wf = new CWorkFlow();
            WorkFlows  wfs = new WorkFlows();
            UI_MISSION ui  = new UI_MISSION();

            ui.WE_Entity_Ser = wfe.WE_Ser;
            ui.WE_Event_Desc = db_miss.Miss_Desc;
            ui.WE_Event_Name = db_miss.Event_Name;
            ui.WE_Name       = db_miss.Miss_Name;
            ui.Mission_Url   = "";                                               //历史任务的页面至空
            ui.Miss_Id       = db_miss.Miss_Id;
            List <Mission_Param> mis_pars = wfsd.GetMissParams(db_miss.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.Miss_Params[cp.name]     = cp.value;
                ui.Miss_ParamsDesc[cp.name] = cp.description;
            }
            List <EquipListModel> EquipList = Zz_Equips(ui.Miss_Params["Zz_Name"].ToString());
            List <object>         miss_obj  = new List <object>();
            int i = 1;

            foreach (var item in EquipList)
            {
                object m = new
                {
                    index           = i,
                    Equip_Id        = item.Equip_Id,
                    Equip_GyCode    = item.Equip_GyCode,
                    Equip_Code      = item.Equip_Code,
                    Equip_Type      = item.Equip_Type,
                    Equip_Specialty = item.Equip_Specialty,
                    Equip_ABCMark   = item.Equip_ABCMark
                };
                miss_obj.Add(m);
                i++;
            }

            string str = JsonConvert.SerializeObject(miss_obj);

            return("{" + "\"data\": " + str + "}");
        }
Ejemplo n.º 9
0
 /// <summary>
 /// 置工作流实体为删除状态——注意对比与DeleteWFEntity的区别
 /// </summary>
 /// <param name="wfEntityId"></param>
 public void SetWFEntityDeleted(int wfEntityId)
 {
     using (var db = base.NewDB())
     {
         WorkFlow_Entity wfe = db.workflow_entities.Where(s => s.WE_Id == wfEntityId).First();
         if (wfe != null)
         {
             wfe.WE_Status = WE_STATUS.DELETED;
         }
         db.SaveChanges();
     }
 }
Ejemplo n.º 10
0
 /// <summary>
 /// 删除工作流实体
 /// </summary>
 /// <param name="wfEntityId"></param>
 public void DeleteWFEntity(int wfEntityId)
 {
     using (var db = base.NewDB())
     {
         WorkFlow_Entity wfe = db.workflow_entities.Where(s => s.WE_Id == wfEntityId).First();
         if (wfe != null)
         {
             wfe.Process_Info.Clear();
             db.workflow_entities.Remove(wfe);
         }
         db.SaveChanges();
     }
 }
Ejemplo n.º 11
0
        // GET: /A7dot1dot1/机动处确认
        public void createA13dot1(string from_wfe_id)
        {
            //create new flow A13.1
            UI_MISSION miss           = CWFEngine.GetActiveMission <Person_Info>(Convert.ToInt32(from_wfe_id), ((IObjectContextAdapter)(new EquipWebContext())).ObjectContext);
            string     th_problem     = Convert.ToString(miss.Miss_Params["Th_ProblemRecords"]);
            JArray     j_Problem_data = JArray.Parse(th_problem);

            for (int i = 0; i < j_Problem_data.Count; i++)
            {
                JObject j_obj            = JObject.Parse(j_Problem_data[i].ToString());
                string  problem_catalogy = j_obj["problem_catalogy"].ToString();
                string  problem_detail   = j_obj["problem_detail"].ToString();
                //将7.1.1的串号赋给新产生的13.1的工作流
                WorkFlows          wfsd       = new WorkFlows();
                WorkFlow_Entity    wfecurrent = wfsd.GetWorkFlowEntity(Convert.ToInt32(from_wfe_id));
                UI_WorkFlow_Entity wfe        = CWFEngine.CreateAWFEntityByName("A13dot1", wfecurrent.WE_Ser);

                if (wfe != null)
                {
                    Dictionary <string, string> record = wfe.GetRecordItems();
                    record["username"] = (Session["User"] as EquipModel.Entities.Person_Info).Person_Name;
                    record["time"]     = DateTime.Now.ToString();
                    wfe.Start(record);
                    int flow_id = wfe.EntityID;
                    Dictionary <string, string> signal1 = new Dictionary <string, string>();
                    signal1["start_done"] = "true";
                    CWFEngine.SubmitSignal(flow_id, signal1, record);
                    //paras
                    Dictionary <string, string> signal = new Dictionary <string, string>();
                    signal["ZzSubmit_done"]        = "true";
                    signal["Cj_Name"]              = miss.Miss_Params["Cj_Name"].ToString();
                    signal["Zz_Name"]              = miss.Miss_Params["Zz_Name"].ToString();
                    signal["Equip_GyCode"]         = miss.Miss_Params["Equip_GyCode"].ToString();
                    signal["Equip_Code"]           = miss.Miss_Params["Equip_Code"].ToString();
                    signal["Equip_Type"]           = miss.Miss_Params["Equip_Type"].ToString();
                    signal["Problem_Desc"]         = problem_detail;
                    signal["Problem_DescFilePath"] = "";
                    signal["Zy_Type"]              = problem_catalogy;
                    signal["Zy_SubType"]           = miss.Miss_Params["Zy_SubType"].ToString();
                    signal["Equip_ABCMark"]        = miss.Miss_Params["Equip_ABCMark"].ToString();
                    signal["Data_Src"]             = "特护记录";

                    //submit
                    //record
                    //record["username"] = (Session["User"] as EquipModel.Entities.Person_Info).Person_Name;
                    record["time"] = DateTime.Now.ToString();
                    //submit
                    CWFEngine.SubmitSignal(flow_id, signal, record);
                }
            }
        }
Ejemplo n.º 12
0
 public bool SaveWorkFlowEntity(WorkFlow_Entity we)
 {
     using (var db = base.NewDB())
     {                
         var wfe = db.workflow_entities.Where(a => a.WE_Id == we.WE_Id).First();
         if (we.WE_Status != WE_STATUS.INVALID) //不更新状态
             wfe.WE_Status = we.WE_Status;
         wfe.WE_Binary = we.WE_Binary;
         wfe.Last_Trans_Time = we.Last_Trans_Time;
         if (db.SaveChanges() >= 1)
             return true;
     }
     return false;
 }
Ejemplo n.º 13
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);
        }
Ejemplo n.º 14
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);
                    }
                }


            }
        }
Ejemplo n.º 15
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);
        }
Ejemplo n.º 16
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);
        }
Ejemplo n.º 17
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);
        }
Ejemplo n.º 18
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;
            }
        }
Ejemplo n.º 19
0
        //更新工作流实体,(修改数据相应的项)
        public void UpdateEntity(WE_STATUS status)
        {
            try
            {
                WorkFlow_Entity wfe = new WorkFlow_Entity
                {
                    WE_Id = m_entityID,
                    WE_Status = status,
                    Last_Trans_Time = this.Last_TransTime
                };
                wfe.WE_Binary = Encoding.Default.GetBytes(WriteToXmlNode().OuterXml);

                WorkFlows wfs = new WorkFlows();
                if (!wfs.SaveWorkFlowEntity(wfe))
                    throw new Exception("Save WorkFlow Entity failed!");

            }
            catch(Exception e)
            {
                return;
            }
        }
Ejemplo n.º 20
0
        public bool AddWorkEntity(string wfName, WorkFlow_Entity we)
        {
            int num = 0;
            lock (insert_lock)
            { //locked
                using (var db = base.NewDB())
                {
                    WorkFlow_Define wd = db.workflow_define.Where(s => s.W_Name == wfName).First();
                    if (we.WE_Ser == "") //2012/2/12--保证子工作流串号与父工作流相同
                    {
                        //对WorkFlow_Entity编号的处理
                        string perFix = DateTime.Now.ToString("yyyyMM");
                        IQueryable<WorkFlow_Entity> we_Ser = db.workflow_entities.Where(s => s.WE_Ser.StartsWith(perFix)).OrderBy(s => s.WE_Ser);
                        if (we_Ser.ToList().Count == 0)
                            we.WE_Ser = perFix + "00001";
                        else
                        {

                            we.WE_Ser = (Convert.ToInt64(we_Ser.ToList().Last().WE_Ser) + 1).ToString();
                        }
                    }


                    if (wd == null)
                        return false;

                    wd.W_Wentities.Add(we);

                  //System.Threading.Thread.Sleep(2000);

                    num = db.SaveChanges();
                    //return (db.SaveChanges() != 0);

                }
            }//unlocked
            return (num != 0);
        }
Ejemplo n.º 21
0
        //根据自身信息创建工作流
        //该函数调用要确保自身信息构建完善
        public bool CreateEntityBySelf(string Ser_Num = null)
        {
            WorkFlows wfs = new WorkFlows();

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

            //2016/2/12 --保证子工作流串号与父工作流相同
            if (Ser_Num == null)
                wfe.WE_Ser = "";
            else
                wfe.WE_Ser = Ser_Num;

            if (!wfs.AddWorkEntity(name, wfe))
                return false;

            m_entityID = wfe.WE_Id;
            m_entitySerial = wfe.WE_Ser;
            //m_defineID = define.W_ID;

            RegEventsTimeOut(true);
            return true;
        }
Ejemplo n.º 22
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);
                }
            }
        }