public RadioTime(RadioTime parent) { Head = new RadioTimeHead(parent.Head); Body = new List <RadioTimeOutline>(parent.Body); Settings = new RadioTimeSetting(parent.Settings); ParentUrl = parent.ParentUrl; CurentUrl = parent.CurentUrl; Parent = parent.Parent; Cache = parent.Cache; NavigationTitle = parent.NavigationTitle; }
/// <summary> /// Initializes a new instance of the <see cref="RadioTime"/> class. /// </summary> public RadioTime() { CurentUrl = "http://opml.radiotime.com/Index.aspx"; ParentUrl = CurentUrl; Head = new RadioTimeHead(); Body = new List<RadioTimeOutline>(); Settings = new RadioTimeSetting(); Cache = new Dictionary<string, RadioTime>(); Parent = null; NavigationTitle = ""; Selected = null; }
/// <summary> /// Initializes a new instance of the <see cref="RadioTime"/> class. /// </summary> public RadioTime() { CurentUrl = "http://opml.radiotime.com/Index.aspx"; ParentUrl = CurentUrl; Head = new RadioTimeHead(); Body = new List <RadioTimeOutline>(); Settings = new RadioTimeSetting(); Cache = new Dictionary <string, RadioTime>(); Parent = null; NavigationTitle = ""; Selected = null; }
/// <summary> /// Get and parse the online data. /// </summary> /// <param name="sUrl">The s URL.</param> /// <param name="useCache">if set to <c>true</c> [use cache].</param> /// <param name="useNavigationLogic">if set to <c>true</c> [use navigation logic].</param> /// <param name="navigationTitle">navigation title.</param> /// <returns></returns> public bool GetData(string sUrl, bool useCache, bool useNavigationLogic, string navigationTitle) { //Log.Debug("GetData " + sUrl); if (string.IsNullOrEmpty(sUrl)) return false; CacheIsUsed = useCache; if (useCache && Cache.ContainsKey(sUrl)) { if (useNavigationLogic) Parent = new RadioTime(this); ParentUrl = CurentUrl; CurentUrl = sUrl; Head = new RadioTimeHead(Cache[sUrl].Head); Body = new List<RadioTimeOutline>(Cache[sUrl].Body); if (useNavigationLogic) { string properTitle = Head.Title == string.Empty ? navigationTitle : Head.Title; NavigationTitle = NavigationTitle == string.Empty ? properTitle : NavigationTitle + " / " + properTitle; Parent.NavigationTitle = NavigationTitle; } return true; } else { Stream response = RetrieveData(sUrl); if (response != null) { if (sUrl != CurentUrl) { if (useNavigationLogic) { Parent = new RadioTime(this); } ParentUrl = CurentUrl; CurentUrl = sUrl; } // Get the stream associated with the response. StreamReader reader = new StreamReader(response, System.Text.Encoding.UTF8, true); String sXmlData = reader.ReadToEnd().Replace('\0', ' '); response.Close(); reader.Close(); try { XmlDocument doc = new XmlDocument(); doc.LoadXml(sXmlData); // skip xml node XmlNode root = doc.FirstChild.NextSibling; XmlNode headnodetitle = root.SelectSingleNode("head/title"); if (headnodetitle != null) { Head.Title = headnodetitle.InnerText.Trim(); } else { Head.Title = ""; } XmlNodeList bodynodes = root.SelectNodes("body/outline"); Body.Clear(); foreach (XmlNode node in bodynodes) { if (node.HasChildNodes) { foreach (XmlNode childnode in node.ChildNodes) { Body.Add(new RadioTimeOutline(childnode)); } } else { Body.Add(new RadioTimeOutline(node)); } } if (useCache) { Cache.Add(sUrl, new RadioTime(this)); } } catch (XmlException) { return false; } response.Close(); if (useNavigationLogic) { string properTitle = Head.Title == string.Empty ? navigationTitle : Head.Title; NavigationTitle = NavigationTitle == string.Empty ? properTitle : NavigationTitle + " / " + properTitle; Parent.NavigationTitle = NavigationTitle; } return true; } return true; } }
public RadioTimeHead(RadioTimeHead head) { Title = head.Title; }
/// <summary> /// Get and parse the online data. /// </summary> /// <param name="sUrl">The s URL.</param> /// <param name="useCache">if set to <c>true</c> [use cache].</param> /// <param name="useNavigationLogic">if set to <c>true</c> [use navigation logic].</param> /// <param name="navigationTitle">navigation title.</param> /// <returns></returns> public bool GetData(string sUrl, bool useCache, bool useNavigationLogic, string navigationTitle) { //Log.Debug("GetData " + sUrl); if (string.IsNullOrEmpty(sUrl)) { return(false); } CacheIsUsed = useCache; if (useCache && Cache.ContainsKey(sUrl)) { if (useNavigationLogic) { Parent = new RadioTime(this); } ParentUrl = CurentUrl; CurentUrl = sUrl; Head = new RadioTimeHead(Cache[sUrl].Head); Body = new List <RadioTimeOutline>(Cache[sUrl].Body); if (useNavigationLogic) { var properTitle = Head.Title == string.Empty ? navigationTitle : Head.Title; NavigationTitle = NavigationTitle == string.Empty ? properTitle : NavigationTitle + " / " + properTitle; Parent.NavigationTitle = NavigationTitle; } return(true); } else { var response = RetrieveData(sUrl); if (response != null) { if (sUrl != CurentUrl) { if (useNavigationLogic) { Parent = new RadioTime(this); } ParentUrl = CurentUrl; CurentUrl = sUrl; } // Get the stream associated with the response. var reader = new StreamReader(response, Encoding.UTF8, true); var sXmlData = reader.ReadToEnd().Replace('\0', ' '); response.Close(); reader.Close(); try { var doc = new XmlDocument(); doc.LoadXml(sXmlData); // skip xml node var root = doc.FirstChild.NextSibling; var headnodetitle = root.SelectSingleNode("head/title"); if (headnodetitle != null) { Head.Title = headnodetitle.InnerText.Trim(); } else { Head.Title = ""; } var bodynodes = root.SelectNodes("body/outline"); Body.Clear(); foreach (XmlNode node in bodynodes) { if (node.HasChildNodes) { foreach (XmlNode childnode in node.ChildNodes) { Body.Add(new RadioTimeOutline(childnode)); } } else { Body.Add(new RadioTimeOutline(node)); } } if (useCache) { Cache.Add(sUrl, new RadioTime(this)); } } catch (XmlException) { return(false); } response.Close(); if (useNavigationLogic) { var properTitle = Head.Title == string.Empty ? navigationTitle : Head.Title; NavigationTitle = NavigationTitle == string.Empty ? properTitle : NavigationTitle + " / " + properTitle; Parent.NavigationTitle = NavigationTitle; } return(true); } return(true); } }