コード例 #1
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);
        }
コード例 #2
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);
        }
コード例 #3
0
        public static async Task deleteAllAppointments(AppointmentCalendar cal)
        {
            var aps = await cal.FindAppointmentsAsync(DateTime.Now.AddYears(-10), TimeSpan.FromDays(365 * 20));

            foreach (var a in aps)
            {
                await cal.DeleteAppointmentAsync(a.LocalId);
            }
        }
コード例 #4
0
        public static async Task updateTimetable(bool forceRemote = false)
        {
            Debug.WriteLine("[Appointment] update start");

            //TODO: request calendar access?

            Timetable timetable = await DataAccess.getTimetable(forceRemote);

            if (timetable.Count == 0)
            {
                throw new Exception();
            }

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


            AppointmentCalendar cal = null;

            if (DataAccess.getLocalSettings()[class_storedKey] != null)
            {
                cal = await store.GetAppointmentCalendarAsync(
                    DataAccess.getLocalSettings()[class_storedKey].ToString());
            }

            if (cal == null)
            {
                cal = await store.CreateAppointmentCalendarAsync(class_cal_name);

                DataAccess.setLocalSettings(class_storedKey, cal.LocalId);
            }


            //TODO: don't delete all and re-insert all
            //
            var aps = await cal.FindAppointmentsAsync(DateTime.Now.AddYears(-10), TimeSpan.FromDays(365 * 20));

            foreach (var ddl_ap in aps)
            {
                await cal.DeleteAppointmentAsync(ddl_ap.LocalId);
            }


            var list = new List <Windows.ApplicationModel.Appointments.Appointment>();

            foreach (var ev in timetable)
            {
                list.Add(getAppointment(ev));
            }
            list = mergeAppointments(list);
            foreach (var e in list)
            {
                await cal.SaveAppointmentAsync(e);
            }

            Debug.WriteLine("[Appointment] update finished");
        }
コード例 #5
0
        public static async Task updateCalendar()
        {
            Debug.WriteLine("[Appointment] calendar begin");

            //TODO: possible duplication, lock?
            var store = await AppointmentManager.RequestStoreAsync(AppointmentStoreAccessType.AppCalendarsReadWrite);

            var current_semester = await DataAccess.getSemester(getNextSemester : false);

            var next_semester = await DataAccess.getSemester(getNextSemester : true);

            if (current_semester.semesterEname == semester_in_system_calendar)
            {
                return;
            }

            //get Calendar object
            AppointmentCalendar cal = null;

            if (DataAccess.getLocalSettings()[cal_storedKey] != null)
            {
                cal = await store.GetAppointmentCalendarAsync(
                    DataAccess.getLocalSettings()[cal_storedKey].ToString());
            }

            if (cal == null)
            {
                cal = await store.CreateAppointmentCalendarAsync(cal_cal_name);

                DataAccess.setLocalSettings(cal_storedKey, cal.LocalId);
            }

            var aps = await cal.FindAppointmentsAsync(DateTime.Now.AddYears(-10), TimeSpan.FromDays(365 * 20));

            foreach (var a in aps)
            {
                await cal.DeleteAppointmentAsync(a.LocalId);
            }

            foreach (var ev in getAppointments(current_semester))
            {
                await cal.SaveAppointmentAsync(ev);
            }

            if (next_semester.id != current_semester.id)
            {
                foreach (var ev in getAppointments(next_semester))
                {
                    await cal.SaveAppointmentAsync(ev);
                }
            }

            semester_in_system_calendar = current_semester.semesterEname;

            Debug.WriteLine("[Appointment] calendar finish");
        }
コード例 #6
0
 private async Task LoadAppointments()
 {
     AppointmentListView.ItemsSource = _appointments = new ObservableCollection <Appointment>(
         await _appointmentCalendar.FindAppointmentsAsync(
             DateTimeOffset.Now.Date.Add(TimeSpan.FromDays(-8)),
             TimeSpan.FromDays(16),
             new FindAppointmentsOptions
     {
         IncludeHidden = true
     }));
 }
コード例 #7
0
ファイル: CalendarService.cs プロジェクト: cmpute/iTV6
        /// <summary>
        /// 删除所有日历提醒
        /// </summary>
        /// <returns>是否成功完成操作</returns>
        public async Task <Messages> DeleteAllAppointments()
        {
            if (_calendar == null)
            {
                return(Messages.NotInitialized);
            }
            var appointments = await _calendar.FindAppointmentsAsync(DateTime.Now.AddYears(-10), TimeSpan.FromDays(365 * 20));

            foreach (var ap in appointments)
            {
                await _calendar.DeleteAppointmentAsync(ap.LocalId);
            }
            return(Messages.Sucess);
        }
コード例 #8
0
    private async Task <IReadOnlyList <Appointment> > ListAppointmentsAsync(DateTimeOffset start, TimeSpan range)
    {
        AppointmentStore store = await Store();

        if (store != null)
        {
            AppointmentCalendar calendar = await GetAsync();

            if (calendar != null)
            {
                return(await calendar.FindAppointmentsAsync(start, range));
            }
        }
        return(null);
    }
コード例 #9
0
        public static async Task <bool> TryDeleteAppointmentAsync(Ritual r)
        {
            try
            {
                TimeSpan ts = new TimeSpan(0, 0, 2);

                var _list = await _calendar.FindAppointmentsAsync(r.EventDate, ts);

                foreach (Appointment a in _list)
                {
                    if (a.Subject == r.Name)
                    {
                        await _calendar.DeleteAppointmentAsync(a.LocalId);
                    }
                }
                return(true);
            }
            catch
            {
                return(false);
            }
        }
コード例 #10
0
        public static async Task updateDeadlines()
        {
            Debug.WriteLine("[Appointment] deadlines begin");


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

            try {
                var deadlines = await DataAccess.getAllDeadlines();

                if (deadlines.Count == 0)
                {
                    throw new Exception();
                }

                //get Calendar object
                AppointmentCalendar ddl_cal = null;
                if (DataAccess.getLocalSettings()[ddl_storedKey] != null)
                {
                    ddl_cal = await store.GetAppointmentCalendarAsync(
                        DataAccess.getLocalSettings()[ddl_storedKey].ToString());
                }

                if (ddl_cal == null)
                {
                    ddl_cal = await store.CreateAppointmentCalendarAsync(ddl_cal_name);

                    DataAccess.setLocalSettings(ddl_storedKey, ddl_cal.LocalId);
                }

                var aps = await ddl_cal.FindAppointmentsAsync(DateTime.Now.AddYears(-10), TimeSpan.FromDays(365 * 20));

                foreach (var ddl_ap in aps)
                {
                    if (ddl_ap.Details == "")
                    {
                        await ddl_cal.DeleteAppointmentAsync(ddl_ap.LocalId);

                        Debug.WriteLine("[updateDeadlines] deleting " + ddl_ap.Subject);
                    }
                }

                var existing = new List <Windows.ApplicationModel.Appointments.Appointment>();
                aps = await ddl_cal.FindAppointmentsAsync(DateTime.Now.AddYears(-10), TimeSpan.FromDays(365 * 20));

                foreach (var a in aps)
                {
                    existing.Add(a);
                }

                var waiting = new List <Windows.ApplicationModel.Appointments.Appointment>();
                foreach (var ev in deadlines)
                {
                    if (ev.shouldBeIgnored())
                    {
                        continue;
                    }
                    if (ev.hasBeenFinished)
                    {
                        continue; //TODO: should be user-configurable
                    }
                    waiting.Add(getAppointment(ev));
                }

                var to_be_deleted  = existing.Except(waiting, new AppointmentComparer());
                var to_be_inserted = waiting.Except(existing, new AppointmentComparer());


                foreach (var i in to_be_deleted)
                {
                    Debug.WriteLine("[updateDeadlines] deleting' " + i.Subject);
                    await ddl_cal.DeleteAppointmentAsync(i.LocalId);
                }

                foreach (var i in to_be_inserted)
                {
                    Debug.WriteLine("[updateDeadlines] inserting " + i.Subject);
                    if (i.StartTime - DateTime.Now < TimeSpan.FromHours(7))
                    {
                        Debug.WriteLine("[updateDeadlines] ignoring " + i.Subject);
                        continue;
                    }
                    await ddl_cal.SaveAppointmentAsync(i);
                }
            } catch (Exception) { }

            Debug.WriteLine("[Appointment] deadlines finish");
        }
コード例 #11
0
ファイル: Connector.cs プロジェクト: Difegue/AREL-UWP
        //Met à jour un calendrier Windows custom avec les données de planning de l'API Arel.
        //On peut par la suite ouvrir l'appli calendrier Windows sur ce cal. custom.
        public async void UpdateWindowsCalendar(string start, string end, string calendarName)
        {
            string apiUrl = "api/planning/slots?start=" + start + "&end=" + end;

            string planningXML = await GetInfo(apiUrl);

            System.Xml.XmlDocument doc = new System.Xml.XmlDocument();//creation d'une instance xml
            try
            {
                doc.LoadXml(planningXML); //chargement de la variable
            }
            catch (Exception)
            {
                return; //Pas très catholique tout ça
            }
            //On a le XML, on ouvre le calendrier custom

            // 1. get access to appointmentstore
            var appointmentStore = await AppointmentManager.RequestStoreAsync(AppointmentStoreAccessType.AppCalendarsReadWrite);

            // 2. get calendar

            AppointmentCalendar calendar
                = (await appointmentStore.FindAppointmentCalendarsAsync())
                  .FirstOrDefault(c => c.DisplayName == calendarName);

            if (calendar == null)
            {
                calendar = await appointmentStore.CreateAppointmentCalendarAsync(calendarName);
            }

            //Et c'est parti pour la boucle de la folie
            foreach (System.Xml.XmlNode node in doc.DocumentElement.ChildNodes)
            {
                // 3. create new Appointment
                var appo = new Windows.ApplicationModel.Appointments.Appointment();

                DateTime startDate = DateTime.Parse(node.ChildNodes[0].InnerText);
                DateTime endDate   = DateTime.Parse(node.ChildNodes[1].InnerText);

                // appointment properties
                appo.AllDay    = false;
                appo.Location  = node.ChildNodes[6].InnerText;
                appo.StartTime = startDate;
                appo.Duration  = new TimeSpan(0, (int)(endDate - startDate).TotalMinutes, 0);


                //Récup non complet rel (aka matière/sujet)
                string idRel = node.ChildNodes[2].InnerText;
                string xmlr  = await GetInfo("/api/rels/" + idRel);

                string relName = getRelName(xmlr, node.ChildNodes[11].InnerText);

                //Récup nom complet prof
                string idProf = node.ChildNodes[3].InnerText;
                string xmlj   = await GetInfo("/api/users/" + idProf);

                string profName = GetUserFullName(xmlj, node.ChildNodes[4].InnerText);
                appo.Organizer             = new Windows.ApplicationModel.Appointments.AppointmentOrganizer();
                appo.Organizer.DisplayName = profName;

                appo.Subject = relName + " - " + profName;

                //Est-ce que cet appointment exact existe déjà
                //On regarde les appointments sur ce créneau

                Appointment apCheck = (await calendar.FindAppointmentsAsync(appo.StartTime, appo.Duration)).FirstOrDefault(a => a.Subject == appo.Subject);
                //Si il en existe un sur ce créneau, on l'efface avant d'ajouter le nouveau

                if (apCheck != null)
                {
                    await calendar.DeleteAppointmentAsync(apCheck.LocalId);
                }

                await calendar.SaveAppointmentAsync(appo);
            }
        }