Ejemplo n.º 1
0
        /// <summary>
        /// If course with exists, function returns ID. If course doesnt exist function
        /// saves this course and returns id of saved course.
        /// </summary>
        public async Task <Course> GetOrAddNotExistsCourse(string courseCode, string courseName)
        {
            var course = await(string.IsNullOrEmpty(courseCode) ? FindByNameAsync(courseName) : FindByCodeAsync(courseCode));

            if (course == null)
            {
                course = new Course()
                {
                    CourseCode            = courseCode,
                    Timetable             = new Timetable(Semester.GetSemester()),
                    LastUpdateOfTimetable = null,
                    CourseName            = courseName,
                    StudyType             = GetCourseStudyType(courseCode)
                };
                if (string.IsNullOrEmpty(courseCode))
                {
                    course.CourseCode = await FindCourseCodeFromProxy(course);
                }
                await FindCourseTimetableFromProxy(course);
                await AddAsync(course);
            }
            else if (IsCourseOutOfDate(course))
            {
                if (string.IsNullOrEmpty(courseCode))
                {
                    course.CourseCode = await FindCourseCodeFromProxy(course);
                }
                await FindCourseTimetableFromProxy(course);
                await UpdateAsync(course);
            }
            return(course);
        }
Ejemplo n.º 2
0
        public async Task <ScheduleTimetableResult> GetBySubjectCode(string subjectCode, string yearOfStudy, string studyType)
        {
            char numStudyType;

            if (studyType.Contains("Celoživotné vzdelávanie"))
            {
                numStudyType = subjectCode[3] == '2' ? '1' : '2';
            }
            else if (studyType.Contains("bak"))
            {
                numStudyType = '2';
            }
            else if (studyType.Contains("inž"))
            {
                numStudyType = '1';
            }
            else if (studyType.Contains("dokt"))
            {
                numStudyType = '3';
            }
            else
            {
                numStudyType = ' ';
            }
            string addition = "," + subjectCode[0] + "," + numStudyType + "," + yearOfStudy;

            return(await CallScheduleContentApi(4, subjectCode + addition, Semester.GetSemester()));
        }
Ejemplo n.º 3
0
        //public static void ImportTestDb(Mongo2Go.MongoDbRunner paRunner, String paPath)
        //{
        //    paRunner.Import("Swapify", "BlockChangeRequest", paPath + Path.DirectorySeparatorChar + "BlockChangeRequest.json", true);
        //    paRunner.Import("Swapify", "Course", paPath + Path.DirectorySeparatorChar + "Course.json", true);
        //    paRunner.Import("Swapify", "Notification", paPath + Path.DirectorySeparatorChar + "Notification.json", true);
        //    paRunner.Import("Swapify", "Student", paPath + Path.DirectorySeparatorChar + "Student.json", true);
        //    paRunner.Import("Swapify", "users", paPath + Path.DirectorySeparatorChar + "users.json", true);
        //}
        private static async Task <Student> CreateStudentAsync(IServiceProvider serviceProvider, Guid studentId = default(Guid), Guid userId = default(Guid))
        {
            var     dbService         = serviceProvider.GetRequiredService <IMongoDatabase>();
            var     studentCollection = dbService.GetCollection <Student>(nameof(Student));
            Student student           = new Student
            {
                Id             = (studentId == default(Guid) ? Guid.NewGuid() : studentId),
                Timetable      = new Timetable(Semester.GetSemester()),
                PersonalNumber = null,
                UserId         = userId
            };
            await studentCollection.InsertOneAsync(student);

            return(student);
        }
Ejemplo n.º 4
0
        public ScheduleTimetableResult GetFromJsonFile(string fileName)
        {
            var myJson = "";

            using (StreamReader file = File.OpenText($@"..\Tests\{fileName}"))
            {
                myJson = file.ReadToEnd();
            }
            return(new ScheduleTimetableResult()
            {
                Result = new UnizaScheduleContentResult()
                {
                    ScheduleContents = ResponseParser.ParseResponse(myJson)
                },
                Semester = Semester.GetSemester()
            });
        }
Ejemplo n.º 5
0
        public async Task <Course> FindCourseTimetableFromProxy(Course course)
        {
            List <ScheduleTimetableResult> schedules = new();
            int years = course.StudyType.Contains("inž") ? 2 : 3;

            for (int i = 1; i <= years; i++)
            {
                try
                {
                    ScheduleTimetableResult schedule = await _scheduleProxy.GetBySubjectCode(course.CourseCode, i + "", course.StudyType);

                    if (schedule != null)
                    {
                        schedules.Add(schedule);
                    }
                } catch (Exception ex)
                {
                    _logger.LogWarning($"Error while searching timetable of course {course.CourseName}({course.CourseCode}): {ex.Message}");
                }
                if (schedules == null)
                {
                    _logger.LogError($"Unable to load schedule for subject {course.CourseCode}. Schedule proxy returned null");
                    return(null);
                }
            }
            course.Timetable = new Timetable(Semester.GetSemester());
            schedules.ForEach(async(schedule) => {
                Timetable t = await ConverterApiToDomain.ConvertTimetableForCourseAsync(schedule, this);
                if (t != null)
                {
                    foreach (Block b in t.AllBlocks)
                    {
                        if (!course.Timetable.ContainsBlock(b))
                        {
                            course.Timetable.AddNewBlock(b);
                        }
                    }
                }
            });
            course.LastUpdateOfTimetable = DateTime.Now;
            await UpdateAsync(course);

            return(course);
        }
