public virtual ITextNode LoadIncludeFile(SnapshotParseContext snapshotParseContext, ISnapshot snapshot, string includeFileName) { var extension = PathHelper.GetExtension(snapshot.SourceFile.AbsoluteFileName); var projectDirectory = snapshot.SourceFile.AbsoluteFileName.Left(snapshot.SourceFile.AbsoluteFileName.Length - snapshot.SourceFile.ProjectFileName.Length - extension.Length + 1); string sourceFileName; if (includeFileName.StartsWith("~/")) { sourceFileName = PathHelper.Combine(projectDirectory, includeFileName.Mid(2)); } else { sourceFileName = PathHelper.Combine(Path.GetDirectoryName(snapshot.SourceFile.AbsoluteFileName) ?? string.Empty, includeFileName); } if (!FileSystem.FileExists(sourceFileName)) { throw new FileNotFoundException("Include file not found", sourceFileName); } var projectFileName = "~/" + PathHelper.NormalizeItemPath(PathHelper.UnmapPath(projectDirectory, PathHelper.GetDirectoryAndFileNameWithoutExtensions(sourceFileName))).TrimStart('/'); var sourceFile = Factory.SourceFile(FileSystem, sourceFileName, projectFileName); var includeSnapshot = LoadSnapshot(snapshotParseContext, sourceFile) as TextSnapshot; return includeSnapshot?.Root ?? TextNode.Empty; }
public override ISnapshot Load(SnapshotParseContext snapshotParseContext, ISourceFile sourceFile) { var contents = sourceFile.ReadAsText(snapshotParseContext.Tokens); var yamlTextSnapshot = CompositionService.Resolve<YamlTextSnapshot>().With(snapshotParseContext, sourceFile, contents); return yamlTextSnapshot; }
public override ISnapshot Load(SnapshotParseContext snapshotParseContext, ISourceFile sourceFile) { var text = sourceFile.ReadAsText(snapshotParseContext.Tokens); var xmlTextSnapshot = CompositionService.Resolve<XmlTextSnapshot>().With(snapshotParseContext, sourceFile, text, SchemaNamespace, SchemaFileName); return xmlTextSnapshot; }
public ISnapshot LoadSnapshot(SnapshotParseContext snapshotParseContext, ISourceFile sourceFile) { foreach (var loader in Loaders.OrderBy(l => l.Priority)) { if (loader.CanLoad(sourceFile)) { return loader.Load(snapshotParseContext, sourceFile); } } return Factory.Snapshot(sourceFile); }
public virtual ISnapshot LoadSnapshot(SnapshotParseContext snapshotParseContext, ISourceFile sourceFile) { foreach (var loader in Loaders.OrderBy(l => l.Priority)) { if (loader.CanLoad(sourceFile)) { return(loader.Load(snapshotParseContext, sourceFile)); } } return(Factory.Snapshot(sourceFile)); }
public virtual void Parse(IProject project, ISourceFile sourceFile) { var itemName = PathHelper.GetItemName(sourceFile); var fileContext = FileContext.GetFileContext(project, Configuration, sourceFile); var filePath = fileContext.FilePath; if (filePath.StartsWith("~/")) { filePath = filePath.Mid(1); } var filePathWithExtensions = PathHelper.NormalizeItemPath(PathHelper.GetDirectoryAndFileNameWithoutExtensions(filePath)); var fileName = Path.GetFileName(filePath); var fileNameWithoutExtensions = PathHelper.GetFileNameWithoutExtensions(fileName); var directoryName = string.IsNullOrEmpty(filePath) ? string.Empty : PathHelper.NormalizeItemPath(Path.GetDirectoryName(filePath) ?? string.Empty); var tokens = new Dictionary<string, string> { ["ItemPath"] = itemName, ["FilePathWithoutExtensions"] = filePathWithExtensions, ["FilePath"] = filePath, ["Database"] = project.Options.DatabaseName, ["FileNameWithoutExtensions"] = fileNameWithoutExtensions, ["FileName"] = fileName, ["DirectoryName"] = directoryName }; var snapshotParseContext = new SnapshotParseContext(SnapshotService, tokens, new Dictionary<string, List<ITextNode>>()); var snapshot = SnapshotService.LoadSnapshot(snapshotParseContext, sourceFile); var parseContext = Factory.ParseContext(project, snapshot); foreach (var parser in Parsers.OrderBy(p => p.Priority)) { try { if (parser.CanParse(parseContext)) { parser.Parse(parseContext); } } catch (Exception ex) { parseContext.Trace.TraceError(Msg.P1013, ex.Message, sourceFile.AbsoluteFileName, TextSpan.Empty); } } }
public virtual YamlTextSnapshot With([NotNull] SnapshotParseContext parseContext, [NotNull] ISourceFile sourceFile, [NotNull] string contents) { base.With(sourceFile); ParseContext = parseContext; var tokenizer = new Tokenizer(contents); Root = Parse(tokenizer, null) ?? TextNode.Empty; if (Root != null) { Root = ParseDirectives(ParseContext, Root); } return this; }
public virtual JsonTextSnapshot With([NotNull] SnapshotParseContext snapshotParseContext, [NotNull] ISourceFile sourceFile, [NotNull] string contents) { base.With(sourceFile); ParseContext = snapshotParseContext; try { RootToken = JToken.Parse(contents); } catch (JsonException ex) { ParseError = ex.Message; RootToken = null; } catch (Exception ex) { ParseError = ex.Message; RootToken = null; } return this; }
public override ISnapshot Load(SnapshotParseContext snapshotParseContext, ISourceFile sourceFile) { var textSnapshot = CompositionService.Resolve<SerializationTextSnapshot>().With(sourceFile); return textSnapshot; }
public virtual XmlTextSnapshot With([NotNull] SnapshotParseContext parseContext, [NotNull] ISourceFile sourceFile, [NotNull] string contents, [NotNull] string schemaNamespace, [NotNull] string schemaFileName) { base.With(sourceFile); SchemaNamespace = schemaNamespace; SchemaFileName = schemaFileName; ParseContext = parseContext; try { var doc = XDocument.Parse(contents, LoadOptions.PreserveWhitespace | LoadOptions.SetLineInfo); RootElement = doc.Root; } catch (XmlException ex) { ParseError = ex.Message; ParseErrorTextSpan = new TextSpan(ex.LineNumber, ex.LinePosition, 0); RootElement = null; } catch (Exception ex) { ParseError = ex.Message; RootElement = null; } return this; }
public virtual void Parse(IProject project, ISourceFile sourceFile) { var pathMappingContext = new PathMappingContext(PathMapper); pathMappingContext.Parse(project, sourceFile); if (!pathMappingContext.IsMapped) { return; } var itemName = PathHelper.GetItemName(sourceFile); var filePath = pathMappingContext.FilePath; if (filePath.StartsWith("~/")) { filePath = filePath.Mid(1); } var filePathWithExtensions = PathHelper.NormalizeItemPath(PathHelper.GetDirectoryAndFileNameWithoutExtensions(filePath)); var fileName = Path.GetFileName(filePath); var fileNameWithoutExtensions = PathHelper.GetFileNameWithoutExtensions(fileName); var directoryName = string.IsNullOrEmpty(filePath) ? string.Empty : PathHelper.NormalizeItemPath(Path.GetDirectoryName(filePath) ?? string.Empty); var tokens = new Dictionary<string, string> { ["ItemPath"] = itemName, ["FilePathWithoutExtensions"] = filePathWithExtensions, ["FilePath"] = filePath, ["Database"] = project.Options.DatabaseName, ["FileNameWithoutExtensions"] = fileNameWithoutExtensions, ["FileName"] = fileName, ["DirectoryName"] = directoryName, ["ProjectDirectory"] = project.Options.ProjectDirectory }; tokens.AddRange(project.Options.Tokens); var snapshotParseContext = new SnapshotParseContext(SnapshotService, tokens, new Dictionary<string, List<ITextNode>>()); var snapshot = SnapshotService.LoadSnapshot(snapshotParseContext, sourceFile); var parseContext = Factory.ParseContext(project, snapshot, pathMappingContext); var parsed = false; foreach (var parser in Parsers.OrderBy(p => p.Priority)) { try { if (parser.CanParse(parseContext)) { parser.Parse(parseContext); parsed = true; } } catch (Exception ex) { parseContext.Trace.TraceError(Msg.P1013, ex.Message, sourceFile); } } if (!parsed) { parseContext.Trace.TraceWarning(Msg.P1024, "No parser found for file. If the file is a content file, add the file extension to the 'project-website-mappings:content-files' setting", sourceFile); } }
public virtual void Parse(IProject project, ISourceFile sourceFile) { var pathMappingContext = new PathMappingContext(PathMapper); pathMappingContext.Parse(project, sourceFile); var parseAllFiles = Configuration.GetBool(Constants.Configuration.BuildProjectParseAllFiles); if (!parseAllFiles && !pathMappingContext.IsMapped) { return; } var itemName = PathHelper.GetItemName(sourceFile); var filePath = pathMappingContext.FilePath; if (filePath.StartsWith("~/")) { filePath = filePath.Mid(1); } var filePathWithExtensions = PathHelper.NormalizeItemPath(PathHelper.GetDirectoryAndFileNameWithoutExtensions(filePath)); var fileName = Path.GetFileName(filePath); var fileNameWithoutExtensions = PathHelper.GetFileNameWithoutExtensions(fileName); var directoryName = string.IsNullOrEmpty(filePath) ? string.Empty : PathHelper.NormalizeItemPath(Path.GetDirectoryName(filePath) ?? string.Empty); var tokens = new Dictionary<string, string> { ["ItemPath"] = itemName, ["FilePathWithoutExtensions"] = filePathWithExtensions, ["FilePath"] = filePath, ["Database"] = project.Options.DatabaseName, ["FileNameWithoutExtensions"] = fileNameWithoutExtensions, ["FileName"] = fileName, ["DirectoryName"] = directoryName, ["ProjectDirectory"] = project.Options.ProjectDirectory }; tokens.AddRange(project.Options.Tokens); var snapshotParseContext = new SnapshotParseContext(SnapshotService, tokens, new Dictionary<string, List<ITextNode>>()); var snapshot = SnapshotService.LoadSnapshot(snapshotParseContext, sourceFile); var parseContext = Factory.ParseContext(project, snapshot, pathMappingContext); var parsed = false; foreach (var parser in Parsers.OrderBy(p => p.Priority)) { try { if (parser.CanParse(parseContext)) { parser.Parse(parseContext); parsed = true; } } catch (Exception ex) { parseContext.Trace.TraceError(Msg.P1013, ex.Message, sourceFile); } } if (!parseAllFiles && !parsed) { parseContext.Trace.TraceWarning(Msg.P1024, Texts.No_parser_found_for_file__If_the_file_is_a_content_file__add_the_file_extension_to_the__project_website_mappings_content_files__setting, sourceFile); } }