// Updates the recurrence of an existing event in the signed-in user's tenant.
        public static async Task <bool> UpdateEventRecurrenceAsync(string eventId, PatternedRecurrence patternedRecurrence)
        {
            bool eventUpdated = false;

            try
            {
                var graphClient   = AuthenticationHelper.GetAuthenticatedClient();
                var eventToUpdate = new Event();

                eventToUpdate.Recurrence = patternedRecurrence;


                var updatedEvent = await graphClient.Me.Events[eventId].Request().UpdateAsync(eventToUpdate);

                if (updatedEvent != null)
                {
                    eventUpdated = true;
                }
            }

            catch (ServiceException e)
            {
                Debug.WriteLine(SampleStrings.UpdateMeetingFailedDebug + e.Error.Message);
                eventUpdated = false;
            }

            return(eventUpdated);
        }
        // Token: 0x06001216 RID: 4630 RVA: 0x00062240 File Offset: 0x00060440
        public override void CopyFrom(IProperty srcProperty)
        {
            if (base.EntityPropertyDefinition.Setter == null)
            {
                throw new ConversionException("Unable to set data of type " + base.EntityPropertyDefinition.Type.FullName);
            }
            INestedProperty nestedProperty = srcProperty as INestedProperty;

            if (nestedProperty == null)
            {
                throw new UnexpectedTypeException("INestedProperty", srcProperty);
            }
            RecurrenceData recurrenceData = nestedProperty.NestedData as RecurrenceData;

            if (recurrenceData == null)
            {
                throw new UnexpectedTypeException("RecurrenceData", nestedProperty.NestedData);
            }
            recurrenceData.Validate();
            PatternedRecurrence patternedRecurrence = new PatternedRecurrence();

            patternedRecurrence.Pattern = EntityRecurrenceProperty.CreateRecurrencePattern(recurrenceData);
            patternedRecurrence.Range   = EntityRecurrenceProperty.CreateRecurrenceRange(base.CalendaringEvent.Start, recurrenceData);
            base.EntityPropertyDefinition.Setter(base.Item, patternedRecurrence);
        }
Ejemplo n.º 3
0
        private async Task CreateEventsForRide(RidePeriod ridePeriod)
        {
            var startEvent = DateTime.Today + User.ArrivalTime.TimeOfDay;
            var endEvent   = DateTime.Today + User.DepartureTime.TimeOfDay;

            if (startEvent.Date.Equals(default(DateTime).Date))
            {
                startEvent = DateTime.Today + App.CurrentUser.ArrivalTime.TimeOfDay;
                endEvent   = DateTime.Today + App.CurrentUser.DepartureTime.TimeOfDay;
            }

            PatternedRecurrence pattern = null;

            if (ridePeriod.Equals(RidePeriod.EveryDay))
            {
                var recurrentEndEvent = endEvent.AddMonths(3);

                pattern = new PatternedRecurrence()
                {
                    Range = new RecurrenceRange()
                    {
                        StartDate          = new Date(startEvent.Year, startEvent.Month, startEvent.Day),
                        EndDate            = new Date(recurrentEndEvent.Year, recurrentEndEvent.Month, recurrentEndEvent.Day),
                        Type               = RecurrenceRangeType.EndDate,
                        RecurrenceTimeZone = "UTC"
                    },
                    Pattern = new RecurrencePattern()
                    {
                        Interval   = 1,
                        DaysOfWeek = new List <Microsoft.Graph.DayOfWeek>()
                        {
                            Microsoft.Graph.DayOfWeek.Monday,
                            Microsoft.Graph.DayOfWeek.Tuesday,
                            Microsoft.Graph.DayOfWeek.Wednesday,
                            Microsoft.Graph.DayOfWeek.Thursday,
                            Microsoft.Graph.DayOfWeek.Friday
                        },
                        Type = RecurrencePatternType.Daily
                    }
                };
            }
            else if (ridePeriod.Equals(RidePeriod.Tomorrow))
            {
                startEvent = startEvent.AddDays(1);
                endEvent   = endEvent.AddDays(1);
            }

            // calculate estimated trip time to event time
            var tripTime = UserHelper.GetTripTimeEstimationAsync(User.Location(), User.WorkLocation());

            await _calendarService.CreateEventAsync(
                startEvent.AddMinutes(-tripTime),
                startEvent,
                $"{AppSettings.CarpoolEventSubject} Pickup",
                User.StreetAddress,
                AppSettings.CarpoolEventSubject,
                new string[] { User.Mail },
                false,
                App.CurrentUser.UserPrincipalName,
                pattern);

            await _calendarService.CreateEventAsync(
                endEvent,
                endEvent.AddMinutes(tripTime),
                $"{AppSettings.CarpoolEventSubject} Dropoff",
                User.StreetAddress,
                AppSettings.CarpoolEventSubject,
                new string[] { User.Mail },
                false,
                App.CurrentUser.UserPrincipalName,
                pattern);
        }
Ejemplo n.º 4
0
        async void OnSaveClicked(Object sender, EventArgs args)
        {
            var  newRecurrence = new PatternedRecurrence();
            Date startDate;
            Date endDate;

            var recurrenceRange   = new RecurrenceRange();
            var recurrencePattern = new RecurrencePattern();
            var daysOfWeek        = new List <Microsoft.Graph.DayOfWeek>();

            if (UpdateRecurrencePatternType == RecurrencePatternType.Daily)
            {
                daysOfWeek.Add(Microsoft.Graph.DayOfWeek.Monday);
                daysOfWeek.Add(Microsoft.Graph.DayOfWeek.Tuesday);
                daysOfWeek.Add(Microsoft.Graph.DayOfWeek.Wednesday);
                daysOfWeek.Add(Microsoft.Graph.DayOfWeek.Thursday);
                daysOfWeek.Add(Microsoft.Graph.DayOfWeek.Friday);
                recurrencePattern.Type           = RecurrencePatternType.Daily;
                recurrencePattern.FirstDayOfWeek = Microsoft.Graph.DayOfWeek.Monday;
                recurrencePattern.DaysOfWeek     = daysOfWeek;
                recurrencePattern.Interval       = 1;
            }
            else if (UpdateRecurrencePatternType == RecurrencePatternType.Weekly)
            {
                daysOfWeek.Add(StringToDayOfWeek[WeeklyDayOfWeek.Text]);
                recurrencePattern.Type       = RecurrencePatternType.Weekly;
                recurrencePattern.DaysOfWeek = daysOfWeek;
                recurrencePattern.Interval   = Convert.ToInt32(NumberOfWeeksEditor.Text);
            }
            else if (UpdateRecurrencePatternType == RecurrencePatternType.AbsoluteMonthly)
            {
                recurrencePattern.Type       = RecurrencePatternType.AbsoluteMonthly;
                recurrencePattern.DayOfMonth = Convert.ToInt32(MonthDayNumberLabel.Text);
                recurrencePattern.Interval   = Convert.ToInt32(MonthIntervalLabel.Text);
            }


            if (String.IsNullOrEmpty(EndAfterOccurrencesEntry.Text))
            {
                recurrenceRange.Type = RecurrenceRangeType.EndDate;
                startDate            = new Date(StartOnDatePicker.Date.Year, StartOnDatePicker.Date.Month, StartOnDatePicker.Date.Day);
                endDate = new Date(EndOnDatePicker.Date.Year, EndOnDatePicker.Date.Month, EndOnDatePicker.Date.Day);
                recurrenceRange.StartDate = startDate;
                recurrenceRange.EndDate   = endDate;
            }
            else
            {
                startDate = new Date(ThisMeetingDate.Date.Year, ThisMeetingDate.Date.Month, ThisMeetingDate.Date.Day);
                recurrenceRange.StartDate           = startDate;
                recurrenceRange.Type                = RecurrenceRangeType.Numbered;
                recurrenceRange.NumberOfOccurrences = Convert.ToInt32(EndAfterOccurrencesEntry.Text);
            }

            newRecurrence.Pattern = recurrencePattern;
            newRecurrence.Range   = recurrenceRange;

            var eventUpdated = await CalendarHelper.UpdateEventRecurrenceAsync(ThisMeeting.Id, newRecurrence);

            if (eventUpdated)
            {
                await Navigation.PopAsync();
            }
            else
            {
                await DisplayAlert(SampleStrings.ErrorText, SampleStrings.CreateMeetingFailed, SampleStrings.OKButtonText);
            }
        }
