示例#1
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);
        }