public virtual ISnapshot LoadSnapshot(IProjectBase project, ISourceFile sourceFile, PathMappingContext pathMappingContext) { var itemName = sourceFile.GetFileNameWithoutExtensions(); 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.ProjectDirectory }; tokens.AddRange(project.Options.Tokens); var snapshotParseContext = Factory.SnapshotParseContext(project, tokens); var snapshot = LoadSnapshot(snapshotParseContext, sourceFile); return(snapshot); }
public PathMappingContext Parse([NotNull] IProjectBase project, [NotNull] ISourceFile sourceFile) { ItemName = sourceFile.GetFileNameWithoutExtensions(); Database = project.GetDatabase(project.Options.DatabaseName); var projectFileName = "/" + PathHelper.NormalizeItemPath(PathHelper.UnmapPath(project.ProjectDirectory, sourceFile.AbsoluteFileName)).TrimStart('/'); if (PathMapper.TryGetWebsiteFileName(projectFileName, out var filePath)) { FilePath = filePath; IsMapped = true; } if (PathMapper.TryGetWebsiteItemPath(projectFileName, out var databaseName, out var itemPath, out var isImport, out var uploadMedia)) { Database = project.GetDatabase(databaseName); ItemPath = itemPath; UploadMedia = uploadMedia; IsMapped = true; } return(this); }