Exemple #1
0
        public async Task GetCalendarAsync()
        {
            if (appointmentStore == null)
            {
                await GetStoreAsync();
            }
            try
            {
                var Cals = (await appointmentStore.FindAppointmentCalendarsAsync(FindAppointmentCalendarsOptions.IncludeHidden)).Where(x => x.DisplayName == Const.CalendarName);
                if (Cals.Count() == 0)
                {
                    CalendarToUse = await appointmentStore.CreateAppointmentCalendarAsync(Const.CalendarName);
                }
                else if (Cals.Count() > 0)
                {
                    foreach (var item in Cals.TakeLast(Cals.Count() - 1))
                    {
                        await item.DeleteAsync();
                    }
                    CalendarToUse = Cals.FirstOrDefault();
                }
            }
            catch (Exception ex)
            {
            }

            if (CalendarToUse != null)
            {
                CalendarToUse.CanCreateOrUpdateAppointments = true;
                CalendarToUse.DisplayColor = Windows.UI.Color.FromArgb(0xFF, 0xB3, 0xE5, 0xB8); //{#FFB3E5B8}
            }
        }
Exemple #2
0
 public static async Task SetCalendars(bool force)
 {
     if (force)
     {
         Calendars = await _appointmentStore.FindAppointmentCalendarsAsync();
     }
     else if (Calendars == null)
     {
         Calendars = await _appointmentStore.FindAppointmentCalendarsAsync();
     }
 }
Exemple #3
0
        /// <summary>
        /// Gets a list of all calendars on the device.
        /// </summary>
        /// <returns>Calendars</returns>
        /// <exception cref="System.UnauthorizedAccessException">Calendar access denied</exception>
        /// <exception cref="Plugin.Calendars.Abstractions.PlatformException">Unexpected platform-specific error</exception>
        public async Task <IList <Calendar> > GetCalendarsAsync()
        {
            await EnsureInitializedAsync().ConfigureAwait(false);

            var allCalendars = await _apptStore.FindAppointmentCalendarsAsync().ConfigureAwait(false);

            var localCalendars = await _localApptStore.FindAppointmentCalendarsAsync().ConfigureAwait(false);

            return(allCalendars
                   .Select(c =>
            {
                bool writeable = localCalendars.Any(l => l.LocalId == c.LocalId);
                return c.ToCalendar(writeable);
            }
                           ).ToList());
        }
Exemple #4
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;
        }
        private async Task CreateOrOpenCalendarAsync()
        {
            const string _calendarName = "Sample Calendar";

            AppointmentStore store = await AppointmentManager.RequestStoreAsync(AppointmentStoreAccessType.AppCalendarsReadWrite);

            var calendars = await store.FindAppointmentCalendarsAsync();

            if (!calendars.Any(i => i.DisplayName == _calendarName))
            {
                calendar = await store.CreateAppointmentCalendarAsync(_calendarName);
            }
            else
            {
                calendar = calendars.First(i => i.DisplayName == _calendarName);
            }
        }
Exemple #6
0
    private async Task <AppointmentCalendar> GetAsync()
    {
        AppointmentCalendar result = null;
        AppointmentStore    store  = await Store();

        if (store != null)
        {
            IReadOnlyList <AppointmentCalendar> list = await store.FindAppointmentCalendarsAsync();

            if (list.Count == 0)
            {
                result = await store.CreateAppointmentCalendarAsync(app_title);
            }
            else
            {
                result = list.FirstOrDefault(s => s.DisplayName == app_title);
            }
        }
        return(result);
    }
Exemple #7
0
            public async Task <Calendar[]> GetCalendarsAsync()
            {
                if (appointStore == null)
                {
                    return(new Calendar[0]);
                }
                var src = await appointStore.FindAppointmentCalendarsAsync().AsTask().ConfigureAwait(false);

                var dst = new Calendar[src.Count];

                for (int i = 0; i < src.Count; i++)
                {
                    var calendar = src[i];
                    dst[i] = new Calendar()
                    {
                        id       = calendar.LocalId,
                        color    = Color.FromArgb(calendar.DisplayColor.A, calendar.DisplayColor.R, calendar.DisplayColor.G, calendar.DisplayColor.B),
                        name     = calendar.DisplayName,
                        isHidden = calendar.IsHidden
                    };
                }
                return(dst);
            }
Exemple #8
0
        async private void ShowAllCalendars()
        {
            try
            {
                int calendarsCount = 0;
                calendars = await appointmentStore.FindAppointmentCalendarsAsync(FindAppointmentCalendarsOptions.IncludeHidden);

                if (calendars != null)
                {
                    calendarsCount = calendars.Count;
                    if (calendarsCount > 0)
                    {
                        CalendarsListBox.ItemsSource = calendars;
                    }
                }
                status.Log(string.Format(CultureInfo.CurrentCulture,
                                         LocalizableStrings.CALENDAR_FIND_CALENDARS_RESULT, calendarsCount));
            }
            catch (Exception ex)
            {
                Debug.WriteLine("CalendarPage.ShowAllCalendars: " + ex.ToString());
                status.Log(ex.GetType().ToString());
            }
        }
        private async Task LoadCalendars()
        {
            _appointmentCalendarAdapters = await _appointmentStore.FindAppointmentCalendarsAsync(FindAppointmentCalendarsOptions.IncludeHidden);

            CalendarListView.ItemsSource = _appointmentCalendarAdapters;
        }