Esempio n. 1
0
        /// <summary>
        /// Process the page in aspFile string. Pagepath is only used for getting included files.
        /// </summary>
        /// <param name="pagePath"></param>
        /// <param name="aspFile"></param>
        /// <param name="virtualRootPath">Physical path of the virtual root used when this class is used
        public void processPage(string pagePath, string aspFile, string virtualRootPath)
        {
            _virtualRootPath = virtualRootPath;
            Dlrsoft.VBScript.Compiler.Range[] lineRanges = SourceUtil.GetLineRanges(aspFile);
            const string    pattern = "<%(?<contents>.*?)%>|<!--\\s*#include\\s+(?<contents>.*?)\\s*-->|<script[^>]+runat=\"?server\"?[^>]*>(?<contents>.*?)</script>";
            Regex           r       = new Regex(pattern, RegexOptions.IgnoreCase | RegexOptions.Singleline);
            MatchCollection ms      = r.Matches(aspFile);

            int p1 = 0;
            int p2 = 0;

            foreach (Match m in ms)
            {
                p2 = m.Index;
                if (p2 - p1 > 0)
                {
                    appendBlock(pagePath, SourceUtil.GetSpan(lineRanges, p1, p2 - 1), GetListeral(aspFile, p1, p2), 1);
                }
                p1 = m.Index + m.Length;

                string value    = m.Value.Trim();
                string contents = m.Groups["contents"].Value.Trim();

                if (value.StartsWith("<!-"))
                {
                    processInclude(pagePath, contents.ToLower());
                }
                else if (Regex.IsMatch(value, "^<%\\s*@"))
                {
                }
                else
                {
                    string temp = contents.Trim();
                    if (!string.IsNullOrEmpty(temp))
                    {
                        if (temp[0] == '=') //Expression
                        {
                            contents = string.Format("response.Write({0})", temp.Substring(1).Trim());
                            appendBlock(pagePath, SourceUtil.GetSpan(lineRanges, m.Index, p1 - 1), contents, 1);
                        }
                        else
                        {
                            appendBlock(pagePath, SourceUtil.GetSpan(lineRanges, m.Index, p1 - 1), contents, SourceUtil.GetLineCount(contents));
                        }
                    }
                }
            }
            p2 = aspFile.Length;
            if (p2 - p1 > 0)
            {
                appendBlock(pagePath, SourceUtil.GetSpan(lineRanges, p1, p2 - 1), GetListeral(aspFile, p1, p2), 1);
            }
        }
Esempio n. 2
0
        /// <summary>
        /// Process the page in aspFile string. Pagepath is only used for getting included files.
        /// </summary>
        /// <param name="pagePath"></param>
        /// <param name="aspFile"></param>
        /// <param name="virtualRootPath">Physical path of the virtual root used when this class is used
        public void processPage(string pagePath, string aspFile, string virtualRootPath)
        {
            _virtualRootPath = virtualRootPath;
            Range[]         lineRanges = SourceUtil.GetLineRanges(aspFile);
            const string    pattern    = "<%(?<contents>.*?)%>|<!--\\s*#include\\s+(?<contents>.*?)\\s*-->|<script[^>]+runat=\"?server\"?[^>]*>(?<contents>.*?)</script>";
            Regex           r          = new Regex(pattern, RegexOptions.IgnoreCase | RegexOptions.Singleline);
            MatchCollection ms         = r.Matches(aspFile);
            int             p1         = 0;
            int             p2         = 0;

            foreach (Match m in ms)
            {
                p2 = m.Index;
                if (p2 - p1 > 0)
                {
                    appendBlock(pagePath, SourceUtil.GetSpan(lineRanges, p1, p2 - 1), GetListeral(aspFile, p1, p2), 1);
                }
                p1 = m.Index + m.Length;
                string value    = m.Value;
                string contents = m.Groups["contents"].Value;
                switch (value.Substring(0, 3))
                {
                case "<!-":     //Include
                    processInclude(pagePath, contents.ToLower(), SourceUtil.GetSpan(lineRanges, m.Index, p1 - 1), value);
                    break;

                case "<%@":     //Declaration. Ignore
                    break;

                default:
                    string temp = contents.Trim();
                    if (!string.IsNullOrEmpty(temp))
                    {
                        if (temp[0] == '=')                                           //Expression
                        {
                            contents = "@Html.Raw(" + temp.Substring(1).Trim() + ")"; //string.Format("response.Write({0})", temp.Substring(1).Trim());
                            appendBlock(pagePath, SourceUtil.GetSpan(lineRanges, m.Index, p1 - 1), contents, 1);
                        }
                        else
                        {
                            if (ProcessCode != null)
                            {
                                contents = ProcessCode(contents);
                            }

                            var preceeding = m.Index > 0 ? aspFile.Substring(m.Index - 1, 1) : " ";
                            var codePrefix = (Regex.IsMatch(preceeding, @"\s|[>='\""]") ? "" : " ")
                                             + "@Code";

                            if (!contents.StartsWith(" "))
                            {
                                codePrefix += " ";
                            }
                            contents = codePrefix + contents;

                            if (!contents.EndsWith("\n") && !contents.EndsWith(" "))
                            {
                                contents += " ";
                            }

                            contents += "End Code";
                            var nextChar  = m.Index + m.Length;
                            var following = nextChar < aspFile.Length ? aspFile.Substring(m.Index + m.Length, 1) : " ";
                            contents += (Regex.IsMatch(following, @"\s|['\""&<]") ? "" : " ");
                            appendBlock(pagePath, SourceUtil.GetSpan(lineRanges, m.Index, p1 - 1), contents, SourceUtil.GetLineCount(contents));
                        }
                    }
                    break;
                }
            }
            p2 = aspFile.Length;
            if (p2 - p1 > 0)
            {
                appendBlock(pagePath, SourceUtil.GetSpan(lineRanges, p1, p2 - 1), GetListeral(aspFile, p1, p2), 1);
            }
        }