public List <FileInfo> FindLatestVersionPackages(string directoryPath) { //Get all package directories var toSearch = _localFileService.FindDirectories(directoryPath, _configurationProvider.PackageDirectoryName); _logger.Debug($"Searching {toSearch.Count} directories for install packages"); var fileList = new List <FileInfo>(); foreach (var dir in toSearch) { //Find install packages _logger.Debug($"Searching {dir.FullName} for install pacakges"); var possibleFiles = _localFileService.FindFiles(dir.FullName, InstallPackageSearchFormat); _logger.Debug($"Found {possibleFiles.Count} possible items"); //if none skip if (possibleFiles.Count == 0) { continue; } //If only 1, go for it if (possibleFiles.Count == 1) { fileList.Add(possibleFiles[0]); continue; } //Otherwise get the most recent var mostRecent = fileList.OrderByDescending(f => f.LastWriteTimeUtc).First(); fileList.Add(mostRecent); } return(fileList); }
public void CleanupLogFiles(SiteCleanupConfiguration siteInfo) { _log.Debug($"Starting clean of {siteInfo.SiteName}"); if (siteInfo.LogHistoryDaysToKeep < 2) { _log.Error("Unable to process, must keep at least 2 days of logs"); return; } var directoryExists = _localFileService.DirectoryExists(siteInfo.DnnRootDirectoryPath); if (!directoryExists) { _log.Error("Provided directory not fount, no further processing for this site"); return; } //Verify that it is a DNN install var dnnLogPath = _localFileService.BuildDnnLogFolderPath(siteInfo.DnnRootDirectoryPath); var dnnLogExists = _localFileService.DirectoryExists(dnnLogPath); if (!dnnLogExists) { _log.Error($"Unable to find DNN log folder. Looked in '{dnnLogPath}'"); return; } //Get the list of log files _log.Debug($"Searching for files in {dnnLogPath}"); var logFiles = _localFileService.FindFiles(dnnLogPath, "*.log.resources"); if (logFiles.Count > siteInfo.LogHistoryDaysToKeep) { //Get the to delete files var toDelete = logFiles.OrderByDescending(lf => lf.CreationTimeUtc).Skip(siteInfo.LogHistoryDaysToKeep); foreach (var fileToDelete in toDelete) { _log.Debug($"Deleting {fileToDelete.FullName}"); _localFileService.DeleteFile(fileToDelete.FullName); } } else { _log.Debug( $"Found {logFiles.Count} files and log rules allow for up to {siteInfo.LogHistoryDaysToKeep} no action taken"); } }