Exemplo n.º 1
0
        /// <summary>
        /// 项目列表
        /// </summary>
        protected string List_Get()
        {
            string prjsListHtml,
            //项目列表Html
                   propertyHtml;


            StringBuilder sb          = new StringBuilder();
            StringBuilder propertyStr = new StringBuilder();


            Project[] projects = this.director.GetProjects();
            if (projects == null)
            {
                sb.Append("<li>暂无采集项目![<a href=\"?action=create\">点击添加</a>]</li>");
            }
            else
            {
                foreach (Project prj in projects)
                {
                    //项目属性
                    foreach (string key in prj.Rules)
                    {
                        propertyStr.Append("[").Append(key).Append("],");
                    }
                    if (propertyStr.Length == 0)
                    {
                        propertyHtml = "无";
                    }
                    else
                    {
                        propertyHtml = propertyStr.Remove(propertyStr.Length - 1, 1).ToString();
                        propertyStr.Remove(0, propertyStr.Length);
                    }

                    //项目基本信息
                    sb.Append("<div class=\"project\"><h2><strong>项目名称:")
                    .Append(prj.Name)
                    .Append("</strong>(编号:")
                    .Append(prj.Id)
                    .Append(")</h2><p class=\"details\"> 编码方式:").Append(prj.RequestEncoding).Append("<br />列表规则:")
                    .Append(prj.ListUriRule).Append("<br />页面规则:")
                    .Append(prj.PageUriRule).Append("<br />采集属性:").Append(propertyHtml)
                    .Append("</p><span class=\"project_operate\">[&nbsp;<a href=\"?action=invoke&projectId=")
                    .Append(prj.Id).Append("\">开始采集</a>&nbsp;]&nbsp;&nbsp;[&nbsp;<a href=\"?action=edit&projectId=")
                    .Append(prj.Id).Append("\">修改</a>&nbsp;]&nbsp;&nbsp;[&nbsp;<a href=\"?action=delete&projectId=")
                    .Append(prj.Id).Append("\">删除</a>&nbsp;]</span></div>");
                }
            }

            prjsListHtml = sb.ToString();

            var html  = ResourcesReader.Read(assembly, prefix + "project_list.html");
            var html2 = ResourcesReader.Read(assembly, prefix + "partial_navigator.html");

            return(html.Replace("${ct_css}", ct_css)
                   .Replace("${subtitle}", subtitle)
                   .Replace("${navigator}", html2)
                   .Replace("${listHtml}", prjsListHtml));
        }
Exemplo n.º 2
0
        /// <summary>
        /// 返回样式表链接
        /// </summary>
        /// <returns></returns>
        public virtual string ReturnStyleLink()
        {
            var assembly = typeof(TagsManager).Assembly;
            var style    = ResourcesReader.Read(assembly, "HttpTag/Assets/style.html");

            return($"<style type=\"text/css\">{style}</style>");
        }
Exemplo n.º 3
0
        protected Task Show_WelcomePage(HttpContext ctx)
        {
            var welcomeHtml   = ResourcesReader.Read(assembly, prefix + "welcome_page.html");
            var navigatorHtml = ResourcesReader.Read(assembly, prefix + "partial_navigator.html");
            var html          = welcomeHtml.Replace("${ct_css}", ct_css)
                                .Replace("${navigator}", navigatorHtml);

            return(ctx.Response.WriteAsync(html));
        }
Exemplo n.º 4
0
        protected string CreateProject_Get()
        {
            var html  = ResourcesReader.Read(assembly, prefix + "project_list.html");
            var html2 = ResourcesReader.Read(assembly, prefix + "partial_navigator.html");

            return(html.Replace("${ct_css}", ct_css)
                   .Replace("${subtitle}", subtitle)
                   .Replace("${navigator}", html2));
        }
Exemplo n.º 5
0
        /// <summary>
        /// 获取内置语言文件
        /// </summary>
        /// <returns></returns>
        public static string GetXmlLangPackage()
        {
            if (InternalXmlLangPackage == null)
            {
                InternalXmlLangPackage = ResourcesReader.Read(typeof(ResourceMap).Assembly, "Infrastructure/Resources/lang_package.xml");
            }

            return(InternalXmlLangPackage);
        }
