private static SqlAdunisAppointment ConvertAppointment(SqlTimeperiod period, WhAdunisCourse course, WhAdunisAppointment aAppointment, AdunisType type)
        {
            var appointment = new SqlAdunisAppointment
            {
                Type       = type,
                CourseName = course.Name,
                StartTime  = aAppointment.StartTime,
                EndTime    = aAppointment.EndTime,
                TermID     = period.TermID
            };

            if (aAppointment.AppointmentRooms != null)
            {
                appointment.AppointmentRooms = string.Join(", ", aAppointment.AppointmentRooms);
            }

            if (aAppointment.Lecturers != null)
            {
                appointment.Lecturers = string.Join(", ", aAppointment.Lecturers);
            }

            appointment.SetId();

            return(appointment);
        }
        public async Task <IEnumerable <WhAdunisCourse> > GetCourseDataAsync(string identity, int termId, AdunisType type, CancellationToken cancellationToken)
        {
            var requestUrlTemplate = type == AdunisType.Timetable ? this.serviceApi.TimetableUri : this.serviceApi.ExamUri;
            var requestUrl         = string.Format(requestUrlTemplate, identity, termId);

            var webClient = new NativeHttpClient(this.httpClientConfiguration);

            webClient
            .AssignAgent(this.device)
            .AssignAcceptTypeJson()
            .AssignBearerToken(await this.oAuth.BearerTokenAsync());

            var response = await webClient.GetStringAsync(requestUrl, cancellationToken);

            if (cancellationToken.IsCancellationRequested)
            {
                return(null);
            }

            var holder = response.CreateFromJsonString <Holder>();

            return(holder?.Courses);
        }
        private static SqlAdunisAppointment ConvertDivAppointment(SqlTimeperiod period, WhAdunisCourse course, AdunisType type)
        {
            // special handling of modules without appointments
            var start = period.Begin.AddDays(-7).SyncWeekday(DayOfWeek.Sunday);

            var appointment = new SqlAdunisAppointment
            {
                Type       = type,
                CourseName = course.Name,
                StartTime  = start.Date,
                EndTime    = period.End,
                TermID     = period.TermID
            };

            appointment.SetId();

            return(appointment);
        }
        public Task <IEnumerable <WhAdunisCourse> > GetCourseDataAsync(string identity, int termId, AdunisType type, CancellationToken cancellationToken)
        {
            string content;

            if (type == AdunisType.Timetable)
            {
                switch (termId)
                {
                case 773:
                    content = TimetableTestData.TimetableData773;
                    break;

                case 774:
                    content = TimetableTestData.TimetableData774;
                    break;

                default:
                    content = string.Empty;
                    break;
                }
            }
            else
            {
                switch (termId)
                {
                case 773:
                    content = TimetableTestData.ExamData;
                    break;

                default:
                    content = string.Empty;
                    break;
                }
            }

            this.appointmentCallCounter++;
            var delay = this.appointmentCallCounter % 14 == 0;

            return(Task <IEnumerable <WhAdunisCourse> > .Factory.StartNew(
                       () =>
            {
                if (delay)
                {
                    Task.Delay(TimeSpan.FromSeconds(5), cancellationToken).Wait(cancellationToken);
                }

                return content?.Length == 0 ? null : JsonConvert.DeserializeObject <Holder>(content).Courses;
            }, cancellationToken));
        }