Ejemplo n.º 5
0
        public async Task <string> CreateEventAsync(DateTime startDateTime, DateTime endDateTime, string eventDescription, string eventLocation, string eventSubject, string[] eventAttendees, bool isAllDay, string aditionalProperty, PatternedRecurrence pattern)
        {
            string createdEventId = null;

            // Prepare the List of attendees
            // Prepare the recipient list
            List <Attendee> attendeesList = new List <Attendee>();

            foreach (string attendee in eventAttendees)
            {
                attendeesList.Add(new Attendee {
                    EmailAddress = new EmailAddress {
                        Address = attendee.Trim()
                    },
                    Type = AttendeeType.Required
                });
            }

            // Event body
            var eventBody = new ItemBody();

            eventBody.Content = string.Format("{0} - {1}{2}",
                                              eventDescription,
                                              AppSettings.CarpoolEventBody,
                                              aditionalProperty);
            eventBody.ContentType = BodyType.Text;

            // Event start and end time
            var eventStartTime = new DateTimeTimeZone();

            eventStartTime.DateTime = startDateTime.ToString("o");
            eventStartTime.TimeZone = TimeZoneInfo.Local.ToString();
            var eventEndTime = new DateTimeTimeZone();

            eventEndTime.TimeZone = TimeZoneInfo.Local.ToString();
            eventEndTime.DateTime = endDateTime.ToString("o");

            // Create an event to add to the events collection
            var location = new Location();

            location.DisplayName = eventLocation;
            var newEvent = new Event();

            newEvent.Subject   = eventSubject;
            newEvent.Location  = location;
            newEvent.Attendees = attendeesList;
            newEvent.Body      = eventBody;
            newEvent.Start     = eventStartTime;
            newEvent.End       = eventEndTime;

            if (pattern != null)
            {
                newEvent.Recurrence = pattern;
            }

            if (isAllDay)
            {
                newEvent.IsAllDay = true;
            }

            var createdEvent = await GraphClient.Instance.Beta.Me.Events.Request().AddAsync(newEvent);

            createdEventId = createdEvent.Id;

            return(createdEventId);
        }
Ejemplo n.º 6
0
        public static Microsoft.Exchange.Connections.Eas.Model.Request.Calendar.Recurrence GetRecurrenceData(PatternedRecurrence recurrence)
        {
            if (recurrence == null)
            {
                return(null);
            }
            Microsoft.Exchange.Connections.Eas.Model.Request.Calendar.Recurrence recurrence2 = new Microsoft.Exchange.Connections.Eas.Model.Request.Calendar.Recurrence();
            recurrence2.Interval = new ushort?((ushort)recurrence.Pattern.Interval);
            RecurrencePatternType type = recurrence.Pattern.Type;

            switch (type)
            {
            case RecurrencePatternType.Daily:
            {
                DailyRecurrencePattern dailyRecurrencePattern = (DailyRecurrencePattern)recurrence.Pattern;
                recurrence2.Type = 0;
                break;
            }

            case RecurrencePatternType.Weekly:
            {
                WeeklyRecurrencePattern weeklyRecurrencePattern = (WeeklyRecurrencePattern)recurrence.Pattern;
                recurrence2.Type      = 1;
                recurrence2.DayOfWeek = new ushort?(SyncCalendarUtils.GetDayOfWeekValue(weeklyRecurrencePattern.DaysOfWeek));
                break;
            }

            case RecurrencePatternType.AbsoluteMonthly:
            {
                AbsoluteMonthlyRecurrencePattern absoluteMonthlyRecurrencePattern = (AbsoluteMonthlyRecurrencePattern)recurrence.Pattern;
                recurrence2.Type       = 2;
                recurrence2.DayOfMonth = new byte?((byte)absoluteMonthlyRecurrencePattern.DayOfMonth);
                break;
            }

            case RecurrencePatternType.RelativeMonthly:
            {
                RelativeMonthlyRecurrencePattern relativeMonthlyRecurrencePattern = (RelativeMonthlyRecurrencePattern)recurrence.Pattern;
                recurrence2.Type        = 3;
                recurrence2.DayOfWeek   = new ushort?(SyncCalendarUtils.GetDayOfWeekValue(relativeMonthlyRecurrencePattern.DaysOfWeek));
                recurrence2.WeekOfMonth = new byte?((byte)relativeMonthlyRecurrencePattern.Index);
                break;
            }

            case RecurrencePatternType.AbsoluteYearly:
            {
                AbsoluteYearlyRecurrencePattern absoluteYearlyRecurrencePattern = (AbsoluteYearlyRecurrencePattern)recurrence.Pattern;
                recurrence2.Type        = 5;
                recurrence2.DayOfMonth  = new byte?((byte)absoluteYearlyRecurrencePattern.DayOfMonth);
                recurrence2.MonthOfYear = new byte?((byte)absoluteYearlyRecurrencePattern.Month);
                break;
            }

            case RecurrencePatternType.RelativeYearly:
            {
                RelativeYearlyRecurrencePattern relativeYearlyRecurrencePattern = (RelativeYearlyRecurrencePattern)recurrence.Pattern;
                recurrence2.Type        = 6;
                recurrence2.DayOfWeek   = new ushort?(SyncCalendarUtils.GetDayOfWeekValue(relativeYearlyRecurrencePattern.DaysOfWeek));
                recurrence2.WeekOfMonth = new byte?((byte)relativeYearlyRecurrencePattern.Index);
                recurrence2.MonthOfYear = new byte?((byte)relativeYearlyRecurrencePattern.Month);
                break;
            }

            default:
                throw new EasSyncFailedPermanentException("Invalid recurrence type: " + type);
            }
            RecurrenceRangeType type2 = recurrence.Range.Type;

            switch (type2)
            {
            case RecurrenceRangeType.EndDate:
            {
                EndDateRecurrenceRange endDateRecurrenceRange = (EndDateRecurrenceRange)recurrence.Range;
                recurrence2.Until = SyncCalendarUtils.ToStringDateTime(endDateRecurrenceRange.EndDate);
                break;
            }

            case RecurrenceRangeType.NoEnd:
                break;

            case RecurrenceRangeType.Numbered:
            {
                NumberedRecurrenceRange numberedRecurrenceRange = (NumberedRecurrenceRange)recurrence.Range;
                recurrence2.Occurrences = new ushort?((ushort)numberedRecurrenceRange.NumberOfOccurrences);
                break;
            }

            default:
                throw new EasSyncFailedPermanentException("Invalid recurrence range type: {0}" + type2);
            }
            return(recurrence2);
        }
