public async Task <AppointmentsWrapper> AddCalendarEvents(List <Appointment> calendarAppointments,
                                                                  bool addDescription,
                                                                  bool addReminder, bool addAttendees, bool attendeesToDescription,
                                                                  IDictionary <string, object> calendarSpecificData)
        {
            var addedAppointments = new AppointmentsWrapper();

            if (!calendarAppointments.Any())
            {
                addedAppointments.IsSuccess = true;
                return(addedAppointments);
            }

            CheckCalendarSpecificData(calendarSpecificData);

            var errorList = new Dictionary <int, Appointment>();
            //Get Calendar Service
            var calendarService = GetCalendarService(AccountName);

            if (calendarAppointments == null || string.IsNullOrEmpty(CalendarId))
            {
                addedAppointments.IsSuccess = false;
                return(addedAppointments);
            }

            try
            {
                if (calendarAppointments.Any())
                {
                    //Split the list of calendarAppointments by 1000 per list
                    var appts =
                        await AddCalendarEventsInternal(calendarAppointments, addDescription, addReminder, addAttendees,
                                                        attendeesToDescription, calendarService, errorList);

                    addedAppointments.AddRange(appts);
                    if (errorList.Count > 0)
                    {
                        var remainingList = errorList.Select(CreateAppointmentWithoutAttendees).ToList();
                        errorList.Clear();

                        appts =
                            await AddCalendarEventsInternal(remainingList, addDescription, addReminder, addAttendees,
                                                            attendeesToDescription, calendarService, errorList);

                        addedAppointments.AddRange(appts);
                    }
                }
            }
            catch (Exception exception)
            {
                Logger.Error(exception);
                addedAppointments.IsSuccess = false;
                return(addedAppointments);
            }
            addedAppointments.IsSuccess = true;
            return(addedAppointments);
        }
Ejemplo n.º 2
0
        public async Task<AppointmentsWrapper> GetCalendarEventsInRangeAsync(DateTime startDate, DateTime endDate,
            IDictionary<string, object> calendarSpecificData)
        {
            CheckCalendarSpecificData(calendarSpecificData);

            //Get Calendar Service
            var calendarService = GetCalendarService(AccountName);

            var finalEventList = new List<Appointment>();

            Events result = null;

            var eventListRequest = calendarService.Events.List(CalendarId);

            // Add Filters to event List Request
            eventListRequest.TimeMin = startDate;
            eventListRequest.TimeMax = endDate;
            eventListRequest.MaxAttendees = 1000;
            eventListRequest.SingleEvents = true;
            try
            {
                result = eventListRequest.Execute();
                if (result != null)
                {
                    while (result.Items != null)
                    {
                        // Add events to list, Split recurring appointments
                        foreach (var eventItem in result.Items)
                        {
                            if (eventItem.Status == "cancelled")
                            {
                                continue;
                            }

                            var appointment = CreateAppointment(eventItem);
                            finalEventList.Add(appointment);
                        }

                        //If all pages are over break
                        if (result.NextPageToken == null)
                        {
                            break;
                        }

                        //Set the next page to pull from request
                        eventListRequest.PageToken = result.NextPageToken;

                        result = await eventListRequest.ExecuteAsync();
                    }
                }
                else
                {
                    return null;
                }
            }
            catch (GoogleApiException exception)
            {
                Logger.Error(exception);
                return null;
            }
            catch (Exception exception)
            {
                Logger.Error(exception);
                return null;
            }

            var calendarAppointments = new AppointmentsWrapper { CalendarId = CalendarId };
            calendarAppointments.AddRange(finalEventList);
            return calendarAppointments;
        }
