public void ReadIncludePatternFromFile() { SaveConfiguration(); TaskConfiguration actualTaskConfiguration = Extensions.Deserialize(new TaskConfiguration(), ConfigurationFile, DefaultNamespace); ArchiveTask task = null; foreach (ArchiveTask archiveTask in actualTaskConfiguration.ArchiveTasks) { if (archiveTask.RegExpressionInclude != null) { task = archiveTask; break; } } DirectoryInfo directoryInfo = new DirectoryInfo(@"..\..\TestFiles\Archive\source"); List<DirectoryInfo> folders = directoryInfo.GetFolders(task); const int expectedValue = 1; Assert.AreEqual(expectedValue, folders.Count); }
private void ExecuteArchiveTasks() { foreach (ArchiveTask task in taskConfiguration.ArchiveTasks) { if (task.ArchiveStatus == ArchiveStatus.Enabled) { Log.Debug("Starting with task: ['{0}']", task.ToString()); DirectoryInfo sourceFolder; try { sourceFolder = new DirectoryInfo(task.Source); } catch (Exception exception) { Log.Debug(exception.StackTrace); throw; } List<DirectoryInfo> sourceFolders = sourceFolder.GetFolders(task); if (task.Action.MinFolderAction > sourceFolders.Count) { Log.Debug("Skiping task because of MinFolderAction > ActualFodlersCount! '{0}' :: {1}", task.Action.MinFolderAction, sourceFolders.Count); continue; } switch (task.Action.Id) { case ArchiveActionAttribute.DateOlder: { foreach (DirectoryInfo directoryInfo in sourceFolders) { var dateTime = new DateTime(DateTime.UtcNow.Ticks); DateTime creationTimeUtc = directoryInfo.CreationTimeUtc; TimeSpan timeSpan = dateTime - creationTimeUtc; if ((UInt64) timeSpan.Days > task.Action.Value) { ExecuteArchiveTask(task, directoryInfo); } } break; } case ArchiveActionAttribute.TotalFolderCount: { if ((UInt64) sourceFolders.Count > task.Action.Value) { ExecuteArchiveTask(task, sourceFolders); } break; } case ArchiveActionAttribute.TotalFreeSpace: { ManageDiskSpace(task, sourceFolders); break; } case ArchiveActionAttribute.TotalUsedSpace: { ManageDiskSpace(task, sourceFolders); break; } case ArchiveActionAttribute.TotalFolderUsedSpace: { UInt64 totalFolderSize = sourceFolders.Aggregate<DirectoryInfo, ulong>(0, (current, directoryInfo) => current + directoryInfo.GetFolderSize()); if (totalFolderSize > task.Action.Value) { ExecuteArchiveTask(task, sourceFolders); } break; } default: { throw new NotSupportedException(); } } } else { Log.Debug("Task is disabled! ['{0}']", task.ToString()); } } }
public void NumberOfFoldersInSource() { DirectoryInfo directoryInfo = new DirectoryInfo(@"..\..\TestFiles\Archive\source"); archiveTask.RegExpressionInclude = null; archiveTask.RegExpressionExclude = @"\b(\.|[Ff]|[Ss])\S*"; List<DirectoryInfo> folders = directoryInfo.GetFolders(archiveTask); const int expectedValue = 4; Assert.AreEqual(expectedValue, folders.Count); }