Exemplo n.º 1
0
        /// <summary>
        /// </summary>
        /// <param name="appointment"></param>
        /// <param name="otherAppointment"></param>
        /// <param name="addAttendeesToDescription"></param>
        /// <returns>
        /// </returns>
        public static bool CompareDescription(this Appointment appointment, Appointment otherAppointment,
            bool addAttendeesToDescription)
        {
            if (String.IsNullOrEmpty(appointment.Description) && String.IsNullOrEmpty(otherAppointment.Description))
            {
                return true;
            }

            var description = ParseDescription(appointment);
            var otherDescription = ParseDescription(otherAppointment);
            if (description.Equals(otherDescription))
            {
                return true;
            }

            if (description.Length > 8000 && description.Length > otherDescription.Length)
            {
                if (description.Contains(otherDescription))
                {
                    return true;
                }
            }

            if (otherDescription.Length > 8000 && otherDescription.Length > description.Length)
            {
                if (otherDescription.Contains(description))
                {
                    return true;
                }
            }

            return false;
        }
 public static void AddCompareForUpdate(this List<Appointment> updateList, Appointment appointment)
 {
     if (!updateList.Exists(t => t.Equals(appointment)))
     {
         updateList.Add(appointment);
     }
 }
Exemplo n.º 3
0
 public static bool CompareSourceId(this Appointment calendarAppointment, Appointment otherAppointment)
 {
     if (otherAppointment.SourceId == null)
     {
         return false;
     }
     return calendarAppointment.AppointmentId.Equals(otherAppointment.SourceId);
 }
Exemplo n.º 4
0
        public async Task <AppointmentsWrapper> GetCalendarEventsInRangeAsync(DateTime startDate, DateTime endDate,
                                                                              bool skipPrivateEntries,
                                                                              IDictionary <string, object> calendarSpecificData)
        {
            CheckCalendarSpecificData(calendarSpecificData);


            var service = GetExchangeService(ExchangeServerSettings);

            var calendarview = new CalendarView(startDate, endDate);

            // Get Default Calendar
            var outlookAppointments  = new AppointmentsWrapper();
            var exchangeAppointments = service.FindAppointments(_ewsCalendar.EntryId,
                                                                calendarview);


            service.LoadPropertiesForItems(
                from Item item in exchangeAppointments select item,
                new PropertySet(BasePropertySet.FirstClassProperties)
            {
                RequestedBodyType = BodyType.Text
            });

            if (exchangeAppointments != null)
            {
                foreach (var exchangeAppointment in exchangeAppointments)
                {
                    var appointment = new Appointment(exchangeAppointment.Body, exchangeAppointment.Location,
                                                      exchangeAppointment.Subject, exchangeAppointment.Start, exchangeAppointment.Start)
                    {
                        AppointmentId              = exchangeAppointment.Id.UniqueId,
                        AllDayEvent                = exchangeAppointment.IsAllDayEvent,
                        OptionalAttendees          = GetAttendees(exchangeAppointment.OptionalAttendees),
                        ReminderMinutesBeforeStart = exchangeAppointment.ReminderMinutesBeforeStart,
                        Organizer =
                            new Attendee
                        {
                            Name  = exchangeAppointment.Organizer.Name,
                            Email = exchangeAppointment.Organizer.Address
                        },
                        ReminderSet       = exchangeAppointment.IsReminderSet,
                        RequiredAttendees = GetAttendees(exchangeAppointment.RequiredAttendees)
                    };
                    outlookAppointments.Add(appointment);
                }
            }
            return(outlookAppointments);
        }
        public static bool CopyDetail(this Appointment appointment, Appointment otherAppointment,
            CalendarEntryOptionsEnum calendarEntryOptions)
        {
            //Copy basic information
            appointment.OldStartTime = appointment.StartTime;
            appointment.StartTime = otherAppointment.StartTime;
            appointment.EndTime = otherAppointment.EndTime;
            appointment.Subject = otherAppointment.Subject;
            appointment.AllDayEvent = otherAppointment.AllDayEvent;
            appointment.Location = otherAppointment.Location;
            appointment.IsRecurring = otherAppointment.IsRecurring;

            //Copy status
            appointment.BusyStatus = otherAppointment.BusyStatus;
            appointment.Privacy = otherAppointment.Privacy;
            appointment.MeetingStatus = otherAppointment.MeetingStatus;

            if (calendarEntryOptions.HasFlag(CalendarEntryOptionsEnum.Description))
            {
                appointment.Description = otherAppointment.ParseDescription();
            }

            if (calendarEntryOptions.HasFlag(CalendarEntryOptionsEnum.Attendees)
                && !calendarEntryOptions.HasFlag(CalendarEntryOptionsEnum.AttendeesToDescription))
            {
                appointment.RequiredAttendees = otherAppointment.RequiredAttendees.Select(t => t).ToList();
                appointment.OptionalAttendees = otherAppointment.OptionalAttendees.Select(t => t).ToList();
                appointment.Organizer = otherAppointment.Organizer;
            }

            if (calendarEntryOptions.HasFlag(CalendarEntryOptionsEnum.Reminders))
            {
                appointment.ReminderSet = otherAppointment.ReminderSet;
                appointment.ReminderMinutesBeforeStart = otherAppointment.ReminderMinutesBeforeStart;
            }

            return true;
        }
