csharp Umbraco安装包动作,向仪表板添加新的“选项卡”(不是“部分”)。用于:https://github.com/EndzoneSoftware/uWhiteL

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了csharp Umbraco安装包动作,向仪表板添加新的“选项卡”(不是“部分”)。用于:https://github.com/EndzoneSoftware/uWhiteL相关的知识,希望对你有一定的参考价值。

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;
        }
    }
}

以上是关于csharp Umbraco安装包动作,向仪表板添加新的“选项卡”(不是“部分”)。用于:https://github.com/EndzoneSoftware/uWhiteL的主要内容,如果未能解决你的问题,请参考以下文章

csharp 一个Umbraco启动课程

csharp 用于嘲弄的Umbraco测试容器

csharp Umbraco获得所有重复的媒体

csharp 一堆Umbraco Membership API片段

csharp 使用Umbraco Examine API搜索多个术语。

csharp Umbraco IPublishedContent的一些有用的扩展方法。