Beispiel #1
0
        /// <summary>
        /// Updates the description of the indicated item in ggList.
        /// </summary>
        /// <param name="ggList">The full list (ggList from GGLogic)</param>
        /// <param name="itemIndex">The index of the list item</param>
        /// <param name="updateTo">The new info of the list item</param>
        /// <returns>The status of the operation</returns>
        public override GGResult Execute(string userCommand, GGList ggList)
        {
            this.SetGGList(ggList);
            Regex regex = new Regex("\\s+");
            string[] userCommandArray = regex.Split(userCommand, 3);

            if (userCommandArray.Count() < 3)
            {
                string errorMsg = "Error: Incorrect input"; // "ch", itemIndex, newInfo
                result = CreateResultInstance(errorMsg, GGResult.RESULT_TYPE.RESULT_INVALID);
                return result;
            }
            string itemIndexString = userCommandArray[1];
            string newInfo = userCommandArray[2];
            if (NewInfoIsEmpty(newInfo))
            {
                string errorMsg = "Error: What do you want to change to?";
                result = CreateResultInstance(errorMsg, GGResult.RESULT_TYPE.RESULT_INVALID);
                return result;
            }
            int.TryParse(itemIndexString, out itemIndex);
            if (IndexOutOfBounds(itemIndex))
            {
                string errorMsg = string.Format("Error: There is no list item of index {0}\n", itemIndex);
                result = CreateResultInstance(errorMsg, GGResult.RESULT_TYPE.RESULT_INVALID);
                return result;
            }
            try
            {
                string oldtag = ggList.GetGGItemAt(itemIndex - 1).GetTag();
                GGItem itemToChange = ggList.GetGGItemAt(itemIndex - 1);
                ggList.RemoveGGItemAt(itemIndex - 1);
                GGItem changedItem = DetermineFieldAndChange(newInfo, itemToChange);
                ggList.InsertGGItem(itemIndex - 1, changedItem);
                string successMsg = string.Format(MESSAGE_CHANGE_SUCCESS, itemIndex);

                result = new GGResult(string.Empty, successMsg, itemIndex - 1, GGResult.RESULT_TYPE.RESULT_UPDATE, oldtag);
                return result;

            }
            catch (Exception e)
            {
                string errorMsg = "Error: Invalid Input";
                result = CreateResultInstance(errorMsg, GGResult.RESULT_TYPE.RESULT_INVALID);
                return result;
            }
        }
Beispiel #2
0
        /// <summary>
        /// Pins path to an item in ggList.
        /// </summary>
        /// <param name="ggList">The full list (ggList from GGLogic)</param>
        /// <param name="itemIndex">The index of the list item</param>
        /// <param name="updateTo">The new info of the list item</param>
        /// <returns>The status of the operation</returns>
        public override GGResult Execute(String userCommand, GGList ggList)
        {
            this.SetGGList(ggList);
            Regex rgx = new Regex("\\s+");
            string[] userCommandArray = rgx.Split(userCommand, 2);

            if (userCommandArray.Count() != 2)
            {
                String errorMsg = "Error: Incorrect input";
                result = new GGResult(String.Empty, errorMsg, -1, GGResult.RESULT_TYPE.RESULT_INVALID);
                return result;
            }
            else
            {
                string itemIndexString = userCommandArray[1];

                if (!int.TryParse(itemIndexString, out itemIndex))
                {
                    String errorMsg = "Error: Incorrect input";
                    result = new GGResult(String.Empty, errorMsg, -1, GGResult.RESULT_TYPE.RESULT_INVALID);
                    return result;
                }
                else if (IndexOutOfBounds(itemIndex))
                {
                    String errorMsg = String.Format("Error: There is no list item of index {0}\n", itemIndex);
                    result = new GGResult(String.Empty, errorMsg, -1, GGResult.RESULT_TYPE.RESULT_INVALID);
                    return result;
                }
                else
                {

                    GGItem itemToChange = ggList.GetGGItemAt(itemIndex - 1);
                    string path = itemToChange.GetPath();

                    if (path.Equals(""))
                    {
                        String errorMsg = String.Format("Error: There is no path pinned to index {0}\n", itemIndex);
                        result = new GGResult(String.Empty, errorMsg, -1, GGResult.RESULT_TYPE.RESULT_INVALID);
                        return result;
                    }

                    try
                    {
                        runpath(path);
                    }
                    catch (Exception e)
                    {
                        String errorMsg = String.Format("Error: Invalid path pinned to index {0}\n", itemIndex);
                        result = new GGResult(String.Empty, errorMsg, -1, GGResult.RESULT_TYPE.RESULT_INVALID);
                        return result;
                    }

                    String successMsg = String.Format(MESSAGE_ACT_SUCCESS, itemIndex);

                    result = new GGResult(String.Empty, successMsg, itemIndex - 1, GGResult.RESULT_TYPE.RESULT_ACT, itemToChange.GetTag());
                    return result;
                }
            }
        }
