Esempio n. 1
0
        /// <summary>
        /// Executes the operation and adds it to the operation history.
        /// This operation tries to delete one or more tasks using the given parameters.
        /// If an index exist, it will delete all tasks by index.
        /// If not, it will perform a search, deleting tasks immediately if the isAll flag
        /// is set.
        /// </summary>
        /// <param name="taskList">List of task this operation will operate on.</param>
        /// <param name="storageIO">Storage controller that will be used to store neccessary data.</param>
        /// <returns>Response indicating the result of the operation execution.</returns>
        public override Response Execute(List<Task> taskList, Storage storageIO)
        {
            SetMembers(taskList, storageIO);

            Func<Task, Response> action = DeleteTask;
            object[] args = null;
            Response response = null;

            response = CheckIfIndexesAreValid(startIndex, endIndex);
            if (response != null) return response;

            if (!hasIndex)
                response = ExecuteBySearch(
                    taskName, startTime, endTime, isAll, searchType, action, args);

            else if (hasIndex)
                response = ExecuteByIndex(startIndex, endIndex, action, args);

            else
                response = new Response(Result.FAILURE, sortType, this.GetType());

            if (response.IsSuccessful())
                AddToOperationHistory();

            return response;
        }
Esempio n. 2
0
        /// <summary>
        /// Undo this operation.
        /// </summary>
        /// <param name="taskList">List of task this method will operate on.</param>
        /// <param name="storageIO">Storage controller that will be used to store neccessary data.</param>
        /// <returns>Response indicating the result of the undo operation.</returns>
        public override Response Undo(List<Task> taskList, Storage storageIO)
        {
            SetMembers(taskList, storageIO);

            Response response = DeleteTask(newTask);
            return response;
        }
        public void OperationAddFailTest()
        {
            testStorage = new Storage("OpUnittest.xml", "OpUnittestsettings.xml");
            testTaskList = testStorage.LoadTasksFromFile();

            OperationAdd Op = new OperationAdd(null, sortType);
            result = Op.Execute(testTaskList, testStorage);
            Assert.AreEqual(result.FeedbackString, "Failed to add task!");
            return;
        }
        public void OperationAddTest()
        {
            testStorage = new Storage("OpUnittest.xml", "OpUnittestsettings.xml");
            testTaskList = testStorage.LoadTasksFromFile();

            OperationAdd Op = new OperationAdd(testTask, sortType);
            result = Op.Execute(testTaskList, testStorage);
            Assert.AreEqual("Added new task \"test\" successfully.", result.FeedbackString);
            return;
        }
Esempio n. 5
0
        /// <summary>
        /// Executes this operation. Returns the currently displayed list back as a Response
        /// with the new sort type.
        /// </summary>
        /// <param name="taskList">The task list which derived operations may operate on.</param>
        /// <param name="storageIO">The storage controller to use to store task data.</param>
        /// <returns>Response with the currently displayed list and the new sort type.</returns>
        public override Response Execute(List<Task> taskList, Storage storageIO)
        {
            this.storageIO = storageIO;
            Response response;

            // sorting is done On-The-Fly in TaskListViewControl.
            if(sortType == SortType.DEFAULT)
                response = new Response(Result.FAILURE, sortType, this.GetType(), currentListedTasks);
            else
                response = new Response(Result.SUCCESS, sortType, this.GetType(), currentListedTasks);
            return response;
        }
 /// <summary>
 /// Executes the operation and adds it to the operation history.
 /// This operation tries to schedule a task within the given parameters.
 /// </summary>
 /// <param name="taskList">List of task this operation will operate on.</param>
 /// <param name="storageIO">Storage controller that will be used to store neccessary data.</param>
 /// <returns>Response indicating the result of the operation execution.</returns>
 public override Response Execute(List<Task> taskList, Storage storageIO)
 {
     Response response;
     SetMembers(taskList, storageIO);
     RetrieveParameters();
     if (!IsTaskDurationWithinRange() || taskDurationAmount == 0)
     {
         response = new Response(Result.INVALID_TASK, sortType, typeof(OperationSchedule), currentListedTasks);
     }
     else
     {
         response = TryScheduleTask();
     }
     return response;
 }
        public void OperationDeleteMultipleTest()
        {
            testStorage = new Storage("OpUnittest.xml", "OpUnittestsettings.xml");
            testTaskList = testStorage.LoadTasksFromFile();

            int[] index = new int[2] { 1, 2 };
            OperationAdd Op = new OperationAdd(testTask, sortType);
            Op.Execute(testTaskList, testStorage);
            Op = new OperationAdd(testTaskNew, sortType);
            Op.Execute(testTaskList, testStorage);
            OperationDelete Op1 = new OperationDelete("", index, null, null, null, false, SearchType.NONE, sortType);
            result = Op1.Execute(testTaskList, testStorage);
            Assert.AreEqual("Deleted all indicated tasks successfully.", result.FeedbackString);
            return;
        }
Esempio n. 8
0
        /// <summary>
        /// Executes the operation and adds it to the global operation history.
        /// </summary>
        /// <param name="taskList">List of task this method will operate on.</param>
        /// <param name="storageIO">Storage controller that will be used to store neccessary data.</param>
        /// <returns>Response indicating the result of the operation execution.</returns>
        public override Response Execute(List<Task> taskList, Storage storageIO)
        {
            SetMembers(taskList, storageIO);

            Response response;
            if (newTask == null)
            {
                return new Response(Result.FAILURE, sortType, this.GetType());
            }
            response = AddTask(newTask);
            if (response.IsSuccessful())
            {
                AddToOperationHistory();
            }
            return response;
        }
Esempio n. 9
0
        /// <summary>
        /// Constructor for Logic class. Initializes all necessary components.
        /// </summary>
        public Logic()
        {
            mainSettings = new Settings();

            storage = new Storage("ToDo++.xml", "ToDoSettings.xml");

            mainSettings.UpdateSettings(storage.LoadSettingsFromFile());
            EventHandlers.UpdateSettingsHandler += UpdateSettings;

            commandParser = new CommandParser();

            taskList = storage.LoadTasksFromFile();
            while (taskList == null)
            {
                PromptUser_CreateNewTaskFile();
                taskList = storage.LoadTasksFromFile();
            }
        }
Esempio n. 10
0
        /// <summary>
        /// Executes the operation and adds it to the operation history.
        /// Modifies the task indicated by the index range to the new
        /// parameters in this operation. If a parameter is left empty or null,
        /// that parameter will remain unchanged in the new task.
        /// </summary>
        /// <param name="taskList">List of task this operation will operate on.</param>
        /// <param name="storageIO">Storage controller that will be used to store neccessary data.</param>
        /// <returns>Response indicating the result of the operation execution.</returns>
        public override Response Execute(List<Task> taskList, Storage storageIO)
        {
            SetMembers(taskList, storageIO);

            Response response = null;

            // No index, do a search instead
            if (!hasIndex && !isAll)
            {
                SetMembers(taskList, storageIO);
                List<Task> searchResults = SearchForTasks(taskName, false, startTime, endTime, searchType);
                response = DisplaySearchResults(searchResults, taskName, startTime, endTime, searchType);
            }
            else
            {
                response = CheckIfIndexesAreValid(startIndex, endIndex);
                if (response != null) return response;

                if (MultipleTasksSelected())
                    return new Response(Result.INVALID_TASK, sortType, this.GetType());

                oldTask = currentListedTasks[startIndex];

                // copy over taskName from indexed task if didn't specify a name
                if (!IsValidString(taskName))
                    taskName = oldTask.TaskName;
                // copy over date/times from indexed task if didn't specify time
                else if (startTime == null && endTime == null)
                    oldTask.CopyDateTimes(ref startTime, ref endTime, ref isSpecific);

                newTask = Task.CreateNewTask(taskName, startTime, endTime, isSpecific);

                response = ModifyTask(oldTask, newTask);
            }

            if (response.IsSuccessful())
            {
                AddToOperationHistory();
            }

            return response;
        }
Esempio n. 11
0
        /// <summary>
        /// Executes the operation according to this operation's parameters.
        /// </summary>
        /// <param name="taskList">List of task this method will operate on.</param>
        /// <param name="storageIO">Storage controller that will be used to store neccessary data.</param>
        /// <returns>Response indicating the result of the operation execution.</returns>
        public override Response Execute(List<Task> taskList, Storage storageIO)
        {
            Response response = null;

            SetMembers(taskList, storageIO);

            List<Task> searchResults = SearchForTasks(searchString, false, startTime, endTime, searchType);

            if (searchResults.Count == 0)
                response = new Response(Result.FAILURE, sortType, this.GetType());

            else
            {
                currentListedTasks = new List<Task>(searchResults);

                string[] criteria;
                SetArgumentsForSearchFeedbackString(out criteria, searchString, startTime, endTime, searchType);
                response = new Response(Result.SUCCESS, sortType, this.GetType(), currentListedTasks, criteria);
            }
            return response;
        }
