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 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);
		}