Ejemplo n.º 1
0
 /// <summary>
 /// Constructor for deadline tasks.
 /// </summary>
 /// <param name="taskName">The task's display name.</param>
 /// <param name="endTime">The task's deadline.</param>
 /// <param name="endDateSpecificity">The task's deadline specificity.</param>
 /// <param name="isDone">The task's done state. Is set to false by default.</param>
 /// <param name="forceID">The task's ID. Is set to -1 by default for the base constructor to generate a new ID.</param>
 /// <returns></returns>
 public TaskDeadline(
     string taskName,
     DateTime endTime,
     DateTimeSpecificity endDateSpecificity,
     Boolean isDone = false,
     int forceID = -1)
     : base(taskName, isDone, forceID)
 {
     this.endDateTime = endTime;
     isSpecific = endDateSpecificity;
     Logger.Info("Created a deadline task", "TaskDeadline::TaskDeadline");
 }
Ejemplo n.º 2
0
 /// <summary>
 /// Constructor for Search operation. Takes in the following parameters
 /// to define the search filters to be used when the operation is executed.
 /// </summary>
 /// <param name="searchString">The string which the task name must contain to match the search.</param>
 /// <param name="startTime">The start time by which the task must within to match the search.</param>
 /// <param name="endTime">The end time by which the task must within to match the search.</param>
 /// <param name="isSpecific">The specificty of the time ranges.</param>
 /// <param name="searchType">The type of search filter to use in addition to the other filters.</param>
 /// <param name="sortType">The type of sort to sort the diplay list by after the operation is executed.</param>
 /// <returns>Response containing the search results, the operation's success or failure, and the new sort type if any.</returns>
 public OperationSearch(
     string searchString,
     DateTime? startTime,
     DateTime? endTime,
     DateTimeSpecificity isSpecific,
     SearchType searchType,
     SortType sortType)
     : base(sortType)
 {
     this.searchString = searchString;
     this.startTime = startTime;
     this.endTime = endTime;
     this.isSpecific = isSpecific;
     this.searchType = searchType;
 }
Ejemplo n.º 3
0
 /// <summary>
 /// This is the constructor for the Schedule operation.
 /// This operation accepts a time range and tries to schedule a task
 /// for the specified time period within the time range at the earliest
 /// possible point on execution.</summary>
 /// <param name="taskName">The name of the task to schedule.</param>
 /// <param name="startDateTime">The start date/time which the task should be scheduled within.</param>
 /// <param name="endDateTime">The end date/time which the task should be scheduled within.</param>
 /// <param name="isSpecific">The specificity of the start and end date time ranges.</param>
 /// <param name="timeRangeAmount">The numerical value of the task length of the task to be scheduled.</param>
 /// <param name="timeRangeType">The type of time length the task uses: hour, day, week or month.</param>
 /// <param name="sortType">The type of sort to sort the diplay list by after the operation is executed.</param>
 /// <returns>Nothing.</returns>
 public OperationSchedule(
     string taskName,
     DateTime startDateTime,
     DateTime? endDateTime,
     DateTimeSpecificity isSpecific,
     int timeRangeAmount,
     TimeRangeType timeRangeType,
     SortType sortType)
     : base(sortType)
 {
     this.taskName = taskName;
     this.startDateTime = startDateTime;
     this.endDateTime = endDateTime;
     this.isSpecific = isSpecific;
     this.taskDurationAmount = timeRangeAmount;
     this.taskDurationType = timeRangeType;
 }
Ejemplo n.º 4
0
 /// <summary>
 /// This is the constructor for the Modify operation.
 /// It will modify the task indicated by the index range to the new
 /// parameters specified by the given arguments. If an arguement
 /// is left empty or null, that parameter will remain unchanged.
 /// </summary>
 /// <param name="taskName">The name of the task to modified. Can be a substring of it.</param>
 /// <param name="indexRange">The display index of the task to be modified.</param>
 /// <param name="startTime">The new start date to set for the task.</param>
 /// <param name="endTime">The new end date to set for the task.</param>
 /// <param name="isSpecific">The new Specificity of the dates for the task.</param>
 /// <param name="isAll">If this boolean is true, the operation will be invalid.</param>
 /// <param name="searchType">The type of search to be carried out (in addition to the other filters) if required.</param>
 /// <param name="sortType">The type of sort to sort the diplay list by after the operation is executed.</param>
 /// <returns>Nothing.</returns>
 public OperationModify(string taskName, int[] indexRange, DateTime? startTime,
     DateTime? endTime, DateTimeSpecificity isSpecific, bool isAll, SearchType searchType, SortType sortType)
     : base(sortType)
 {
     if (indexRange == null) hasIndex = false;
     else
     {
         hasIndex = true;
         this.startIndex = indexRange[TokenIndexRange.START_INDEX] - 1;
         this.endIndex = indexRange[TokenIndexRange.END_INDEX] - 1;
     }
     if (taskName == null) this.taskName = "";
     else this.taskName = taskName;
     this.startTime = startTime;
     this.endTime = endTime;
     this.isSpecific = isSpecific;
     this.isAll = isAll;
     this.searchType = searchType;
 }
        /// <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);
        }
