⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 htmlcategory.cs

📁 动易SiteFactory&#8482 网上商店系统1.0源代码
💻 CS
字号:
namespace PowerEasy.StaticHtml
{
    using PowerEasy.Common;
    using PowerEasy.Components;
    using PowerEasy.Contents;
    using PowerEasy.Enumerations;
    using PowerEasy.Model.Contents;
    using PowerEasy.Model.TemplateProc;
    using PowerEasy.Templates;
    using System;
    using System.Collections.Generic;
    using System.Collections.Specialized;
    using System.Web;

    public sealed class HtmlCategory : HtmlAbstract
    {
        private string m_NodeIdArray;

        private static bool CheckIsNeedCreatHtml(NodeInfo nodeInfo)
        {
            return (nodeInfo.IsCreateListPage && (nodeInfo.PurviewType == 0));
        }

        private bool CreateAndCheckFolderPermission(NodeInfo nodeInfo)
        {
            string file = VirtualPathUtility.AppendTrailingSlash(SiteConfig.SiteOption.CreateHtmlPath) + nodeInfo.ParentDir + nodeInfo.NodeDir;
            file = VirtualPathUtility.AppendTrailingSlash(this.PhysicalApplicationPath) + file;
            if (!FileSystemObject.IsExist(file, FsoMethod.Folder))
            {
                try
                {
                    FileSystemObject.Create(file, FsoMethod.Folder);
                }
                catch
                {
                    string errMsg = "栏目ID:" + nodeInfo.NodeId.ToString() + "  " + nodeInfo.NodeName + " 生成失败! 失败原因:请检查服务器是否给网站" + SiteConfig.SiteOption.CreateHtmlPath + "文件夹写入权限!";
                    this.ErrorLog(errMsg);
                    return false;
                }
            }
            return true;
        }

        public void CreateNode()
        {
            IList<NodeInfo> nodesList = Nodes.GetNodesList(this.m_NodeIdArray);
            this.CreateCount = nodesList.Count;
            this.CreateStartTime = DateTime.Now;
            this.CreateMessage = "";
            foreach (NodeInfo info in nodesList)
            {
                if (CheckIsNeedCreatHtml(info))
                {
                    if (!this.CreateAndCheckFolderPermission(info))
                    {
                        this.CreateMessage = "<li>栏目ID:" + info.NodeId.ToString() + "&nbsp;&nbsp;栏目名: " + info.NodeName + " 生成失败! 失败原因:请检查服务器是否给网站" + SiteConfig.SiteOption.CreateHtmlPath + "文件夹写入权限!</li>";
                        break;
                    }
                    this.CreateNodesHtml(info);
                }
                else
                {
                    this.CreateMessage = "<li><font color='red'>栏目ID:" + info.NodeId.ToString() + "&nbsp;&nbsp;栏目名: " + info.NodeName + "因设置了访问权限而跳过生成!</font></li>" + this.CreateMessage;
                }
                this.CreateCompleted++;
            }
            this.CreateMessage = "全部生成完成!" + this.CreateMessage;
            this.CreateCompleted = this.CreateCount;
            this.CreateEndTime = DateTime.Now;
        }

        private void CreateNodeDefalutPageHtml(NodeInfo nodeInfo, TemplateInfo templateInfo)
        {
            string path = string.Empty;
            if (string.IsNullOrEmpty(nodeInfo.DefaultTemplateFile))
            {
                path = nodeInfo.ContainChildTemplateFile;
                templateInfo.PageName = SiteConfig.SiteInfo.VirtualPath + SiteConfig.SiteOption.CreateHtmlPath + nodeInfo.ListHtmlPageName("{$pageid/}");
            }
            else
            {
                templateInfo.PageName = SiteConfig.SiteInfo.VirtualPath + SiteConfig.SiteOption.CreateHtmlPath + nodeInfo.ListHtmlPageName("0");
                path = nodeInfo.DefaultTemplateFile;
            }
            try
            {
                string str2;
                templateInfo.CurrentPage = 1;
                templateInfo.TemplateContent = Template.GetTemplateContent(path, this.PhysicalApplicationPath);
                TemplateTransform.GetHtml(templateInfo);
                if (nodeInfo.NodeId == -2)
                {
                    str2 = nodeInfo.ListHtmlPageName("0");
                }
                else
                {
                    str2 = VirtualPathUtility.AppendTrailingSlash(SiteConfig.SiteOption.CreateHtmlPath) + nodeInfo.ListHtmlPageName("0");
                }
                FileSystemObject.WriteFile(VirtualPathUtility.AppendTrailingSlash(this.PhysicalApplicationPath) + str2, templateInfo.TemplateContent);
                string str3 = (VirtualPathUtility.AppendTrailingSlash(SiteConfig.SiteInfo.VirtualPath) + str2).Replace("//", "/");
                this.CreateMessage = string.Concat(new object[] { "<li>成功生成第", this.CreateCompleted + 1, "个栏目的栏目首页,栏目名:<a target=_blank href=", str3, ">", nodeInfo.NodeName, "</a></li>", this.CreateMessage });
            }
            catch
            {
                this.CreateMessage = string.Concat(new object[] { "<li>第<font color='red'><b>", this.CreateCompleted + 1, "</b>条信息生成失败</font>&nbsp;&nbsp;栏目名:", nodeInfo.NodeName, "&nbsp;&nbsp;标签解析出现异常,跳过生成</li>", this.CreateMessage });
            }
        }

