/// <summary> /// Converts an XML string to a list of ITrack objects /// </summary> /// <param name="xml">xml string to be converted</param> /// <returns>A list of ITrack objects</returns> public List<ITrack> itemReader(string xml) { var doc = new XmlDocument(); //doc.Load("item.xml"); List<ITrack> tracks = null; if (xml != "") { doc.LoadXml(xml); tracks = new List<ITrack>(); XmlNodeList nodeList = doc.GetElementsByTagName("item"); foreach (XmlElement elm in nodeList) { ITrack track = new Track(); track.ParentID = elm.GetAttribute("parentID"); XmlNodeList titleList = elm.GetElementsByTagName("upnp:album"); track.Album = titleList[0].InnerText; titleList = elm.GetElementsByTagName("dc:title"); track.Title = titleList[0].InnerText; titleList = elm.GetElementsByTagName("upnp:artist"); track.Artist = titleList[0].InnerText; titleList = elm.GetElementsByTagName("upnp:genre"); track.Genre = titleList[0].InnerText; titleList = elm.GetElementsByTagName("res"); string[] s = titleList[0].InnerText.Split('/'); track.Protocol = s[0] + "//"; track.DeviceIP = s[2]; track.FileName = s.Last(); string tmpString = "/"; for (int i = 3; i < s.Count() - 1; i++) { tmpString = tmpString + s[i] + "/"; } track.Path = tmpString; track.Duration = titleList[0].Attributes["duration"].Value; tracks.Add(track); } } return tracks; }
/* public List<Container> containerReader(string xml) { var xmlDocument = new XmlDocument(); xmlDocument.Load("container.xml"); //xmlDocument.LoadXml(xml); var tmpList = new List<Container>(); XmlNodeList nodeList = xmlDocument.GetElementsByTagName("container"); foreach (XmlElement elm in nodeList) { var container = new Container(); XmlNodeList titleList = elm.GetElementsByTagName("dc:title"); container.title = titleList[0].InnerText; titleList = elm.GetElementsByTagName("upnp:class"); container.upnpClass = titleList[0].InnerText; container.id = elm.GetAttribute("id"); container.parentID = elm.GetAttribute("parentID"); tmpList.Add(container); } return tmpList; }*/ public List<ITrack> itemReader(string xml) { var doc = new XmlDocument(); doc.Load("item.xml"); //doc.LoadXml(xml); var tracks = new List<ITrack>(); XmlNodeList nodeList = doc.GetElementsByTagName("item"); foreach (XmlElement elm in nodeList) { ITrack track = new Track(); XmlNodeList titleList = elm.GetElementsByTagName("upnp:album"); track.Album = titleList[0].InnerText; titleList = elm.GetElementsByTagName("dc:title"); track.Title = titleList[0].InnerText; titleList = elm.GetElementsByTagName("upnp:artist"); track.Artist = titleList[0].InnerText; titleList = elm.GetElementsByTagName("upnp:genre"); track.Genre = titleList[0].InnerText; //ToDo string split path and ip string[] s = titleList[0].InnerText.Split('/'); titleList = elm.GetElementsByTagName("res"); track.Path = titleList[0].InnerText; //ToDo string split path and ip track.DeviceIP = titleList[0].InnerText; track.Duration = titleList[0].Attributes["duration"].Value; track.Protocol = titleList[0].Attributes["protocolInfo"].Value; tracks.Add(track); } return tracks; }
/// <summary> /// Browse the database /// </summary> /// <param name="info">Info used for browsing the database</param> /// <returns>List of tracks matching the search criteria</returns> public List<ITrack> Browse(string info) { List<ITrack> trkList; SetupConnection(); string stm = "SELECT * FROM PIMusikData " + "INNER JOIN PIFilePath ON PIMusikData.FilePath_UUIDPath = PIFilePath.UUIDPath " + "INNER JOIN PIDevice ON PIFilePath.Device_UUIDDevice = PIDevice.UUIDDevice"; MySqlCommand cmd = new MySqlCommand(stm, _con); using (MySqlDataReader reader = cmd.ExecuteReader()) { trkList = new List<ITrack>(); while (reader.Read()) { var trk = new Track(); trk.Title = reader.GetString(1); trk.Duration = reader.GetUInt32(2).ToString(); trk.FileName = reader.GetString(3); trk.Artist = reader.GetString(4); trk.Album = reader.GetString(5); trk.Genre = reader.GetString(6); trk.Path = reader.GetString(9); trk.DeviceIP = reader.GetString(12); trk.Protocol = reader.GetString(14); trk.ParentID = "all"; trkList.Add(trk); } } if (_con != null) _con.Close(); return trkList; }
//private MySqlConnection _con; public List<ITrack> Browse(string info) { //MySqlCommand c = new MySqlCommand("Hej"); MySqlConnection _con; try { _con = new MySqlConnection(_conStr); _con.Open(); } catch (Exception) { Console.WriteLine("DB Connetion error"); throw; } /* var t = new List<ITrack>(); Console.WriteLine("In dblookup handler"); t.Add(new Track()); return t; */ List<ITrack> trkList; //SetupConnection(); string stm = "SELECT * FROM PIMusikData " + "INNER JOIN PIFilePath ON PIMusikData.FilePath_UUIDPath = PIFilePath.UUIDPath " + "INNER JOIN PIDevice ON PIFilePath.Device_UUIDDevice = PIDevice.UUIDDevice"; MySqlCommand cmd = new MySqlCommand(stm, _con); using (MySqlDataReader reader = cmd.ExecuteReader()) { trkList = new List<ITrack>(); while (reader.Read()) { var trk = new Track(); trk.Title = reader.GetString(1); trk.Duration = reader.GetUInt32(2).ToString(); trk.FileName = reader.GetString(3); trk.Artist = reader.GetString(4); trk.Album = reader.GetString(5); trk.Genre = reader.GetString(6); trk.Path = reader.GetString(9); trk.DeviceIP = reader.GetString(12); trk.Protocol = reader.GetString(14); trkList.Add(trk); } } if (_con != null) _con.Close(); return trkList; }