From 379a0d68f7b39658c5115a2e9be99695fdba97cf Mon Sep 17 00:00:00 2001 From: Claus Date: Tue, 26 Jul 2016 13:38:06 +0200 Subject: [PATCH] U4-8733 Trying to include a stylesheet in a package results in a YSOD --- .../developer/Packages/editPackage.aspx.cs | 18 +++++---- .../PackageInstance/CreatedPackage.cs | 9 ++--- .../Packager/PackageInstance/utill.cs | 38 ++++++++++--------- 3 files changed, 33 insertions(+), 32 deletions(-) diff --git a/src/Umbraco.Web/umbraco.presentation/umbraco/developer/Packages/editPackage.aspx.cs b/src/Umbraco.Web/umbraco.presentation/umbraco/developer/Packages/editPackage.aspx.cs index e58cc2f045..05989ba28e 100644 --- a/src/Umbraco.Web/umbraco.presentation/umbraco/developer/Packages/editPackage.aspx.cs +++ b/src/Umbraco.Web/umbraco.presentation/umbraco/developer/Packages/editPackage.aspx.cs @@ -114,16 +114,18 @@ namespace umbraco.presentation.developer.packages } /*Stylesheets */ - StyleSheet[] sheets = StyleSheet.GetAll(); - foreach (StyleSheet st in sheets) + var sheets = Services.FileService.GetStylesheets(); + foreach (var st in sheets) { - ListItem li = new ListItem(st.Text, st.Id.ToString()); - if (pack.Stylesheets.Contains(st.Id.ToString())) - li.Selected = true; - - stylesheets.Items.Add(li); - + if (string.IsNullOrEmpty(st.Name) == false) + { + var li = new ListItem(st.Alias, st.Name); + if (pack.Stylesheets.Contains(st.Name)) + li.Selected = true; + stylesheets.Items.Add(li); + } } + /* MACROS */ Macro[] umbMacros = Macro.GetAll(); foreach (Macro m in umbMacros) diff --git a/src/umbraco.cms/businesslogic/Packager/PackageInstance/CreatedPackage.cs b/src/umbraco.cms/businesslogic/Packager/PackageInstance/CreatedPackage.cs index aa3a788be4..3d9ef6a827 100644 --- a/src/umbraco.cms/businesslogic/Packager/PackageInstance/CreatedPackage.cs +++ b/src/umbraco.cms/businesslogic/Packager/PackageInstance/CreatedPackage.cs @@ -246,13 +246,10 @@ namespace umbraco.cms.businesslogic.packager //Stylesheets var stylesheets = _packageManifest.CreateElement("Stylesheets"); - foreach (var ssId in pack.Stylesheets) + foreach (var stylesheetName in pack.Stylesheets) { - if (int.TryParse(ssId, out outInt)) - { - var s = new StyleSheet(outInt); - stylesheets.AppendChild(s.ToXml(_packageManifest)); - } + var stylesheetXmlNode = utill.Stylesheet(stylesheetName, true, _packageManifest); + stylesheets.AppendChild(stylesheetXmlNode); } AppendElement(stylesheets); diff --git a/src/umbraco.cms/businesslogic/Packager/PackageInstance/utill.cs b/src/umbraco.cms/businesslogic/Packager/PackageInstance/utill.cs index 5c1d6cf662..f31862b842 100644 --- a/src/umbraco.cms/businesslogic/Packager/PackageInstance/utill.cs +++ b/src/umbraco.cms/businesslogic/Packager/PackageInstance/utill.cs @@ -92,37 +92,39 @@ namespace umbraco.cms.businesslogic.packager { return template; } - /// /// Converts a umbraco stylesheet to a package xml node /// - /// The ss id. - /// if set to true [incluce properties]. + /// The name of the stylesheet. + /// if set to true [incluce properties]. /// The doc. /// - public static XmlNode Stylesheet(int ssId, bool incluceProperties, XmlDocument doc) { - - StyleSheet sts = new StyleSheet(ssId); - XmlNode stylesheet = doc.CreateElement("Stylesheet"); - stylesheet.AppendChild(_node("Name", sts.Text, doc)); - stylesheet.AppendChild(_node("FileName", sts.Filename, doc)); + public static XmlNode Stylesheet(string name, bool includeProperties, XmlDocument doc) + { + if (ApplicationContext.Current == null) + throw new NullReferenceException("ApplicationContext is null"); + var fileService = ApplicationContext.Current.Services.FileService; + + var sts = fileService.GetStylesheetByName(name); + var stylesheet = doc.CreateElement("Stylesheet"); + stylesheet.AppendChild(_node("Name", sts.Alias, doc)); + stylesheet.AppendChild(_node("FileName", sts.Name, doc)); stylesheet.AppendChild(_node("Content", "", doc)); - if (incluceProperties) { - XmlNode properties = doc.CreateElement("Properties"); - foreach (StylesheetProperty ssP in sts.Properties) { - XmlNode property = doc.CreateElement("Property"); - property.AppendChild(_node("Name", ssP.Text, doc)); + if (includeProperties) + { + var properties = doc.CreateElement("Properties"); + foreach (var ssP in sts.Properties) + { + var property = doc.CreateElement("Property"); + property.AppendChild(_node("Name", ssP.Name, doc)); property.AppendChild(_node("Alias", ssP.Alias, doc)); - property.AppendChild(_node("Value", ssP.value, doc)); - - //xnode += "" + ssP.Text + "" + ssP.Alias + "" + ssP.value + "\n"; + property.AppendChild(_node("Value", ssP.Value, doc)); } stylesheet.AppendChild(properties); } return stylesheet; } - /// /// Converts a macro to a package xml node ///