Пример #1
0
        /// <summary>
        /// Creates and then adds comment with the given text, organization ID, and time
        /// <see cref="EDXLSharp.NIEMEMLCLib.EventComment"/>.
        /// </summary>
        public void AddComment(string text, string organizationId, string personHumanResourceIdentification, DateTime time)
        {
            EventComment comment = new EventComment();

            comment.OrganizationIdentification = organizationId;
            comment.DateTime    = time;
            comment.CommentText = text;
            comment.PersonHumanResourceIdentification = personHumanResourceIdentification;

            this.EventComment.Add(comment);
        }
Пример #2
0
        /// <summary>
        /// Reads in the xml
        /// </summary>
        /// <param name="xmlData">Xml as string</param>
        public void ReadXML(string xmlData)
        {
            if (string.IsNullOrEmpty(xmlData))
            {
                throw new ArgumentNullException("XMLData Can't Be Null!");
            }

            XmlDocument doc = new XmlDocument();

            try
            {
                doc.LoadXml(xmlData);
            }
            catch (XmlException)
            {
                throw new ArgumentException("Invalid XML String");
            }

            XmlNodeList denodelist = doc.GetElementsByTagName("Event", Constants.EmlcNamespace);

            if (denodelist.Count == 0)
            {
                throw new FormatException("No Event Element found!");
            }
            else if (denodelist.Count > 1)
            {
                throw new FormatException("Multiple Event Elements found!");
            }

            XmlNode deroot = denodelist[0];

            foreach (XmlNode node in deroot.ChildNodes)
            {
                if (string.IsNullOrEmpty(node.InnerText))
                {
                    continue;
                }

                switch (node.LocalName)
                {
                case "EventID":
                    this.EventID = node.InnerText;
                    break;

                case "EventTypeDescriptor":
                    EventTypeDescriptor.EventTypeCode = new ValueList(doc.GetElementsByTagName("EventTypeCode", Constants.EmeventNamespace)[0]);
                    //this.EventTypeDescriptor.SerialEventTypeCode = doc.GetElementsByTagName("EventTypeCode", Constants.EmeventNamespace)[0];//.InnerText; // 1/11/2017 changed property to "SerialEventTypeCode"
                    // to be consistent with LinkedEventCategory....should it be "EventTypeCode",
                    // or will XML be updated to be "SerialEventTypeCode"?
                    this.EventTypeDescriptor.EventTypeDescriptorExtension = new List <string>(0);
                    XmlNodeList extensions = doc.GetElementsByTagName("EventTypeDescriptorExtension", Constants.EmeventNamespace);
                    foreach (XmlNode extension in extensions)
                    {
                        this.EventTypeDescriptor.EventTypeDescriptorExtension.Add(extension.InnerText);
                    }
                    break;

                case "EventLocation":
                    this.EventLocation.LocationCylinder = new LocationCylinder();
                    this.EventLocation.LocationCylinder.LocationPoint               = new LocationPoint();
                    this.EventLocation.LocationCylinder.LocationPoint.Point         = new Point();
                    this.EventLocation.LocationCylinder.LocationPoint.Point.pos     = doc.GetElementsByTagName("Point", Constants.GmlNamespace)[0].InnerText;
                    this.EventLocation.LocationCylinder.LocationCylinderRadiusValue = decimal.Parse(doc.GetElementsByTagName("LocationCylinderRadiusValue", Constants.MofNamespace)[0].InnerText);
                    this.EventLocation.LocationCylinder.LocationCreationCode        = doc.GetElementsByTagName("LocationCreationCode", Constants.MofNamespace)[0].InnerText;
                    break;

                case "EventValidityDateTimeRange":
                    this.EventValidityDateTimeRange           = new EventValidityDateTimeRange();
                    this.EventValidityDateTimeRange.StartDate = Convert.ToDateTime(doc.GetElementsByTagName("StartDate", Constants.NiemcoreNamespace)[0].InnerText);
                    this.EventValidityDateTimeRange.EndDate   = Convert.ToDateTime(doc.GetElementsByTagName("EndDate", Constants.NiemcoreNamespace)[0].InnerText);
                    break;

                case "EventComment":
                    EventComment newComment     = new EventComment();
                    XmlNodeList  commentContent = node.ChildNodes;
                    foreach (XmlNode childNode in commentContent)
                    {
                        if (string.IsNullOrEmpty(childNode.InnerText))
                        {
                            continue;
                        }
                        switch (childNode.LocalName)
                        {
                        case "DateTime":
                            newComment.DateTime = Convert.ToDateTime(childNode.InnerText);
                            break;

                        case "CommentText":
                            newComment.CommentText = childNode.InnerText;
                            break;

                        case "OrganizationIdentification":
                            newComment.OrganizationIdentification = childNode.InnerText;
                            break;

                        case "PersonHumanResourceIdentification":
                            newComment.PersonHumanResourceIdentification = childNode.InnerText;
                            break;

                        default:
                            throw new ArgumentException("Unexpected Node Name: " + childNode.Name + " in NIEM Event Comment");
                        }
                    }
                    this.EventComment.Add(newComment);
                    break;

                case "EventMessageDateTime":
                    this.EventMessageDateTime = Convert.ToDateTime(node.FirstChild.InnerXml);
                    break;

                case "ResourceDetail":
                    ResourceDetail resource = new ResourceDetail();
                    this.Details = CreateResourceDetail(node, resource);
                    break;

                case "IncidentDetail":
                    IncidentDetail incident = new IncidentDetail();
                    this.Details = CreateIncidentDetail(node, incident);
                    break;

                case "InfrastructureDetail":
                    throw new NotImplementedException("ReadXML for " + node.Name + " not implemented yet");

                default:
                    throw new ArgumentException("Unexpected Node Name: " + node.Name + " in NIEM Event");
                }
            }
        }