internal string PreParse(string content, out string docType, out AspxInfo info) { content = StripDocType(content, out docType); content = ParseAspTags(content, out info); return(content); }
private AspxInfo ParsePageInfo(string tag) { var info = new AspxInfo(); string[] tokens = tag.Split(' '); int index = 1; int count = tokens.Length; for (int i = index; i < count; i++) { if (tokens[i].IndexOf("=") > -1) { // We have a name-value pair string name = tokens[i].Substring(0, tokens[i].IndexOf("=")); string value = tokens[i].Substring(tokens[i].IndexOf("=") + 2).Trim('"'); switch (name) { case Inherits: info.CodeBehindTypeName = value; break; case CodeBehind: info.CodeBehindAssemblyName = value; break; case AutoEventWireup: try { info.AutoEventWireup = bool.Parse(value); } catch { info.AutoEventWireup = true; } break; } } } return(info); }
internal string ParseAspTags(string source, out AspxInfo info) { info = new AspxInfo(); string regex = "<%(.*?)%>"; var matches = Regex.Matches(source, regex, RegexOptions.IgnoreCase | RegexOptions.Multiline); foreach (Match match in matches) { if (match.Value.StartsWith("<%@ Page")) { info = ParsePageInfo(match.Value); source = source.Replace(match.Value, string.Empty); } else { source = source.Replace(match.Value, ParseASP(match.Groups[1].Value)); } } return(source); }
internal AspxInfo Parse(string filePath) { var info = new AspxInfo(); string line; using (var stream = File.Open(filePath, FileMode.Open, FileAccess.Read)) { StreamReader r = new StreamReader(stream); // We're only interested in the first line line = r.ReadLine(); if (!line.StartsWith("<%@") || !line.EndsWith("%>")) { // TODO: Stub out InvalidPageException throw new /*InvalidPage*/ Exception(); } string[] tokens = line.Split(' '); int index = 1; int count = tokens.Length; if (!tokens[index++].Equals(Page)) { throw new /*InvalidPage*/ Exception(); } for (int i = index; i < count; i++) { if (tokens[i].IndexOf("=") > -1) { // We have a name-value pair string name = tokens[i].Substring(0, tokens[i].IndexOf("=")); string value = tokens[i].Substring(tokens[i].IndexOf("=") + 2).Trim('"'); switch (name) { case Inherits: info.CodeBehindTypeName = value; break; case CodeBehind: info.CodeBehindAssemblyName = value; break; case AutoEventWireup: try { info.AutoEventWireup = bool.Parse(value); } catch { info.AutoEventWireup = true; } break; } } } //StringBuilder content = new StringBuilder(); //StringBuilder aspx = new StringBuilder("<?xml version=\"1.0\" encoding=\"UTF-8\" ?>"); //aspx.Append(r.ReadToEnd()); //XmlTextReader reader = XmlReader.Create( //var doc = new XmlDocument(); //doc.Load(aspx.ToString()); //XmlParserContext ctx = new XmlParserContext(null, null, string.Empty, XmlSpace.Default); //XmlTextReader reader = new XmlTextReader(tmp, XmlNodeType.Element, ctx); //while (reader.Read()) //{ // Debug.WriteLine(reader.Name); //} //var doc = new XmlDocument(); //doc.Load(stream); //info.Content = content.ToString(); } return(info); }