コード例 #1
0
ファイル: Storage.cs プロジェクト: soulslicer/ToDoPlusPlus
        /// <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;
        }
コード例 #2
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;
        }