Beispiel #1
0
        /// <summary>
        /// Gets all events for a calendar within the specified time range.
        /// </summary>
        /// <param name="calendar">Calendar containing events</param>
        /// <param name="start">Start of event range</param>
        /// <param name="end">End of event range</param>
        /// <returns>Calendar events</returns>
        /// <exception cref="System.ArgumentException">Calendar does not exist on device</exception>
        /// <exception cref="System.UnauthorizedAccessException">Calendar access denied</exception>
        /// <exception cref="Plugin.Calendars.Abstractions.PlatformException">Unexpected platform-specific error</exception>
        public async Task <IList <CalendarEvent> > GetEventsAsync(Calendar calendar, DateTime start, DateTime end)
        {
            await EnsureInitializedAsync().ConfigureAwait(false);

            AppointmentCalendar deviceCalendar = null;

            try
            {
                deviceCalendar = await _apptStore.GetAppointmentCalendarAsync(calendar.ExternalID).ConfigureAwait(false);
            }
            catch (ArgumentException ex)
            {
                throw new ArgumentException("Specified calendar not found on device", ex);
            }

            // Not all properties are populated by default
            //
            var options = new FindAppointmentsOptions {
                IncludeHidden = false
            };

            options.FetchProperties.Add(AppointmentProperties.Subject);
            options.FetchProperties.Add(AppointmentProperties.Details);
            options.FetchProperties.Add(AppointmentProperties.StartTime);
            options.FetchProperties.Add(AppointmentProperties.Duration);
            options.FetchProperties.Add(AppointmentProperties.AllDay);
            options.FetchProperties.Add(AppointmentProperties.Location);

            var appointments = await deviceCalendar.FindAppointmentsAsync(start, end - start, options).ConfigureAwait(false);

            var events = appointments.Select(a => a.ToCalendarEvent()).ToList();

            return(events);
        }
Beispiel #2
0
        async private void ShowAllAppointments()
        {
            try
            {
                FindAppointmentsOptions findOptions = new FindAppointmentsOptions();
                findOptions.MaxCount = 20;
                findOptions.FetchProperties.Add(AppointmentProperties.Subject);
                findOptions.FetchProperties.Add(AppointmentProperties.StartTime);
                findOptions.FetchProperties.Add(AppointmentProperties.Location);
                findOptions.FetchProperties.Add(AppointmentProperties.Details);

                int appointmentsCount = 0;
                IReadOnlyList <Appointment> appointments = await appointmentStore.FindAppointmentsAsync(DateTime.Now, TimeSpan.FromDays(5), findOptions);

                if (appointments != null)
                {
                    appointmentsCount = appointments.Count;
                    if (appointmentsCount > 0)
                    {
                        AppointmentListBox.ItemsSource       = appointments;
                        AppointmentListBox.SelectionChanged += AppointmentListBox_SelectionChanged;
                    }
                }
                status.Log(string.Format(CultureInfo.CurrentCulture,
                                         LocalizableStrings.CALENDAR_FIND_APPOINTMENTS_RESULT, appointmentsCount));
            }
            catch (Exception ex)
            {
                Debug.WriteLine("CalendarPage.ShowAllAppointments: " + ex.ToString());
                status.Log(ex.GetType().ToString());
            }
        }
Beispiel #3
0
        async Task <int> FindAllAsync()
        {
            if (CalendarToUse == null)
            {
                await GetCalendarAsync();
            }
            if (CalendarToUse == null)
            {
                return(0);
            }
            var Start = DateTimeOffset.MinValue;
            var Range = TimeSpan.MaxValue;

            FindAppointmentsOptions op = new FindAppointmentsOptions()
            {
                IncludeHidden = true
            };

            //NewNot("Searching all Appointments from {0} over {1}", Start, Range);
            AllAppointments = await CalendarToUse.FindAppointmentsAsync(Start, Range, op);

            foreach (var item in AllAppointments)
            {
                //NewNot("Found Element \"{0}\" lID: {1} rID: {2}", item.Subject, item.LocalId, item.RoamingId);
            }
            return(AllAppointments.Count);
            //NewNot("Found {0} Appointments", AllAppointments.Count);
        }
        private async void StartSearchAppointments()
        {
            listLog.Items.Add("Searching  Appointments...");
            listLog.SelectedIndex = listLog.Items.Count - 1;

            AppointmentStore appointmentStore = await AppointmentManager.RequestStoreAsync(AppointmentStoreAccessType.AllCalendarsReadOnly);

            FindAppointmentsOptions options = new FindAppointmentsOptions();

            options.FetchProperties.Add(AppointmentProperties.Subject);
            options.FetchProperties.Add(AppointmentProperties.Location);
            options.FetchProperties.Add(AppointmentProperties.Invitees);
            options.FetchProperties.Add(AppointmentProperties.Details);
            options.FetchProperties.Add(AppointmentProperties.StartTime);
            options.FetchProperties.Add(AppointmentProperties.ReplyTime);
            options.FetchProperties.Add(AppointmentProperties.Duration);
            options.FetchProperties.Add(AppointmentProperties.IsCanceledMeeting);
            options.FetchProperties.Add(AppointmentProperties.IsOrganizedByUser);
            options.FetchProperties.Add(AppointmentProperties.OnlineMeetingLink);
            options.FetchProperties.Add(AppointmentProperties.Organizer);
            options.FetchProperties.Add(AppointmentProperties.OriginalStartTime);
            options.FetchProperties.Add(AppointmentProperties.Sensitivity);


            var utcDateTime = new DateTime(DateTime.Now.Year, 01, 01, 00, 00, 0, DateTimeKind.Utc);
            IReadOnlyList <Appointment> apointments = await appointmentStore.FindAppointmentsAsync(utcDateTime, TimeSpan.FromDays(365), options);

            listLog.Items.Add("Total appointments from : " + utcDateTime + " to " + utcDateTime.AddDays(365).ToUniversalTime() + " is: " + apointments.Count.ToString());
            Save_Appointements(apointments);
        }
Beispiel #5
0
        public async void Initialize()
        {
            var client = new Client();
            var venue = new Venue();
            var start = new Start();

            if (RetrieveSettings("onTheWay") != "yes")
            {
                AppointmentStore store = await AppointmentManager.RequestStoreAsync(AppointmentStoreAccessType.AllCalendarsReadOnly);

                FindAppointmentsOptions options = new FindAppointmentsOptions();
                options.MaxCount = 100;
                options.FetchProperties.Add(AppointmentProperties.Subject);
                options.FetchProperties.Add(AppointmentProperties.Location);
                options.FetchProperties.Add(AppointmentProperties.AllDay);
                options.FetchProperties.Add(AppointmentProperties.StartTime);
                options.FetchProperties.Add(AppointmentProperties.Duration);
                IReadOnlyList<Appointment> appointments = await store.FindAppointmentsAsync(DateTime.Now, TimeSpan.FromHours(2), options);

                if (appointments.Count > 0)
                {
                    var i = 0;

                    while((appointments[i].AllDay) && (i < appointments.Count))
                        i++;
                    if (!appointments[i].AllDay)
                    {
                        SaveSettings("clientName", appointments[i].Subject);
                        SaveSettings("venueName", appointments[i].Location);
                        SaveSettings("startTime", appointments[i].StartTime.ToString());
                        SaveSettings("localID", appointments[i].LocalId);
                    }
                    else
                    {
                        SaveSettings("clientName", "Client");
                        SaveSettings("venueName", "Venue");
                        SaveSettings("startTime", DateTime.Now.ToString());
                        SaveSettings("localID", null);
                    }
                }
                else
                {
                    SaveSettings("clientName", "Client");
                    SaveSettings("venueName", "Venue");
                    SaveSettings("startTime", DateTime.Now.ToString());
                    SaveSettings("localID", null);
                }
            }

            client.ClientName = RetrieveSettings("clientName");
            clientNameTextBox.DataContext = client;

            venue.VenueName = RetrieveSettings("venueName");
            venueNameTextBox.DataContext = venue;

            start.StartTime = DateTime.Parse(RetrieveSettings("startTime"));
            //startDatePicker.DataContext = new DateTimeOffset();

        }
Beispiel #6
0
        public static FindAppointmentsOptions GetFindOptions()
        {
            var findOptions = new FindAppointmentsOptions();

            //findOptions.MaxCount = 100;
            findOptions.FetchProperties.Add(AppointmentProperties.Subject);
            findOptions.FetchProperties.Add(AppointmentProperties.Location);
            findOptions.FetchProperties.Add(AppointmentProperties.Details);
            findOptions.FetchProperties.Add(AppointmentProperties.StartTime);
            findOptions.FetchProperties.Add(AppointmentProperties.AllDay);
            findOptions.FetchProperties.Add(AppointmentProperties.Duration);
            return(findOptions);
        }
        /// <summary>
        /// Gets all events for a calendar within the specified time range.
        /// </summary>
        /// <param name="calendar">Calendar containing events</param>
        /// <param name="start">Start of event range</param>
        /// <param name="end">End of event range</param>
        /// <returns>Calendar events</returns>
        /// <exception cref="System.ArgumentException">Calendar does not exist on device</exception>
        /// <exception cref="System.UnauthorizedAccessException">Calendar access denied</exception>
        /// <exception cref="Calendars.Plugin.Abstractions.PlatformException">Unexpected platform-specific error</exception>
        public async Task<IList<CalendarEvent>> GetEventsAsync(Calendar calendar, DateTime start, DateTime end)
        {
            await EnsureInitializedAsync().ConfigureAwait(false);

            AppointmentCalendar deviceCalendar = null;

            try
            {
                deviceCalendar = await _apptStore.GetAppointmentCalendarAsync(calendar.ExternalID).ConfigureAwait(false);
            }
            catch (ArgumentException ex)
            {
                throw new ArgumentException("Specified calendar not found on device", ex);
            }

            // Not all properties are populated by default
            //
            var options = new FindAppointmentsOptions { IncludeHidden = false };
            options.FetchProperties.Add(AppointmentProperties.Subject);
            options.FetchProperties.Add(AppointmentProperties.Details);
            options.FetchProperties.Add(AppointmentProperties.StartTime);
            options.FetchProperties.Add(AppointmentProperties.Duration);
            options.FetchProperties.Add(AppointmentProperties.AllDay);

            var appointments = await deviceCalendar.FindAppointmentsAsync(start, end - start, options).ConfigureAwait(false);
            var events = appointments.Select(a => a.ToCalendarEvent()).ToList();

            return events;
        }
        //Synchronize calender
        public async Task Synchronize()
        {
            try
            {
                _PebbleConnector = Connector.PebbleConnector.GetInstance();

                //Load synchronized calender items
                PreviousSynchronizedItems = null;
                SynchronizedItems         = null;

                String XMLList = await Common.LocalStorage.Load("calenderitems.xml");

                if (XMLList.Length > 0)
                {
                    PreviousSynchronizedItems = (List <CalenderItem>)Common.Serializer.XMLDeserialize(XMLList, typeof(List <CalenderItem>));
                }
                if (PreviousSynchronizedItems == null)
                {
                    PreviousSynchronizedItems = new List <CalenderItem>();
                }
                SynchronizedItems = new List <CalenderItem>();
                PreviousSynchronizedItems.RemoveAll(x => x.Time < (DateTime.Now - new TimeSpan(3, 0, 0, 0))); // remove old items from items

                //Retrieve all appointments for the previous 2 days and next
                var appointmentStore = await AppointmentManager.RequestStoreAsync(AppointmentStoreAccessType.AllCalendarsReadOnly);

                FindAppointmentsOptions findOptions = new FindAppointmentsOptions();
                findOptions.MaxCount = 64;
                findOptions.FetchProperties.Add(AppointmentProperties.Subject);
                findOptions.FetchProperties.Add(AppointmentProperties.Location);
                findOptions.FetchProperties.Add(AppointmentProperties.StartTime);
                findOptions.FetchProperties.Add(AppointmentProperties.Duration);
                findOptions.FetchProperties.Add(AppointmentProperties.Details);
                findOptions.FetchProperties.Add(AppointmentProperties.Reminder);

                IReadOnlyList <Appointment> _appointments =
                    await appointmentStore.FindAppointmentsAsync(DateTime.Now - new TimeSpan(2, 0, 0, 0), TimeSpan.FromDays(4), findOptions);

                //Send all items to Pebble
                foreach (Appointment _appointment in _appointments)
                {
                    await AddCalenderItem(
                        _appointment.RoamingId,
                        _appointment.Subject,
                        _appointment.Location,
                        _appointment.StartTime.DateTime,
                        (int)_appointment.Duration.TotalMinutes,
                        _appointment.Details,
                        _appointment.Reminder);

                    Log.Add("Appointment: " + _appointment.Subject);
                }

                //Remove items
                foreach (CalenderItem _item in PreviousSynchronizedItems)
                {
                    if (_item.CalenderItemID.Length != 0)
                    {
                        await RemoveCalenderItem(Guid.Parse(_item.CalenderItemID));
                    }
                    if (_item.ReminderID.Length != 0)
                    {
                        await RemoveCalenderReminderItem(Guid.Parse(_item.ReminderID));
                    }
                }


                //Save synchronized items
                XMLList = Common.Serializer.XMLSerialize(SynchronizedItems);
                await Common.LocalStorage.Save(XMLList, "calenderitems.xml", false);
            }
            catch (Exception e)
            {
            }
        }