public void FailsWhenNoSourceFilesToZipTest() { IAction action = new ZipFilesAction() { LoggingService = ServicesContainer.ServicesProvider.GetLoggingService(null) }; string outputZipPath = Path.Combine(Path.GetTempPath(), Path.GetRandomFileName() + ".zip"); var actionResult = action.Execute(ArgumentCollection.New() .WithArgument(ZipFilesActionInstanceArgs.ArchivePath, outputZipPath)); Assert.IsNotNull(actionResult); Assert.IsFalse(actionResult.Result); Assert.IsNotNull(actionResult.AttachedException); Assert.AreEqual(typeof(MissingArgumentsException), actionResult.AttachedException.GetType()); actionResult = action.Execute(ArgumentCollection.New() .WithArgument(ZipFilesActionExecutionArgs.ArchivePath, outputZipPath)); Assert.IsNotNull(actionResult); Assert.IsFalse(actionResult.Result); Assert.IsNotNull(actionResult.AttachedException); Assert.AreEqual(typeof(MissingArgumentsException), actionResult.AttachedException.GetType()); // CLEANUP if (File.Exists(outputZipPath)) { File.Delete(outputZipPath); } }
public void GenerateQRCodeSuccessfulTest() { string imageFormat = "png"; string eccl = QRCodeGenerator.ECCLevel.H.ToString("G"); string output = Path.Combine(Path.GetTempPath(), "output.png"); const bool eraseExistingFile = true; const bool forceUtf8 = true; const int pixelPerModule = 20; GenerateQRCodeAction action = new GenerateQRCodeAction() { ImageFormat = imageFormat, ErrorCorrectLevel = eccl, OutputFilePath = output, EraseExistingFile = eraseExistingFile, ForceUtf8 = forceUtf8, PixelPerModule = pixelPerModule }; var actionResult = action.Execute(ArgumentCollection.New() .WithArgument(GenerateQRCodeActionExecutionArgs.PlainText, qrCodeContent)); Assert.IsNotNull(actionResult); Assert.IsTrue(actionResult.Result); Assert.IsTrue(File.Exists(output)); File.Delete(output); }
public void SendSampleFileTest() { FtpUploadAction action = new FtpUploadAction() { Id = PluginUtilities.GetUniqueId(), LoggingService = ServicesContainer.ServicesProvider.GetLoggingService(nameof(FtpUploadAction)), Host = FtpTestCredentials.Host, Username = FtpTestCredentials.User, Password = FtpTestCredentials.Password, Port = FtpTestCredentials.Port, DestinationFolderPath = "Data", DestinationFileName = "renamed.txt", UseRemoteTemporaryExtension = true, RemoteTemporaryExtension = "remote", UseLocalTemporaryExtension = true, LocalTemporaryExtension = "local", Overwrite = true, CreateRemoteDirectory = true }; string sourceFileName = Path.Combine(Path.GetTempPath(), "test.txt"); File.WriteAllText(sourceFileName, "Hello world! This is a remote message!"); var result = action.Execute(ArgumentCollection.New() .WithArgument(FtpUploadActionExecutionArgs.SourceFilesCollection, new List <string> { sourceFileName })); Console.WriteLine(result.AttachedException); Assert.IsTrue(result.Result); File.Delete(sourceFileName); }
public void KillProcessByNameFromExecutionArgsTest() { var processId = StartNotepad(); Assert.AreNotEqual(0, processId); Console.WriteLine($"Created Process with ID {processId}"); Thread.Sleep(1000); KillProcessByNameAction action = new KillProcessByNameAction() { Id = PluginUtilities.GetUniqueId(), LoggingService = ServicesContainer.ServicesProvider.GetLoggingService(nameof(KillProcessByNameAction)), }; var actionResult = action.Execute(ArgumentCollection.New() .WithArgument(KillProcessByNameActionExecutionArgs.ProcessName, "notepad") ); Assert.IsNotNull(actionResult); Assert.IsTrue(actionResult.Result); Assert.IsTrue( actionResult.AdditionalInformation.HasArgument(KillProcessActionResultArgs .ProcessesKilledSuccessfully)); Assert.AreEqual(1, actionResult.AdditionalInformation .GetValue<List<int>>(KillProcessActionResultArgs.ProcessesKilledSuccessfully).Count); Assert.AreEqual(processId, actionResult.AdditionalInformation .GetValue<List<int>>(KillProcessActionResultArgs.ProcessesKilledSuccessfully).Single()); Thread.Sleep(2000); actionResult = action.Execute(ArgumentCollection.New() .WithArgument(KillProcessByNameActionExecutionArgs.ProcessName, "notepad") ); Assert.IsNotNull(actionResult); Assert.IsFalse(actionResult.Result); }
public void CreateZipOnSameExistingOptionTest() { var outputDirectory = Path.GetTempPath(); IAction action = new ZipDirectoryAction() { EraseOutputIfExists = true, UseLocationAsOutput = true, Id = PluginUtilities.GetUniqueId(), LoggingService = ServicesContainer.ServicesProvider.GetLoggingService(null) }; var testDir = Path.Combine(Path.GetTempPath(), "TEMPO_TEST"); if (!Directory.Exists(testDir)) { Directory.CreateDirectory(testDir); } File.WriteAllText(Path.Combine(outputDirectory, "TEMPO_TEST.zip"), ""); var actionResult = action.Execute(ArgumentCollection.New() .WithArgument(ZipDirectoryActionExecutionArgs.Directory, testDir)); Assert.IsNotNull(actionResult); Assert.IsTrue(actionResult.Result); }
public void DeleteFilesTest() { var localWriteDir = Path.GetDirectoryName(Environment.ExpandEnvironmentVariables(LocalWorkingDir)); FtpDeleteAction ftpDeleteAction = new FtpDeleteAction() { Id = PluginUtilities.GetUniqueId(), LoggingService = ServicesContainer.ServicesProvider.GetLoggingService(nameof(FtpDownloadAction)) }; ftpDeleteAction.Host = FtpTestCredentials.Host; ftpDeleteAction.Username = FtpTestCredentials.User; ftpDeleteAction.Password = FtpTestCredentials.Password; ftpDeleteAction.Port = FtpTestCredentials.Port; ftpDeleteAction.RemoteWorkingDir = "/"; var fileNamePath = CreateTestFile(localWriteDir); var actionResult = ftpDeleteAction.Execute(ArgumentCollection.New() .WithArgument(FtpDownloadActionExecutionArgs.RemoteFilesCollection, new List <string>() { Path.GetFileName(fileNamePath) }) ); Assert.IsNotNull(actionResult); Assert.IsTrue(actionResult.Result); }
public void DownloadFileFromWorkingDirAndRenameTest() { var localWriteDir = Environment.ExpandEnvironmentVariables(LocalWorkingDir); FtpDownloadAction ftpDownloadAction = new FtpDownloadAction { Id = PluginUtilities.GetUniqueId(), LoggingService = ServicesContainer.ServicesProvider.GetLoggingService(nameof(FtpDownloadAction)), Host = FtpTestCredentials.Host, Username = FtpTestCredentials.User, Password = FtpTestCredentials.Password, Port = FtpTestCredentials.Port, DirectoryPath = LocalDownloadDir, RemoteWorkingDir = "test" }; ftpDownloadAction.RenameDownloaded = true; ftpDownloadAction.RenameDownloadedNewName = "ROUTINDO_"; var fileNamePath = CreateTestFile(localWriteDir); var actionResult = ftpDownloadAction.Execute(ArgumentCollection.New() .WithArgument(FtpDownloadActionExecutionArgs.RemoteFilesCollection, new List <string>() { Path.GetFileName(fileNamePath) }) ); Assert.IsNotNull(actionResult); Assert.IsTrue(actionResult.Result); }
public void CreateResultSucceedInstanceTest() { var watcherResult = WatcherResult.Succeed(ArgumentCollection.New()); Assert.IsNotNull(watcherResult); Assert.IsTrue(watcherResult.Result); }
public WatcherResult Watch() { try { if (string.IsNullOrWhiteSpace(ProcessName)) { throw new MissingArgumentException(ProcessWatcherArgs.ProcessName); } var processes = System.Diagnostics.Process.GetProcessesByName(ProcessName); var process = processes.FirstOrDefault(e => !e.HasExited); if (!NotifyOnlyOnFirstOccurrence) { _lastStatus = null; } if (WatchForStopped) { if (process == null && ( // First Time after service started !_lastStatus.HasValue // Or process was previously running || _lastStatus.Value)) { _lastStatus = false; return(WatcherResult.Succeed( ArgumentCollection.New() .WithArgument(ProcessWatcherResultArgs.ProcessName, ProcessName) )); } _lastStatus = process != null; return(WatcherResult.NotFound); } if (process != null && ( // First Time after service started !_lastStatus.HasValue // Or process was previously stopped || !_lastStatus.Value) ) { _lastStatus = true; return(WatcherResult.Succeed( ArgumentCollection.New() .WithArgument(ProcessWatcherResultArgs.ProcessName, process.ProcessName) .WithArgument(ProcessWatcherResultArgs.ProcessId, process.Id) )); } _lastStatus = process != null; return(WatcherResult.NotFound); } catch (Exception exception) { LoggingService.Error(exception); return(WatcherResult.NotFound.WithException(exception)); } }
public WatcherResult Watch() { try { var usage = Counter.NextValue(); // LoggingService.Debug($"Last Usage: {_lastUsage}, Current Usage: {usage}, Target {TargetMaximumUsage}"); if (usage > TargetMaximumUsage && CanNotify()) { // Notify only for the first occurrence when exceeding the target maximum if (_lastUsage < TargetMaximumUsage // Current usage is greater than previous notification usage || _lastNotificationUsage < usage) { _lastUsage = usage; _lastNotificationUsage = usage; _lastNotificationTime = DateTime.Now; return(WatcherResult.Succeed(ArgumentCollection.New() .WithArgument(UsageWatcherResultArgs.Usage, usage.ToString("F")) )); } } _lastUsage = usage; return(WatcherResult.NotFound); } catch (Exception exception) { LoggingService.Error(exception); return(WatcherResult.NotFound); } }
public virtual WatcherResult Watch() { try { LoggingService.Trace("Watching."); if (DataManager == null) { LoggingService.Debug("Creating new instance of Plugin Data Manager."); DataManager = new PluginDataManager(this.Id); LoggingService.Debug("Setting Data File."); DataManager.SetDataFile(); } var plannedExecutionTime = DataManager.GetPlannedExecutionTime(); LoggingService.Trace("Planned Execution Time: {0}", plannedExecutionTime.ToString("G")); if (DateTime.Compare(DateTime.Now, plannedExecutionTime) >= 0) { LoggingService.Debug("Time Reached"); var nextExecutionTime = GetNextExecutionTime(); LoggingService.Debug("Saving Next Execution Time: {0}", nextExecutionTime.ToString("G")); DataManager.SaveNextExecutionTime(nextExecutionTime); return(WatcherResult.Succeed(ArgumentCollection.New())); } LoggingService.Trace("Time Not Reached Yet!"); return(WatcherResult.NotFound); } catch (Exception exception) { LoggingService.Error(exception); return(WatcherResult.NotFound); } }
public WatcherResult Watch() { try { if (string.IsNullOrWhiteSpace(Host)) { throw new Exception($"{nameof(Host)} not set"); } bool?oldStatus = _lastStatus; bool status; try { using (var ping = new Ping()) { PingReply pingReply = ping.Send(Host); status = (pingReply != null && pingReply.Status == IPStatus.Success); } } catch (PingException pingException) { LoggingService.Error(pingException); LoggingService.Error($"Exception HResult = {pingException.HResult}"); status = false; } bool notify = false; if (!_lastStatus.HasValue || status != _lastStatus.Value) { _lastStatus = status; if (AnyStatus) { notify = true; } else if (status == Reachable) { notify = true; } } if (!notify) { return(WatcherResult.NotFound); } _lastStatus = status; var statusString = status ? "Reachable" : "Unreachable"; return(WatcherResult.Succeed(ArgumentCollection.New() .WithArgument(PingStatusWatcherResultArgs.Host, this.Host) .WithArgument(PingStatusWatcherResultArgs.IsReachable, status)) .WithArgument(PingStatusWatcherResultArgs.ResultMessage, $"Host {Host} is {statusString}")); } catch (Exception exception) { LoggingService.Error(exception); return(WatcherResult.NotFound); } }
public void CreateArgumentsCollectionAsNewWithOneArgumentAttachedTest() { string key = "key"; int value = 10; ArgumentCollection argumentCollection = ArgumentCollection.New().WithArgument(key, value); Assert.IsTrue(argumentCollection.Any()); Assert.IsTrue(argumentCollection.HasArgument(key)); Assert.AreEqual(value, argumentCollection[key]); }
public void MoveZippedFilesTest() { ZipFilesAction action = new ZipFilesAction() { LoggingService = ServicesContainer.ServicesProvider.GetLoggingService(nameof(ZipFilesAction)), MoveZippedFiles = true }; string ticks = $"{DateTime.Now.Ticks}"; string filesDirectory = Path.Combine(Path.GetTempPath(), $"dir-{ticks}"); string movingDirectory = Path.Combine(filesDirectory, "moved"); action.MoveZippedFilesToPath = movingDirectory; string file1ToZip = Path.Combine(filesDirectory, $"file-1-{ticks}.txt"); string file2ToZip = Path.Combine(filesDirectory, $"file-1-{ticks}.txt"); string outputZip = Path.Combine(filesDirectory, $"output-{ticks}.zip"); // Create filesDirectory Directory.CreateDirectory(filesDirectory); Assert.IsTrue(Directory.Exists(filesDirectory)); // Create file 1 File.WriteAllText(file1ToZip, nameof(file1ToZip)); File.WriteAllText(file2ToZip, nameof(file2ToZip)); // With execution: list of files var actionResult = action.Execute(ArgumentCollection.New() .WithArgument(ZipFilesActionExecutionArgs.FilesPaths, new List <string>() { file1ToZip, file2ToZip }) .WithArgument(ZipFilesActionExecutionArgs.ArchivePath, outputZip) ); Assert.IsNotNull(actionResult); Assert.IsTrue(actionResult.Result); Assert.IsTrue(File.Exists(outputZip)); File.Delete(outputZip); Assert.IsFalse(File.Exists(file1ToZip)); Assert.IsFalse(File.Exists(file2ToZip)); Assert.IsTrue(File.Exists(Path.Combine(movingDirectory, Path.GetFileName(file1ToZip)))); Assert.IsTrue(File.Exists(Path.Combine(movingDirectory, Path.GetFileName(file2ToZip)))); // CLEANUP if (Directory.Exists(filesDirectory)) { Directory.Delete(filesDirectory, true); } }
public ArgumentCollection Map(ArgumentCollection arguments) { ArgumentCollection argumentCollection = ArgumentCollection.New(); if (arguments.HasArgument(ProcessWatcherResultArgs.ProcessName)) { argumentCollection.Add(KillProcessByNameActionExecutionArgs.ProcessName, arguments[ProcessWatcherResultArgs.ProcessName]); } return(argumentCollection); }
public ArgumentCollection Map(ArgumentCollection arguments) { if (!arguments.HasArgument(WinServiceWatcherResultArgs.ServiceName) || !(arguments[WinServiceWatcherResultArgs.ServiceName] is string)) { return(null); } return(ArgumentCollection.New() .WithArgument(WinServiceActionExecutionArgs.ServiceName, arguments.GetValue <string>(WinServiceWatcherResultArgs.ServiceName))); }
public ActionResult Execute(ArgumentCollection arguments) { try { var processes = GetProcesses(arguments).ToList(); if (!processes.Any()) { LoggingService.Error("No process found."); return(ActionResult.Failed()); } List <int> succeeded = new List <int>(); List <int> failed = new List <int>(); foreach (var process in processes) { int processId = process.Id; if (!process.HasExited) { string processName = process.ProcessName; if (KillProcess(process)) { LoggingService.Debug($"Killed Process ({processName}) [{processId}]"); succeeded.Add(processId); } else { LoggingService.Debug($"Failed to kill Process ({processName}) [{processId}]"); failed.Add(processId); } } else { LoggingService.Debug($"Failed to kill Process [{processId}] - Process Already Exited"); failed.Add(processId); } } var result = ActionResult.Succeeded() .WithAdditionInformation( ArgumentCollection.New() .WithArgument(KillProcessActionResultArgs.ProcessesKilledSuccessfully, succeeded) .WithArgument(KillProcessActionResultArgs.ProcessesKillingFailed, failed) ); return(result); } catch (Exception exception) { LoggingService.Error(exception); return(ActionResult.Failed().WithException(exception)); } }
public void DownloadFileWithAppendTest() { var localWriteDir = Path.GetDirectoryName(Environment.ExpandEnvironmentVariables(LocalWorkingDir)); FtpDownloadAction ftpDownloadAction = new FtpDownloadAction() { Id = PluginUtilities.GetUniqueId(), LoggingService = ServicesContainer.ServicesProvider.GetLoggingService(nameof(FtpDownloadAction)) }; ftpDownloadAction.Host = FtpTestCredentials.Host; ftpDownloadAction.Username = FtpTestCredentials.User; ftpDownloadAction.Password = FtpTestCredentials.Password; ftpDownloadAction.Port = FtpTestCredentials.Port; ftpDownloadAction.DirectoryPath = LocalDownloadDir; ftpDownloadAction.Append = true; var fileNamePath = CreateTestFile(localWriteDir); var actionResult = ftpDownloadAction.Execute(ArgumentCollection.New() .WithArgument(FtpDownloadActionExecutionArgs.RemoteFilesCollection, new List <string>() { Path.GetFileName(fileNamePath) }) ); Assert.IsNotNull(actionResult); Assert.IsTrue(actionResult.Result); File.AppendAllLines(Path.Combine(Environment.ExpandEnvironmentVariables(localWriteDir), fileNamePath), new List <string>() { // Environment.NewLine, $"{Environment.NewLine}Hello world!" }); actionResult = ftpDownloadAction.Execute(ArgumentCollection.New() .WithArgument(FtpDownloadActionExecutionArgs.RemoteFilesCollection, new List <string>() { Path.GetFileName(fileNamePath) }) ); Assert.IsNotNull(actionResult); Assert.IsTrue(actionResult.Result); var fileLines = File.ReadAllLines(Path.Combine( Environment.ExpandEnvironmentVariables(ftpDownloadAction.DirectoryPath), Path.GetFileName(fileNamePath))); Assert.AreEqual(2, fileLines.Count()); }
public void CreateResultSucceedWithArgumentFailsOnGettingWrongTypeTest() { var argumentKey = "key"; var argumentValue = "vale"; var watcherResult = WatcherResult.Succeed(ArgumentCollection.New().WithArgument(argumentKey, argumentValue)); Assert.IsNotNull(watcherResult); Assert.IsTrue(watcherResult.Result); Assert.IsNotNull(watcherResult.WatchingArguments); Assert.IsTrue(watcherResult.WatchingArguments.Any()); Assert.AreEqual(1, watcherResult.WatchingArguments.Count); Assert.IsTrue(watcherResult.WatchingArguments.HasArgument(argumentKey)); watcherResult.WatchingArguments.GetValue <int>(argumentKey); }
public void ActionFailsOnServiceSpecificName() { WinServiceAction controlServiceAction = new WinServiceAction() { Status = 1, Wait = false, WaitTimeout = 0 }; var actionResult = controlServiceAction.Execute(ArgumentCollection.New()); Assert.IsNotNull(actionResult); Assert.IsFalse(actionResult.Result); Assert.IsNotNull(actionResult.AttachedException); }
public void CreateZipFromDirectoryTest() { var outputDirectory = Path.Combine(Path.GetTempPath(), "TEST_OUTPUT"); IAction action = new ZipDirectoryAction() { OutputDirectory = outputDirectory, CreateOutputDirectory = true, EraseOutputIfExists = true, Id = PluginUtilities.GetUniqueId(), LoggingService = ServicesContainer.ServicesProvider.GetLoggingService(null) }; var testDir = Path.Combine(Path.GetTempPath(), "TEMPO_TEST"); if (!Directory.Exists(testDir)) { Directory.CreateDirectory(testDir); } var createdDir = new DirectoryInfo(testDir); Assert.IsTrue(Directory.Exists(createdDir.FullName)); var file1 = Path.Combine(createdDir.FullName, "file1.txt"); if (!File.Exists(file1)) { File.WriteAllText(file1, "Hello world"); } Assert.IsTrue(File.Exists(file1)); var file2 = Path.Combine(createdDir.FullName, "file2.txt"); if (!File.Exists(file2)) { File.WriteAllText(file2, "Hello world"); } Assert.IsTrue(File.Exists(file2)); var actionResult = action.Execute(ArgumentCollection.New() .WithArgument(ZipDirectoryActionExecutionArgs.Directory, createdDir.FullName)); Assert.IsNotNull(actionResult); Assert.IsTrue(actionResult.Result); Assert.IsTrue(File.Exists(Path.Combine(outputDirectory, "TEMPO_TEST.zip"))); Directory.Delete(createdDir.FullName, true); File.Delete(Path.Combine(Path.GetTempPath(), "TEMPO_TEST.zip")); }
public void SetArgumentsTest() { var arguments = ArgumentCollection.New() .WithArgument(FtpItemsSelectorArgs.Port, FtpTestCredentials.Port) .WithArgument(FtpItemsSelectorArgs.Host, FtpTestCredentials.Host) .WithArgument(FtpItemsSelectorArgs.Username, FtpTestCredentials.User) .WithArgument(FtpItemsSelectorArgs.Password, FtpTestCredentials.Password) .WithArgument(FtpItemsSelectorArgs.RemoteWorkingDir, "/") .WithArgument(FtpItemsSelectorArgs.MaximumFiles, 100) .WithArgument(FtpItemsSelectorArgs.SortingCriteria, ItemsSelectionSortingCriteria.CreationTimeDescending) .WithArgument(FtpItemsSelectorArgs.CreatedBefore, 1) .WithArgument(FtpItemsSelectorArgs.CreatedAfter, 1000) .WithArgument(FtpItemsSelectorArgs.EditedBefore, 60000) .WithArgument(FtpItemsSelectorArgs.EditedAfter, 120000); FtpWatcherViewModel viewModel = new FtpWatcherViewModel() { }; viewModel.SetArguments(arguments); Assert.AreEqual(viewModel.Port, arguments.GetValue <int>(FtpItemsSelectorArgs.Port)); Assert.AreEqual(viewModel.Host, arguments.GetValue <string>(FtpItemsSelectorArgs.Host)); Assert.AreEqual(viewModel.Username, arguments.GetValue <string>(FtpItemsSelectorArgs.Username)); Assert.AreEqual(viewModel.Password, arguments.GetValue <string>(FtpItemsSelectorArgs.Username)); Assert.AreEqual(viewModel.RemoteWorkingDir, arguments.GetValue <string>(FtpItemsSelectorArgs.RemoteWorkingDir)); Assert.AreEqual(viewModel.MaximumFiles, arguments.GetValue <int>(FtpItemsSelectorArgs.MaximumFiles)); Assert.AreEqual(viewModel.SortingCriteria, arguments.GetValue <ItemsSelectionSortingCriteria>(FtpItemsSelectorArgs.SortingCriteria)); Assert.AreEqual(1, viewModel.CreatedBefore); Assert.AreEqual(1, viewModel.CreatedAfter); Assert.AreEqual(1, viewModel.EditedBefore); Assert.AreEqual(2, viewModel.EditedAfter); Assert.AreEqual(TimePeriod.Milliseconds, viewModel.CreatedBeforePeriod); Assert.AreEqual(TimePeriod.Seconds, viewModel.CreatedAfterPeriod); Assert.AreEqual(TimePeriod.Minutes, viewModel.EditedBeforePeriod); Assert.AreEqual(TimePeriod.Minutes, viewModel.EditedAfterPeriod); Assert.IsTrue(viewModel.FilterByCreatedBefore); Assert.IsTrue(viewModel.FilterByCreatedAfter); Assert.IsTrue(viewModel.FilterByEditedBefore); Assert.IsTrue(viewModel.FilterByEditedAfter); Assert.IsTrue(viewModel.FilterByCreationTime); Assert.IsTrue(viewModel.FilterByEditionTime); }
public ActionResult Execute(ArgumentCollection arguments) { List <string> deletedFiles = new List <string>(); try { // Must provide arguments if (arguments == null) { throw new ArgumentNullException(nameof(arguments)); } if (!arguments.HasArgument(DeleteFilesActionExecutionArgs.FilesPaths)) { throw new MissingArgumentException(DeleteFilesActionExecutionArgs.FilesPaths); } if (!(arguments[DeleteFilesActionExecutionArgs.FilesPaths] is List <string> filePaths)) { throw new ArgumentsValidationException( $"unable to cast argument value into list of string. key({DeleteFilesActionExecutionArgs.FilesPaths})"); } foreach (var filePath in filePaths) { // File must exist if (!File.Exists(filePath)) { throw new FileNotFoundException("File not found", filePath); } File.Delete(filePath); LoggingService.Info($"File ({filePath}) deleted successfully"); deletedFiles.Add(filePath); } return(ActionResult.Succeeded().WithAdditionInformation(ArgumentCollection.New() .WithArgument(DeleteFilesActionResultsArgs.DeletedFiles, deletedFiles) )); } catch (Exception exception) { LoggingService.Error(exception); return(ActionResult.Failed(exception).WithAdditionInformation(ArgumentCollection.New() .WithArgument(DeleteFilesActionResultsArgs.DeletedFiles, deletedFiles) )); } }
public void ActionFailsOnWrongStatusToAct() { WinServiceAction controlServiceAction = new WinServiceAction() { ServiceName = "YOUNESCHEIKH", Status = 28, Wait = false, WaitTimeout = 0 }; var actionResult = controlServiceAction.Execute(ArgumentCollection.New()); Assert.IsNotNull(actionResult); Assert.IsFalse(actionResult.Result); Assert.IsNotNull(actionResult.AttachedException); }
public void CreateZipFailsOnSourceDirectoryNotFoundTest() { var outputDirectory = Path.Combine(Path.GetTempPath(), "TEST_OUTPUT"); IAction action = new ZipDirectoryAction() { OutputDirectory = outputDirectory, Id = PluginUtilities.GetUniqueId(), LoggingService = ServicesContainer.ServicesProvider.GetLoggingService(null) }; var testDir = Path.Combine(Path.GetTempPath(), "TEMPO_TEST"); var actionResult = action.Execute(ArgumentCollection.New() .WithArgument(ZipDirectoryActionExecutionArgs.Directory, testDir)); Assert.IsNotNull(actionResult); Assert.IsFalse(actionResult.Result); }
public MainWindowViewModel() { FilesWatcherConfiguratorViewModel = new FilesWatcherConfiguratorViewModel(); FilesWatcherConfiguratorViewModel.SetArguments(ArgumentCollection.New() .WithArgument(FilesSelectorArgs.CreatedAfter, TimeSpan.FromHours(1).TotalMilliseconds) .WithArgument(FilesSelectorArgs.CreatedBefore, TimeSpan.FromMinutes(1).TotalMilliseconds) .WithArgument(FilesSelectorArgs.EditedAfter, TimeSpan.FromMinutes(45).TotalMilliseconds) .WithArgument(FilesSelectorArgs.EditedBefore, TimeSpan.FromMinutes(15).TotalMilliseconds) .WithArgument(FilesSelectorArgs.SortingCriteria, FilesSelectionSortingCriteria.CreationTimeDescending) .WithArgument(FilesSelectorArgs.Pattern, "*.txt") ); ConfigureCommand = new RelayCommand(() => FilesWatcherConfiguratorViewModel.Configure(), () => this.FilesWatcherConfiguratorViewModel.CanConfigure()); SetArgumentCommand = new RelayCommand(() => this.FilesWatcherConfiguratorViewModel.SetArguments(FilesWatcherConfiguratorViewModel.InstanceArguments)); // FilesWatcherConfiguratorViewModel.PropertyChanged += FilesWatcherConfiguratorViewModelOnPropertyChanged; }
public void CreateResultSucceedWithArgumentInstanceTest() { var argumentKey = "key"; var argumentValue = "vale"; var watcherResult = WatcherResult.Succeed(ArgumentCollection.New().WithArgument(argumentKey, argumentValue)); Assert.IsNotNull(watcherResult); Assert.IsTrue(watcherResult.Result); Assert.IsNotNull(watcherResult.WatchingArguments); Assert.IsTrue(watcherResult.WatchingArguments.Any()); Assert.AreEqual(1, watcherResult.WatchingArguments.Count); Assert.IsTrue(watcherResult.WatchingArguments.HasArgument(argumentKey)); Assert.IsNotNull(watcherResult.WatchingArguments[argumentKey]); Assert.IsNotNull(watcherResult.WatchingArguments.GetValue <string>(argumentKey)); Assert.AreEqual(argumentValue, watcherResult.WatchingArguments[argumentKey]); Assert.AreEqual(argumentValue, watcherResult.WatchingArguments.GetValue <string>(argumentKey)); }
public void StartProcessNotepadTest() { string processPath = @"notepad"; StartProcessAction startProcessAction = new StartProcessAction() { Id = PluginUtilities.GetUniqueId(), LoggingService = ServicesContainer.ServicesProvider.GetLoggingService(nameof(StartProcessAction)), ProcessPath = processPath, }; var actionResult = startProcessAction.Execute(ArgumentCollection.New()); Assert.IsNotNull(actionResult); Assert.IsTrue(actionResult.Result); System.Diagnostics.Process.GetProcessesByName(processPath).FirstOrDefault()?.Kill(); }
public ActionResult Execute(ArgumentCollection arguments) { List <string> deletedFiles = new List <string>(); List <string> failedFiles = new List <string>(); try { if (!Directory.Exists(DirectoryPath)) { LoggingService.Error($"Directory doesn't exist [{DirectoryPath}]"); return(ActionResult.Failed()); } var files = this.Select(); foreach (var file in files) { try { LoggingService.Debug($"Deleting ({file})"); File.Delete(file); LoggingService.Info($"({file}) deleted successfully"); deletedFiles.Add(file); } catch (Exception exception) { LoggingService.Error($"Deletion failed of ({file})"); LoggingService.Error(exception); failedFiles.Add(file); continue; } } return(ActionResult.Succeeded().WithAdditionInformation(ArgumentCollection.New() .WithArgument(DeleteFilesByPatternFromDirectoryResultsArgs.DeletedFiles, deletedFiles) .WithArgument(DeleteFilesByPatternFromDirectoryResultsArgs.FailedFiles, failedFiles) )); } catch (Exception exception) { LoggingService.Error(exception); return(ActionResult.Failed(exception).WithAdditionInformation(ArgumentCollection.New() .WithArgument(DeleteFilesByPatternFromDirectoryResultsArgs.DeletedFiles, deletedFiles) .WithArgument(DeleteFilesByPatternFromDirectoryResultsArgs.FailedFiles, failedFiles) )); } }
public WatcherResult Watch() { try { if (string.IsNullOrWhiteSpace(ServiceName)) { throw new Exception("ServiceName is incorrect ! NULL or EMPTY"); } var status = WinServiceUtilities.GetServiceStatus(ServiceName); bool notify = false; if (!_serviceStatus.HasValue || status != _serviceStatus.Value) { _serviceStatus = status; if (AnyStatus) { notify = true; } else if ((int)status == Status) { notify = true; } } if (!notify) { return(WatcherResult.NotFound); } _serviceStatus = status; return(WatcherResult.Succeed(ArgumentCollection.New() .WithArgument(WinServiceWatcherResultArgs.ServiceName, ServiceName) .WithArgument(WinServiceWatcherResultArgs.Status, status.ToString("G")))); } catch (Exception exception) { LoggingService.Error(exception); return(WatcherResult.NotFound .WithException(exception)); } }