Ejemplo n.º 1
0
        private void processOutlookExceptions(AppointmentItem ai, Event ev, Boolean forceCompare)
        {
            if (!HasExceptions(ev, checkLocalCacheOnly: true))
            {
                return;
            }

            if (!ai.Saved)
            {
                ai.Save();
            }

            RecurrencePattern oPattern = ai.GetRecurrencePattern();

            foreach (Event gExcp in Recurrence.Instance.googleExceptions.Where(exp => exp.RecurringEventId == ev.Id))
            {
                log.Fine("Found Google exception for " + (gExcp.OriginalStartTime.DateTime ?? gExcp.OriginalStartTime.Date));

                DateTime        oExcpDate = DateTime.Parse(gExcp.OriginalStartTime.DateTime ?? gExcp.OriginalStartTime.Date);
                AppointmentItem newAiExcp = getOutlookInstance(oPattern, oExcpDate);
                if (newAiExcp == null)
                {
                    continue;
                }

                if (gExcp.Status != "cancelled")
                {
                    int itemModified = 0;
                    newAiExcp = OutlookCalendar.Instance.UpdateCalendarEntry(newAiExcp, gExcp, ref itemModified, forceCompare);
                    if (itemModified > 0)
                    {
                        try {
                            newAiExcp.Save();
                        } catch (System.Exception ex) {
                            log.Warn(ex.Message);
                            if (ex.Message == "Cannot save this item.")
                            {
                                MainForm.Instance.Logboxout("Uh oh! Outlook wasn't able to save this recurrence exception! " +
                                                            "You may have two occurences on the same day, which it doesn't allow.");
                            }
                        }
                    }
                }
                else
                {
                    MainForm.Instance.Logboxout(OutlookCalendar.GetEventSummary(ai) + "\r\nDeleted.");
                    newAiExcp.Delete();
                }
                newAiExcp = (AppointmentItem)OutlookCalendar.ReleaseObject(newAiExcp);
            }
            if (!ai.Saved)
            {
                ai.Save();
            }
            oPattern = (RecurrencePattern)OutlookCalendar.ReleaseObject(oPattern);
        }
