Created
March 22, 2016 15:08
-
-
Save barryokane/fef9996ef6fb9c639672 to your computer and use it in GitHub Desktop.
Umbraco install package action that adds a new "tab" to the dashboard (not a "Section"). Used in: https://github.com/EndzoneSoftware/uWhiteLabel
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System.Xml; | |
using umbraco.interfaces; | |
using Umbraco.Core.IO; | |
using Umbraco.Core; | |
using uWhiteLabel.Properties; | |
namespace uWhiteLabel.Install | |
{ | |
public class uWhiteLabelDashboardAction : IPackageAction | |
{ | |
private const string startupSectionXPth = "//section[@alias='StartupDashboardSection']"; | |
// we assume that no tab with same caption attribute value exists, if it does then do nothing! | |
private const string welcomeTabXPath = "//section[@alias='StartupDashboardSection']/tab[@caption='Welcome']"; | |
public string Alias() | |
{ | |
return "uWhiteLabelDashboard"; | |
} | |
public bool Execute(string packageName, XmlNode xmlData) | |
{ | |
string xmlTab = Resources.DashboardWelcomeTab; | |
string dbConfig = SystemFiles.DashboardConfig; | |
XmlDocument dashboardFile = XmlHelper.OpenAsXmlDocument(dbConfig); | |
XmlNode existingWelcomeTab = dashboardFile.SelectSingleNode(welcomeTabXPath); | |
if (existingWelcomeTab == null) | |
{ | |
XmlNode section = dashboardFile.SelectSingleNode(startupSectionXPth); | |
XmlDocumentFragment xfrag = dashboardFile.CreateDocumentFragment(); | |
xfrag.InnerXml = xmlTab; | |
section.PrependChild(xfrag); | |
dashboardFile.Save(IOHelper.MapPath(dbConfig)); | |
} | |
return true; | |
} | |
public bool Undo(string packageName, XmlNode xmlData) | |
{ | |
string dbConfig = SystemFiles.DashboardConfig; | |
XmlDocument dashboardFile = XmlHelper.OpenAsXmlDocument(dbConfig); | |
XmlNode section = dashboardFile.SelectSingleNode(welcomeTabXPath); | |
if (section != null) | |
{ | |
dashboardFile.SelectSingleNode(startupSectionXPth).RemoveChild(section); | |
dashboardFile.Save(IOHelper.MapPath(dbConfig)); | |
} | |
return true; | |
} | |
public XmlNode SampleXml() | |
{ | |
var xml = "<Action runat=\"install\" undo=\"true\" alias=\"uWhiteLabelDashboard\" />"; | |
XmlDocument x = new XmlDocument(); | |
x.LoadXml(xml); | |
return x; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment