public IParseContext With(IProject project, ISnapshot snapshot, PathMappingContext pathMappingContext) { Project = project; Snapshot = snapshot; FilePath = pathMappingContext.FilePath; ItemName = pathMappingContext.ItemName; ItemPath = pathMappingContext.ItemPath; DatabaseName = pathMappingContext.DatabaseName; UploadMedia = pathMappingContext.UploadMedia; Trace = new ProjectDiagnosticTraceService(Configuration, Console, Factory).With(Project); return this; }
public virtual IParseContext ParseContext(IProject project, ISnapshot snapshot, PathMappingContext pathMappingContext) { return new ParseContext(Configuration, Console, this, PipelineService, SchemaService, ReferenceParser).With(project, snapshot, pathMappingContext); }
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 ParseContext([NotNull] IConfiguration configuration, [NotNull] IProject project, [NotNull] ISnapshot snapshot, [NotNull] PathMappingContext pathMappingContext) { Snapshot = Snapshots.Snapshot.Empty; Culture = configuration.GetCulture(); Project = project; Snapshot = snapshot; FilePath = pathMappingContext.FilePath; ItemName = pathMappingContext.ItemName; ItemPath = pathMappingContext.ItemPath; Database = pathMappingContext.Database; }
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); } }