Esempio n. 12
0
        /// <summary>
        /// Executes the operation and adds it to the global operation history.
        /// </summary>
        /// <param name="taskList">List of task this method will operate on.</param>
        /// <param name="storageIO">Storage controller that will be used to store neccessary data.</param>
        /// <returns>Response indicating the result of the operation execution.</returns>
        public override Response Execute(List<Task> taskList, Storage storageIO)
        {
            SetMembers(taskList, storageIO);

            Operation redoOp = GetLastRevertedOperation();
            if (redoOp == null)
                return new Response(Result.FAILURE, sortType, this.GetType());

            Response result = redoOp.Redo(taskList, storageIO);
            if (result == null)
                return result;

            if (result.IsSuccessful())
            {
                undoStack.Push(redoOp);
                result = new Response(Result.SUCCESS, sortType, typeof(OperationRedo), currentListedTasks);
            }
            else
                result = new Response(Result.FAILURE, sortType, typeof(OperationRedo), currentListedTasks);

            return result;
        }
        /// <summary>
        /// Executes the operation.
        /// </summary>
        /// <param name="taskList">List of task this method will operate on.</param>
        /// <param name="storageIO">Storage controller that will be used to store neccessary data.</param>
        /// <returns>Response indicating the result of the operation execution.</returns>
        public override Response Execute(List<Task> taskList, Storage storageIO)
        {
            SetMembers(taskList, storageIO);

            DateTimeSpecificity isSpecific = new DateTimeSpecificity();

            List<Task> mostRecentTasks =
                (from task in taskList
                 where task.IsWithinTime(DateTime.Today, DateTime.Today.AddDays(7))
                 select task).ToList();

            mostRecentTasks.Sort(Task.CompareByDateTime);

            if (mostRecentTasks.Count > MAX_TASKS)
                mostRecentTasks = mostRecentTasks.GetRange(0, MAX_TASKS);

            mostRecentTasks.AddRange(from task in taskList where task is TaskFloating select task);

            currentListedTasks = new List<Task>(mostRecentTasks);

            return new Response(Result.SUCCESS, SortType.DATE_TIME, this.GetType(), currentListedTasks);
        }
Esempio n. 14
0
        public void OperationSortTest()
        {
            testStorage = new Storage("OpUnittest.xml", "OpUnittestsettings.xml");
            testTaskList = testStorage.LoadTasksFromFile();

            OperationSort Op = new OperationSort(SortType.NAME);
            result = Op.Execute(testTaskList, testStorage);
            Assert.AreEqual("Sorting by name.", result.FeedbackString);
            return;
        }
Esempio n. 15
0
 /// <summary>
 /// Redoes this operation.
 /// </summary>
 /// <param name="taskList">List of task this method will operate on.</param>
 /// <param name="storageIO">Storage controller that will be used to store neccessary data.</param>
 /// <returns>Response indicating the result of the undo operation.</returns>
 public override Response Redo(List<Task> taskList, Storage storageIO)
 {
     SetMembers(taskList, storageIO);
     Response response = ModifyTask(oldTask, newTask);
     return response;
 }
Esempio n. 16
0
        /// <summary>
        /// Undoes this operation.
        /// </summary>
        /// <param name="taskList">List of task this method will operate on.</param>
        /// <param name="storageIO">Storage controller that will be used to store neccessary data.</param>
        /// <returns>Response indicating the result of the undo operation.</returns>
        public override Response Undo(List<Task> taskList, Storage storageIO)
        {
            SetMembers(taskList, storageIO);

            Response response = null;

            for (int i = 0; i < executedTasks.Count; i++)
            {
                Task taskToUndo = executedTasks.Dequeue();
                response = PostponeTask(taskToUndo, postponeDuration.Negate());
                if (!response.IsSuccessful())
                    return response;
            }

            if (response == null)
                response = new Response(Result.FAILURE, sortType, this.GetType());

            return response;
        }
Esempio n. 17
0
 /// <summary>
 /// Base method to execute this Operation. Must be overriden by all derived Operations.
 /// </summary>
 /// <param name="taskList">The list of task to execute the Operation on.</param>
 /// <param name="storageIO">The Storage controller to use for reading/writing to file.</param>
 /// <returns></returns>
 public abstract Response Execute(List<Task> taskList, Storage storageIO);
