#pragma warning disable S1541 // Methods should not be too complex private static Info ParseInfo(XElement infoElement) #pragma warning restore S1541 // Methods should not be too complex { var info = new Info(); var capNamespace = infoElement.Name.Namespace; var languageNode = infoElement.Element(capNamespace + "language"); if (languageNode != null) { info.Language = languageNode.Value; } var categoryNodes = infoElement.Elements(capNamespace + "category"); var categories = from categoryNode in categoryNodes where categoryNode != null select EnumParse <Category>(categoryNode.Value); info.Categories.AddRange(categories); var eventNode = infoElement.Element(capNamespace + "event"); if (eventNode != null) { info.Event = eventNode.Value; } var responseTypeNodes = infoElement.Elements(capNamespace + "responseType"); var responseTypes = from responseTypeNode in responseTypeNodes where responseTypeNode != null select EnumParse <ResponseType>(responseTypeNode.Value); info.ResponseTypes.AddRange(responseTypes); var urgencyNode = infoElement.Element(capNamespace + "urgency"); if (urgencyNode != null) { info.Urgency = string.IsNullOrWhiteSpace(urgencyNode.Value) ? Urgency.Unknown : EnumParse <Urgency>(urgencyNode.Value); } var certaintyNode = infoElement.Element(capNamespace + "certainty"); if (certaintyNode != null) { if (string.IsNullOrWhiteSpace(certaintyNode.Value)) { info.Certainty = Certainty.Unknown; } else if (certaintyNode.Value == "Very Likely") { info.Certainty = Certainty.Likely; } else { info.Certainty = EnumParse <Certainty>(certaintyNode.Value); } } var audienceNode = infoElement.Element(capNamespace + "audience"); if (audienceNode != null) { info.Audience = audienceNode.Value; } var eventCodeNodes = infoElement.Elements(capNamespace + "eventCode"); var eventCodes = from ev in eventCodeNodes where ev != null let value = ev.Element(capNamespace + "value").Value let valueName = ev.Element(capNamespace + "valueName").Value select new EventCode(valueName, value); info.EventCodes.AddRange(eventCodes); var effectiveNode = infoElement.Element(capNamespace + "effective"); if (effectiveNode != null) { info.Effective = TryParseDateTime(effectiveNode.Value); } var severityNode = infoElement.Element(capNamespace + "severity"); if (severityNode != null) { info.Severity = string.IsNullOrWhiteSpace(severityNode.Value) ? Severity.Unknown : EnumParse <Severity>(severityNode.Value); } var onsetNode = infoElement.Element(capNamespace + "onset"); if (onsetNode != null) { info.Onset = TryParseDateTime(onsetNode.Value); } var expiresNode = infoElement.Element(capNamespace + "expires"); if (expiresNode != null) { info.Expires = TryParseDateTime(expiresNode.Value); } var senderNameNode = infoElement.Element(capNamespace + "senderName"); if (senderNameNode != null) { info.SenderName = senderNameNode.Value; } var headlineNode = infoElement.Element(capNamespace + "headline"); if (headlineNode != null) { info.Headline = headlineNode.Value; } var descriptionNode = infoElement.Element(capNamespace + "description"); if (descriptionNode != null) { info.Description = descriptionNode.Value; } var instructionNode = infoElement.Element(capNamespace + "instruction"); if (instructionNode != null) { info.Instruction = instructionNode.Value; } var webNode = infoElement.Element(capNamespace + "web"); if (webNode != null) { info.Web = new Uri(webNode.Value); } var contactNode = infoElement.Element(capNamespace + "contact"); if (contactNode != null) { info.Contact = contactNode.Value; } var parameterNodes = infoElement.Elements(capNamespace + "parameter"); var parameters = from parameter in parameterNodes let valueNameNode = parameter.Element(capNamespace + "valueName") let valueNode = parameter.Element(capNamespace + "value") where valueNameNode != null && valueNode != null select new Parameter(valueNameNode.Value, valueNode.Value); info.Parameters.AddRange(parameters); var resourceNodes = infoElement.Elements(capNamespace + "resource"); var resources = from resourceNode in resourceNodes where resourceNode != null select ParseResource(resourceNode); info.Resources.AddRange(resources); var areaNodes = infoElement.Elements(capNamespace + "area"); var areas = from areaNode in areaNodes where areaNode != null select ParseArea(areaNode); info.Areas.AddRange(areas); return(info); }
private static Alert ParseInternal(XmlDocument document) { var alert = new Alert(); XmlNodeList elements = document.GetElementsByTagName("alert", "urn:oasis:names:tc:emergency:cap:1.1"); foreach (XmlNode element in elements) { foreach (XmlNode alertNode in element.ChildNodes) { switch (alertNode.Name) { case "identifier": alert.Identifier = alertNode.InnerText; break; case "sender": alert.Sender = alertNode.InnerText; break; case "sent": alert.Sent = DateTime.Parse(alertNode.InnerText); break; case "status": // TODO: Parse status to enum alert.Status = Status.Test; break; case "msgType": // TODO: Parse message type to enum alert.MessageType = MessageType.Alert; break; case "source": alert.Source = alertNode.InnerText; break; case "scope": // TODO: Parse scope to enum alert.Scope = Scope.Public; break; case "restriction": alert.Restriction = alertNode.InnerText; break; case "addresses": alert.Addresses = alertNode.InnerText; break; case "code": alert.Code = alertNode.InnerText; break; case "note": alert.Note = alertNode.InnerText; break; case "references": alert.References = alertNode.InnerText; break; case "incidents": alert.Incidents = alertNode.InnerText; break; case "info": var info = new Info(); foreach (XmlNode infoNode in alertNode.ChildNodes) { switch (infoNode.Name) { case "language": info.Language = infoNode.InnerText; break; case "category": //info.Category = infoNode.InnerText; break; case "event": info.Event = infoNode.InnerText; break; case "responseType": info.ResponseType = infoNode.InnerText; break; case "urgency": info.Urgency = infoNode.InnerText; break; case "severity": Severity severity; if (Enum.TryParse(infoNode.InnerText, out severity)) { info.Severity = severity; } else { info.Severity = null; } break; case "certainty": info.Certainty = infoNode.InnerText; break; case "audience": info.Audience = infoNode.InnerText; break; case "eventCode": info.EventCode = infoNode.InnerText; break; case "effective": info.Effective = DateTime.Parse(infoNode.InnerText); break; case "onset": info.Onset = DateTime.Parse(infoNode.InnerText); break; case "expires": info.Expires = DateTime.Parse(infoNode.InnerText); break; case "senderName": info.SenderName = infoNode.InnerText; break; case "headline": info.Headline = infoNode.InnerText; break; case "description": info.Description = infoNode.InnerText; break; case "instruction": info.Instruction = infoNode.InnerText; break; case "web": info.Web = infoNode.InnerText; break; case "contact": info.Contact = infoNode.InnerText; break; case "area": var area = new Area(); foreach (XmlNode areaNode in infoNode.ChildNodes) { switch (areaNode.Name) { case "areaDesc": area.Description = areaNode.InnerText; break; default: break; } } info.Areas.Add(area); break; default: break; } } alert.Info.Add(info); break; default: break; } } } return alert; }