// Constructor used for testing the XDOM public WebFormsParsedDocument(string fileName, WebSubtype type, WebFormsPageInfo info, XDocument xDoc) : base(fileName) { Flags |= ParsedDocumentFlags.NonSerializable; Info = info; Type = type; XDocument = xDoc; }
// Constructor used for testing the XDOM public WebFormsParsedDocument (string fileName, WebSubtype type, WebFormsPageInfo info, XDocument xDoc) : base (fileName) { Flags |= ParsedDocumentFlags.NonSerializable; Info = info; Type = type; XDocument = xDoc; }
public override System.Threading.Tasks.Task <ParsedDocument> Parse(ParseOptions parseOptions, System.Threading.CancellationToken cancellationToken) { var info = new WebFormsPageInfo(); var errors = new List <Error> (); var parser = new XmlParser( new WebFormsRootState(), true ); try { parser.Parse(parseOptions.Content.CreateReader()); } catch (Exception ex) { LoggingService.LogError("Unhandled error parsing ASP.NET document '" + (parseOptions.FileName ?? "") + "'", ex); errors.Add(new Error(ErrorType.Error, "Unhandled error parsing ASP.NET document: " + ex.Message)); } // get the errors from the StateEngine parser errors.AddRange(parser.Errors); // populating the PageInfo instance XDocument xDoc = parser.Nodes.GetRoot(); info.Populate(xDoc, errors); var type = AspNetAppProjectFlavor.DetermineWebSubtype(parseOptions.FileName); if (type != info.Subtype) { if (info.Subtype == WebSubtype.None) { errors.Add(new Error(ErrorType.Error, "File directive is missing", new DocumentLocation(1, 1))); } else { type = info.Subtype; errors.Add(new Error(ErrorType.Warning, "File directive does not match page extension", new DocumentLocation(1, 1))); } } var result = new WebFormsParsedDocument(parseOptions.FileName, type, info, xDoc); result.AddRange(errors); return(System.Threading.Tasks.Task.FromResult((ParsedDocument)result)); }
public override ParsedDocument Parse(bool storeAst, string fileName, TextReader tr, Project project = null) { var info = new WebFormsPageInfo(); var errors = new List <Error> (); var parser = new XmlParser( new WebFormsRootState(), true ); try { parser.Parse(tr); } catch (Exception ex) { LoggingService.LogError("Unhandled error parsing ASP.NET document '" + (fileName ?? "") + "'", ex); errors.Add(new Error(ErrorType.Error, "Unhandled error parsing ASP.NET document: " + ex.Message)); } // get the errors from the StateEngine parser errors.AddRange(parser.Errors); // populating the PageInfo instance XDocument xDoc = parser.Nodes.GetRoot(); info.Populate(xDoc, errors); var type = AspNetAppProject.DetermineWebSubtype(fileName); if (type != info.Subtype) { if (info.Subtype == WebSubtype.None) { errors.Add(new Error(ErrorType.Error, "File directive is missing", 1, 1)); } else { type = info.Subtype; errors.Add(new Error(ErrorType.Warning, "File directive does not match page extension", 1, 1)); } } var result = new WebFormsParsedDocument(fileName, type, info, xDoc); result.Add(errors); return(result); }
public override System.Threading.Tasks.Task<ParsedDocument> Parse (ParseOptions parseOptions, System.Threading.CancellationToken cancellationToken) { var info = new WebFormsPageInfo (); var errors = new List<Error> (); var parser = new XmlParser ( new WebFormsRootState (), true ); try { parser.Parse (parseOptions.Content.CreateReader ()); } catch (Exception ex) { LoggingService.LogError ("Unhandled error parsing ASP.NET document '" + (parseOptions.FileName ?? "") + "'", ex); errors.Add (new Error (ErrorType.Error, GettextCatalog.GetString ("Unhandled error parsing ASP.NET document: {0}", ex.Message))); } // get the errors from the StateEngine parser errors.AddRange (parser.Errors); // populating the PageInfo instance XDocument xDoc = parser.Nodes.GetRoot (); info.Populate (xDoc, errors); var type = AspNetAppProjectFlavor.DetermineWebSubtype (parseOptions.FileName); if (type != info.Subtype) { if (info.Subtype == WebSubtype.None) { errors.Add (new Error (ErrorType.Error, GettextCatalog.GetString ("File directive is missing"), new DocumentLocation (1, 1))); } else { type = info.Subtype; errors.Add (new Error (ErrorType.Warning, GettextCatalog.GetString ("File directive does not match page extension"), new DocumentLocation (1, 1))); } } var result = new WebFormsParsedDocument (parseOptions.FileName, type, info, xDoc); result.AddRange (errors); return System.Threading.Tasks.Task.FromResult((ParsedDocument)result); }
public override ParsedDocument Parse (bool storeAst, string fileName, TextReader tr, Project project = null) { var info = new WebFormsPageInfo (); var errors = new List<Error> (); var parser = new XmlParser ( new WebFormsRootState (), true ); try { parser.Parse (tr); } catch (Exception ex) { LoggingService.LogError ("Unhandled error parsing ASP.NET document '" + (fileName ?? "") + "'", ex); errors.Add (new Error (ErrorType.Error, "Unhandled error parsing ASP.NET document: " + ex.Message)); } // get the errors from the StateEngine parser errors.AddRange (parser.Errors); // populating the PageInfo instance XDocument xDoc = parser.Nodes.GetRoot (); info.Populate (xDoc, errors); var type = AspNetAppProject.DetermineWebSubtype (fileName); if (type != info.Subtype) { if (info.Subtype == WebSubtype.None) { errors.Add (new Error (ErrorType.Error, "File directive is missing", 1, 1)); } else { type = info.Subtype; errors.Add (new Error (ErrorType.Warning, "File directive does not match page extension", 1, 1)); } } var result = new WebFormsParsedDocument (fileName, type, info, xDoc); result.Add (errors); return result; }
public void AddRegisterDirective (WebFormsPageInfo.RegisterDirective directive, TextEditorData editor, bool preserveCaretPosition) { if (doc == null) return; var node = GetRegisterInsertionPointNode (); if (node == null) return; doc.Info.RegisteredTags.Add (directive); var line = Math.Max (node.Region.EndLine, node.Region.BeginLine); var pos = editor.Document.LocationToOffset (line, editor.Document.GetLine (line - 1).Length); if (pos < 0) return; using (var undo = editor.OpenUndoGroup ()) { var oldCaret = editor.Caret.Offset; var inserted = editor.Insert (pos, editor.EolMarker + directive); if (preserveCaretPosition) { editor.Caret.Offset = (pos < oldCaret)? oldCaret + inserted : oldCaret; } } }
/// <summary> /// Gets a tag prefix, also returning the directive that would have to be added if necessary. /// </summary> public string GetTagPrefixWithNewDirective (IType control, string assemblyName, string desiredPrefix, out WebFormsPageInfo.RegisterDirective directiveNeededToAdd) { directiveNeededToAdd = null; string existingPrefix = GetTagPrefix (control); if (existingPrefix != null) return existingPrefix; //TODO: detect control name conflicts string prefix = desiredPrefix; if (desiredPrefix == null) prefix = GetPrefix (control); var an = SystemAssemblyService.ParseAssemblyName (assemblyName); directiveNeededToAdd = new WebFormsPageInfo.AssemblyRegisterDirective (prefix, control.Namespace, an.Name); return prefix; }