Esempio n. 18
0
 /// <summary>
 /// Sets the operating task list and storage IO controller
 /// this Operation will use to the instances referred to by the input parameters.
 /// </summary>
 /// <param name="taskList">The task list this Operation will execute on.</param>
 /// <param name="storageIO">The storage IO controller this Operation will use to store data.</param>
 /// <returns></returns>
 protected void SetMembers(List<Task> taskList, Storage storageIO)
 {
     this.storageIO = storageIO;
     this.taskList = taskList;
 }
Esempio n. 19
0
 /// <summary>
 /// Base Undo method. All undoable operations must override this method.
 /// This base method will throw an assertion if called without being overriden
 /// and debug mode is on.
 /// </summary>
 /// <param name="taskList">Current task list for task updates to be applied on.</param>
 /// <param name="storageIO">Storage controller to be used to write task changes.</param>
 public virtual Response Undo(List<Task> taskList, Storage storageIO)
 {
     Debug.Assert(false, "This operation should not be undoable!");
     return null;
 }
Esempio n. 20
0
        public void OperationDeleteRangeFailTest()
        {
            testStorage = new Storage("OpUnittest.xml", "OpUnittestsettings.xml");
            testTaskList = testStorage.LoadTasksFromFile();

            int[] index = new int[2] { 1, 4 };
            OperationDelete Op1;
            OperationAdd Op = new OperationAdd(testTask, sortType);
            result = Op.Execute(testTaskList, testStorage);
            Op1 = new OperationDelete("", index, null, null, null, false, SearchType.NONE, sortType);
            result = Op1.Execute(testTaskList, testStorage);
            Assert.AreEqual("Invalid task index!", result.FeedbackString);
            index = new int[2] { 1, 1 };
            Op1 = new OperationDelete("", index, null, null, null, false, SearchType.NONE, sortType);
            result = Op1.Execute(testTaskList, testStorage);
            Assert.AreEqual("Deleted task \"test\" successfully.", result.FeedbackString);
            return;
        }
Esempio n. 21
0
 public abstract string Undo(List<Task> taskList, Storage strorageXML);
Esempio n. 22
0
 /// <summary>
 /// Redoes this operation.
 /// </summary>
 /// <param name="taskList">List of task this method will operate on.</param>
 /// <param name="storageIO">Storage controller that will be used to store neccessary data.</param>
 /// <returns>Response indicating the result of the undo operation.</returns>
 public override Response Redo(List<Task> taskList, Storage storageIO)
 {
     SetMembers(taskList, storageIO);
     Response response = AddTask(scheduledTask);
     if (response.IsSuccessful())
         return new Response(Result.SUCCESS, sortType, typeof(OperationRedo), currentListedTasks);
     else
         return new Response(Result.FAILURE, sortType, typeof(OperationRedo), currentListedTasks);
 }
Esempio n. 23
0
        public void OperationUndoAddTest()
        {
            testStorage = new Storage("OpUnittest.xml", "OpUnittestsettings.xml");
            testTaskList = testStorage.LoadTasksFromFile();

            OperationAdd Op = new OperationAdd(testTask, sortType);
            Op.Execute(testTaskList, testStorage);
            result = Op.Undo(testTaskList, testStorage);
            Assert.AreEqual(result.FormatType.ToString(), "DEFAULT");
            return;
        }
Esempio n. 24
0
 public abstract string Execute(List<Task> taskList, Storage storageXML);
Esempio n. 25
0
        public void OperationSearchTest()
        {
            testStorage = new Storage("OpUnittest.xml", "OpUnittestsettings.xml");
            testTaskList = testStorage.LoadTasksFromFile();
            DateTime timeTest;
            timeTest = DateTime.ParseExact("10/15/2013 5:00 AM", formats,
                                                new CultureInfo("en-US"),
                                                DateTimeStyles.None);
            DateTimeSpecificity specific = new DateTimeSpecificity();

            TaskDeadline testDeadline = new TaskDeadline("test", timeTest, specific);
               OperationAdd Op1 = new OperationAdd(testDeadline, sortType);
            OperationSearch Op2 = new OperationSearch("SearchConditionCannotBeMatching",DateTime.Now,timeTest.AddDays(1),specific,SearchType.NONE,SortType.DEFAULT);
            result = Op2.Execute(testTaskList, testStorage);
             Assert.AreEqual("No matching tasks found!", result.FeedbackString);
            result = Op1.Execute(testTaskList, testStorage);
            result = Op2.Execute(testTaskList, testStorage);
             Assert.AreEqual("No matching tasks found!", result.FeedbackString);

            return;
        }