コード例 #1
0
        public override void Initialize(ISchildTuitionResolver inputSetting)
        {
            if (cacheCreatedAt != null)
            {
                var cacheAge = DateTime.Now - cacheCreatedAt.Value;

                if (cacheAge.TotalMinutes < CacheLifetimeInMinutes)
                {
                    // Use cache instead of new query
                    return;
                }
            }

            gradeStudyGroupsCache.Clear();
            tuitionsCache.Clear();

            logger.LogDebug("Initialize SchILD exporter...");

            try
            {
                var schildExporter = schildAdapter.GetExporter();
                var schoolInfoTask = schildExporter.GetSchoolInfoAsync();
                schoolInfoTask.Wait();
                var schoolInfo = schoolInfoTask.Result;

                logger.LogDebug($"Current academic year: {schoolInfo.CurrentYear} - section {schoolInfo.CurrentSection}");

                var tuitions = schildAdapter.LoadTuitions(schoolInfo.CurrentYear.Value, schoolInfo.CurrentSection.Value);

                foreach (var kv in tuitions)
                {
                    tuitionsCache.Add(kv.Key, kv.Value);
                }

                var studyGroups = schildAdapter.GetGradeStudyGroups(schoolInfo.CurrentYear.Value, schoolInfo.CurrentSection.Value);

                foreach (var kv in studyGroups)
                {
                    gradeStudyGroupsCache.Add(kv.Key, kv.Value);
                }

                cacheCreatedAt = DateTime.Now;
            }
            catch (Exception e)
            {
                logger.LogError(e, "Failed to load tuitions from SchILD database. Study group resolving will fail.");
            }
        }
コード例 #2
0
        public void Initialize(Settings.ExamWriters.IExamWritersResolver inputSetting)
        {
            settings = inputSetting as ISchildExamWritersResolver;

            var exporter = schildAdapter.GetExporter();
            var grades   = settings.Rules.SelectMany(x => x.Grades).Distinct().ToList();

            tuitionCache.Clear();

            logger.LogDebug($"Getting study groups from SchILD...");

            foreach (var section in settings.Sections)
            {
                var key = $"{section.SchoolYear}-{section.Section}";
                logger.LogDebug($"Getting study groups from SchILD ({section.SchoolYear}/{section.Section})...");
                var tuitions = schildAdapter.LoadTuitions(section.SchoolYear, section.Section);

                tuitionCache.Add(key, new List <TuitionStudyGroupTuple>());

                foreach (var kv in tuitions)
                {
                    if (grades.Contains(kv.Key))
                    {
                        tuitionCache[key].AddRange(kv.Value);
                    }
                }
            }

            logger.LogDebug("Getting students from SchILD...");
            var studentTask = schildAdapter.GetExporter().GetStudentsAsync();

            studentTask.Wait();

            foreach (var student in studentTask.Result)
            {
                if (!studentCache.ContainsKey(student.Id.ToString()))
                {
                    studentCache.Add(student.Id.ToString(), student);
                }
            }
        }