Exemplo n.º 6
0
        private Appointment CreateAppointment(Event googleEvent)
        {
            Appointment appointment;

            if (googleEvent.Start.DateTime == null && googleEvent.End.DateTime == null)
            {
                appointment = new Appointment(googleEvent.Description, googleEvent.Location, googleEvent.Summary,
                    DateTime.Parse(googleEvent.End.Date),
                    DateTime.Parse(googleEvent.Start.Date), googleEvent.Id) { AllDayEvent = true };
            }
            else
            {
                appointment = new Appointment(googleEvent.Description, googleEvent.Location, googleEvent.Summary,
                    googleEvent.End.DateTime,
                    googleEvent.Start.DateTime, googleEvent.Id);
            }

            if (googleEvent.Reminders != null)
            {
                if (!googleEvent.Reminders.UseDefault.GetValueOrDefault() && googleEvent.Reminders.Overrides != null)
                {
                    appointment.ReminderSet = true;
                    appointment.ReminderMinutesBeforeStart =
                        googleEvent.Reminders.Overrides.First().Minutes.GetValueOrDefault();
                }
            }


            appointment.CalendarId = CalendarId;
            if (googleEvent.ExtendedProperties != null && googleEvent.ExtendedProperties.Private__ != null)
            {
                foreach (var property in googleEvent.ExtendedProperties.Private__)
                {
                    appointment.ExtendedProperties.Add(property.Key, property.Value);
                }
            }
            
            appointment.Created = googleEvent.Created;
            appointment.LastModified = googleEvent.Updated;

            if (googleEvent.Organizer != null)
            {
                //Add Organizer
                appointment.Organizer = new Attendee
                {
                    Name = googleEvent.Organizer.DisplayName,
                    Email = googleEvent.Organizer.Email
                };
            }

            //Add Required Attendee
            GetAttendees(googleEvent, appointment.RequiredAttendees, false);

            //Add optional Attendee
            GetAttendees(googleEvent, appointment.OptionalAttendees, true);


            return appointment;
        }