Ejemplo n.º 6
0
        public async Task UpdateStudentTest()
        {
            IMongoDatabase database = _mongoFixture.MongoClient.GetDatabase("StudentsDB");
            StudentService stSer    = new(database);
            Student        st       = new();

            Block bl1 = new() { Room = "room1" };
            Block bl2 = new() { Room = "room2" };
            Block bl3 = new() { Room = "room3" };

            st.Timetable = new Timetable(Semester.GetSemester());
            st.Timetable.AddNewBlock(bl1);
            st.Timetable.AddNewBlock(bl2);
            await stSer.AddAsync(st);

            st.Timetable.AllBlocks.Count().Should().Be(2);

            st = await stSer.FindByIdAsync(st.Id);

            st.Timetable.RemoveBlock(bl1.BlockId).Should().Be(true);
            st.Timetable.AllBlocks.Count().Should().Be(1);
            st.Timetable.AllBlocks.FirstOrDefault().Room.Should().Be("room2");
            st.Timetable.AddNewBlock(bl3);

            await stSer.UpdateStudentAsync(st);

            st.Timetable.AllBlocks.Count().Should().Be(2);
            st.Timetable.AllBlocks.Any(x => x.Room == "room3").Should().Be(true);
            st.Timetable.AllBlocks.Any(x => x.Room == "room2").Should().Be(true);
        }

        private IOptions <ProxySettings> GetProxyOptions()
        {
            var settings = new ProxySettings()
            {
                Base_URL           = "https://nic.uniza.sk/webservices",
                CourseContentURL   = "getUnizaScheduleType4.php",
                ScheduleContentURL = "getUnizaScheduleContent.php"
            };

            return(Options.Create(settings));
        }
    }
}
Ejemplo n.º 7
0
        public static Timetable GetFakeTimetable()
        {
            Timetable tt = new Timetable(Semester.GetSemester());

            tt.AddNewBlock(new Block
            {
                BlockType = BlockType.Excercise,
                Day       = Day.Monday,
                Duration  = 2,
                StartHour = 7
            });
            tt.AddNewBlock(new Block
            {
                BlockType = BlockType.Excercise,
                Day       = Day.Monday,
                Duration  = 2,
                StartHour = 10
            });
            tt.AddNewBlock(new Block
            {
                BlockType = BlockType.Excercise,
                Day       = Day.Tuesday,
                Duration  = 2,
                StartHour = 16
            });
            tt.AddNewBlock(new Block
            {
                BlockType = BlockType.Lecture,
                Day       = Day.Wednesday,
                Duration  = 2,
                StartHour = 12
            });
            tt.AddNewBlock(new Block
            {
                BlockType = BlockType.Lecture,
                Day       = Day.Thursday,
                Duration  = 2,
                StartHour = 11
            });
            return(tt);
        }
Ejemplo n.º 8
0
        public static Timetable MergeSameBlocksWithDifferentTeacher(IEnumerable <Block> blocks)
        {
            var sortedBlocks = blocks
                               .OrderBy(b => b.Day)
                               .ThenBy(b => b.StartHour)
                               .ThenBy(b => b.Duration)
                               .ThenBy(b => b.Room)
                               .ThenBy(b => b.BlockType)
                               .ThenBy(b => b.CourseId)
                               .ToList();

            IEnumerable <Block> mergedBlocks = Merge(sortedBlocks,
                                                     (group, b2) =>
            {
                Block b1 = group.Last();
                return(b1.Day == b2.Day &&
                       b1.StartHour == b2.StartHour &&
                       b1.Duration == b2.Duration &&
                       b1.Room == b2.Room &&
                       b1.BlockType == b2.BlockType &&
                       b1.CourseId == b2.CourseId);
            },
                                                     (blocksGroup) =>
            {
                Block block   = blocksGroup[0].Clone();
                block.Teacher = string.Join(",", blocksGroup.Select(b => b.Teacher));
                return(block);
            }
                                                     );
            Timetable mergedTimetable = new(Semester.GetSemester());

            foreach (var mergedBlock in mergedBlocks)
            {
                mergedTimetable.AddNewBlock(mergedBlock);
            }
            return(mergedTimetable);
        }
Ejemplo n.º 9
0
 public async Task <ScheduleTimetableResult> GetByRoomNumber(string roomNumber)
 {
     return(await CallScheduleContentApi(3, roomNumber, Semester.GetSemester()));
 }
Ejemplo n.º 10
0
 public async Task <ScheduleTimetableResult> GetByTeacherName(string teacherNumber)
 {
     return(await CallScheduleContentApi(1, teacherNumber, Semester.GetSemester()));
 }
Ejemplo n.º 11
0
 public async Task <ScheduleTimetableResult> GetByPersonalNumber(string personalNumber)
 {
     return(await CallScheduleContentApi(5, personalNumber, Semester.GetSemester()));
 }