示例#1
0
        //internal static bool Equals(ExtensionCollection<Who> googleAttendees, vbMAPI_Recipients outlookAttendees)
        //{
        //    /// if Google item has recipients and their quantity is different than Outlook's one there is no reason to compare them
        //    if ((googleAttendees.Count > 1) && (googleAttendees.Count != outlookAttendees.Count))
        //        return false;
        //    /// if Outlook item has no recipients (we verified above Google item hasn't) return true immediately
        //    if (outlookAttendees.Count == 0)
        //        return true;

        //    foreach (vbMAPI_Recipient outlookAttendee in outlookAttendees)
        //    {
        //        try
        //        {
        //            if ((outlookAttendee.AddressEntry.Address == "Unknown") || (outlookAttendee.RecipientType == EnumRecipientType.Recipient_TO))
        //                continue;
        //            var equal = false;
        //            foreach (var googleAttendee in googleAttendees)
        //            {
        //                if (Equals(googleAttendee, outlookAttendee))
        //                {
        //                    equal = true;
        //                    break;
        //                }
        //            }
        //            if (!equal)
        //                return false;
        //        }
        //        finally
        //        {
        //            Marshal.ReleaseComObject(outlookAttendee);
        //        }
        //    }
        //    return true;
        //}

        private static bool Equals(EventAttendee googleRecipient, Outlook.Recipient outlookRecipient)
        {
            return
                (googleRecipient.Email.Equals(outlookRecipient.Address, System.StringComparison.InvariantCultureIgnoreCase) &&
                 (
                     (googleRecipient.Organizer.HasValue && googleRecipient.Organizer.Value && (Outlook.OlMeetingRecipientType)outlookRecipient.Type == Outlook.OlMeetingRecipientType.olOrganizer) ||
                     (googleRecipient.Optional.HasValue && googleRecipient.Optional.Value && (Outlook.OlMeetingRecipientType)outlookRecipient.Type == Outlook.OlMeetingRecipientType.olOptional) ||
                     (googleRecipient.Resource.HasValue && googleRecipient.Resource.Value && (Outlook.OlMeetingRecipientType)outlookRecipient.Type == Outlook.OlMeetingRecipientType.olResource) ||
                     ((Outlook.OlMeetingRecipientType)outlookRecipient.Type == Outlook.OlMeetingRecipientType.olRequired)
                 ) &&
                 (googleRecipient.ResponseStatus == ConvertTo.GoogleResponseStatus(outlookRecipient.MeetingResponseStatus)));
        }
示例#2
0
        private void SetAttendees(Event googleItem, object outlookItem, Target target)
        {
            if (target == Target.Google)
            {
                if (googleItem.Attendees == null)
                {
                    googleItem.Attendees = new List <EventAttendee>();
                }
                foreach (Outlook.Recipient outlookRecipient in ((Outlook.AppointmentItem)outlookItem).Recipients)
                {
                    try
                    {
#if DEBUG
                        Logger.Log(string.Format("Adding attendee {0} to Google event", outlookRecipient.Address), EventType.Debug);
#endif
                        /// Organizator is omited
                        if (((Outlook.OlMeetingRecipientType)outlookRecipient.Type == Outlook.OlMeetingRecipientType.olOrganizer) ||
                            (outlookRecipient.Address == null) ||
                            !Utilities.SMTPAddressPattern.IsMatch(outlookRecipient.Address))
                        {
#if DEBUG
                            Logger.Log(string.Format("{0} is a meeting organizer or it's not valid SMTP address, so it won't be added", outlookRecipient.Address),
                                       EventType.Debug);
#endif
                            continue;
                        }
                        var googleRecipient = googleItem.Attendees.FirstOrDefault(recipient => recipient.Email == outlookRecipient.Address);
                        if (googleRecipient == null)
                        {
                            googleRecipient = new EventAttendee
                            {
                                Email = outlookRecipient.Address
                            };
                            googleItem.Attendees.Add(googleRecipient);
                        }
                        else if (AttendeeComparer.Equals(googleRecipient, outlookRecipient))
                        {
                            continue;
                        }
                        googleRecipient = ConvertTo.GoogleRecipientType(googleRecipient, (Outlook.OlMeetingRecipientType)outlookRecipient.Type);
                        googleRecipient.ResponseStatus = ConvertTo.GoogleResponseStatus(outlookRecipient.MeetingResponseStatus);
                    }
                    finally
                    {
                        Marshal.ReleaseComObject(outlookRecipient);
                    }
                }
            }
            else
            {
                if (googleItem.Attendees != null)
                {
                    foreach (var googleRecipient in googleItem.Attendees)
                    {
                        /// Organizator and not valid SMTP addresses are omited
                        if (googleRecipient.Organizer.HasValue && googleRecipient.Organizer.Value ||
                            !Utilities.SMTPAddressPattern.IsMatch(googleRecipient.Email))
                        {
                            continue;
                        }
                        var matchIsFound = false;
                        foreach (Outlook.Recipient outlookRecipient in ((Outlook.AppointmentItem)outlookItem).Recipients)
                        {
                            if (googleRecipient.Email == outlookRecipient.Address)
                            {
                                matchIsFound = true;
                                Marshal.ReleaseComObject(outlookRecipient);
                                break;
                            }
                            Marshal.ReleaseComObject(outlookRecipient);
                        }
                        if (!matchIsFound)
                        {
                            Outlook.Recipient outlookRecipient = ((Outlook.AppointmentItem)outlookItem).Recipients.Add(googleRecipient.Email);
                            outlookRecipient.Type = (int)ConvertTo.OutlookRecipientType(googleRecipient);
                            Marshal.ReleaseComObject(outlookRecipient);
                        }
                    }
                }
            }
        }