/// <summary> /// Loads the XML. /// </summary> /// <param name="filename"> /// The filename. /// </param> /// <returns> /// A bool value... /// </returns> private bool LoadXml(string filename) { var nt = new NameTable(); var nsm = new XmlNamespaceManager(nt); nsm.AddNamespace(string.Empty, "http://www.w3.org/1999/xhtml"); var context = new XmlParserContext(nt, nsm, string.Empty, XmlSpace.None); var returnValue = false; try { // Create an XmlTextReader using a FileStream. using (Stream fs = new FileStream(filename, FileMode.Open, FileAccess.Read, FileShare.Read)) { try { var xtr = new XmlTextReader(fs, XmlNodeType.Document, context) { WhitespaceHandling = WhitespaceHandling.None }; ThemeImage themeImage; var themePart = new ThemePart(); while (!xtr.EOF) { if (xtr.MoveToContent() == XmlNodeType.Element) { switch (xtr.LocalName) { case "Name": this.currentTheme.Name = xtr.ReadString(); break; case "Type": this.currentTheme.Type = xtr.ReadString(); break; case "Css": this.currentTheme.Css = xtr.ReadString(); break; case "MinimizeColor": this.currentTheme.MinimizeColor = xtr.ReadString(); break; case "ThemeImage": themeImage = new ThemeImage(); while (xtr.MoveToNextAttribute()) { switch (xtr.LocalName) { case "Name": themeImage.Name = xtr.Value; break; case "ImageUrl": themeImage.ImageUrl = xtr.Value; break; case "Width": themeImage.Width = double.Parse(xtr.Value); break; case "Height": themeImage.Height = double.Parse(xtr.Value); break; default: break; } } this.currentTheme.ThemeImages.Add(themeImage.Name, themeImage); xtr.MoveToElement(); break; case "ThemePart": themePart = new ThemePart(); while (xtr.MoveToNextAttribute()) { switch (xtr.LocalName) { case "Name": themePart.Name = xtr.Value; break; default: break; } } xtr.MoveToElement(); break; case "HTML": if (themePart.Name.Length != 0) { themePart.Html = xtr.ReadString(); } // Moved here on load instead on retrival. // by Manu var w = string.Concat(this.currentTheme.WebPath, "/"); themePart.Html = themePart.Html.Replace("src='", string.Concat("src='", w)); themePart.Html = themePart.Html.Replace("src=\"", string.Concat("src=\"", w)); themePart.Html = themePart.Html.Replace( "background='", string.Concat("background='", w)); themePart.Html = themePart.Html.Replace( "background=\"", string.Concat("background=\"", w)); this.currentTheme.ThemeParts.Add(themePart.Name, themePart); break; default: // Debug.WriteLine(" - unwanted"); break; } } xtr.Read(); } returnValue = true; } catch (Exception ex) { ErrorHandler.Publish( LogLevel.Error, string.Format("Failed to Load XML Theme : {0} Message was: {1}", filename, ex.Message)); } finally { fs.Close(); } } } catch (Exception ex) { ErrorHandler.Publish( LogLevel.Error, string.Format("Failed to open XML Theme : {0} Message was: {1}", filename, ex.Message)); } return(returnValue); }
/// <summary> /// Loads the XML. /// </summary> /// <param name="filename"> /// The filename. /// </param> /// <returns> /// A bool value... /// </returns> private bool LoadXml(string filename) { var nt = new NameTable(); var nsm = new XmlNamespaceManager(nt); nsm.AddNamespace(string.Empty, "http://www.w3.org/1999/xhtml"); var context = new XmlParserContext(nt, nsm, string.Empty, XmlSpace.None); var returnValue = false; try { // Create an XmlTextReader using a FileStream. using (Stream fs = new FileStream(filename, FileMode.Open, FileAccess.Read, FileShare.Read)) { try { var xtr = new XmlTextReader(fs, XmlNodeType.Document, context) { WhitespaceHandling = WhitespaceHandling.None }; ThemeImage themeImage; var themePart = new ThemePart(); while (!xtr.EOF) { if (xtr.MoveToContent() == XmlNodeType.Element) { switch (xtr.LocalName) { case "Name": this.currentTheme.Name = xtr.ReadString(); break; case "Type": this.currentTheme.Type = xtr.ReadString(); break; case "Css": this.currentTheme.Css = xtr.ReadString(); break; case "MinimizeColor": this.currentTheme.MinimizeColor = xtr.ReadString(); break; case "ThemeImage": themeImage = new ThemeImage(); while (xtr.MoveToNextAttribute()) { switch (xtr.LocalName) { case "Name": themeImage.Name = xtr.Value; break; case "ImageUrl": themeImage.ImageUrl = xtr.Value; break; case "Width": themeImage.Width = double.Parse(xtr.Value); break; case "Height": themeImage.Height = double.Parse(xtr.Value); break; default: break; } } this.currentTheme.ThemeImages.Add(themeImage.Name, themeImage); xtr.MoveToElement(); break; case "ThemePart": themePart = new ThemePart(); while (xtr.MoveToNextAttribute()) { switch (xtr.LocalName) { case "Name": themePart.Name = xtr.Value; break; default: break; } } xtr.MoveToElement(); break; case "HTML": if (themePart.Name.Length != 0) { themePart.Html = xtr.ReadString(); } // Moved here on load instead on retrival. // by Manu var w = string.Concat(this.currentTheme.WebPath, "/"); themePart.Html = themePart.Html.Replace("src='", string.Concat("src='", w)); themePart.Html = themePart.Html.Replace("src=\"", string.Concat("src=\"", w)); themePart.Html = themePart.Html.Replace( "background='", string.Concat("background='", w)); themePart.Html = themePart.Html.Replace( "background=\"", string.Concat("background=\"", w)); this.currentTheme.ThemeParts.Add(themePart.Name, themePart); break; default: // Debug.WriteLine(" - unwanted"); break; } } xtr.Read(); } returnValue = true; } catch (Exception ex) { ErrorHandler.Publish( LogLevel.Error, string.Format("Failed to Load XML Theme : {0} Message was: {1}", filename, ex.Message)); } finally { fs.Close(); } } } catch (Exception ex) { ErrorHandler.Publish( LogLevel.Error, string.Format("Failed to open XML Theme : {0} Message was: {1}", filename, ex.Message)); } return returnValue; }