示例#1
0
文件: Invoker.cs 项目: wertkh32/gg
 /// <summary>
 /// The state of the program is initialized here.
 /// </summary>
 private Invoker()
 {
     undoableCommands = new Stack<IUndoable>();
     ggList = new GGList();
     fileCtrl = new GGFileController();
     ggList = fileCtrl.ReadFromFile();
 }
示例#2
0
 /// <summary>
 /// Deletes an item from the ggList as specified by the user
 /// </summary>
 /// <param name="userCommand">The command issued by the user</param>
 /// <param name="ggList">The list of task items</param>
 public override GGResult Execute(string userCommand, GGList list)
 {
     Debug.Assert(userCommand != null && !userCommand.Equals(string.Empty));
     this.SetGGList(list);
     if (InvalidInput(userCommand))
     {
         string errorMsg = "Error: Please specify an item id to remove\n";
         Debug.WriteLine(errorMsg);
         return CreateErrorResultInstance(errorMsg);
     }
     int itemIndexToShow = GetItemIndexFromUserCommand(userCommand);
     itemIndex = itemIndexToShow - 1;
     if (IndexOutOfBounds(itemIndex))
     {
         string errorMsg = string.Format("Error: There is no list item of index {0}\n", itemIndexToShow);
         Debug.WriteLine(errorMsg);
         return CreateErrorResultInstance(errorMsg);
     }
     GGList ggList = this.GetGGList();
     removedGgItem = ggList.GetGGItemAt(itemIndex);
     ggList.RemoveGGItemAt(itemIndex);
     this.SetIsSuccessful(true);
     string successMsg = string.Format(MESSAGE_REMOVE_SUCCESS, removedGgItem.GetDescription());
     Debug.WriteLine(successMsg);
     result = new GGResult(string.Empty, successMsg, itemIndex, GGResult.RESULT_TYPE.RESULT_REMOVE, removedGgItem.GetTag()); //useless to return itemindex since item does not exist
     return result;
 }
示例#3
0
文件: AddCommand.cs 项目: wertkh32/gg
 public override GGResult Execute(string userCommand, GGList ggList)
 {
     Debug.Assert(userCommand != null && !userCommand.Equals(string.Empty));
     Debug.Assert(ggList != null);
     this.SetGGList(ggList);
     userCommand = StripAddCommandFromUserCommand(userCommand).Trim();
     try
     {
         ThrowExceptionIfIsEmptyInput(userCommand);
         newGgItem = QuickParser.Parse(userCommand);
         ggList.AddGGItem(newGgItem);
         this.SetIsSuccessful(true);
         string successMsg = string.Format(MESSAGE_ADD_SUCCESS, newGgItem.GetDescription());
         Debug.WriteLine(successMsg, "info");
         result = CreateResultInstance(successMsg, GGResult.RESULT_TYPE.RESULT_ADD, ggList.IndexOfGGItem(newGgItem),newGgItem.GetTag());
     }
     catch (Exception e)
     {
         error = e.Message;
         string errorMsg = string.Format(MESSAGE_ERROR, error);
         Debug.WriteLine(errorMsg, "error");
         result = CreateResultInstance(errorMsg, GGResult.RESULT_TYPE.RESULT_INVALID);
     }
     return result;
 }
示例#4
0
文件: ActCommand.cs 项目: wertkh32/gg
        /// <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;
                }
            }
        }
示例#5
0
 private static void AddOriginalDataToList(GGList originalList)
 {
     for (int i = 0; i < originalData.Length / 3; i++)
     {
         GGItem item = new GGItem(originalData[i, 0], DateTime.Parse(originalData[i, 1], usCulture), originalData[i, 2]);
         originalList.AddGGItem(item);
     }
 }
示例#6
0
 public static void GenerateAndRunTestCases(string command, string type, int itemIdToChange, string expectedChange, string expectedResultMessage, string message)
 {
     GGList originalList = new GGList();
     AddOriginalDataToList(originalList);
     GGList expectedList = new GGList();
     CreateExpectedList(expectedList, type, itemIdToChange, expectedChange);
     ChangeCommand cmd = new ChangeCommand();
     GGResult actualResult = cmd.Execute(command, originalList);
     Assert.AreEqual(expectedList, originalList, message);
     Assert.AreEqual(expectedResultMessage, actualResult.GetNotice(), "result message");
 }
示例#7
0
 public override GGResult Execute(string userCommand, GGList list)
 {
     Invoker invoker = Invoker.GetInstance();
     string msg = string.Empty;
     if (invoker.PopAndUndo())
     {
         msg = successMsg;
     }
     else
     {
         msg = errorMsg;
     }
     GGResult result = new GGResult(string.Empty, msg, -1, GGResult.RESULT_TYPE.RESULT_UNDO);
     return result;
 }
示例#8
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;
            }
        }
示例#9
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;
 }
示例#10
0
 public override GGResult Execute(string userCommand, GGList list)
 {
     string username = string.Empty;
     string password = string.Empty;
     try
     {
         GetLoginCredentialsFromUserCommand(userCommand, out username, out password);
         GGSync sync = new GGSync(username, password);
         bool IsSuccessfulSync = sync.SyncWithGoogleCalendar(list);
         if (IsSuccessfulSync)
             result = CreateResultInstance(MESSAGE_SYNC_SUCCESS, GGResult.RESULT_TYPE.RESULT_SYNC);
         else
         {
             result = CreateResultInstance("Sync Error!", GGResult.RESULT_TYPE.RESULT_INVALID);
         }
     }
     catch (FormatException e)
     {
         result = CreateResultInstance(e.Message, GGResult.RESULT_TYPE.RESULT_INVALID);
     }
     return result;
 }
示例#11
0
        /// <summary>
        /// Loops through GGList and displays relevant items to the user in the console.
        /// </summary>
        /// <param name="ggList">The main list</param>
        /// <param name="userCommand">ls, followed by an empty string, a tag query, or a search query</param>
        /// <returns> The list of items (in string form) to display to the user.</returns>
        public override GGResult Execute(string userCommand, GGList ggList)
        {
            this.SetGGList(ggList);
            ggList.SortGGList();

            string pattern = "ls\\s*";
            Regex rgx = new Regex(pattern, RegexOptions.IgnoreCase);
            string parameter = rgx.Replace(userCommand, "", 1); // strip "ls"

            if (IsDisplayAll(parameter))
            {
                result = DisplayAll();
            }
            else if (isDisplayTag(parameter))
            {
                result = DisplayByTag(parameter);
            }
            else // search in descriptions
            {
                result = DisplayBySearch(parameter);
            }
            return result;
        }
示例#12
0
文件: Command.cs 项目: wertkh32/gg
 public void SetGGList(GGList ggList)
 {
     this.ggList = ggList;
 }
示例#13
0
文件: Command.cs 项目: wertkh32/gg
 public abstract GGResult Execute(string userCommand, GGList list);
示例#14
0
文件: Command.cs 项目: wertkh32/gg
 public Command()
 {
     ggList = new GGList();
     //initialize to empty list to prevent null exceptions
 }
示例#15
0
文件: Command.cs 项目: wertkh32/gg
 public override GGResult Execute(string userCommand, GGList list)
 {
     string errorMsg = "Error: Invalid Input\n";
     GGResult result = new GGResult(string.Empty, errorMsg, -1,GGResult.RESULT_TYPE.RESULT_INVALID);
     return result;
 }
示例#16
0
文件: TestGGSync.cs 项目: wertkh32/gg
        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();
        }
示例#17
0
        /// <summary>
        /// Read from files
        /// </summary>
        /// <returns>GGList object</returns>
        public GGList ReadFromFile()
        {
            List<GGItem> innerList = ReadFromACSVFile(pathToStorageFile);
            List<GGItem> deletedList = ReadFromACSVFile(pathToDeletedStorageFile);

            GGList ggList = new GGList();

            ggList.SetInnerList(innerList);
            ggList.SetDeletedList(deletedList);

            return ggList;
        }
示例#18
0
文件: GGSync.cs 项目: wertkh32/gg
        /// <summary>
        /// Prepare for synchronization
        /// </summary>
        /// <param name="ggList">Local GGList</param>
        /// <param name="addToLocal">List of GGItems to be added to local GGList</param>
        /// <param name="removeFromLocal">List of GGItems to be removed from local GGList</param>
        /// <param name="GGService">Google calendar service object</param>
        /// <param name="GGCalendar">GG calendar</param>
        /// <param name="GGEvents">Google event query results</param>
        /// <param name="server">List of bools to indicate if a Google event has a local version</param>
        /// <param name="toBeSyncedList">List of GGItems to be synced</param>
        /// <param name="toBeDeletedList">List of GGItems to be deleted on Google calendar</param>
        private void PrepareForSync(GGList ggList, out List<GGItem> addToLocal, out List<GGItem> removeFromLocal, out CalendarService GGService, out CalendarEntry GGCalendar, out EventFeed GGEvents, out List<bool> server, out List<GGItem> toBeSyncedList, out List<GGItem> toBeDeletedList)
        {
            // List of GGItems to be add to local GGList
            addToLocal = new List<GGItem>();
            // List of GGItems to be removed from local GGList
            removeFromLocal = new List<GGItem>();

            // Create Google calendar service object
            GGService = new CalendarService("GG");
            // Set credentials
            GGService.setUserCredentials(username, password);

            // Select GG calendar, create one if not exists
            GGCalendar = SelectGGCalendar(GGService);
            if (GGCalendar == null)
            {
                GGCalendar = CreateGGCalendar(GGService);
            }

            Log("operate on calender: " + GGCalendar.Title.Text);

            // Query and get all events on GG calendar
            EventQuery q = new EventQuery();
            q.Uri = new Uri("https://www.google.com/calendar/feeds/" + GGCalendar.Id.AbsoluteUri.Substring(63) + "/private/full");
            GGEvents = GGService.Query(q);

            // True if a Google event has a coresponding GGItem
            server = new List<bool>();
            for (int i = 0; i < GGEvents.Entries.Count; i++)
            {
                server.Add(false);
            }

            toBeSyncedList = ggList.GetInnerList();
            toBeDeletedList = ggList.GetDeletedList();
        }
