Example #1
0
        private void LoadTasks()
        {
            Logger.Log(LogLevel.Info, "Tasker", "Loading tasks...", _Configfile);

            Tasks = new Dictionary<string, Task>();
            if (!File.Exists(_Configfile)) File.Create(_Configfile).Close();
            using (StreamReader sr = File.OpenText(_Configfile))
            {
                while (!sr.EndOfStream)
                {
	                try
	                {
		                Task t = new Task(sr.ReadLine());
		                Logger.Log(LogLevel.Info, "Tasker", "Parsed task", t.ToString());
		                Tasks.Add(t.Name, t);
	                }
	                catch (Exception ex)
	                {
						Logger.Log(LogLevel.Warning, "Tasker", "Failed to parse task", ex.Message);
	                }

                }
            }
            Logger.Log(LogLevel.Info, "Tasker", "Loaded all tasks");
        }
Example #2
0
 /// <summary>
 ///     Save (update) a task
 /// </summary>
 /// <param name="oldTask"></param>
 /// <param name="newTask"></param>
 public void SaveTask(Task oldTask, Task newTask)
 {
     DeleteTask(oldTask);
     AddTask(newTask);
     // events are fired by delete & add operations
 }
Example #3
0
        /// <summary>
        ///     Delete a task
        /// </summary>
        /// <param name="task">the task to delete</param>
        public void DeleteTask(Task task)
        {
	        if (task == null) return;

            task.Disable();
            task.TaskExecuted -= OnTaskExecuted;

            if (Tasks != null && Tasks.ContainsKey(task.Name)) Tasks.Remove(task.Name);

            task.Dispose(); // make sure it's removed
			OnTaskListAltered();// list changed, invoke event
            SaveConfig();
        }
Example #4
0
 /// <summary>
 ///     Add a new task
 /// </summary>
 /// <param name="task">the task to add</param>
 public void AddTask(Task task)
 {
     task.Enable();
     task.TaskExecuted += OnTaskExecuted;
     if (Tasks != null && !Tasks.ContainsKey(task.Name)) Tasks.Add(task.Name, task);
     OnTaskListAltered();
     SaveConfig();
 }