public void LoadSettings(UserSettings userSettings, bool load) { if (!load) { return; } try { userSettings = GetLocalUserSettings(userSettings); } catch (Exception) { if (!FilesHelper.FileExists(userSettings.SettingsFileLocation)) { NotificationsHelper.DisplayMessage(Messages.Preparing); PrepareEnvironment(new UserSettings()); } else if (!CommandsHelper.ShouldExecuteTasks()) { NotificationsHelper.DisplayMessage(Messages.Ready); } else { NotificationsHelper.DisplayMessage(Messages.ErrorInSettings); } } }
private void ExecuteDownloadTask(Task task) { NotificationsHelper.DisplayMessage(Messages.StartsDownloading); if (_downloadFileTaskHandler.DownloadFileAndReturnStatus(task.Value, _userSettings.DownloadLocation)) { task.TaskStatus = TaskStatus.Done; } }
public static void Main(string[] args) { RegisterServices(); var tasksHandler = DependencyInjectionHelper.InjectDependency <ITasksHandler>(); CommandsHelper.AnalyseCommandArgs(args); tasksHandler.ExecuteTasks(); NotificationsHelper.DisplayMessage(Messages.Finish); SystemsHelper.Sleep(); }
private void ExtractTasks() { var tasks = FilesHelper.ReadAllLines(_userSettings.TasksLocation).ToList(); if (tasks.Count <= 0) { return; } NotificationsHelper.DisplayMessage(Messages.Welcome(tasks.Count, _userSettings.TasksLocation)); foreach (var taskString in tasks) { var task = new Task(); task.Parse(taskString, _userSettings.TaskTypeSplitter); ProcessTask(task, tasks.IndexOf(taskString)); } }
public bool DownloadFileAndReturnStatus(string url, string downloadLocation) { var doesSucceed = NetworkHelper.DownloadFile(url, downloadLocation); if (doesSucceed) { NotificationsHelper.DisplayMessage(Messages.SuccessfulDownload(PathsHelper.GetFileNameFromPath(url))); } else { NotificationsHelper.DisplayMessage(Messages.FailedDownload(PathsHelper.GetFileNameFromPath(url))); NotificationsHelper.DisplayMessage(Messages.StartAgain); return(true); } return(false); }
public void ExecuteTasks() { if (CommandsHelper.ShouldOpenSettings()) { SystemsHelper.OpenFile(_userSettings.SettingsFileLocation); } if (CommandsHelper.ShouldOpenTasks()) { SystemsHelper.OpenFile(_userSettings.TasksLocation); } if (CommandsHelper.ShouldOpenDownloadsDirectory()) { SystemsHelper.OpenDirectory(_userSettings.DownloadLocation); } if (CommandsHelper.ShouldExecuteTasks()) { ExtractTasks(); } else { NotificationsHelper.DisplayMessage(Messages.CommandNotRecognized); } }
private static void PrepareEnvironment(UserSettings userSettings) { try { if (!FilesHelper.FileExists(userSettings.TasksLocation)) { FilesHelper.OpenOrCreateFile(userSettings.TasksLocation); } if (!FilesHelper.FileExists(userSettings.SettingsFileLocation)) { FilesHelper.OpenOrCreateFile(userSettings.SettingsFileLocation); FilesHelper.WriteAllText(userSettings.SettingsFileLocation, JsonHelper.Serialize(userSettings)); } if (!DirectoriesHelper.DirectoryExists(userSettings.DownloadLocation)) { DirectoriesHelper.CreateDirectory(userSettings.DownloadLocation); } } catch { NotificationsHelper.DisplayMessage(Messages.ErrorInitiatingConfiguration); } }
private static void ExecuteCmdTask(Task task) { NotificationsHelper.DisplayMessage(Messages.ExecutingTask); SystemsHelper.ExecuteCommand(task.Value); task.TaskStatus = TaskStatus.Done; }
private static void TaskNotExecuted(Task task, string messageType) { NotificationsHelper.DisplayMessage(messageType); task.TaskStatus = TaskStatus.HasErrors; }