示例#19
0
文件: TestGGSync.cs 项目: wertkh32/gg
 private void PostTestPrint(GGList ggList)
 {
     Console.WriteLine("\nAfter sycn gglist: ");
     PrintList(ggList);
 }
示例#20
0
文件: GGSync.cs 项目: wertkh32/gg
 /// <summary>
 /// Update GGList
 /// </summary>
 /// <param name="addToLocal">List of GGItems to be added to local GGList</param>
 /// <param name="removeFromLocal">List of GGItems to be removed from local GGList</param>
 /// <param name="toBeSyncedList">List of GGItems to be synced</param>
 /// <param name="toBeDeletedList">List of GGItems to be deleted on Google calendar</param>
 private void UpdateLocalList(List<GGItem> addToLocal, List<GGItem> removeFromLocal, GGList ggList, List<GGItem> toBeDeletedist)
 {
     for (int i = 0; i < removeFromLocal.Count; i++)
     {
         ggList.RemoveGGItem(removeFromLocal[i]);
     }
     for (int i = 0; i < addToLocal.Count; i++)
     {
         ggList.AddGGItem(addToLocal[i]);
     }
     toBeDeletedist.Clear();
 }
示例#21
0
文件: PinCommand.cs 项目: wertkh32/gg
        /// <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;

            }
        }
示例#22
0
文件: TestGGSync.cs 项目: wertkh32/gg
        private void GGSyncCornerCaseTest()
        {
            GGSync syncTest = new GGSync("*****@*****.**", "cs2103trocks");
            GGList testList = new GGList();

            PrintSperateLine();

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

            Console.WriteLine("\nTest: Sync with empty GGList");
            Console.ReadKey();

            PreTestPrint(testList);
            syncTest.SyncWithGoogleCalendar(testList);
            PostTestPrint(testList);

            Console.WriteLine("\nPlease check: there should be no event on both sides");

            PrintSperateLine();

            Console.WriteLine("\nTest: Add to empty calendar");
            Console.ReadKey();

            for (int i = 0; i < 3; i++)
            {
                testList.AddGGItem(new GGItem("corner test description " + i, DateTime.Now.AddDays(-i).AddHours(i), "corner test tag " + i));
            }

            PreTestPrint(testList);
            syncTest.SyncWithGoogleCalendar(testList);
            PostTestPrint(testList);

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

            PrintSperateLine();

            Console.WriteLine("\nTest: Add to non-empty calendar");
            Console.ReadKey();

            for (int i = 3; i < 5; i++)
            {
                GGItem testItem = new GGItem("corner test description " + i, DateTime.Now.AddDays(-i).AddHours(i), "corner test tag " + i);
                testList.AddGGItem(testItem);
                Console.WriteLine("\nAdd to local GGList: " + testItem.ToString());
            }

            PreTestPrint(testList);
            syncTest.SyncWithGoogleCalendar(testList);
            PostTestPrint(testList);

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

            PrintSperateLine();

            Console.WriteLine("\nTest: Sync after deleting all events in local GGList");
            Console.ReadKey();

            testList.ClearGGList();

            PreTestPrint(testList);
            syncTest.SyncWithGoogleCalendar(testList);
            PostTestPrint(testList);

            Console.WriteLine("\nPlease check: there should be no event on Google Calendar");
            Console.ReadKey();

            PrintSperateLine();

            Console.WriteLine("\nTest: Sync after deleting all events on Google Calendar");

            for (int i = 0; i < 3; i++)
            {
                testList.AddGGItem(new GGItem("corner test description " + i, DateTime.Now.AddDays(-i).AddHours(i), "corner test tag " + i));
            }

            syncTest.SyncWithGoogleCalendar(testList);

            Console.WriteLine("\nPlease delete all 3 events on Google Calendar");
            Console.ReadKey();

            PreTestPrint(testList);
            syncTest.SyncWithGoogleCalendar(testList);
            PostTestPrint(testList);

            Console.WriteLine("Please check: there should be no events in local GGList");
            Console.ReadKey();

            PrintSperateLine();

            Console.WriteLine("\nTest: Delete the same event both sides");

            testList.AddGGItem(new GGItem("corner test description 0", DateTime.Now, "corner test tag 0"));
            syncTest.SyncWithGoogleCalendar(testList);

            Console.WriteLine("Please delete the only event on Google Calendar");
            Console.ReadKey();

            testList.ClearGGList();

            PreTestPrint(testList);
            syncTest.SyncWithGoogleCalendar(testList);
            PostTestPrint(testList);

            Console.WriteLine("Please check: there should be no event on both sides");

            Console.ReadKey();
        }