Exemplo n.º 6
0
        protected string Edit_Get()
        {
            string  projectId = request.GetParameter("projectId");
            Project prj       = this.director.GetProject(projectId);

            if (prj == null)
            {
                var html_  = ResourcesReader.Read(assembly, prefix + "error.html");
                var html2_ = ResourcesReader.Read(assembly, prefix + "partial_navigator.html");
                return(html_.Replace("${ct_css}", ct_css)
                       .Replace("${subtitle}", subtitle)
                       .Replace("${navigator}", html2_)
                       .Replace("${msg}", "项目不存在"));
            }

            StringBuilder sb = new StringBuilder();
            int           i  = 0;

            foreach (string key in prj.Rules)
            {
                ++i;
                sb.Append("<p><input type=\"text\" name=\"p").Append(i.ToString()).Append("\" value=\"")
                .Append(key).Append("\"/><textarea name=\"r").Append(i.ToString()).Append("\" class=\"rulebox2\">")
                .Append(prj.Rules[key]).Append("</textarea>")
                .Append(
                    "<span class=\"removeProperty\">[&nbsp;<a href=\"javascript:;\" onclick=\"removeProperty(this)\">删除</a>&nbsp;]</span></p>");
            }


            var html  = ResourcesReader.Read(assembly, prefix + "update_project.html");
            var html2 = ResourcesReader.Read(assembly, prefix + "partial_navigator.html");

            return(html
                   .Replace("${ct_css}", ct_css)
                   .Replace("${subtitle}", subtitle)
                   .Replace("${navigator}", html2)
                   .Replace("${id}", projectId)
                   .Replace("${name}", prj.Name)
                   .Replace("${encoding}", prj.RequestEncoding)
                   .Replace("${listUriRule}", prj.ListUriRule)
                   .Replace("${listBlockRule}", prj.ListBlockRule)
                   .Replace("${pageUriRule}", prj.PageUriRule)
                   .Replace("${filterWordsRule}", prj.FilterWordsRule)
                   .Replace("${propertiesHtml}", sb.ToString()));
        }
Exemplo n.º 7
0
        protected string Delete_Get()
        {
            string projectId = request.GetParameter("projectId");
            string confirm   = request.GetParameter("confirm");

            string msg; //返回信息


            Project prj = this.director.GetProject(projectId);

            if (prj == null)
            {
                msg = "<span style=\"color:red\">项目不存在!\"></span>";
            }


            if (String.IsNullOrEmpty(confirm))
            {
                msg = String.Format(
                    "您确定删除项目:<span style=\"color:red\">{0}</span>&nbsp;吗?<br /><a href=\"?action=delete&confirm=ok&projectid={1}\">确定</a>&nbsp;<a href=\"?action=list\">取消</a>"
                    , prj.Name, projectId);
            }
            else
            {
                msg = "项目删除成功!";

                this.director.RemoveProject(prj);

                //更新项目缓存
                this.director.ClearProjects();
            }

            var html  = ResourcesReader.Read(assembly, prefix + "delete_project.html");
            var html2 = ResourcesReader.Read(assembly, prefix + "partial_navigator.html");


            return(html
                   .Replace("${ct_css}", ct_css)
                   .Replace("${subtitle}", subtitle)
                   .Replace("${navigator}", html2)
                   .Replace("${msg}", msg));
        }
Exemplo n.º 8
0
        /// <summary>
        /// 处理请求
        /// </summary>
        /// <param name="context"></param>
        /// <param name="pageContent"></param>
        public void ProcessRequest(HttpContext context, string pageContent)
        {
            request  = context.Request;
            response = context.Response;



            //获取请求方式,确定执行的方法
            string method = request.Method;

            if (method == "GET")
            {
                string action = request.GetParameter("tag.action");
                if (String.IsNullOrEmpty(action))
                {
                    var assembly   = typeof(TagsManager).Assembly;
                    var tagManager = ResourcesReader.Read(assembly, "HttpTag/Assets/tags_manager.html");
                    Display_TagsList(String.IsNullOrEmpty(pageContent)?tagManager:pageContent);
                }
                else if (action == "test")
                {
                    Invoke_TestReplace();
                }
            }
            else
            {
                string action = request.Form["tag.action"];

                switch (action)
                {
                case "save": SaveTags(); break;

                case "delete": DeleteTags(); break;

                case "create": CreateTags(); break;
                }
            }
        }
Exemplo n.º 9
0
        /********************************************************
         *
         *  采集说明:
         *
         *  1.开始采集时读取继承类返回的Html代码,供重写Invoke方法读取某些参数!
         *
         *  2.客户端通过设置HiddenField  [typeid]的值,来识别采集单页或是列表
         *    [typeid]:1:采集单页,2:传递列表页参数采集,3:输入列表页参数采集
         *
         *  3.通过识别采集方式,来调用继承类的采集处理代码。执行完毕,想客户端传送
         *    采集完成指令!
         *
         */

        /// <summary>
        /// 开始执行采集
        /// </summary>
        protected string Invoke_Get()
        {
            string projectId = request.GetParameter("projectId");

            Project prj = this.director.GetProject(projectId);

            if (prj == null)
            {
                return("<script>window.parent.tip('项目不存在!');</script>");
            }

            var html  = ResourcesReader.Read(assembly, prefix + "invoke_collect.html");
            var html2 = ResourcesReader.Read(assembly, prefix + "partial_navigator.html");

            return(html
                   .Replace("${ct_css}", ct_css)
                   .Replace("${subtitle}", subtitle)
                   .Replace("${navigator}", html2)
                   .Replace("${customHtml}", Return_InvokePageHtml())
                   .Replace("${pageUriRule}", HttpUtility.HtmlEncode(prj.PageUriRule))
                   .Replace("${listUriRule}", HttpUtility.HtmlEncode(prj.ListUriRule)
                            .Replace("{0}", "<span style=\"color:red\">{0}</span>"))
                   .Replace("${listBlockRule}", HttpUtility.HtmlEncode(prj.ListBlockRule)));
        }
