private async void DeleteAppointmentButton_OnClick(object sender, RoutedEventArgs e)
        {
            var frameworkElement = (FrameworkElement)sender;
            var appointment      = (Appointment)frameworkElement.DataContext;
            await _appointmentCalendar.DeleteAppointmentAsync(appointment.LocalId);

            _appointments.Remove(appointment);
        }
Ejemplo n.º 2
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);
            }
        }
Ejemplo n.º 3
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");
        }
Ejemplo n.º 4
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");
        }
Ejemplo n.º 5
0
        /// <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);
        }
Ejemplo n.º 6
0
    public async Task <bool> DeleteAsync(AppBarButton button)
    {
        Item        item        = (Item)button.Tag;
        Appointment appointment = await GetAppointmentAsync(item.Id);

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

            if (calendar != null)
            {
                await calendar.DeleteAppointmentAsync(item.Id);

                return(true);
            }
        }
        return(false);
    }
Ejemplo n.º 7
0
        public async Task <(int, int)> DeleteAllEntrysAsync()
        {
            if (CalendarToUse == null)
            {
                await GetCalendarAsync();
            }
            if (AllAppointments == null)
            {
                try
                {
                    await FindAllAsync();

                    if (AllAppointments == null)
                    {
                        return(0, 0);
                    }
                }
                catch (Exception)
                {
                    return(0, 0);
                }
            }
            int DeleteCounter = 0;
            int ToDelete      = AllAppointments.Count;

            foreach (var item in AllAppointments)
            {
                try
                {
                    await CalendarToUse.DeleteAppointmentAsync(item.LocalId);

                    //NewNot("Deleting Element {0} now lID: {1} rID: {2}", item.Subject, item.LocalId, item.RoamingId);
                    DeleteCounter++;
                }
                catch (Exception ex)
                {
                }
            }
            await SaveAsync();

            AllAppointments = null;
            return(DeleteCounter, ToDelete);
        }
Ejemplo n.º 8
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);
            }
        }
Ejemplo n.º 9
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");
        }
Ejemplo n.º 10
0
        //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);
            }
        }