public static DialogResult Show(CalendarItem outlook, CalendarItem google) { using (var form = new DifferencesForm()) { form.LoadData(outlook, google); return(form.ShowDialog()); } }
/// <summary> /// Compares the two lists of calendar items and finds the differences in the lists. /// </summary> /// <param name="outlookList">The outlook list</param> /// <param name="googleList">The google list</param> /// <returns>A list of calendar items with the appropriate changes specified.</returns> private List <CalendarItem> CompareLists(List <CalendarItem> outlookList, List <CalendarItem> googleList, bool forceContentsEqual = false) { var finalList = new List <CalendarItem>(); foreach (var calendarItem in outlookList) { // Check to see if Item is not in google list if (!googleList.Contains(calendarItem)) { // It's not, check the archiver. Maybe it was deleted in google. if (m_archiver.Contains(calendarItem.CalendarItemIdentifier)) { // It appears to have been deleted in the google cal. // Do you want to delete it from outlook? if ( MessageBox.Show( "It appears the calendar event '" + calendarItem.Subject + "' was deleted from Google. Would you like to remove it from Outlook also?", "Delete Event?", MessageBoxButtons.YesNo) == DialogResult.Yes) { // Yes, delete it calendarItem.Action |= CalendarItemAction.OutlookDelete; finalList.Add(calendarItem); } } else { // It is not it google's list or the archiver, add it to google if (calendarItem.Recurrence != null) { if (calendarItem.IsFirstOccurence) { calendarItem.Action |= CalendarItemAction.GoogleAdd; finalList.Add(calendarItem); } } else { calendarItem.Action |= CalendarItemAction.GoogleAdd; finalList.Add(calendarItem); } } } else { // It is in googles list. Find them differences. var item = googleList.Find(x => x.CalendarItemIdentifier.GoogleId.Equals(calendarItem.CalendarItemIdentifier.GoogleId)); // Get the differences if (item != null && !item.IsContentsEqual(calendarItem)) { // Should we do the same action to every calendar item? if (PerformActionToAll) { // Check and make sure there is an action to perform if (Action != CalendarItemAction.Nothing) { calendarItem.Action |= Action; finalList.Add(calendarItem); } } else { // We are not performing the same action to every item, yet. // Are we performing a silentSync? if (m_silentSync && m_precedence != Precedence.None) { // Yep, setup the action to be performed PerformActionToAll = true; Action = m_precedence == Precedence.Outlook ? CalendarItemAction.GoogleUpdate : CalendarItemAction.OutlookUpdate; } else { // No we are not performing a silent sync var result = (DifferencesFormResults)DifferencesForm.Show(calendarItem, item); // Save Outlook Version Once if (result == DifferencesFormResults.KeepOutlookSingle) { calendarItem.Action |= CalendarItemAction.GoogleUpdate; finalList.Add(calendarItem); // Save Outlook Version for All } else if (result == DifferencesFormResults.KeepOutlookAll) { calendarItem.Action |= CalendarItemAction.GoogleUpdate; finalList.Add(calendarItem); Action = CalendarItemAction.GoogleUpdate; PerformActionToAll = true; // Save Google Version Once } else if (result == DifferencesFormResults.KeepGoogleSingle) { item.Action |= CalendarItemAction.OutlookUpdate; finalList.Add(item); // Save Google Version for All } else if (result == DifferencesFormResults.KeepGoogleAll) { item.Action |= CalendarItemAction.OutlookUpdate; finalList.Add(item); Action = CalendarItemAction.OutlookUpdate; PerformActionToAll = true; // Ignore All } else if (result == DifferencesFormResults.IgnoreAll) { PerformActionToAll = true; Action = CalendarItemAction.Nothing; } } } } } } foreach (var calendarItem in googleList) { if (!outlookList.Contains(calendarItem)) { if (m_archiver.Contains(calendarItem.CalendarItemIdentifier)) { if ( MessageBox.Show( "It appears the calendar event '" + calendarItem.Subject + "' was deleted from Outlook. Would you like to remove it from Google also?", "Delete Event?", MessageBoxButtons.YesNo) == DialogResult.Yes) { calendarItem.Action |= CalendarItemAction.GoogleDelete; finalList.Add(calendarItem); } } else { calendarItem.Action |= CalendarItemAction.OutlookAdd; finalList.Add(calendarItem); } } } return(finalList); }