/// <summary> /// Takes an xml node which describes a homestore app and returns /// a HomeStoreApp structure /// </summary> /// <param name="xmlDevice">the xml subtree of the app</param> /// <returns>The relevant HomeStoreApp structure</returns> public static HomeStoreDevice ReadHomeStoreDeviceFromXml(Uri baseUri, XmlElement xmlDevice) { if (!xmlDevice.Name.Equals("Device")) { throw new Exception("child is not a Device in " + xmlDevice); } HomeStoreDevice homeStoreDev = new HomeStoreDevice(); homeStoreDev.DeviceName = xmlDevice.GetAttribute("DeviceName"); homeStoreDev.ManufacturerName = xmlDevice.GetAttribute("ManufacturerName"); homeStoreDev.Description = xmlDevice.GetAttribute("Description"); homeStoreDev.Rating = int.Parse(xmlDevice.GetAttribute("Rating")); homeStoreDev.Model = xmlDevice.GetAttribute("Model"); try { string iconUrlString = xmlDevice.GetAttribute("IconUrl"); if (!iconUrlString.Equals("")) { homeStoreDev.IconUrl = new Uri(baseUri, xmlDevice.GetAttribute("IconUrl")).ToString(); } else { homeStoreDev.IconUrl = null; } } catch (Exception) { homeStoreDev.IconUrl = null; } homeStoreDev.Roles = new List <string>(); homeStoreDev.ValidDrivers = new List <string>(); foreach (XmlElement child in xmlDevice.ChildNodes) { if (child.Name.Equals("RoleList")) { foreach (XmlElement role in child) { if (role.Name.Equals("Role")) { homeStoreDev.Roles.Add(role.GetAttribute("Name")); } } } else if (child.Name.Equals("DriverList")) { foreach (XmlElement driver in child) { if (driver.Name.Equals("Driver")) { homeStoreDev.ValidDrivers.Add(driver.GetAttribute("Name")); } } } } return(homeStoreDev); }
public void ReadHomeStoreDevices(Uri fileName) { System.Net.WebRequest req = System.Net.WebRequest.Create(fileName); System.Net.WebResponse resp; try { resp = req.GetResponse(); } catch (System.Net.WebException) { logger.Log("error reading HomeStoreDevices from {0}", fileName.ToString()); return; } XmlDocument xmlDoc = new XmlDocument(); XmlReader xmlReader = XmlReader.Create(resp.GetResponseStream(), xmlReaderSettings); xmlDoc.Load(xmlReader); XmlElement root = xmlDoc.FirstChild as XmlElement; if (!root.Name.Equals("Devices")) { throw new Exception(fileName + " doesn't start with Devicess"); } foreach (XmlElement xmlModule in root.ChildNodes) { HomeStoreDevice homeStoreDev = ReadHomeStoreDeviceFromXml(fileName, xmlModule); AddDeviceToDB(homeStoreDev); } xmlReader.Close(); }
private void AddDeviceToDB(HomeStoreDevice dev) { deviceDb.Add(dev.DeviceName, dev); }