Ejemplo n.º 1
0
        /// <summary>
        /// Creates a new calendar or updates the name and color of an existing one.
        /// </summary>
        /// <param name="calendar">The calendar to create/update</param>
        /// <exception cref="System.ArgumentException">Calendar does not exist on device or is read-only</exception>
        /// <exception cref="System.UnauthorizedAccessException">Calendar access denied</exception>
        /// <exception cref="Plugin.Calendars.Abstractions.PlatformException">Unexpected platform-specific error</exception>
        public async Task AddOrUpdateCalendarAsync(Calendar calendar)
        {
            await EnsureInitializedAsync().ConfigureAwait(false);

            AppointmentCalendar existingCalendar = null;

            if (!string.IsNullOrEmpty(calendar.ExternalID))
            {
                existingCalendar = await GetAndValidateLocalCalendarAsync(calendar.ExternalID).ConfigureAwait(false);
            }

            // Note: DisplayColor is read-only, we cannot set/update it.

            if (existingCalendar == null)
            {
                // Create new calendar
                //
                var appCalendar = await CreateAppCalendarAsync(calendar.Name).ConfigureAwait(false);

                calendar.ExternalID = appCalendar.LocalId;
                calendar.Color      = appCalendar.DisplayColor.ToString();
            }
            else
            {
                // Edit existing calendar
                //
                existingCalendar.DisplayName = calendar.Name;

                await existingCalendar.SaveAsync().ConfigureAwait(false);
            }
        }
Ejemplo n.º 2
0
 public async Task <bool> SaveAsync()
 {
     try
     {
         await CalendarToUse.SaveAsync();
     }
     catch (Exception)
     {
         return(false);
     }
     return(true);
 }
Ejemplo n.º 3
0
        private static async Task CreateNewCalendarAsync()
        {
            await EnsureAvailabilityAsync();

            var appCalendars = await _store.FindAppointmentCalendarsAsync();

            foreach (AppointmentCalendar cal in appCalendars)
            {
                await cal.DeleteAsync();
            }

            AppointmentCalendar calendar = await _store.CreateAppointmentCalendarAsync("Home Automation Calendar");

            calendar.OtherAppReadAccess  = AppointmentCalendarOtherAppReadAccess.SystemOnly;
            calendar.OtherAppWriteAccess = AppointmentCalendarOtherAppWriteAccess.None;
            await calendar.SaveAsync();

            _calendar = calendar;
        }