Ejemplo n.º 1
0
        public string ToXml()
        {
            XmlDocument xdoc = new XmlDocument();

            xdoc.LoadXml("<monitorState state=\"NotAvailable\" currentValue=\"\" lastStateChangeTime=\"\" />");
            XmlElement root = xdoc.DocumentElement;

            root.SetAttributeValue("state", State.ToString());
            root.SetAttributeValue("stateChangedTime", StateChangedTime.ToString("yyyy-MM-dd HH:mm:ss"));
            root.SetAttributeValue("timeStamp", Timestamp.ToString("yyyy-MM-dd HH:mm:ss"));
            root.SetAttributeValue("callDurationMS", CallDurationMS.ToString());
            if (CurrentValue != null)
            {
                root.SetAttributeValue("currentValue", CurrentValue.ToString());
            }
            else
            {
                root.SetAttributeValue("currentValue", "");
            }
            root.SetAttributeValue("executedOnHostComputer", ExecutedOnHostComputer);

            XmlElement rawDetailsNode = xdoc.CreateElement("rawDetails");

            rawDetailsNode.InnerText = RawDetails;
            root.AppendChild(rawDetailsNode);
            XmlElement htmlDetailsNode = xdoc.CreateElement("htmlDetails");

            htmlDetailsNode.InnerText = HtmlDetails;
            root.AppendChild(htmlDetailsNode);
            XmlElement alerts = xdoc.CreateElement("alerts");

            foreach (string alert in AlertsRaised)
            {
                XmlElement alertNode = xdoc.CreateElement("alert");
                alertNode.InnerText = alert;
                alerts.AppendChild(alertNode);
            }
            root.AppendChild(alerts);
            return(xdoc.OuterXml);
        }
Ejemplo n.º 2
0
        public string ToXml()
        {
            XmlDocument xdoc = new XmlDocument();

            xdoc.LoadXml("<monitorState uniqueId=\"\" state=\"NotAvailable\" currentValue=\"\" lastStateChangeTime=\"\" forAgent=\"\" />");
            XmlElement root = xdoc.DocumentElement;

            root.SetAttributeValue("uniqueId", UniqueId);
            root.SetAttributeValue("state", State.ToString());
            root.SetAttributeValue("stateChangedTime", StateChangedTime.ToString("yyyy-MM-dd HH:mm:ss"));
            root.SetAttributeValue("forAgent", ForAgent);
            root.SetAttributeValue("forAgentType", ForAgentType);
            root.SetAttributeValue("forAgentId", ForAgentId);
            root.SetAttributeValue("timeStamp", Timestamp.ToString("yyyy-MM-dd HH:mm:ss"));
            root.SetAttributeValue("callDurationMS", CallDurationMS.ToString());
            root.SetAttributeValue("repeatCount", RepeatCount);

            if (CurrentValue != null)
            {
                root.SetAttributeValue("currentValue", CurrentValue.ToString());
            }
            else
            {
                root.SetAttributeValue("currentValue", "");
            }
            root.SetAttributeValue("primaryUIValue", PrimaryUIValue);
            root.SetAttributeValue("executedOnHostComputer", ExecutedOnHostComputer);
            root.SetAttributeValue("ranAs", RanAs);

            XmlElement alertHeaderNode = xdoc.CreateElement("alertHeader");

            alertHeaderNode.InnerText = AlertHeader;
            root.AppendChild(alertHeaderNode);
            XmlElement alertFooterNode = xdoc.CreateElement("alertFooter");

            alertFooterNode.InnerText = AlertFooter;
            root.AppendChild(alertFooterNode);
            XmlElement additionalAlertTextNode = xdoc.CreateElement("additionalAlertText");

            additionalAlertTextNode.InnerText = AdditionalAlertText;
            root.AppendChild(additionalAlertTextNode);

            XmlElement rawDetailsNode = xdoc.CreateElement("rawDetails");

            rawDetailsNode.InnerText = RawDetails;
            root.AppendChild(rawDetailsNode);
            XmlElement htmlDetailsNode = xdoc.CreateElement("htmlDetails");

            htmlDetailsNode.InnerText = HtmlDetails;
            root.AppendChild(htmlDetailsNode);
            XmlElement alerts = xdoc.CreateElement("alerts");

            foreach (string alert in AlertsRaised)
            {
                XmlElement alertNode = xdoc.CreateElement("alert");
                alertNode.InnerText = alert;
                alerts.AppendChild(alertNode);
            }
            root.AppendChild(alerts);

            XmlElement scriptsRanElement = xdoc.CreateElement("scriptsRan");

            foreach (string scriptName in ScriptsRan)
            {
                XmlElement scriptNode = xdoc.CreateElement("script");
                scriptNode.InnerText = scriptName;
                scriptsRanElement.AppendChild(scriptNode);
            }
            root.AppendChild(scriptsRanElement);


            StringBuilder childStates = new StringBuilder();

            if (ChildStates != null && ChildStates.Count > 0)
            {
                childStates.AppendLine("<childStates>");
                foreach (MonitorState childState in ChildStates)
                {
                    childStates.AppendLine(childState.ToXml());
                }
                childStates.AppendLine("</childStates>");
            }
            return(xdoc.OuterXml.Replace("</monitorState>", childStates.ToString() + "</monitorState>"));
        }