Beispiel #3
0
 private static GGList CreateExpectedList( GGList expectedList, string type, int itemIdToChange, string expectedChange)
 {
     AddOriginalDataToList(expectedList);
     if (type.Equals("desc"))
     {
         expectedList.GetGGItemAt(itemIdToChange - 1).SetDescription(expectedChange);
     }
     else if (type.Equals("tag"))
     {
         expectedList.GetGGItemAt(itemIdToChange - 1).SetTag(expectedChange);
     }
     else if (type.Equals("date"))
     {
         expectedList.GetGGItemAt(itemIdToChange - 1).SetEndDate(DateTime.Parse(expectedChange, usCulture).Date.AddHours(23.9833333));
     }
     return expectedList;
 }
Beispiel #4
0
        /// <summary>
        /// Pins path to an item in ggList.
        /// </summary>
        /// <param name="ggList">The full list (ggList from GGLogic)</param>
        /// <param name="itemIndex">The index of the list item</param>
        /// <param name="updateTo">The new info of the list item</param>
        /// <returns>The status of the operation</returns>
        public override GGResult Execute(String userCommand, GGList ggList)
        {
            this.SetGGList(ggList);
            Regex rgx = new Regex("\\s+");
            string[] userCommandArray = rgx.Split(userCommand, 3);

            if (userCommandArray.Count() < 3)
            {
                String errorMsg = "Error: Incorrect input"; // "ch", itemIndex, newInfo
                result = new GGResult(String.Empty, errorMsg, -1, GGResult.RESULT_TYPE.RESULT_INVALID);
                return result;
            }
            else
            {
                string itemIndexString = userCommandArray[1];
                string path = userCommandArray[2].Equals("none") ? "" : userCommandArray[2];
                int.TryParse(itemIndexString, out itemIndex);
                if (IndexOutOfBounds(itemIndex))
                {
                    String errorMsg = String.Format("Error: There is no list item of index {0}\n", itemIndex);
                    result = new GGResult(String.Empty, errorMsg, -1, GGResult.RESULT_TYPE.RESULT_INVALID);
                    return result;
                }

                if (path.Equals("file"))
                    {
                        Microsoft.Win32.OpenFileDialog dlg = new Microsoft.Win32.OpenFileDialog();
                        if (dlg.ShowDialog() == true)
                        {
                            path = dlg.FileName;
                        }
                        else
                        {
                            String errorMsg = "Error: No File Selected"; // "ch", itemIndex, newInfo
                            result = new GGResult(String.Empty, errorMsg, -1, GGResult.RESULT_TYPE.RESULT_INVALID);
                            return result;
                        }
                    }
                else if (path.Equals("folder"))
                {
                    System.Windows.Forms.FolderBrowserDialog fb= new System.Windows.Forms.FolderBrowserDialog();
                    fb.ShowNewFolderButton = true;
                    fb.Description = "Select folder to pin to your item.";

                    if (fb.ShowDialog() == System.Windows.Forms.DialogResult.OK)
                    {
                        path = fb.SelectedPath;
                    }
                    else
                    {
                        String errorMsg = "Error: No Folder Selected"; // "ch", itemIndex, newInfo
                        result = new GGResult(String.Empty, errorMsg, -1, GGResult.RESULT_TYPE.RESULT_INVALID);
                        return result;
                    }
                }

                    GGItem itemToChange = ggList.GetGGItemAt(itemIndex - 1);
                    itemToChange.SetPath(path);
                    String successMsg = path.Equals("") ? String.Format(MESSAGE_PIN_REMOVED,itemIndex)
                        : String.Format(MESSAGE_PIN_SUCCESS, path, itemIndex);

                    result = new GGResult(String.Empty, successMsg, itemIndex - 1, GGResult.RESULT_TYPE.RESULT_PIN, itemToChange.GetTag());
                    return result;

            }
        }
