protected override async Task <IEnumerable <EventBase> > OnFilesChanged() { var exams = new List <Exam>(); foreach (var adapter in adapters) { if (adapter.Use(settings)) { var files = FilesystemUtils.GetFiles(settings.Path, adapter.SearchPattern); logger.LogDebug($"Found {files.Length} file(s) matching '{adapter.SearchPattern}'."); foreach (var file in files) { logger.LogDebug($"Found file {file}."); var contents = await fileReader.GetContentsAsync(file, Encoding.GetEncoding(settings.Encoding)); logger.LogDebug($"File {file} was read. Parsing exams."); var result = await adapter.GetExamsAsync(contents, settings); exams.AddRange(result.Exams); logger.LogDebug($"Got {result.Exams.Count} exam(s)."); } } } return(FromSingleEvent(new ExamEvent(exams))); }
protected override async Task <IEnumerable <EventBase> > OnFilesChanged() { var periodLessons = new Dictionary <string, List <Lesson> >(); foreach (var adapter in adapters) { var files = FilesystemUtils.GetFiles(settings.Path, adapter.SearchPattern); logger.LogDebug($"{adapter.GetType().ToString()} found {files.Length} file(s)."); if (settings.OnlyLastPeriod) { logger.LogDebug("Removing all files but the most recent period."); files = FilterLastPeriod(files, settings.Path); logger.LogDebug($"Still got {files.Length} file(s)."); } foreach (var file in files) { logger.LogDebug($"Found file {file}."); var contents = await fileReader.GetContentsAsync(file, Encoding.GetEncoding(settings.Encoding)); logger.LogDebug($"File {file} was read. Parsing timetable."); var result = await adapter.GetLessonsAsync(contents, settings); logger.LogDebug($"Period: {result.Period}, Lessons: {result.Lessons.Count}."); if (adapter.IsMarkedToExport(result.Objective, settings) == false) { logger.LogDebug($"Ignoring timetable for objective '{result.Objective}' as it is not whitelisted in the config."); continue; } if (periodLessons.ContainsKey(result.Period) == false) { periodLessons.Add(result.Period, new List <Lesson>()); } periodLessons[result.Period].AddRange(result.Lessons); } } var events = new List <EventBase>(); foreach (var kv in periodLessons) { events.Add(new TimetableEvent(kv.Key, kv.Value)); } return(events); }
protected override async Task <IEnumerable <EventBase> > OnFilesChanged() { var substitutions = new List <Substitution>(); var infotexts = new List <Infotext>(); var absences = new List <Absence>(); var freeLessons = new List <FreeLessonsTimespan>(); foreach (var adapter in adapters) { if (adapter.Use(settings)) { var files = FilesystemUtils.GetFiles(settings.Path, adapter.SearchPattern); logger.LogDebug($"Found {files.Length} file(s) matching '{adapter.SearchPattern}'."); foreach (var file in files) { logger.LogDebug($"Found file {file}."); var contents = await fileReader.GetContentsAsync(file, Encoding.GetEncoding(settings.Encoding)); logger.LogDebug($"File {file} was read. Parsing substitutions."); var result = await adapter.GetSubstitutionsAsync(contents, settings); logger.LogDebug($"Got {result.Substitutions.Count} substitution(s)."); logger.LogDebug($"Got {result.Absences.Count} absence(s)."); logger.LogDebug($"Got {result.Infotexts.Count} infotext(s)."); substitutions.AddRange(result.Substitutions); infotexts.AddRange(result.Infotexts); absences.AddRange(result.Absences); freeLessons.AddRange(result.FreeLessons); } await ReplaceSubstitutionTypesAsync(substitutions); substitutions = await RemoveSubsitutionsWithRemovableTypeAsync(substitutions); } } return(new EventBase[] { new SubstitutionEvent(substitutions), new AbsenceEvent(absences), new InfotextEvent(infotexts), new FreeLessonEvent(freeLessons) }); }