public static DeviceCollection ParseConfigFile(string xml) { var deviceList = new DeviceCollection(); if (string.IsNullOrEmpty(xml)) { return(deviceList); } var doc = XDocument.Parse(xml); var ns = doc.Root.Name.Namespace; var header = doc.Descendants(ns + "Header").FirstOrDefault(); if (header != null) { deviceList.CreateTime = (DateTime)header.Attribute("creationTime"); deviceList.AgentInformation = AgentInformation.FromXml(header); } var devices = from d in doc.Descendants(ns + NodeNames.Device) select d; foreach (var deviceNode in devices) { deviceList.Add(Device.FromXElement <Device>(ns, deviceNode)); } return(deviceList); }
public static AgentInformation FromXml(XElement element) { var ai = new AgentInformation() { Name = element.AttributeValue("sender"), Version = element.AttributeValue("version"), BufferSize = (int)element.Attribute("bufferSize"), InstanceID = element.AttributeValue("instanceId"), AgentType = element.AttributeValue("agentType") ?? "Default" }; return(ai); }