Example #1
0
        public XmlElement ToXml(XmlDocument document)
        {
            XmlElement alertNode = document.CreateElement("idmef:Alert", "http://iana.org/idmef");

            alertNode.SetAttribute("messageId", messageId);

            alertNode.AppendChild(analyzer.ToXml(document));
            alertNode.AppendChild(createTime.ToXml(document));
            alertNode.AppendChild(classification.ToXml(document));
            if (detectTime != null)
            {
                alertNode.AppendChild(detectTime.ToXml(document));
            }
            if (analyzerTime != null)
            {
                alertNode.AppendChild(analyzerTime.ToXml(document));
            }
            if (source != null)
            {
                foreach (var src in source)
                {
                    if (src != null)
                    {
                        alertNode.AppendChild(src.ToXml(document));
                    }
                }
            }
            if (target != null)
            {
                foreach (var tgt in target)
                {
                    if (tgt != null)
                    {
                        alertNode.AppendChild(tgt.ToXml(document));
                    }
                }
            }
            if (assessment != null)
            {
                alertNode.AppendChild(assessment.ToXml(document));
            }

            int subs = 0;

            if (toolAlert != null)
            {
                subs++;
                alertNode.AppendChild(toolAlert.ToXml(document));
            }
            if (overflowAlert != null)
            {
                subs++;
                alertNode.AppendChild(overflowAlert.ToXml(document));
            }
            if (correlationAlert != null)
            {
                subs++;
                alertNode.AppendChild(correlationAlert.ToXml(document));
            }
            if (subs > 1)
            {
                throw new InvalidOperationException("Only one subclass of Alert can be attached.");
            }

            if (additionalData != null)
            {
                foreach (var ad in additionalData)
                {
                    if (ad != null)
                    {
                        alertNode.AppendChild(ad.ToXml(document));
                    }
                }
            }

            return(alertNode);
        }