/// <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); }
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(); }
private void PrintList(GGList myList) { for (int i = 0; i < myList.GetInnerList().Count; i++) { Console.WriteLine(myList.GetGGItemAt(i).ToString()); } }
/// <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(); }