ATUL_v1.Schedule.GetScheduleMessageBodyXML C# (CSharp) Method

GetScheduleMessageBodyXML() public method

public GetScheduleMessageBodyXML ( ) : XmlDocument
return System.Xml.XmlDocument
        public XmlDocument GetScheduleMessageBodyXML()
        {
            XmlDocument doc = new XmlDocument();
            doc.LoadXml("<servicerequest><verb>INITINSTANCE</verb></servicerequest>");
            XmlNode serviceRequestNode = doc.SelectSingleNode("//servicerequest");
            XmlNode processIdElement = doc.CreateElement("parameter");
            XmlNode processIdName = doc.CreateElement("name");
            processIdName.InnerText = "AtulProcessID";
            processIdElement.AppendChild(processIdName);
            XmlNode processIdValue = doc.CreateElement("value");
            processIdValue.InnerText = AtulProcessID.ToString();
            processIdElement.AppendChild(processIdValue);
            serviceRequestNode.AppendChild(processIdElement);
            XmlNode scheduleIdElement = doc.CreateElement("parameter");
            XmlNode scheduleIdName = doc.CreateElement("name");
            scheduleIdName.InnerText = "AtulProcessScheduleID";
            scheduleIdElement.AppendChild(scheduleIdName);
            XmlNode scheduleIdValue = doc.CreateElement("value");
            scheduleIdValue.InnerText = AtulProcessScheduleID.ToString();
            scheduleIdElement.AppendChild(scheduleIdValue);
            serviceRequestNode.AppendChild(scheduleIdElement);
            XmlNode scheduleVersionElement = doc.CreateElement("parameter");
            XmlNode scheduleVersionName = doc.CreateElement("name");
            scheduleVersionName.InnerText = "ScheduleVersion";
            scheduleVersionElement.AppendChild(scheduleVersionName);
            XmlNode scheduleVersionValue = doc.CreateElement("value");
            scheduleVersionValue.InnerText = ScheduleVersion;
            scheduleVersionElement.AppendChild(scheduleVersionValue);
            serviceRequestNode.AppendChild(scheduleVersionElement);
            return doc;
        }

Usage Example

Example #1
0
 public string PushNextScheduleToAdminQueue(Schedule s, DateTime next)
 {
     string correlationid = "";
     string env = ConfigurationManager.AppSettings.Get("Environment");
     string queue = ConfigurationManager.AppSettings.Get(env.ToUpper() + ".AtulAdminQueue");
     XmlDocument doc = s.GetScheduleMessageBodyXML();
     string body = doc.InnerXml;
     List<KeyValuePair<string, string>> headerList = new List<KeyValuePair<string, string>>();
     headerList.Add(new KeyValuePair<string, string>("VERB", "INITINSTANCE"));
     // scale tells how much to multiply the delay by, since the ESB system is passing the delay header from one queue to the next, thus doubling it.
     // when it's fixed, we can push config change to set scale to 1 and thus delay is intact.
     double timescale = Convert.ToDouble(ConfigurationManager.AppSettings.Get("MsgTimeScale"));
     // calculate delay by subtracting now from next scheduled date
     long delay = Convert.ToInt64(Math.Floor(next.Subtract(DateTime.Now).TotalMilliseconds * timescale));
     // if they're scheduled for the next couple minutes, just push it now with no delay so that it doesn't get
     // caught in lag
     if (delay >= 100000)
     {
         headerList.Add(new KeyValuePair<string, string>("AMQ_SCHEDULED_DELAY", delay.ToString()));
     }
     correlationid = this.PushToQueue(queue, body, headerList);
     return correlationid;
 }