Ejemplo n.º 7
0
        /// <summary>
        /// Sets recurrent events
        /// </summary>
        /// <param name="subject"></param>
        /// <param name="startDate"></param>
        /// <param name="endDate"></param>
        /// <param name="startTime"></param>
        /// <param name="endTime"></param>
        /// <returns></returns>
        public async Task SetRecurrentAsync(string subject, string startDate, string endDate, string startTime, string endTime)
        {
            // Sets the event to happen every week
            RecurrencePattern pattern = new RecurrencePattern
            {
                Type     = RecurrencePatternType.Weekly,
                Interval = 1
            };

            /**
             * Sets the days of the week the event occurs.
             *
             * For this sample it occurs every Monday
             ***/
            List <Microsoft.Graph.DayOfWeek> daysOfWeek = new List <Microsoft.Graph.DayOfWeek>();

            daysOfWeek.Add(Microsoft.Graph.DayOfWeek.Monday);
            pattern.DaysOfWeek = daysOfWeek;

            /**
             * Sets the duration of time the event will keep recurring.
             *
             * In this case the event runs from Nov 6th to Nov 26th 2018.
             **/
            int startDay   = int.Parse(startDate.Substring(0, 2));
            int startMonth = int.Parse(startDate.Substring(3, 2));
            int startYear  = int.Parse(startDate.Substring(6, 4));

            int endDay   = int.Parse(endDate.Substring(0, 2));
            int endMonth = int.Parse(endDate.Substring(3, 2));
            int endYear  = int.Parse(endDate.Substring(6, 4));

            RecurrenceRange range = new RecurrenceRange
            {
                Type      = RecurrenceRangeType.EndDate,
                StartDate = new Date(startYear, startMonth, startDay),
                EndDate   = new Date(endYear, endMonth, endDay)
            };

            /**
             * This brings together the recurrence pattern and the range to define the
             * PatternedRecurrence property.
             **/
            PatternedRecurrence recurrence = new PatternedRecurrence
            {
                Pattern = pattern,
                Range   = range
            };

            DateTime dateTime = DateTime.Today;
            // set the start and end time for the event
            DateTimeTimeZone start = new DateTimeTimeZone
            {
                TimeZone = "Pacific Standard Time",
                DateTime = $"{startYear}-{startMonth}-{startDay}T{startTime}:00:00"
            };

            DateTimeTimeZone end = new DateTimeTimeZone
            {
                TimeZone = "Pacific Standard Time",
                DateTime = $"{startYear}-{startMonth}-{startDay}T{startTime}:00:00"
            };

            Event eventObj = new Event
            {
                Recurrence = recurrence,
                Subject    = subject,
            };

            try
            {
                var recurrentEvent = await graphClient
                                     .Me
                                     .Events
                                     .Request()
                                     .AddAsync(eventObj);

                Console.WriteLine($"Created {recurrentEvent.Subject}," +
                                  $" happens every week on Monday from {startTime}:00 to {endTime}:00");
            }
            catch (Exception error)
            {
                Console.WriteLine(error.Message);
            }
        }