Ejemplo n.º 2
0
        public void DeleteCalendarEntries(List <AppointmentItem> oAppointments)
        {
            for (int o = oAppointments.Count - 1; o >= 0; o--)
            {
                AppointmentItem ai       = oAppointments[o];
                Boolean         doDelete = false;
                try {
                    doDelete = deleteCalendarEntry(ai);
                } catch (System.Exception ex) {
                    if (!Settings.Instance.VerboseOutput)
                    {
                        MainForm.Instance.Logboxout(OutlookCalendar.GetEventSummary(ai));
                    }
                    MainForm.Instance.Logboxout("WARNING: Appointment deletion failed.\r\n" + ex.Message);
                    log.Error(ex.StackTrace);
                    if (MessageBox.Show("Outlook appointment deletion failed. Continue with synchronisation?", "Sync item failed", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
                    {
                        continue;
                    }
                    else
                    {
                        ai = (AppointmentItem)ReleaseObject(ai);
                        throw new UserCancelledSyncException("User chose not to continue sync.");
                    }
                }

                try {
                    if (doDelete)
                    {
                        deleteCalendarEntry_save(ai);
                    }
                    else
                    {
                        oAppointments.Remove(ai);
                    }
                } catch (System.Exception ex) {
                    MainForm.Instance.Logboxout("WARNING: Deleted appointment failed to remove.\r\n" + ex.Message);
                    log.Error(ex.StackTrace);
                    if (MessageBox.Show("Deleted Outlook appointment failed to remove. Continue with synchronisation?", "Sync item failed", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
                    {
                        continue;
                    }
                    else
                    {
                        throw new UserCancelledSyncException("User chose not to continue sync.");
                    }
                } finally {
                    ai = (AppointmentItem)ReleaseObject(ai);
                }
            }
        }
Ejemplo n.º 3
0
        private void processOutlookExceptions(AppointmentItem ai, Event ev, Boolean forceCompare)
        {
            if (!HasExceptions(ev, checkLocalCacheOnly: true))
            {
                return;
            }

            if (!ai.Saved)
            {
                ai.Save();
            }

            RecurrencePattern oPattern = ai.GetRecurrencePattern();

            foreach (Event gExcp in Recurrence.Instance.googleExceptions.Where(exp => exp.RecurringEventId == ev.Id))
            {
                log.Fine("Found Google exception for " + (gExcp.OriginalStartTime.DateTime ?? gExcp.OriginalStartTime.Date));

                DateTime        oExcpDate = DateTime.Parse(gExcp.OriginalStartTime.DateTime ?? gExcp.OriginalStartTime.Date);
                AppointmentItem newAiExcp = getOutlookInstance(oPattern, oExcpDate);
                if (newAiExcp == null)
                {
                    continue;
                }

                if (gExcp.Status != "cancelled")
                {
                    int itemModified = 0;
                    newAiExcp = OutlookCalendar.Instance.UpdateCalendarEntry(newAiExcp, gExcp, ref itemModified, forceCompare);
                    if (itemModified > 0)
                    {
                        newAiExcp.Save();
                    }
                }
                else
                {
                    MainForm.Instance.Logboxout(OutlookCalendar.GetEventSummary(ai) + "\r\nDeleted.");
                    newAiExcp.Delete();
                }
                newAiExcp = (AppointmentItem)OutlookCalendar.ReleaseObject(newAiExcp);
            }
            if (!ai.Saved)
            {
                ai.Save();
            }
            oPattern = (RecurrencePattern)OutlookCalendar.ReleaseObject(oPattern);
        }
Ejemplo n.º 4
0
        public Event GetGoogleMasterEvent(AppointmentItem ai)
        {
            log.Fine("Found a master Outlook recurring item outside sync date range: " + OutlookCalendar.GetEventSummary(ai));
            List <Event> events = new List <Event>();

            if (ai.UserProperties[OutlookCalendar.gEventID] == null)
            {
                events = GoogleCalendar.Instance.GetCalendarEntriesInRange(ai.Start.Date, ai.Start.Date.AddDays(1));
                List <AppointmentItem> ais = new List <AppointmentItem>();
                ais.Add(ai);
                GoogleCalendar.Instance.ReclaimOrphanCalendarEntries(ref events, ref ais, neverDelete: true);
            }
            else
            {
                Event ev = GoogleCalendar.Instance.GetCalendarEntry(ai.UserProperties[OutlookCalendar.gEventID].Value.ToString());
                if (ev != null)
                {
                    events.Add(ev);
                }
            }
            for (int g = 0; g < events.Count(); g++)
            {
                String gEntryID;
                Event  ev = events[g];
                if (GoogleCalendar.GetOGCSproperty(ev, GoogleCalendar.oEntryID, out gEntryID))
                {
                    if (gEntryID == ai.EntryID)
                    {
                        log.Info("Migrating Master Event from EntryID to GlobalAppointmentID...");
                        GoogleCalendar.AddOutlookID(ref ev, ai);
                        GoogleCalendar.Instance.UpdateCalendarEntry_save(ref ev);
                        return(ev);
                    }
                    else if (gEntryID == OutlookCalendar.Instance.IOutlook.GetGlobalApptID(ai))
                    {
                        log.Fine("Found master event.");
                        return(ev);
                    }
                }
            }
            log.Warn("Failed to find master Google event for: " + OutlookCalendar.GetEventSummary(ai));
            return(null);
        }
Ejemplo n.º 5
0
        public static void UpdateGoogleExceptions(AppointmentItem ai, Event ev)
        {
            if (ai.IsRecurring)
            {
                RecurrencePattern recurrence = ai.GetRecurrencePattern();
                try {
                    if (recurrence.Exceptions.Count > 0)
                    {
                        log.Debug(OutlookCalendar.GetEventSummary(ai));
                        log.Debug("This is a recurring appointment with " + recurrence.Exceptions.Count + " exceptions that will now be iteratively compared.");
                        foreach (Microsoft.Office.Interop.Outlook.Exception oExcp in recurrence.Exceptions)
                        {
                            int excp_itemModified = 0;

                            //Check the exception falls in the date range being synced
                            Boolean  oIsDeleted     = exceptionIsDeleted(oExcp);
                            String   logDeleted     = oIsDeleted ? " deleted and" : "";
                            DateTime oExcp_currDate = oIsDeleted ? oExcp.OriginalDate : oExcp.AppointmentItem.Start;
                            if (oExcp_currDate < Settings.Instance.SyncStart.Date || oExcp_currDate > Settings.Instance.SyncEnd.Date)
                            {
                                log.Fine("Exception is" + logDeleted + " outside date range being synced: " + oExcp_currDate.Date.ToString("dd/MM/yyyy"));
                                continue;
                            }

                            Event gExcp = Recurrence.Instance.GetGoogleInstance(oExcp, ev.RecurringEventId ?? ev.Id, OutlookCalendar.Instance.IOutlook.GetGlobalApptID(ai));
                            if (gExcp != null)
                            {
                                log.Debug("Matching Google Event recurrence found.");
                                if (gExcp.Status == "cancelled")
                                {
                                    log.Debug("It is deleted in Google, so cannot compare items.");
                                    if (!oIsDeleted)
                                    {
                                        log.Warn("Outlook is NOT deleted though - a mismatch has occurred somehow");
                                    }
                                    continue;
                                }
                                try {
                                    GoogleCalendar.Instance.UpdateCalendarEntry(oExcp.AppointmentItem, gExcp, ref excp_itemModified);
                                } catch (System.Exception ex) {
                                    if (oIsDeleted)
                                    {
                                        if (gExcp.Status != "cancelled")
                                        {
                                            gExcp.Status = "cancelled";
                                            excp_itemModified++;
                                        }
                                    }
                                    else
                                    {
                                        log.Error(ex.Message);
                                        log.Error(ex.StackTrace);
                                        throw ex;
                                    }
                                }
                                if (excp_itemModified > 0)
                                {
                                    try {
                                        GoogleCalendar.Instance.UpdateCalendarEntry_save(ref gExcp);
                                    } catch (System.Exception ex) {
                                        MainForm.Instance.Logboxout("WARNING: Updated event exception failed to save.\r\n" + ex.Message);
                                        log.Error(ex.StackTrace);
                                        if (MessageBox.Show("Updated Google event exception failed to save. Continue with synchronisation?", "Sync item failed", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
                                        {
                                            continue;
                                        }
                                        else
                                        {
                                            throw new UserCancelledSyncException("User chose not to continue sync.");
                                        }
                                    }
                                }
                            }
                            else
                            {
                                log.Debug("No matching Google Event recurrence found.");
                                if (oIsDeleted)
                                {
                                    log.Debug("The Outlook appointment is deleted, so not a problem.");
                                }
                            }
                        }
                    }
                } finally {
                    recurrence = (RecurrencePattern)OutlookCalendar.ReleaseObject(recurrence);
                }
            }
        }
Ejemplo n.º 6
0
        public Event GetGoogleMasterEvent(AppointmentItem ai)
        {
            log.Fine("Found a master Outlook recurring item outside sync date range: " + OutlookCalendar.GetEventSummary(ai));
            List <Event> events = new List <Event>();
            String       googleIdValue;
            Boolean      haveMatchingEv = false;

            if (OutlookCalendar.GetOGCSproperty(ai, OutlookCalendar.MetadataId.gEventID, out googleIdValue))
            {
                Event ev = GoogleCalendar.Instance.GetCalendarEntry(googleIdValue);
                if (ev != null)
                {
                    events.Add(ev);
                    haveMatchingEv = true;
                    log.Fine("Found single hard-matched Event.");
                }
            }
            if (!haveMatchingEv)
            {
                events = GoogleCalendar.Instance.GetCalendarEntriesInRange(ai.Start.Date, ai.Start.Date.AddDays(1));
                List <AppointmentItem> ais = new List <AppointmentItem>();
                ais.Add(ai);
                GoogleCalendar.Instance.ReclaimOrphanCalendarEntries(ref events, ref ais, neverDelete: true);
            }
            for (int g = 0; g < events.Count(); g++)
            {
                String gEntryID = null;
                Event  ev       = events[g];
                if (haveMatchingEv || GoogleCalendar.GetOGCSproperty(ev, GoogleCalendar.MetadataId.oEntryId, out gEntryID))
                {
                    if (GoogleCalendar.OutlookIdMissing(ev))
                    {
                        String compare_oID;
                        if (gEntryID != null && gEntryID.StartsWith("040000008200E00074C5B7101A82E008"))   //We got a Global ID, not Entry ID
                        {
                            compare_oID = OutlookCalendar.Instance.IOutlook.GetGlobalApptID(ai);
                        }
                        else
                        {
                            compare_oID = ai.EntryID;
                        }
                        if (haveMatchingEv || gEntryID == compare_oID)
                        {
                            log.Info("Adding Outlook IDs to Master Google Event...");
                            GoogleCalendar.AddOutlookIDs(ref ev, ai);
                            try {
                                GoogleCalendar.Instance.UpdateCalendarEntry_save(ref ev);
                            } catch (System.Exception ex) {
                                log.Error("Failed saving Outlook IDs to Google Event.");
                                OGCSexception.Analyse(ex, true);
                            }
                            return(ev);
                        }
                    }
                    else if (GoogleCalendar.ItemIDsMatch(ref ev, ai))
                    {
                        log.Fine("Found master event.");
                        return(ev);
                    }
                }
                else
                {
                    log.Debug("Event \"" + ev.Summary + "\" did not have Outlook EntryID stored.");
                }
            }
            log.Warn("Failed to find master Google event for: " + OutlookCalendar.GetEventSummary(ai));
            return(null);
        }