Exemplo n.º 1
0
        public ServerResponse SavePage([FromBody] ReportPageContent page)
        {
            ServerResponse result = new ServerResponse();

            try
            {
                StringBuilder sb = new StringBuilder();
                if (!string.IsNullOrEmpty(page.Css))
                {
                    sb.AppendLine("<style type=\"text/css\">");
                    sb.AppendLine(page.Css);
                    sb.AppendLine("</style>");
                }
                sb.AppendLine("<!-- start html content -->");
                sb.AppendLine(page.Html);
                sb.AppendLine("<!-- end html content -->");
                if (!string.IsNullOrEmpty(page.Js))
                {
                    sb.AppendLine("<script type=\"text/javascript\">");
                    sb.AppendLine(page.Js);
                    sb.AppendLine("</script>");
                }
                File.WriteAllText(page.File, sb.ToString(), System.Text.Encoding.UTF8);

                result.Status  = ResponseStatus.Success;
                result.Message = "成功保存页面";
            }
            catch (Exception ex)
            {
                result.Status  = ResponseStatus.Exception;
                result.Message = ex.Message;
            }
            return(result);
        }
Exemplo n.º 2
0
        public ReportPageContent GetPage(string path)
        {
            FileInfo f = new FileInfo(path);

            if (!f.Exists)
            {
                f.Create();
            }

            var content               = System.IO.File.ReadAllText(path, System.Text.Encoding.UTF8);
            ReportPageContent page    = new ReportPageContent();
            StringReader      sr      = new StringReader(content);
            string            line    = string.Empty;
            int           contentType = 0; // 0: none, 1: css, 2: html, 3: js
            StringBuilder sbCss       = new StringBuilder();
            StringBuilder sbHtml      = new StringBuilder();
            StringBuilder sbJs        = new StringBuilder();

            line = sr.ReadLine();
            while (line != null)
            {
                switch (contentType)
                {
                case 1:
                    if (line == "</style>")
                    {
                        contentType = 0;
                    }
                    else
                    {
                        sbCss.AppendLine(line);
                    }
                    break;

                case 2:
                    if (line == "<!-- end html content -->")
                    {
                        contentType = 0;
                    }
                    else
                    {
                        sbHtml.AppendLine(line);
                    }
                    break;

                case 3:
                    if (line == "</script>")
                    {
                        contentType = 0;
                    }
                    else
                    {
                        sbJs.AppendLine(line);
                    }
                    break;

                case 0:
                    if (line == "<style type=\"text/css\">")
                    {
                        contentType = 1;
                    }
                    else if (line == "<!-- start html content -->")
                    {
                        contentType = 2;
                    }
                    else if (line == "<script type=\"text/javascript\">")
                    {
                        contentType = 3;
                    }
                    break;
                }
                line = sr.ReadLine();
            }
            page.Css  = sbCss.ToString();
            page.Html = sbHtml.ToString();
            page.Js   = sbJs.ToString();
            return(page);
        }