Ejemplo n.º 3
0
        public async Task<AppointmentsWrapper> AddCalendarEvents(List<Appointment> calendarAppointments,
            bool addDescription,
            bool addReminder, bool addAttendees, bool attendeesToDescription,
            IDictionary<string, object> calendarSpecificData)
        {
            var addedAppointments = new AppointmentsWrapper();
            if (!calendarAppointments.Any())
            {
                addedAppointments.IsSuccess = true;
                return addedAppointments;
            }

            CheckCalendarSpecificData(calendarSpecificData);

            var errorList = new Dictionary<int, Appointment>();
            //Get Calendar Service
            var calendarService = GetCalendarService(AccountName);

            if (calendarAppointments == null || string.IsNullOrEmpty(CalendarId))
            {
                addedAppointments.IsSuccess = false;
                return addedAppointments;
            }
            try
            {
                if (calendarAppointments.Any())
                {
                    //Split the list of calendarAppointments by 1000 per list
                    var appts =
                        await AddCalendarEventsInternal(calendarAppointments, addDescription, addReminder, addAttendees,
                            attendeesToDescription, calendarService, errorList);
                    addedAppointments.AddRange(appts);
                    if (errorList.Count > 0)
                    {
                        var remaningList = errorList.Select(CreateAppointmentWithoutAttendees).ToList();
                        errorList.Clear();

                        appts = await AddCalendarEventsInternal(remaningList, addDescription, addReminder, addAttendees,
                            attendeesToDescription, calendarService, errorList);
                        addedAppointments.AddRange(appts);
                    }
                }
            }
            catch (Exception exception)
            {
                Logger.Error(exception);
                addedAppointments.IsSuccess = false;
                return addedAppointments;
            }
            addedAppointments.IsSuccess = true;
            return addedAppointments;
        }
        public async Task<AppointmentsWrapper> GetCalendarEventsInRangeAsync(DateTime startDate, DateTime endDate,bool skipPrivateEntries,
            IDictionary<string, object> calendarSpecificData)
        {
            CheckCalendarSpecificData(calendarSpecificData);
            var calendarAppointments = new AppointmentsWrapper();

            var appointmentList =
                await
                    Task<List<Appointment>>.Factory.StartNew(
                        () => GetAppointments(startDate, endDate, skipPrivateEntries));

            if (appointmentList == null)
            {
                return null;
            }

            if (OutlookCalendar != null)
            {
                calendarAppointments.CalendarId = OutlookCalendar.EntryId;
            }

            calendarAppointments.AddRange(appointmentList);

            return calendarAppointments;
        }
        public async Task <AppointmentsWrapper> GetCalendarEventsInRangeAsync(DateTime startDate, DateTime endDate, bool skipPrivateEntries,
                                                                              IDictionary <string, object> calendarSpecificData)
        {
            CheckCalendarSpecificData(calendarSpecificData);

            //Get Calendar Service
            var calendarService = GetCalendarService(AccountName);

            var finalEventList = new List <Appointment>();

            Events result = null;

            var eventListRequest = calendarService.Events.List(CalendarId);

            // Add Filters to event List Request
            eventListRequest.TimeMin               = startDate;
            eventListRequest.TimeMax               = endDate;
            eventListRequest.MaxAttendees          = 1000;
            eventListRequest.SingleEvents          = true;
            eventListRequest.ShowHiddenInvitations = !skipPrivateEntries;
            try
            {
                result = eventListRequest.Execute();
                if (result != null)
                {
                    while (result.Items != null)
                    {
                        // Add events to list, Split recurring appointments
                        foreach (var eventItem in result.Items)
                        {
                            if (eventItem.Status == "cancelled")
                            {
                                continue;
                            }

                            var appointment = CreateAppointment(eventItem);
                            finalEventList.Add(appointment);
                        }

                        //If all pages are over break
                        if (result.NextPageToken == null)
                        {
                            break;
                        }

                        //Set the next page to pull from request
                        eventListRequest.PageToken = result.NextPageToken;

                        result = await eventListRequest.ExecuteAsync();
                    }
                }
                else
                {
                    return(null);
                }
            }
            catch (GoogleApiException exception)
            {
                Logger.Error(exception);
                return(null);
            }
            catch (Exception exception)
            {
                Logger.Error(exception);
                return(null);
            }

            var calendarAppointments = new AppointmentsWrapper {
                CalendarId = CalendarId
            };

            calendarAppointments.AddRange(finalEventList);
            return(calendarAppointments);
        }