Exemplo n.º 7
0
        private Event CreateGoogleCalendarEvent(Appointment calendarAppointment, bool addDescription, bool addReminder,
            bool addAttendees, bool attendeesToDescription)
        {
            //Create Event
            var googleEvent = new Event
            {
                Start = new EventDateTime(),
                End = new EventDateTime(),
                Summary = calendarAppointment.Subject,
                Description = calendarAppointment.GetDescriptionData(addDescription, attendeesToDescription),
                Location = calendarAppointment.Location,
                Visibility = calendarAppointment.Privacy,
                Transparency = (calendarAppointment.BusyStatus == BusyStatusEnum.Free) ? "transparent" : "opaque",
                //Need to make recurring appointment IDs unique - append the item's date   
                ExtendedProperties =
                    new Event.ExtendedPropertiesData
                    {
                        Private__ = 
                            new Dictionary<string, string>
                            {
                                {calendarAppointment.GetSourceEntryKey(), calendarAppointment.AppointmentId}
                            }
                    }
            };

            if (EventCategory != null && !string.IsNullOrEmpty(EventCategory.ColorNumber))
            {
                googleEvent.ColorId = EventCategory.ColorNumber;
            }
            //Add Start/End Time
            if (calendarAppointment.AllDayEvent)
            {
                if (calendarAppointment.StartTime.HasValue)
                {
                    googleEvent.Start.Date = calendarAppointment.StartTime.Value.ToString("yyyy-MM-dd");
                }
                if (calendarAppointment.EndTime.HasValue)
                {
                    googleEvent.End.Date = calendarAppointment.EndTime.Value.ToString("yyyy-MM-dd");
                }
            }
            else
            {
                googleEvent.Start.DateTimeRaw = calendarAppointment.Rfc339FormatStartTime;
                googleEvent.End.DateTimeRaw = calendarAppointment.Rfc339FormatEndTime;
            }

            //Add Reminder
            if (addReminder && calendarAppointment.ReminderSet)
            {
                googleEvent.Reminders = new Event.RemindersData
                {
                    UseDefault = false,
                    Overrides = new List<EventReminder>
                    {
                        new EventReminder
                        {
                            Method = "popup",
                            Minutes = calendarAppointment.ReminderMinutesBeforeStart
                        }
                    }
                };
            }

            if (googleEvent.Attendees == null)
            {
                googleEvent.Attendees = new List<EventAttendee>();
            }

            if (addAttendees && !attendeesToDescription)
            {
                //Add Required Attendees
                AddEventAttendees(calendarAppointment.RequiredAttendees, googleEvent, false);

                //Add optional Attendees
                AddEventAttendees(calendarAppointment.OptionalAttendees, googleEvent, true);
            }
            //Add Organizer
            if (calendarAppointment.Organizer != null && calendarAppointment.Organizer.Email.IsValidEmailAddress())
            {
                googleEvent.Organizer = new Event.OrganizerData
                {
                    DisplayName = calendarAppointment.Organizer.Name,
                    Email = calendarAppointment.Organizer.Email
                };
            }

            return googleEvent;
        }
