public bool AddTimingTrigger(T_WF_TIMINGTRIGGERACTIVITY entity) { try { EngineServicesDAL dal = new EngineServicesDAL(); if (string.IsNullOrWhiteSpace(entity.TRIGGERID)) { entity.TRIGGERID = Guid.NewGuid().ToString(); } if (entity.TRIGGERACTIVITYTYPE < 1) { throw new Exception("触发类型必填"); } if (entity.TRIGGERTIME == null) { throw new Exception("触发时间必填"); } if (entity.TRIGGERROUND < 0) { throw new Exception("触发周期必填"); } if (entity.TRIGGERSTART == null) { entity.TRIGGERSTART = DateTime.Now; } if (entity.TRIGGEREND == null) { entity.TRIGGEREND = DateTime.Now.AddYears(60); } if (entity.TRIGGERMULTIPLE <= 0) { entity.TRIGGERMULTIPLE = 1; } return dal.AddTimingTrigger(entity); } catch (Exception ex) { throw new Exception(ex.Message, ex); } }
/// <summary> /// 事件定时 /// </summary> /// <param name="strEventXml">定时所需的XML模版</param> /// <returns></returns> public bool SaveEventTriggerData(string strEventXml) { if (!string.IsNullOrEmpty(strEventXml)) { try { Byte[] b = System.Text.UTF8Encoding.UTF8.GetBytes(strEventXml); XElement xele = XElement.Load(System.Xml.XmlReader.Create(new MemoryStream(b))); T_WF_TIMINGTRIGGERACTIVITY trigger = new T_WF_TIMINGTRIGGERACTIVITY(); trigger.COMPANYID = EventXmlAttribute(xele, "CompanyCode"); trigger.SYSTEMCODE = EventXmlAttribute(xele, "SystemCode"); trigger.MODELCODE = EventXmlAttribute(xele, "ModelCode"); trigger.TRIGGERTIME = Convert.ToDateTime(EventXmlAttribute(xele, "TaskStartDate")); trigger.BUSINESSID = EventXmlAttribute(xele, "ApplicationOrderCode"); string ProcessCycle = EventXmlAttribute(xele, "ProcessCycle"); // 0 只触发一次 1 分钟 2小时 3 天 4 月 5年 6周 7未知 switch (ProcessCycle.ToUpper()) { case "YEAR": trigger.TRIGGERROUND = 5; break; case "MONTH": trigger.TRIGGERROUND = 4; break; case "DAY": trigger.TRIGGERROUND = 3; break; case "HOUR": trigger.TRIGGERROUND = 2; break; case "MINUTE": trigger.TRIGGERROUND = 1; break; case "WEEK": trigger.TRIGGERROUND = 6; break; case " ": trigger.TRIGGERROUND = 0; break; case "": trigger.TRIGGERROUND = 0; break; default: trigger.TRIGGERROUND = 100; trigger.REMARK = "未知的触发周期:" + ProcessCycle; break; } trigger.RECEIVERUSERID = EventXmlAttribute(xele, "ReceiveUser"); trigger.RECEIVEROLE = EventXmlAttribute(xele, "ReceiveRole"); trigger.MESSAGEBODY = EventXmlAttribute(xele, "MessageBody"); trigger.WCFURL = EventXmlAttribute(xele, "ProcessWcfUrl"); trigger.FUNCTIONNAME = EventXmlAttribute(xele, "WcfFuncName"); string TriggerType = EventXmlAttribute(xele, "TriggerType"); if (string.IsNullOrEmpty(TriggerType))// { TriggerType = "User"; } trigger.TRIGGERTYPE = TriggerType; string WcfFuncParamter = string.Empty; string MsgLinkUrl = string.Empty; try { WcfFuncParamter = xele.Element("WcfFuncParamter").ToString().Replace("<WcfFuncParamter>", "").Replace("</WcfFuncParamter>", ""); trigger.FUNCTIONPARAMTER = WcfFuncParamter; } catch { } try { MsgLinkUrl = xele.Element("MsgLinkUrl").ToString().Replace("<MsgLinkUrl>", "").Replace("</MsgLinkUrl>", ""); trigger.MESSAGEURL = MsgLinkUrl; } catch { } trigger.PAMETERSPLITCHAR = EventXmlAttribute(xele, "WcfParamSplitChar"); trigger.WCFBINDINGCONTRACT = EventXmlAttribute(xele, "WcfBinding"); trigger.TRIGGERDESCRIPTION = "EventTrigger"; if (trigger.TRIGGERSTART == null) { trigger.TRIGGERSTART = DateTime.Now; } if (trigger.TRIGGEREND == null) { trigger.TRIGGEREND = DateTime.Now.AddYears(60); } if (trigger.TRIGGERMULTIPLE <= 0) { trigger.TRIGGERMULTIPLE = 1; } EngineServicesDAL dal = new EngineServicesDAL(); return dal.AddTimingTrigger(trigger); } catch (Exception e) { string cMessage = "<消息引擎>Message=[" + e.Message + "]" + "<消息引擎>Source=[" + e.Source + "]<消息引擎>StackTrace=[" + e.StackTrace + "]<消息引擎>TargetSite=[" + e.TargetSite + "]"; Tracer.Debug(cMessage); return false; } } else { return false; } }