Ejemplo n.º 6
0
        /// <summary>
        /// Regenerates a task from an XElement node
        /// </summary>
        /// <param name="task">The XElement node to regenerate the task from.</param>
        /// <returns>The regenerated task.</returns>
        private Task GenerateTaskFromXElement(XElement task)
        {
            Task newTask = null;

            try
            {
                string type = task.Attribute("type").Value;
                int id = Int32.Parse(task.Attribute("id").Value);
                string taskName = task.Element("Name").Value;
                DateTime startTime, endTime;
                DateTimeSpecificity isSpecific = new DateTimeSpecificity();

                XElement DTSpecElement = task.Element("DateTimeSpecificity");
                if (DTSpecElement != null) isSpecific = DTSpecElement.FromXElement<DateTimeSpecificity>();
                bool state;

                if (task.Element("Done").Value == "True") state = true;
                else state = false;
                switch (type)
                {
                    case "Floating":
                        newTask = new TaskFloating(taskName, state, id);
                        break;
                    case "Deadline":
                        endTime = DateTime.Parse(task.Element("EndTime").Value);
                        newTask = new TaskDeadline(taskName, endTime, isSpecific, state, id);
                        break;
                    case "Event":
                        endTime = DateTime.Parse(task.Element("EndTime").Value);
                        startTime = DateTime.Parse(task.Element("StartTime").Value);
                        newTask = new TaskEvent(taskName, startTime, endTime, isSpecific, state, id);
                        break;
                }
            }
            catch (NullReferenceException)
            {
                throw new TaskFileCorruptedException();
            }
            return newTask;
        }
Ejemplo n.º 7
0
 /// <summary>
 /// Copies over the start and end date times and specificity of this task into the reference inputs.
 /// </summary>
 /// <param name="startTime">The start time to copy to.</param>
 /// <param name="endTime">The end time to copy to.</param>
 /// <param name="specific">The specificity to copy to.</param>  
 public override void CopyDateTimes(ref DateTime? startTime, ref DateTime? endTime, ref DateTimeSpecificity specific)
 {
     startTime = null;
     endTime = null;
     specific = new DateTimeSpecificity();
 }
Ejemplo n.º 8
0
        /// <summary>
        /// Initializes the generator's configuration to it's default values.
        /// </summary>
        /// <returns></returns>
        public void InitializeNewConfiguration()
        {
            commandType = new CommandType();
            isSpecific = new DateTimeSpecificity();
            timeRangeType = new TimeRangeType();
            timeRangeOne = new TimeRangeKeywordsType();
            timeRangeTwo = new TimeRangeKeywordsType();
            sortType = new SortType();
            searchType = new SearchType();
            taskName = null;
            taskRangeIndex = null;
            timeRangeIndex = 0;
            rangeIsAll = false;
            startDateTime = null; endDateTime = null;
            startTimeOnly = null; endTimeOnly = null;
            startDateOnly = null; endDateOnly = null;
            startDayOfWeekSet = false; endDayOfWeekSet = false;
            currentSpecifier = new ContextType();
            currentMode = new ContextType();
            crossDayBoundary = false;

            ResetEnumerations();
        }
Ejemplo n.º 9
0
 /// <summary>
 /// Copies over the start and end date times and specificity of this task into the reference inputs.
 /// </summary>
 /// <param name="startTime">The start time to copy to.</param>
 /// <param name="endTime">The end time to copy to.</param>
 /// <param name="specific">The specificity to copy to.</param>        
 public override void CopyDateTimes(ref DateTime? startTime, ref DateTime? endTime, ref DateTimeSpecificity specific)
 {
     startTime = null;
     endTime = this.endDateTime;
     specific = this.isSpecific;
 }
Ejemplo n.º 10
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;
        }
Ejemplo n.º 11
0
 /// <summary>
 /// Copies over the start and end date times and specificity of this task into the reference inputs.
 /// </summary>
 /// <param name="startTime">The start time to copy to.</param>
 /// <param name="endTime">The end time to copy to.</param>
 /// <param name="specific">The specificity to copy to.</param>        
 public abstract void CopyDateTimes(ref DateTime? startTime, ref DateTime? endTime, ref DateTimeSpecificity specific);
Ejemplo n.º 12
0
 /// <summary>
 /// Creates a new task with the given parameters.
 /// </summary>
 /// <param name="taskName">The task name of the new task.</param>
 /// <param name="startTime">The start time of the new task.</param>
 /// <param name="endTime">The end time of the new task.</param>
 /// <param name="isSpecific">The specificity of the new task's times.</param>
 /// <returns>The newly created task.</returns>
 public static Task CreateNewTask(
     string taskName,
     DateTime? startTime,
     DateTime? endTime,
     DateTimeSpecificity isSpecific
     )
 {
     if (taskName == String.Empty || taskName == null)
     {
         Logger.Warning("Attempted to create a task with no task name", "GenerateNewTask::Task");
         return null; // don't accept empty task names
     }
     if (startTime == null && endTime == null)
     {
         Logger.Info("Creating a floating task", "GenerateNewTask::Task");
         return new TaskFloating(taskName);
     }
     else if (startTime == null && endTime != null)
     {
         Logger.Info("Creating a deadline task", "GenerateNewTask::Task");
         return new TaskDeadline(taskName, (DateTime)endTime, isSpecific);
     }
     else if (startTime != null && endTime == null)
     {
         // If endTime is not specified set endTime based on startTime.
         endTime = startTime;
         isSpecific.EndTime = isSpecific.StartTime;
         isSpecific.EndDate = isSpecific.StartDate;
         if (!isSpecific.StartTime)
         {
             endTime = ((DateTime)endTime).AddDays(1).AddMinutes(-1);
         }
         Logger.Info("Creating an event task with only one user specified datetime", "GenerateNewTask::Task");
         return new TaskEvent(taskName, (DateTime)startTime, (DateTime)startTime, isSpecific);
     }
     else
     {
         Logger.Info("Creating an event task with user specified start and end datetimes", "GenerateNewTask::Task");
         return new TaskEvent(taskName, (DateTime)startTime, (DateTime)endTime, isSpecific);
     }
 }