Exemplo n.º 8
0
 public object Clone()
 {
     var appointment = new Appointment(Description, Location, Subject, EndTime, StartTime, AppointmentId);
     appointment.Organizer = Organizer;
     appointment.RequiredAttendees = RequiredAttendees;
     appointment.OptionalAttendees = OptionalAttendees;
     appointment.Created = Created;
     appointment.LastModified = LastModified;
     appointment.CalendarId = CalendarId;
     appointment.ExtendedProperties = ExtendedProperties;
     appointment.AllDayEvent = AllDayEvent;
     return appointment;
 }
        /// <summary>
        /// </summary>
        /// <param name="appointmentItem"></param>
        /// <param name="app"></param>
        private void GetRecipients(AppointmentItem appointmentItem, Appointment app)
        {
            foreach (Recipient attendee in appointmentItem.Recipients)
            {
                var recipient = new Attendee();
                string name, email;
                if (attendee.GetEmailFromName(out name, out email))
                {
                    recipient.Name = name;
                    recipient.Email = email;
                }
                else
                {
                    recipient.Name = attendee.Name;
                    recipient.Email = GetSMTPAddressForRecipients(attendee);
                }
                recipient.MeetingResponseStatus = attendee.GetMeetingResponseStatus();

                if (appointmentItem.RequiredAttendees != null &&
                    appointmentItem.RequiredAttendees.Contains(recipient.Name))
                {
                    if (!app.RequiredAttendees.Any(reci => reci.Email.Equals(recipient.Email)))
                    {
                        app.RequiredAttendees.Add(recipient);
                    }
                }

                if (appointmentItem.OptionalAttendees != null &&
                    appointmentItem.OptionalAttendees.Contains(recipient.Name))
                {
                    if (!app.OptionalAttendees.Any(reci => reci.Email.Equals(recipient.Email)))
                    {
                        app.OptionalAttendees.Add(recipient);
                    }
                }

                if (appointmentItem.Organizer != null &&
                    appointmentItem.Organizer.Contains(recipient.Name))
                {
                    app.Organizer = recipient;
                }
            }
        }
 private void GetExtendedProperties(AppointmentItem appointmentItem, Appointment app)
 {
     app.ExtendedProperties = new Dictionary<string, string>();
     var userProperties = appointmentItem.UserProperties;
     try
     {
         if (userProperties != null)
         {
             foreach (UserProperty userProperty in userProperties)
             {
                 if (userProperty != null && !app.ExtendedProperties.ContainsKey(userProperty.Name)
                     && userProperty.Value != null)
                 {
                     app.ExtendedProperties.Add(userProperty.Name,
                         userProperty.Value.ToString());
                 }
             }
         }
     }
     catch (Exception exception)
     {
         Logger.Error(exception);
     }
     finally
     {
         if (userProperties != null)
         {
             Marshal.FinalReleaseComObject(userProperties);
         }
     }
 }
        /// <summary>
        /// </summary>
        /// <param name="id"></param>
        /// <param name="appointmentItem"></param>
        /// <returns>
        /// </returns>
        private Appointment GetAppointmentFromItem(string id, AppointmentItem appointmentItem)
        {
            var app = new Appointment(appointmentItem.Body, appointmentItem.Location,
                appointmentItem.Subject, appointmentItem.End, appointmentItem.Start)
            {
                AllDayEvent = appointmentItem.AllDayEvent,
                ReminderMinutesBeforeStart = appointmentItem.ReminderMinutesBeforeStart,
                ReminderSet = appointmentItem.ReminderSet,
                IsRecurring = appointmentItem.IsRecurring,
                AppointmentId = appointmentItem.IsRecurring
                    ? $"{appointmentItem.EntryID}_{appointmentItem.Start.ToString("yy-MM-dd")}"
                    : appointmentItem.EntryID,
                Privacy = appointmentItem.GetAppointmentSensitivity(),
                MeetingStatus = appointmentItem.GetMeetingStatus()
            };

            GetRecipients(appointmentItem, app);

            app.Created = appointmentItem.CreationTime;
            app.LastModified = appointmentItem.LastModificationTime;
            app.SetBusyStatus(appointmentItem.BusyStatus);

            GetExtendedProperties(appointmentItem, app);
            app.CalendarId = id;
            return app;
        }
        private bool UpdateAppointment(bool addDescription, bool addReminder, bool addAttendees,
            bool attendeesToDescription, AppointmentItem appItem,
            Appointment calendarAppointment)
        {
            Recipients recipients = null;
            UserProperties userProperties = null;
            try
            {
                appItem.Subject = calendarAppointment.Subject;
                appItem.Location = calendarAppointment.Location;
                appItem.BusyStatus = calendarAppointment.GetOutlookBusyStatus();
                
                if (EventCategory != null)
                {
                    appItem.Categories = EventCategory.CategoryName;
                }

                if (calendarAppointment.AllDayEvent != appItem.AllDayEvent)
                {
                    appItem.AllDayEvent = calendarAppointment.AllDayEvent;
                }

                appItem.Sensitivity = calendarAppointment.GetAppointmentSensitivity();
                appItem.Start = calendarAppointment.StartTime.GetValueOrDefault();
                appItem.End = calendarAppointment.EndTime.GetValueOrDefault();
                if (addDescription)
                {
                    appItem.Body = calendarAppointment.Description;
                }

                if (addAttendees && !attendeesToDescription)
                {
                    recipients = appItem.Recipients;
                    if (calendarAppointment.RequiredAttendees != null)
                    {
                        calendarAppointment.RequiredAttendees.ForEach(rcptName =>
                        {
                            if (!CheckIfRecipientExists(recipients, rcptName))
                            {
                                var recipient =
                                    appItem.Recipients.Add($"{rcptName.Name}<{rcptName.Email}>");
                                recipient.Type = (int) OlMeetingRecipientType.olRequired;
                                recipient.Resolve();
                            }
                        });
                    }

                    if (calendarAppointment.OptionalAttendees != null)
                    {
                        calendarAppointment.OptionalAttendees.ForEach(rcptName =>
                        {
                            if (!CheckIfRecipientExists(recipients, rcptName))
                            {
                                var recipient =
                                    appItem.Recipients.Add($"{rcptName.Name}<{rcptName.Email}>");
                                recipient.Type = (int) OlMeetingRecipientType.olOptional;
                                recipient.Resolve();
                            }
                        });
                    }
                }
                

                if (addReminder)
                {
                    if (appItem.ReminderSet != calendarAppointment.ReminderSet)
                    {
                        appItem.ReminderMinutesBeforeStart = calendarAppointment.ReminderMinutesBeforeStart;
                        if (calendarAppointment.ReminderSet &&
                            appItem.ReminderMinutesBeforeStart != calendarAppointment.ReminderMinutesBeforeStart)
                        {
                            appItem.ReminderMinutesBeforeStart = calendarAppointment.ReminderMinutesBeforeStart;
                        }
                    }
                }

                userProperties = appItem.UserProperties;
                if (userProperties != null)
                {
                    for (var i = 0; i < userProperties.Count; i++)
                    {
                        userProperties.Remove(i + 1);
                    }

                    foreach (var extendedProperty in calendarAppointment.ExtendedProperties)
                    {
                        var sourceProperty = userProperties.Add(extendedProperty.Key,
                            OlUserPropertyType.olText);
                        sourceProperty.Value = extendedProperty.Value;
                    }
                }

                appItem.Save();
            }
            catch (Exception exception)
            {
                Logger.Error(exception);
                return false;
            }
            finally
            {
                if (recipients != null)
                {
                    Marshal.FinalReleaseComObject(recipients);
                }
                if (userProperties != null)
                {
                    Marshal.FinalReleaseComObject(userProperties);
                }
                if (appItem != null)
                {
                    Marshal.FinalReleaseComObject(appItem);
                }
            }
            return true;
        }
        /// <summary>
        /// </summary>
        /// <param name="addDescription"></param>
        /// <param name="addReminder"></param>
        /// <param name="addAttendees"></param>
        /// <param name="attendeesToDescription"></param>
        /// <param name="appItem"></param>
        /// <param name="calendarAppointment"></param>
        private Appointment AddAppointment(bool addDescription, bool addReminder, bool addAttendees,
            bool attendeesToDescription, AppointmentItem appItem,
            Appointment calendarAppointment, string id)
        {
            Recipients recipients = null;
            UserProperties userProperties = null;
            Appointment createdAppointment = null;
            try
            {
                appItem.Subject = calendarAppointment.Subject;
                if (!calendarAppointment.RequiredAttendees.Any() && !calendarAppointment.OptionalAttendees.Any()
                    && AddAsAppointments)
                {
                    appItem.MeetingStatus = OlMeetingStatus.olNonMeeting;
                }
                else
                {
                    appItem.MeetingStatus = OlMeetingStatus.olMeeting;
                }
                appItem.Sensitivity = calendarAppointment.GetAppointmentSensitivity();
                appItem.Location = calendarAppointment.Location;
                appItem.BusyStatus = calendarAppointment.GetOutlookBusyStatus();
                recipients = appItem.Recipients;
                if (EventCategory != null)
                {
                    appItem.Categories = EventCategory.CategoryName;
                }

                if (calendarAppointment.AllDayEvent)
                {
                    appItem.AllDayEvent = true;
                }

                appItem.Start = calendarAppointment.StartTime.GetValueOrDefault();
                appItem.End = calendarAppointment.EndTime.GetValueOrDefault();


                appItem.Body = calendarAppointment.GetDescriptionData(addDescription, attendeesToDescription);
                
                Recipient organizer = null;
                if (addAttendees && !attendeesToDescription)
                {
                    calendarAppointment.RequiredAttendees?.ForEach(rcptName =>
                    {
                        var recipient =
                            appItem.Recipients.Add($"{rcptName.Name}<{rcptName.Email}>");
                        if (SetOrganizer && calendarAppointment.Organizer != null &&
                            rcptName.Name.Equals(calendarAppointment.Organizer.Name))
                        {
                            recipient.Type = (int) OlMeetingRecipientType.olOrganizer;
                            recipient.Resolve();
                            organizer = recipient;
                        }
                        else
                        {
                            recipient.Type = (int) OlMeetingRecipientType.olRequired;
                            recipient.Resolve();
                        }
                    });

                    calendarAppointment.OptionalAttendees?.ForEach(rcptName =>
                    {
                        var recipient =
                            appItem.Recipients.Add($"{rcptName.Name}<{rcptName.Email}>");
                        if (SetOrganizer && calendarAppointment.Organizer != null &&
                            rcptName.Name.Equals(calendarAppointment.Organizer.Name))
                        {
                            recipient.Type = (int) OlMeetingRecipientType.olOrganizer;
                            recipient.Resolve();
                            organizer = recipient;
                        }
                        else
                        {
                            recipient.Type = (int)OlMeetingRecipientType.olOptional;
                            recipient.Resolve();
                        }
                    });
                }
                else if (SetOrganizer && calendarAppointment.Organizer != null)
                {
                    var recipient =
                                appItem.Recipients.Add(
                                    $"{calendarAppointment.Organizer.Name}<{calendarAppointment.Organizer.Email}>");
                    recipient.Type = (int)OlMeetingRecipientType.olOrganizer;
                    recipient.Resolve();
                    organizer = recipient;
                }

                SetAppointmentOrganizer(appItem, organizer);

                if (addReminder)
                {
                    appItem.ReminderMinutesBeforeStart = calendarAppointment.ReminderMinutesBeforeStart;
                    appItem.ReminderSet = calendarAppointment.ReminderSet;
                }

                userProperties = appItem.UserProperties;
                if (userProperties != null)
                {
                    var sourceProperty = userProperties.Add(calendarAppointment.GetSourceEntryKey(),
                        OlUserPropertyType.olText);
                    sourceProperty.Value = calendarAppointment.AppointmentId;
                }
                appItem.Save();

                createdAppointment = GetAppointmentFromItem(id, appItem);
            }
            catch (Exception exception)
            {
                Logger.Error(exception);
            }
            finally
            {
                if (userProperties != null)
                {
                    Marshal.FinalReleaseComObject(userProperties);
                }
                if (recipients != null)
                {
                    Marshal.FinalReleaseComObject(recipients);
                }
                if (appItem != null)
                {
                    Marshal.FinalReleaseComObject(appItem);
                }
            }
            return createdAppointment;
        }
        private bool UpdateAppointment(bool addDescription, bool addReminder, bool addAttendees,
            bool attendeesToDescription, AppointmentItem appItem,
            Appointment calendarAppointment)
        {
            Recipients recipients = null;
            UserProperties userProperties = null;
            try
            {
                appItem.Subject = calendarAppointment.Subject;
                if (!calendarAppointment.RequiredAttendees.Any() && !calendarAppointment.OptionalAttendees.Any()
                    && AddAsAppointments)
                {
                    appItem.MeetingStatus = OlMeetingStatus.olNonMeeting;
                }
                else
                {
                    appItem.MeetingStatus = OlMeetingStatus.olMeeting;
                }

                appItem.Location = calendarAppointment.Location;
                appItem.BusyStatus = calendarAppointment.GetOutlookBusyStatus();
                recipients = appItem.Recipients;
                if (EventCategory != null)
                {
                    appItem.Categories = EventCategory.CategoryName;
                }

                if (calendarAppointment.AllDayEvent)
                {
                    appItem.AllDayEvent = true;
                }

                appItem.Start = calendarAppointment.StartTime.GetValueOrDefault();
                appItem.End = calendarAppointment.EndTime.GetValueOrDefault();
                appItem.Body = calendarAppointment.GetDescriptionData(addDescription, attendeesToDescription);

                if (addAttendees && !attendeesToDescription)
                {
                    if (calendarAppointment.RequiredAttendees != null)
                    {
                        calendarAppointment.RequiredAttendees.ForEach(rcptName =>
                        {
                            var recipient =
                                appItem.Recipients.Add(string.Format("{0}<{1}>", rcptName.Name, rcptName.Email));
                            recipient.Type = (int) OlMeetingRecipientType.olRequired;
                            recipient.Resolve();
                        });
                    }

                    if (calendarAppointment.OptionalAttendees != null)
                    {
                        calendarAppointment.OptionalAttendees.ForEach(rcptName =>
                        {
                            var recipient =
                                appItem.Recipients.Add(string.Format("{0}<{1}>", rcptName.Name, rcptName.Email));
                            recipient.Type = (int) OlMeetingRecipientType.olOptional;
                            recipient.Resolve();
                        });
                    }
                }

                if (addReminder)
                {
                    appItem.ReminderMinutesBeforeStart = calendarAppointment.ReminderMinutesBeforeStart;
                    appItem.ReminderSet = calendarAppointment.ReminderSet;
                }

                userProperties = appItem.UserProperties;
                if (userProperties != null)
                {
                    for (var i = 0; i < userProperties.Count; i++)
                    {
                        userProperties.Remove(i + 1);
                    }

                    foreach (var extendedProperty in calendarAppointment.ExtendedProperties)
                    {
                        var sourceProperty = userProperties.Add(extendedProperty.Key,
                            OlUserPropertyType.olText);
                        sourceProperty.Value = extendedProperty.Value;
                    }
                }

                appItem.Save();
            }
            catch (Exception exception)
            {
                ApplicationLogger.Error(exception);
                return false;
            }
            finally
            {
                if (recipients != null)
                {
                    Marshal.FinalReleaseComObject(recipients);
                }
                if (userProperties != null)
                {
                    Marshal.FinalReleaseComObject(userProperties);
                }
                if (appItem != null)
                {
                    Marshal.FinalReleaseComObject(appItem);
                }
            }
            return true;
        }