示例#23
0
文件: TestGGSync.cs 项目: wertkh32/gg
 private void PrintList(GGList myList)
 {
     for (int i = 0; i < myList.GetInnerList().Count; i++)
     {
         Console.WriteLine(myList.GetGGItemAt(i).ToString());
     }
 }
示例#24
0
文件: TestGGSync.cs 项目: wertkh32/gg
 private void PreTestPrint(GGList ggList)
 {
     Console.WriteLine("\nBefore sycn gglist: ");
     PrintList(ggList);
 }
示例#25
0
 /// <summary>
 /// Write to files
 /// </summary>
 /// <param name="ggList">GGList object to be written</param>
 public void WriteToFile(GGList ggList)
 {
     WriteToACSVFile(ggList.GetInnerList(), pathToStorageFile);
     WriteToACSVFile(ggList.GetDeletedList(), pathToDeletedStorageFile);
 }
示例#26
0
文件: GGSync.cs 项目: wertkh32/gg
        /// <summary>
        /// Synchronize GGList with Google Calendar
        /// Solve confict according to the last modified time
        /// </summary>
        /// <param name="userName">Gmail address</param>
        /// <param name="password">Gmail password</param>
        /// <param name="ggList">GGList to be synchronized</param>
        public bool SyncWithGoogleCalendar(GGList ggList)
        {
            try
            {
                List<GGItem> addToLocal;
                List<GGItem> removeFromLocal;
                CalendarService GGService;
                CalendarEntry GGCalendar;
                EventFeed GGEvents;
                List<bool> server;
                List<GGItem> toBeSyncedList;
                List<GGItem> toBeDeletedList;

                // Prepare for synchronization
                PrepareForSync(ggList, out addToLocal, out removeFromLocal, out GGService, out GGCalendar, out GGEvents, out server, out toBeSyncedList, out toBeDeletedList);

                Log("GGSync: username: "******"\nFor loop through deleted list:\n");
                // Loop through toBeDeletedList
                for (int i = 0; i < toBeDeletedList.Count; i++)
                {
                    GGItem ggItem = toBeDeletedList[i];
                    Log("\nNow at: " + ggItem.ToString() + "\n");
                    DeleteEvents(GGEvents, server, ggItem);
                }

                Log("For loop through local list\n");
                // Loop through toBeSyncedList
                for (int i = 0; i < toBeSyncedList.Count; i++)
                {
                    GGItem ggItem = toBeSyncedList[i];
                    Log("\nNow at: " + ggItem.ToString() + "\n");
                    SyncFromLocalToServer(addToLocal, removeFromLocal, GGService, GGCalendar, GGEvents, server, ggItem);
                }

                Log("\nFor loop through the rest server list\n");
                SyncFromServerToLocal(addToLocal, GGEvents, server);

                Log("\n Sync addToLocal and removeFromLocal with GGList");
                UpdateLocalList(addToLocal, removeFromLocal, ggList, toBeDeletedList);

                Log("GGSync: " + username + "'s sync successful");
                return true;
            }
            catch (Google.GData.Client.CaptchaRequiredException e)
            {
                Debug.WriteLine("GGSync.SyncWithGoogleCalendar: " + e.Message);
                return false;
            }
            catch (Google.GData.Client.InvalidCredentialsException e)
            {
                Debug.WriteLine("GGSync.SyncWithGoogleCalendar: " + e.Message);
                return false;
            }
            catch (Google.GData.Client.GDataRequestException e)
            {
                Debug.WriteLine("GGSync.SyncWithGoogleCalendar: " + e.Message);
                return false;
            }
        }