Beispiel #5
0
 private void PrintList(GGList myList)
 {
     for (int i = 0; i < myList.GetInnerList().Count; i++)
     {
         Console.WriteLine(myList.GetGGItemAt(i).ToString());
     }
 }
Beispiel #6
0
        private void GGSyncUnitTest()
        {
            GGSync mySync = new GGSync("*****@*****.**", "cs2103trocks");

            PrintSperateLine();
            Console.WriteLine("\nPlease delete GG to-do calendar\n");
            Console.ReadKey();

            GGList myList = new GGList();
            for (int i = 0; i < 3; i++)
            {
                myList.AddGGItem(new GGItem("desciption_test" + i, DateTime.Now.AddDays(i + 1), "tag_test" + i));
            }

            PrintSperateLine();
            Console.WriteLine("\nTest: add to empty google calender\n");

            PreTestPrint(myList);
            mySync.SyncWithGoogleCalendar(myList);
            PostTestPrint(myList);

            Console.WriteLine("\nPlease check if Google Calendar has 3 events.");

            PrintSperateLine();
            Console.WriteLine("\nTest: local has the latest version\n");
            Console.ReadKey();

            myList.GetGGItemAt(0).SetDescription(myList.GetGGItemAt(0).GetDescription() + " local updated");
            Console.WriteLine("\nupdate local: " + myList.GetGGItemAt(0).ToString());

            GGItem newGGItem = new GGItem("description_test_new", DateTime.Now.AddDays(5).AddHours(3), "tag_test3");
            myList.AddGGItem(newGGItem);
            Console.WriteLine("\nadd local: " + newGGItem.ToString());

            PreTestPrint(myList);
            mySync.SyncWithGoogleCalendar(myList);
            PostTestPrint(myList);

            Console.WriteLine("\nPlease check Google Calendar: event0->description: 'local updated' appended");
            Console.WriteLine("\nPlease check Google Calendar: new event added: tag_test3");

            PrintSperateLine();
            Console.WriteLine("\nTest: server has the latest version\n");
            Console.WriteLine("\nPlease modified one task, add one task and delete one task on calendar");
            Console.ReadKey();

            PreTestPrint(myList);
            mySync.SyncWithGoogleCalendar(myList);
            PostTestPrint(myList);

            Console.WriteLine("\nPlease check: there should be 4 items after sync");

            PrintSperateLine();
            Console.WriteLine("\nTest: both have some latest events\n");
            myList.GetGGItemAt(2).SetTag(myList.GetGGItemAt(2).GetTag() + " local update");
            Console.WriteLine("\nupdate local: " + myList.GetGGItemAt(2).ToString());
            Console.WriteLine("\nPlease update on server");
            Console.ReadKey();

            PreTestPrint(myList);
            mySync.SyncWithGoogleCalendar(myList);
            PostTestPrint(myList);

            Console.WriteLine("\nPlease check Google Calendar: event_2->tag: 'local update' appended");
            Console.WriteLine("\nPlease check: there should be 4 items after sync");

            PrintSperateLine();
            Console.WriteLine("\nTest: delete from server");

            Console.WriteLine("\nRemove at local list: " + myList.GetGGItemAt(0));
            myList.GetDeletedList().Add(myList.GetGGItemAt(0));
            myList.GetInnerList().Remove(myList.GetGGItemAt(0));
            Console.ReadKey();

            PreTestPrint(myList);
            mySync.SyncWithGoogleCalendar(myList);
            PostTestPrint(myList);

            Console.WriteLine("\nPlease check Google Calendar: there should be 3 events");

            Console.ReadKey();
        }