Exemplo n.º 10
0
 private static string GetResource(string fileName)
 {
     return(ResourcesReader.Read(typeof(SiteResourceInit).Assembly, fileName));
 }
Exemplo n.º 11
0
 /// <summary>
 /// 加载样式表
 /// </summary>
 protected string Css_Get()
 {
     return(ResourcesReader.Read(assembly, prefix + "style.css"));
 }
Exemplo n.º 12
0
        /// <summary>
        /// 显示模板信息到页面
        /// </summary>
        public static string GetTemplatePagesHTML()
        {
            string templateContent = ResourcesReader.Read(typeof(TemplateUtility).Assembly,
                                                          "Template/Resources/SysTemplatePage.html");
            StringBuilder sb = new StringBuilder();

            sb.Append(@"<style type=""text/css"">
                          table{width:100%;background:#eee;margin:0 auto;line-height:25px;color:#222;cursor:pointer}
                          table td{background:white;padding:0 8px;}
                          table th{background:#006699;color:white;}
                          table tr.hover td{background:#222;color:white;}
                          table tr.even td{}
                        </style>
                        <script type=""text/javascript"">
                             function dynamicTable(table) {
                                if (table && table.nodeName === 'TABLE') {
                                    var rows = table.getElementsByTagName('tr');
                                    for (var i = 0; i < rows.length; i++) {
                                    if (i % 2 == 1) if (!rows[i].className) rows[i].className = 'even';
                                    rows[i].onmouseover = function () {
                                        this.className = this.className.indexOf('even') != -1 ? 'hover even' : 'hover';
                                    };
                                    rows[i].onmouseout = function () {
                                        this.className = this.className.indexOf('even') == -1 ? '' : 'even';
                                    };
                                 }
                               }
                            }</script>

                        <table cellspacing=""1"" id=""templates"">
                            <tr>
                                <th style=""width:50px;""></th><th style=""width:150px;"">模板编号</th><th style=""width:80px;"">模板类型</th><th>文件名</th><th>模板注释</th><th>文件路径</th></tr>
				<!--
                <tr><td colspan=""6"" align=""center"" style=""background:#c20000;color:white"">扩展名为“.phtml”表示为一个部分视图;部分视图只能使用ID命名</td></tr>
                -->"        );

            string tplContent; //模板文件名,内容
            int    i = 0;

            foreach (string key in TemplateCache.TemplateDictionary.Keys)
            {
                var tpl         = TemplateCache.TemplateDictionary[key];
                var tplFileName = new Regex("templates(/|\\\\)+#*(.+?)$", RegexOptions.IgnoreCase).Match(tpl.FilePath).Groups[2].Value
                                  .Replace("\\", "/"); //模板文件名,内容
                tplContent = tpl.GetContent();

                sb.Append("<tr><td class=\"center\">").Append((++i).ToString()).Append("</td><td class=\"center\">")
                .Append(key.ToLower()).Append("</td><td class=\"center\">")
                .Append(
                    //RegexUtility.partialRegex.IsMatch(tplContent) && tplContent.IndexOf("<title>") != -1
                    !tpl.FilePath.EndsWith(".phtml")
                            ? "<span style=\"color:#333\">模板页面</span>"
                            : "<span style=\"color:#006699\">部分视图</span>")
                .Append("</td><td>/").Append(tplFileName).Append("</td><td>").Append(tpl.Comment)
                .Append("</td><td>").Append(tpl.FilePath).Append("</td></tr>");
            }

            sb.Append(@"<tr><td colspan=""6"" align=""center"" style=""background:#f0f0f0;color:#333"">
						部分视图扩展名为“.phtml”,可允许格式如:
						&nbsp;&nbsp;A:${include:""inc/header.html""}
						&nbsp;&nbsp;B:${include:""/tmpdir/inc/header.html""}
						&nbsp;&nbsp;C:${include:""../../inc/header.html""}
						</td></tr>"                        );

            sb.Append(
                "</table><script type=\"text/javascript\">dynamicTable(document.getElementsByTagName('table')[0]);</script>");

            templateContent = TemplateRegexUtility.Replace(templateContent, match =>
            {
                switch (match.Groups[1].Value)
                {
                case "title":
                    return("模板信息");

                case "content":
                    return(sb.ToString());

                case "year":
                    return(DateTime.Now.Year.ToString());
                }

                return(String.Empty);
            });
            return(TemplateUtils.CompressHtml(templateContent));
        }
Exemplo n.º 13
0
 public int Read(string type, Bitmap image)
 {
     return(ResourcesReader.Read(type, image));
 }