Exemplo n.º 15
0
        public async Task<AppointmentsWrapper> GetCalendarEventsInRangeAsync(DateTime startDate, DateTime endDate,
            IDictionary<string, object> calendarSpecificData)
        {
            CheckCalendarSpecificData(calendarSpecificData);


            var service = GetExchangeService(ExchangeServerSettings);

            var calendarview = new CalendarView(startDate, endDate);

            // Get Default Calendar
            var outlookAppointments = new AppointmentsWrapper();
            var exchangeAppointments = service.FindAppointments(_ewsCalendar.EntryId,
                calendarview);


            service.LoadPropertiesForItems(
                from Item item in exchangeAppointments select item,
                new PropertySet(BasePropertySet.FirstClassProperties) {RequestedBodyType = BodyType.Text});

            if (exchangeAppointments != null)
            {
                foreach (var exchangeAppointment in exchangeAppointments)
                {
                    var appointment = new Appointment(exchangeAppointment.Body, exchangeAppointment.Location,
                        exchangeAppointment.Subject, exchangeAppointment.Start, exchangeAppointment.Start)
                    {
                        AppointmentId = exchangeAppointment.Id.UniqueId,
                        AllDayEvent = exchangeAppointment.IsAllDayEvent,
                        OptionalAttendees = GetAttendees(exchangeAppointment.OptionalAttendees),
                        ReminderMinutesBeforeStart = exchangeAppointment.ReminderMinutesBeforeStart,
                        Organizer =
                            new Attendee
                            {
                                Name = exchangeAppointment.Organizer.Name,
                                Email = exchangeAppointment.Organizer.Address
                            },
                        ReminderSet = exchangeAppointment.IsReminderSet,
                        RequiredAttendees = GetAttendees(exchangeAppointment.RequiredAttendees)
                    };
                    outlookAppointments.Add(appointment);
                }
            }
            return outlookAppointments;
        }
        /// <summary>
        /// </summary>
        /// <param name="destAppointment"></param>
        /// <param name="sourceAppointment"></param>
        /// <param name="addDescription"></param>
        /// <param name="addReminders"></param>
        /// <param name="addAttendeesToDescription"></param>
        /// <returns>
        /// </returns>
        private bool CompareAppointments(Appointment destAppointment,
            Appointment sourceAppointment, bool addDescription, bool addReminders, bool addAttendeesToDescription)
        {
            var isFound = destAppointment.Equals(sourceAppointment);
            //If both entries have same content

            if (isFound)
            {
                //If description flag is on, compare description
                if (addDescription)
                {
                    if (!sourceAppointment.CompareDescription(destAppointment, addAttendeesToDescription))
                    {
                        isFound = false;
                    }
                }
            }

            if (isFound)
            {
                //If reminder flag is on, compare reminder
                if (addReminders)
                {
                    //Check if reminders match
                    if (sourceAppointment.ReminderSet != destAppointment.ReminderSet)
                    {
                        isFound = false;
                    }
                    else if (sourceAppointment.ReminderSet)
                    {
                        if (sourceAppointment.ReminderMinutesBeforeStart !=
                            destAppointment.ReminderMinutesBeforeStart)
                        {
                            isFound = false;
                        }
                    }
                }
            }

            return isFound;
        }