예제 #1
0
 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);
         }
     }
 }
예제 #2
0
 private void ExecuteDownloadTask(Task task)
 {
     NotificationsHelper.DisplayMessage(Messages.StartsDownloading);
     if (_downloadFileTaskHandler.DownloadFileAndReturnStatus(task.Value, _userSettings.DownloadLocation))
     {
         task.TaskStatus = TaskStatus.Done;
     }
 }
예제 #3
0
        public static void Main(string[] args)
        {
            RegisterServices();
            var tasksHandler = DependencyInjectionHelper.InjectDependency <ITasksHandler>();

            CommandsHelper.AnalyseCommandArgs(args);
            tasksHandler.ExecuteTasks();
            NotificationsHelper.DisplayMessage(Messages.Finish);
            SystemsHelper.Sleep();
        }
예제 #4
0
        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));
            }
        }
예제 #5
0
        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);
        }
예제 #6
0
 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);
     }
 }
예제 #7
0
        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);
            }
        }
예제 #8
0
 private static void ExecuteCmdTask(Task task)
 {
     NotificationsHelper.DisplayMessage(Messages.ExecutingTask);
     SystemsHelper.ExecuteCommand(task.Value);
     task.TaskStatus = TaskStatus.Done;
 }
예제 #9
0
 private static void TaskNotExecuted(Task task, string messageType)
 {
     NotificationsHelper.DisplayMessage(messageType);
     task.TaskStatus = TaskStatus.HasErrors;
 }