private static void Main(string[] args) { ReadConfig(); CalendarManagerGoogle gManager = new CalendarManagerGoogle(user, pass, calendarId); //List<CalendarEvent> events = CalendarManagerOutlook.GetAllEvents(); List<CalendarEvent> eventsInExchange = CalendarManagerExchange.GetAllEvents(exchangeurl, exchangeuser, exchangepassword); Console.WriteLine("Found {0} events in the outlook calendar", eventsInExchange.Count); List<CalendarEvent> eventsInGoogle = gManager.GetAllEvents(); //Error check to make sure we do not need to implement paging if (eventsInGoogle.Count == CalendarGlobals.MaxGoogleEntriesToReturn) throw new Exception("Google event feed paging needs to be implemented."); Console.WriteLine("Found {0} events in the google calendar", eventsInGoogle.Count); CalendarEvent searchEvent; foreach (CalendarEvent cEvent in eventsInExchange) { //searchEvent = gManager.GetEventFromSyncId(cEvent.Id); searchEvent = eventsInGoogle.Find(t => t.Id.Equals(cEvent.Id)); if (searchEvent == null) { // -> create a new event Console.Write("Creating event \"{0}\" ... ", cEvent.Subject); gManager.CreateEvent(cEvent); Console.WriteLine("Created"); } else if (cEvent.IsChanged(searchEvent)) { // -> update event Console.Write("Update event \"{0}\" ... ", cEvent.Subject); gManager.UpdateEvent(cEvent); Console.WriteLine("Updated"); } } //Find all events that exist in Google that do not exist in Exchange List<CalendarEvent> deleteList = new List<CalendarEvent>(); foreach (CalendarEvent googleEvent in eventsInGoogle) { if (eventsInExchange.Exists(t => t.Id.Equals(googleEvent.Id))) continue; deleteList.Add(googleEvent); } Console.WriteLine("Found {0} events needing deletion in google", deleteList.Count); foreach (CalendarEvent googleEvent in deleteList) { Console.WriteLine("Deleting event \"{0}\" {1} ... ", googleEvent.Subject, googleEvent.StartDate); gManager.DeleteEvent(googleEvent.Id); } #if DEBUG Console.WriteLine("Press any key to continue ..."); Console.ReadLine(); #endif }
private static void Main(string[] args) { ReadConfig(); CalendarManagerGoogle gManager = new CalendarManagerGoogle(user, pass, calendarId); List <CalendarEvent> events = CalendarManagerOutlook.GetAllEvents(); List <CalendarEvent> eventsInGoogle = gManager.GetAllEvents(); List <CalendarEvent> eventsProcessed = new List <CalendarEvent>(); Console.WriteLine("Found {0} events in the outlook calendar", events.Count); CalendarEvent searchEvent; foreach (CalendarEvent cEvent in events) { searchEvent = gManager.GetEventFromSyncId(cEvent.Id); if (searchEvent == null) { // -> create a new event Console.Write("Creating event \"{0}\" ... ", cEvent.Subject); gManager.CreateEvent(cEvent); Console.WriteLine("Created"); } else if (cEvent.IsChanged(searchEvent)) { // -> update event Console.Write("Update event \"{0}\" ... ", cEvent.Subject); gManager.UpdateEvent(cEvent); Console.WriteLine("Updated"); } eventsProcessed.Add(cEvent); } List <CalendarEvent> eventsNotProcessed = eventsInGoogle.Except <CalendarEvent>(eventsProcessed).ToList <CalendarEvent>(); if (eventsNotProcessed.Count > 0) { //TO DO: Fix Delete, only 25 items in google list and I should also ask outlook if item still exists... foreach (CalendarEvent cEvent in eventsNotProcessed) { //gManager.DeleteEvent(cEvent.Id); } } #if DEBUG Console.WriteLine("Press any key to continue ..."); Console.ReadLine(); #endif }