        private void CreateNodeListPageHtml(NodeInfo nodeInfo, TemplateInfo templateInfo)
        {
            if (nodeInfo.NodeType != NodeType.Single)
            {
                try
                {
                    templateInfo.PageName = SiteConfig.SiteInfo.VirtualPath + VirtualPathUtility.AppendTrailingSlash(SiteConfig.SiteOption.CreateHtmlPath) + nodeInfo.ListHtmlPageName("{$pageid/}");
                    templateInfo.TemplateContent = Template.GetTemplateContent(nodeInfo.ContainChildTemplateFile, this.PhysicalApplicationPath);
                    TemplateTransform.GetHtml(templateInfo);
                    string str = VirtualPathUtility.AppendTrailingSlash(SiteConfig.SiteOption.CreateHtmlPath) + nodeInfo.ListHtmlPageName("1");
                    FileSystemObject.WriteFile(VirtualPathUtility.AppendTrailingSlash(this.PhysicalApplicationPath) + str, templateInfo.TemplateContent);
                    int pageNum = templateInfo.PageNum;
                    string str2 = (VirtualPathUtility.AppendTrailingSlash(SiteConfig.SiteInfo.VirtualPath) + str).Replace("//", "/");
                    this.CreateMessage = string.Concat(new object[] { "<li>成功生成第", this.CreateCompleted + 1, "个栏目的栏目列表页,栏目名:<a target=_blank href=", str2, ">", nodeInfo.NodeName, "</a></li>", this.CreateMessage });
                    for (int i = 1; i < pageNum; i++)
                    {
                        templateInfo.TemplateContent = Template.GetTemplateContent(nodeInfo.ContainChildTemplateFile, this.PhysicalApplicationPath);
                        NameValueCollection values = new NameValueCollection();
                        values.Add("id", nodeInfo.NodeId.ToString());
                        values.Add("page", (i + 1).ToString());
                        templateInfo.QueryList = values;
                        templateInfo.PageName = SiteConfig.SiteInfo.VirtualPath + VirtualPathUtility.AppendTrailingSlash(SiteConfig.SiteOption.CreateHtmlPath) + nodeInfo.ListHtmlPageName("{$pageid/}");
                        templateInfo.CurrentPage = i + 1;
                        TemplateTransform.GetHtml(templateInfo);
                        int num5 = i + 1;
                        str = VirtualPathUtility.AppendTrailingSlash(SiteConfig.SiteOption.CreateHtmlPath) + nodeInfo.ListHtmlPageName(num5.ToString());
                        FileSystemObject.WriteFile(VirtualPathUtility.AppendTrailingSlash(this.PhysicalApplicationPath) + str, templateInfo.TemplateContent);
                        str2 = (VirtualPathUtility.AppendTrailingSlash(SiteConfig.SiteInfo.VirtualPath) + str).Replace("//", "/");
                        this.CreateMessage = string.Concat(new object[] { "<li>成功生成第", this.CreateCompleted + 1, "个栏目的栏目列表页的第", i, "个分页,栏目名:<a target=_blank href=", str2, ">", nodeInfo.NodeName, "</a></li>", this.CreateMessage });
                    }
                }
                catch
                {
                    this.CreateMessage = string.Concat(new object[] { "<li>第<font color='red'><b>", this.CreateCompleted + 1, "</b>条信息生成失败</font>&nbsp;&nbsp;栏目名:", nodeInfo.NodeName, "&nbsp;&nbsp;标签解析出现异常,跳过生成</li>", this.CreateMessage });
                }
            }
        }

        public void CreateNodesHtml(NodeInfo nodeInfo)
        {
            TemplateInfo templateInfo = new TemplateInfo();
            NameValueCollection values = new NameValueCollection();
            values.Add("id", nodeInfo.NodeId.ToString());
            values.Add("page", "1");
            templateInfo.QueryList = values;
            templateInfo.RootPath = this.PhysicalApplicationPath;
            templateInfo.SiteUrl = this.SiteUrl;
            templateInfo.IsDynamicPage = false;
            templateInfo.PageType = 1;
            this.CreateNodeDefalutPageHtml(nodeInfo, templateInfo);
            templateInfo = new TemplateInfo();
            values = new NameValueCollection();
            values.Add("id", nodeInfo.NodeId.ToString());
            values.Add("page", "1");
            templateInfo.QueryList = values;
            templateInfo.RootPath = this.PhysicalApplicationPath;
            templateInfo.SiteUrl = this.SiteUrl;
            templateInfo.IsDynamicPage = false;
            templateInfo.PageType = 1;
            this.CreateNodeListPageHtml(nodeInfo, templateInfo);
        }

        public override void Work()
        {
            this.CreateMessage = "正在准备生成......";
            try
            {
                lock (this)
                {
                    this.CreateNode();
                }
            }
            catch
            {
                this.CreateCompleted = this.CreateCount;
            }
            finally
            {
                if ((this.CreateThread != null) && (this.CreateCompleted == this.CreateCount))
                {
                    this.CreateThread.Abort();
                }
            }
        }

        public string NodeIdArray
        {
            get
            {
                return this.m_NodeIdArray;
            }
            set
            {
                this.m_NodeIdArray = value;
            }
        }
    }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -