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");
        }
Exemplo n.º 2
0
        public async Task <bool> SaveAppointmentAsync(CustomAppointment a)
        {
            if (CalendarToUse == null)
            {
                await GetCalendarAsync();
            }
            var A = new Appointment
            {
                AllDay     = a.AllDay,
                Details    = a.Details,
                Reminder   = a.Reminder,
                RoamingId  = a.RoamingId,
                StartTime  = a.StartTime,
                Subject    = a.Subject,
                BusyStatus = AppointmentBusyStatus.Free
            };

            try
            {
                await CalendarToUse.SaveAppointmentAsync(A);
            }
            catch (Exception ex)
            {
                return(false);
            }
            return(true);
        }
Exemplo n.º 3
0
        /// <summary>
        /// 由节目生成日历提醒
        /// </summary>
        /// <param name="program"></param>
        public async Task <Messages> CreateAppoint(Models.Program program)
        {
            if (_calendar == null)
            {
                return(Messages.NotInitialized);
            }
            if (_container.Values.Keys.Contains(program.UniqueId))
            {
                return(Messages.AlreadyExists);
            }
            var appointment = new Appointment()
            {
                Subject              = program.Name,
                StartTime            = program.StartTime,
                Duration             = program.Duration,
                AllowNewTimeProposal = false,
                Details              = $"第{program.Episode}集",
                Location             = program.Channel.Name,
                Reminder             = (bool)SettingService.Instance.Get("EnableCalendarNotification", true) ?
                                       (TimeSpan)SettingService.Instance.Get("ReminderSpanAhead", TimeSpan.FromMinutes(5)) as TimeSpan? : null
            };
            await _calendar.SaveAppointmentAsync(appointment);

            _container.Values.Add(program.UniqueId, appointment.LocalId);
            LoggingService.Debug("Service", $"为节目{program}添加日历提醒成功,ID为{appointment.LocalId}");
            return(Messages.Sucess);
        }
Exemplo n.º 4
0
        /// <summary>
        /// Add new event to a calendar or update an existing event.
        /// If a new event was added, the ExternalID property will be set on the CalendarEvent object,
        /// to support future queries/updates.
        /// Throws if Calendar ID is empty, calendar does not exist, or calendar is read-only.
        /// </summary>
        /// <param name="calendar">Destination calendar</param>
        /// <param name="calendarEvent">Event to add or update</param>
        /// <exception cref="System.ArgumentException">Calendar is not specified, does not exist on device, or is read-only</exception>
        /// <exception cref="System.UnauthorizedAccessException">Calendar access denied</exception>
        /// <exception cref="System.InvalidOperationException">Editing recurring events is not supported</exception>
        /// <exception cref="System.ArgumentOutOfRangeException">Windows does not support multiple reminders</exception>
        /// <exception cref="Plugin.Calendars.Abstractions.PlatformException">Unexpected platform-specific error</exception>
        public async Task AddOrUpdateEventAsync(Calendar calendar, CalendarEvent calendarEvent)
        {
            await EnsureInitializedAsync().ConfigureAwait(false);

            AppointmentCalendar appCalendar = null;

            if (string.IsNullOrEmpty(calendar.ExternalID))
            {
                throw new ArgumentException("Missing calendar identifier", "calendar");
            }
            else
            {
                appCalendar = await GetAndValidateLocalCalendarAsync(calendar.ExternalID).ConfigureAwait(false);
            }


            // Android/iOS support multiple reminders, but Windows only allows one
            if (calendarEvent.Reminders?.Count > 1)
            {
                throw new ArgumentOutOfRangeException(nameof(calendarEvent), "Windows does not support multiple reminders");
            }

            Appointment appt = null;

            // If Event already corresponds to an existing Appointment in the target
            // Calendar, then edit that instead of creating a new one.
            //
            if (!string.IsNullOrEmpty(calendarEvent.ExternalID))
            {
                var existingAppt = await _localApptStore.GetAppointmentAsync(calendarEvent.ExternalID);

                if (existingAppt?.Recurrence != null)
                {
                    throw new InvalidOperationException("Editing recurring events is not supported");
                }

                if (existingAppt != null && existingAppt.CalendarId == appCalendar.LocalId)
                {
                    appt = existingAppt;
                }
            }

            if (appt == null)
            {
                appt = new Appointment();
            }

            appt.Subject   = calendarEvent.Name;
            appt.Details   = calendarEvent.Description ?? string.Empty;
            appt.StartTime = calendarEvent.Start;
            appt.Duration  = calendarEvent.End - calendarEvent.Start;
            appt.AllDay    = calendarEvent.AllDay;
            appt.Location  = calendarEvent.Location ?? string.Empty;
            appt.Reminder  = calendarEvent.Reminders?.FirstOrDefault()?.TimeBefore;

            await appCalendar.SaveAppointmentAsync(appt);

            calendarEvent.ExternalID = appt.LocalId;
        }
        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");
        }
Exemplo n.º 6
0
        public static async Task updateCalendar()
        {
            Debug.WriteLine("[Appointment] calendar begin");

            //TODO: possible duplication, lock?

            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 = await getAppointmentCalendar(cal_cal_name, cal_storedKey);

            await deleteAllAppointments(cal);

            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");
        }
        private async Task AddAppointment()
        {
            var now = DateTimeOffset.Now;

            var appointment = new Appointment
            {
                Subject   = "Appointment",
                StartTime = now,
                Duration  = TimeSpan.FromMinutes(30),
            };

            await _appointmentCalendar.SaveAppointmentAsync(appointment);

            if (appointment.LocalId != string.Empty)
            {
                _appointments.Add(appointment);
            }

            var appointmentRecurrence = new AppointmentRecurrence {
                Unit = AppointmentRecurrenceUnit.Weekly, Interval = 1, DaysOfWeek = (AppointmentDaysOfWeek)(now.DayOfWeek + 1)
            };

            appointment = new Appointment
            {
                Subject    = "Appointment with recurrence",
                StartTime  = now.AddHours(1),
                Duration   = TimeSpan.FromMinutes(30),
                Recurrence = appointmentRecurrence
            };

            await _appointmentCalendar.SaveAppointmentAsync(appointment);

            if (appointment.LocalId != string.Empty)
            {
                _appointments.Add(appointment);
            }
        }
        private async Task AddSampleEventAsync()
        {
            if (calendar == null)
            {
                await CreateOrOpenCalendarAsync();
            }

            await calendar.SaveAppointmentAsync(
                new Appointment()
            {
                Subject   = "Sample Event",
                StartTime = DateTime.Now,
                Duration  = TimeSpan.FromHours(1)
            });
        }
Exemplo n.º 9
0
    public async Task <bool> AddAsync(AppBarButton button, ResourceDictionary resources)
    {
        Appointment appointment = await Dialog(new Appointment(), resources);

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

            if (calendar != null)
            {
                await calendar.SaveAppointmentAsync(appointment);

                return(true);
            }
        }
        return(false);
    }
Exemplo n.º 10
0
        /// <summary>
        /// Add new event to a calendar or update an existing event.
        /// Throws if Calendar ID is empty, calendar does not exist, or calendar is read-only.
        /// </summary>
        /// <param name="calendar">Destination calendar</param>
        /// <param name="calendarEvent">Event to add or update</param>
        /// <exception cref="System.ArgumentException">Calendar is not specified, does not exist on device, or is read-only</exception>
        /// <exception cref="System.UnauthorizedAccessException">Calendar access denied</exception>
        /// <exception cref="Calendars.Plugin.Abstractions.PlatformException">Unexpected platform-specific error</exception>
        public async Task AddOrUpdateEventAsync(Calendar calendar, CalendarEvent calendarEvent)
        {
            await EnsureInitializedAsync().ConfigureAwait(false);

            AppointmentCalendar appCalendar = null;

            if (string.IsNullOrEmpty(calendar.ExternalID))
            {
                throw new ArgumentException("Missing calendar identifier", "calendar");
            }
            else
            {
                appCalendar = await GetAndValidateLocalCalendarAsync(calendar.ExternalID).ConfigureAwait(false);
            }

            Appointment appt = null;

            // If Event already corresponds to an existing Appointment in the target
            // Calendar, then edit that instead of creating a new one.
            //
            if (!string.IsNullOrEmpty(calendarEvent.ExternalID))
            {
                var existingAppt = await _localApptStore.GetAppointmentAsync(calendarEvent.ExternalID);

                if (existingAppt != null && existingAppt.CalendarId == appCalendar.LocalId)
                {
                    appt = existingAppt;
                }
            }

            if (appt == null)
            {
                appt = new Appointment();
            }

            appt.Subject   = calendarEvent.Name;
            appt.Details   = calendarEvent.Description ?? string.Empty;
            appt.StartTime = calendarEvent.Start;
            appt.Duration  = calendarEvent.End - calendarEvent.Start;
            appt.AllDay    = calendarEvent.AllDay;
            appt.Location  = calendarEvent.Location ?? string.Empty;

            await appCalendar.SaveAppointmentAsync(appt);

            calendarEvent.ExternalID = appt.LocalId;
        }
Exemplo n.º 11
0
        public static async Task updateLectures()   //always force remote
        {
            Debug.WriteLine("[Appointment] lecture begin");

            //TODO: possible duplication, lock?

            var lectures = await Remote.getHostedLectures();

            //get Calendar object
            AppointmentCalendar cal = await getAppointmentCalendar(lec_cal_name, lec_storedKey);

            await deleteAllAppointments(cal);

            foreach (var lec in lectures)
            {
                await cal.SaveAppointmentAsync(getAppointment(lec));
            }

            Debug.WriteLine("[Appointment] lecture finish");
        }
Exemplo n.º 12
0
        public static async Task <bool> TryWriteAppointmentAsync(Ritual r)
        {
            try{
                Appointment appt = new Appointment();

                appt.Subject   = r.Name;
                appt.StartTime = r.EventDate;
                appt.Details   = r.Description;

                var reminderTime = new TimeSpan();
                appt.Reminder = reminderTime;  //vinay

                await _calendar.SaveAppointmentAsync(appt);

                return(true);
            }
            catch
            {
                return(false);
            }
        }
Exemplo n.º 13
0
    public async Task <bool> EditAsync(AppBarButton button, ResourceDictionary resources)
    {
        Item        item        = (Item)button.Tag;
        Appointment appointment = await GetAppointmentAsync(item.Id);

        if (appointment != null)
        {
            appointment = await Dialog(appointment, resources);

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

                if (calendar != null)
                {
                    await calendar.SaveAppointmentAsync(appointment);

                    return(true);
                }
            }
        }
        return(false);
    }
Exemplo n.º 14
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");
        }
Exemplo n.º 15
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);
            }
        }