public async Task <string> ResolvePath(string projectId, string key = "", string fileExtension = ".json", bool ensureFoldersExist = false, CancellationToken cancellationToken = default(CancellationToken)) { var pathOptions = await optionsResolver.Resolve(projectId).ConfigureAwait(false); var firstFolderPath = pathOptions.AppRootFolderPath + pathOptions.BaseFolderVPath.Replace("/", pathOptions.FolderSeparator); if (ensureFoldersExist && !Directory.Exists(firstFolderPath)) { Directory.CreateDirectory(firstFolderPath); } var projectIdFolderPath = Path.Combine(firstFolderPath, projectId); if (ensureFoldersExist && !Directory.Exists(projectIdFolderPath)) { Directory.CreateDirectory(projectIdFolderPath); } if (ensureFoldersExist && !Directory.Exists(projectIdFolderPath)) { Directory.CreateDirectory(projectIdFolderPath); } if (string.IsNullOrWhiteSpace(key)) { return(projectIdFolderPath + pathOptions.FolderSeparator); } return(Path.Combine(projectIdFolderPath, key + fileExtension)); }
private async Task <string> GetProjectsFolderPath() { var pathOptions = await storageOptionsResolver.Resolve("").ConfigureAwait(false); var projectsFolder = pathOptions.AppRootFolderPath + pathOptions.BaseFolderVPath.Replace("/", pathOptions.FolderSeparator) + pathOptions.FolderSeparator + pathOptions.ProjectsFolderName ; return(projectsFolder); }
public async Task <string> ResolvePath( string projectId, string key = "", string fileExtension = ".json", bool ensureFoldersExist = false, CancellationToken cancellationToken = default(CancellationToken) ) { if (string.IsNullOrWhiteSpace(projectId)) { throw new ArgumentException("projectId must be provided"); } var pathOptions = await optionsResolver.Resolve(projectId).ConfigureAwait(false); var firstFolderPath = pathOptions.AppRootFolderPath + pathOptions.BaseFolderVPath.Replace("/", pathOptions.FolderSeparator); if (ensureFoldersExist && !Directory.Exists(firstFolderPath)) { Directory.CreateDirectory(firstFolderPath); } var projectsFolderPath = Path.Combine(firstFolderPath, pathOptions.ProjectsFolderName); if (ensureFoldersExist && !Directory.Exists(projectsFolderPath)) { Directory.CreateDirectory(projectsFolderPath); } var projectIdFolderPath = Path.Combine(projectsFolderPath, projectId); if (ensureFoldersExist && !Directory.Exists(projectIdFolderPath)) { Directory.CreateDirectory(projectIdFolderPath); } var type = typeof(LogItem).Name.ToLowerInvariant(); var typeFolderPath = Path.Combine(projectIdFolderPath, type.ToLowerInvariant().Trim()); if (ensureFoldersExist && !Directory.Exists(typeFolderPath)) { Directory.CreateDirectory(typeFolderPath); } if (string.IsNullOrWhiteSpace(key)) { return(typeFolderPath); } var fileName = key + fileExtension; var filePath = Path.Combine(typeFolderPath, key + fileExtension); if (File.Exists(filePath)) { return(filePath); } // if the file is not found in the type folder // we need to check for deeper folders // if the file is found there then return the path foreach (string file in Directory.EnumerateFiles( typeFolderPath, fileName, SearchOption.AllDirectories) ) { return(file); } //var typeDir = new DirectoryInfo(typeFolderPath); //foreach (var levelDir in typeDir.GetDirectories()) //{ // foreach (var dateDir in levelDir.GetDirectories()) // { // var fp = Path.Combine(dateDir.FullName, fileName); // if (File.Exists(fp)) return fp; // } //} // otherwise return the best path calculation based on info provided // ie to save a file the other ResolvePath method should be used and the // LogEvent should be passed in to determine the path return(filePath); }
/// <summary> /// if key is not provided this method will return the post folder path /// if key is provided it will try to find the file which should be nested in year/month /// folder based on pubdate, if the file exists it will return the path to the file /// if not it will return the post folder plus key plus file extension /// however that is not the correct place to store a new post. The other ResolvePath method /// which takes an instance of Post should be used for determining where to save a post /// </summary> /// <param name="projectId"></param> /// <param name="key"></param> /// <param name="fileExtension"></param> /// <param name="ensureFoldersExist"></param> /// <param name="cancellationToken"></param> /// <returns></returns> public async Task <string> ResolvePath( string projectId, string key = "", string fileExtension = ".json", bool ensureFoldersExist = false, CancellationToken cancellationToken = default(CancellationToken) ) { if (string.IsNullOrWhiteSpace(projectId)) { throw new ArgumentException("projectId must be provided"); } var pathOptions = await optionsResolver.Resolve(projectId).ConfigureAwait(false); var firstFolderPath = pathOptions.AppRootFolderPath + pathOptions.BaseFolderVPath.Replace("/", pathOptions.FolderSeparator); if (ensureFoldersExist && !Directory.Exists(firstFolderPath)) { Directory.CreateDirectory(firstFolderPath); } var projectsFolderPath = Path.Combine(firstFolderPath, pathOptions.ProjectsFolderName); if (ensureFoldersExist && !Directory.Exists(projectsFolderPath)) { Directory.CreateDirectory(projectsFolderPath); } var projectIdFolderPath = Path.Combine(projectsFolderPath, projectId); if (ensureFoldersExist && !Directory.Exists(projectIdFolderPath)) { Directory.CreateDirectory(projectIdFolderPath); } var type = typeof(Post).Name.ToLowerInvariant(); var typeFolderPath = Path.Combine(projectIdFolderPath, type.ToLowerInvariant().Trim()); if (ensureFoldersExist && !Directory.Exists(typeFolderPath)) { Directory.CreateDirectory(typeFolderPath); } if (string.IsNullOrWhiteSpace(key)) { return(typeFolderPath); } var fileName = key + ".xml"; var filePath = Path.Combine(typeFolderPath, key + fileExtension); if (File.Exists(filePath)) { return(filePath); } // if the file is not found in the type folder // we need to check for deeper folders year/month // if the file is found there then return the path foreach (string file in Directory.EnumerateFiles( typeFolderPath, fileName, SearchOption.AllDirectories) // this is needed for blog posts which are nested in year/month folders ) { return(file); } fileName = key + ".md"; filePath = Path.Combine(typeFolderPath, key + fileExtension); if (File.Exists(filePath)) { return(filePath); } //try again with .md foreach (string file in Directory.EnumerateFiles( typeFolderPath, fileName, SearchOption.AllDirectories) // this is needed for blog posts which are nested in year/month folders ) { return(file); } // otherwise return the best path calculation based on info provided // ie to save a file the other ResolvePath method should be used and the // Post should be passed in to determine the year/month path return(filePath); }
public async Task <string> ResolvePath( string projectId, string key = "", string fileExtension = ".json", bool ensureFoldersExist = false, CancellationToken cancellationToken = default(CancellationToken) ) { if (string.IsNullOrWhiteSpace(projectId)) { throw new ArgumentException("projectId must be provided"); } if (string.IsNullOrWhiteSpace(fileExtension)) { fileExtension = ".json"; } var pathOptions = await _optionsResolver.Resolve(projectId).ConfigureAwait(false); var firstFolderPath = pathOptions.AppRootFolderPath + pathOptions.BaseFolderVPath.Replace("/", pathOptions.FolderSeparator); if (ensureFoldersExist && !Directory.Exists(firstFolderPath)) { Directory.CreateDirectory(firstFolderPath); } var projectsFolderPath = Path.Combine(firstFolderPath, pathOptions.ProjectsFolderName); if (ensureFoldersExist && !Directory.Exists(projectsFolderPath)) { Directory.CreateDirectory(projectsFolderPath); } var projectIdFolderPath = Path.Combine(projectsFolderPath, projectId); if (ensureFoldersExist && !Directory.Exists(projectIdFolderPath)) { Directory.CreateDirectory(projectIdFolderPath); } var type = typeof(Page).Name.ToLowerInvariant(); var typeFolderPath = Path.Combine(projectIdFolderPath, type.ToLowerInvariant().Trim()); if (ensureFoldersExist && !Directory.Exists(typeFolderPath)) { Directory.CreateDirectory(typeFolderPath); } if (string.IsNullOrWhiteSpace(key)) { return(typeFolderPath + pathOptions.FolderSeparator); } var filePath = Path.Combine(typeFolderPath, key + ".md"); if (File.Exists(filePath)) { return(filePath); } return(Path.Combine(typeFolderPath, key + fileExtension)); }