Ejemplo n.º 1
0
        /// <summary>
        /// Validates the CAP 1.1 Area elements are IPAWS Profile 1.0 compliant
        /// </summary>
        /// <param name="infoBlock">The information block portion of the CAP message</param>
        private void ValidateIPAWSProfilev10ForCAPv11AreaBlocks(InfoType infoBlock)
        {
            if (infoBlock.Area != null && infoBlock.Area.Count > 0)
            {
                AreaType ablock = infoBlock.Area[0]; // only first area is processed by IPAWS
                if (string.IsNullOrEmpty(ablock.AreaDesc))
                {
                    throw new System.ArgumentNullException("IPAWS Profile v1.0 requires that the areaDesc block not be null or empty.");
                }

                List <NameValueType> geoCodes = ablock.GeoCode.FindAll(g => g.Name.Equals("SAME"));
                if (geoCodes == null || geoCodes.Count < 1)
                {
                    throw new System.ArgumentException("IPAWS Profile v1.0 requires that there is at least one geoCode block with the valueName of SAME");
                }

                foreach (NameValueType geoCode in geoCodes)
                {
                    if (geoCode.Value.Length != 6)
                    {
                        throw new System.ArgumentException("IPAWS Profile v1.0 requires that the value of a geoCode block with the valueName of SAME be in PSSCCC format.");
                    }

                    int  psscccCode = 0;
                    bool canParse   = int.TryParse(geoCode.Value, out psscccCode);
                    if (!canParse)
                    {
                        throw new System.ArgumentException("IPAWS Profile v1.0 requires that the value of a geoCode block with the valueName of SAME be in PSSCCC format.");
                    }
                }
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Reads an XML Object From An Existing DOM
        /// </summary>
        /// <param name="rootNode">Node Containing the Root Object Element</param>
        /// <param name="sentDateTime">DateTime From Parent for Default Value</param>
        internal void ReadXML(XmlNode rootNode, DateTime sentDateTime)
        {
            ResourceType  resourcetypetmp;
            AreaType      areatypetmp;
            NameValueType eventcodetmp, parametertmp;

            this.sent = sentDateTime;
            foreach (XmlNode node in rootNode.ChildNodes)
            {
                if (string.IsNullOrEmpty(node.InnerText))
                {
                    continue;
                }

                if (node.InnerText != string.Empty)
                {
                    switch (node.LocalName)
                    {
                    case "language":
                        this.language = node.InnerText;
                        break;

                    case "category":
                        this.category.Add((CategoryType)Enum.Parse(typeof(CategoryType), node.InnerText));
                        break;

                    case "event":
                        this.eventType = node.InnerText;
                        break;

                    case "responseType":
                        this.responseType.Add((ResponseType)Enum.Parse(typeof(ResponseType), node.InnerText));
                        break;

                    case "urgency":
                        this.urgency = (UrgencyType)Enum.Parse(typeof(UrgencyType), node.InnerText);
                        break;

                    case "severity":
                        this.severity = (SeverityType)Enum.Parse(typeof(SeverityType), node.InnerText);
                        break;

                    case "certainty":
                        this.certainty = (CertaintyType)Enum.Parse(typeof(CertaintyType), node.InnerText);
                        break;

                    case "audience":
                        this.audience = node.InnerText;
                        break;

                    case "eventCode":
                        eventcodetmp = new NameValueType();
                        eventcodetmp.ReadXML(node);
                        this.eventCode.Add(eventcodetmp);
                        break;

                    case "effective":
                        this.effective = DateTime.Parse(node.InnerText);
                        if (this.effective.Kind == DateTimeKind.Unspecified)
                        {
                            this.effective = DateTime.MinValue;
                            throw new ArgumentException("TimeZone Information Must Be Specified");
                        }

                        this.effective = this.effective.ToUniversalTime();
                        break;

                    case "onset":
                        this.infoOnSet = DateTime.Parse(node.InnerText);
                        if (this.infoOnSet.Kind == DateTimeKind.Unspecified)
                        {
                            this.infoOnSet = DateTime.MinValue;
                            throw new ArgumentException("TimeZone Information Must Be Specified");
                        }

                        this.infoOnSet = this.infoOnSet.ToUniversalTime();
                        break;

                    case "expires":
                        this.expires = DateTime.Parse(node.InnerText);
                        if (this.expires.Kind == DateTimeKind.Unspecified)
                        {
                            this.expires = DateTime.MinValue;
                            throw new ArgumentException("TimeZone Information Must Be Specified");
                        }

                        this.expires = this.expires.ToUniversalTime();
                        break;

                    case "senderName":
                        this.senderName = node.InnerText;
                        break;

                    case "headline":
                        this.headline = node.InnerText;
                        break;

                    case "description":
                        this.description = node.InnerText;
                        break;

                    case "instruction":
                        this.instruction = node.InnerText;
                        break;

                    case "web":
                        this.web = new Uri(node.InnerText);
                        break;

                    case "contact":
                        this.contact = node.InnerText;
                        break;

                    case "parameter":
                        parametertmp = new NameValueType();
                        parametertmp.ReadXML(node);
                        this.parameter.Add(parametertmp);
                        break;

                    case "resource":
                        resourcetypetmp = new ResourceType();
                        resourcetypetmp.ReadXML(node);
                        this.resource.Add(resourcetypetmp);
                        break;

                    case "area":
                        areatypetmp = new AreaType();
                        areatypetmp.ReadXML(node);
                        this.area.Add(areatypetmp);
                        break;

                    case "#comment":
                        break;

                    default:
                        throw new FormatException("Invalid value: " + node.Name + " found in Info Type");
                    }
                }
            }
        }