Exemple #1
0
        private async Task ScanForDistrictsToProcess(ApplicationDbContext db)
        {
            var now = DateTime.UtcNow;

            // First find districts scheduled and mark them "FullProcess"
            var districts = await db.Districts.Where(d => d.NextProcessingTime.HasValue && d.NextProcessingTime <= now).ToListAsync();

            if (districts.Any())
            {
                foreach (var d in districts)
                {
                    d.ProcessingAction = ProcessingAction.FullProcess;
                }
                await db.SaveChangesAsync();
            }

            // Now find any district that has any ProcessingAction
            districts = await db.Districts.Where(d => d.ProcessingAction != ProcessingAction.None).ToListAsync();

            // walk the districts ready to be processed
            foreach (var district in districts)
            {
                var worker = new RosterProcessorWorker(district.DistrictId, Services, district.ProcessingAction);
                TaskQueue.QueueBackgroundWorkItem(async token => await worker.Invoke(token));

                // clear the action out and reset the next processing time so it won't get picked up again
                district.ProcessingAction = ProcessingAction.None;
                DistrictRepo.UpdateNextProcessingTime(district);
                district.Touch();
                await db.SaveChangesAsync();
            }
        }
        public async Task <IActionResult> DistrictEdit(District postedDistrict)
        {
            if (!ModelState.IsValid)
            {
                return(View(postedDistrict));
            }

            var district = await db.Districts.FindAsync(postedDistrict.DistrictId);

            if (postedDistrict.DailyProcessingTime.HasValue)
            {
                TimeSpan t   = postedDistrict.DailyProcessingTime.Value;
                TimeSpan min = new TimeSpan(0);
                TimeSpan max = new TimeSpan(hours: 24, minutes: 0, seconds: 0);
                if (t < min || t > max)
                {
                    ModelState.AddModelError(
                        key: nameof(postedDistrict.DailyProcessingTime),
                        errorMessage: "Invalid Daily Processing Time.  Please enter a time between 0:0:0 and 23:59:59.  Or clear to disable daily processing.");
                    return(View(postedDistrict));
                }
            }

            district.BasePath            = postedDistrict.BasePath;
            district.DailyProcessingTime = postedDistrict.DailyProcessingTime;
            district.EmailsEachProcess   = postedDistrict.EmailsEachProcess;
            district.EmailsOnChanges     = postedDistrict.EmailsOnChanges;
            district.IsApprovalRequired  = postedDistrict.IsApprovalRequired;
            district.LmsApiBaseUrl       = postedDistrict.LmsApiBaseUrl;
            district.Name     = postedDistrict.Name;
            district.TargetId = postedDistrict.TargetId;
            district.LmsApiAuthenticatorType      = postedDistrict.LmsApiAuthenticatorType;
            district.LmsApiAuthenticationJsonData = postedDistrict.LmsApiAuthenticationJsonData;

            district.LmsOrgEndPoint             = postedDistrict.LmsOrgEndPoint;
            district.LmsCourseEndPoint          = postedDistrict.LmsCourseEndPoint;
            district.LmsClassEndPoint           = postedDistrict.LmsClassEndPoint;
            district.LmsUserEndPoint            = postedDistrict.LmsUserEndPoint;
            district.LmsEnrollmentEndPoint      = postedDistrict.LmsEnrollmentEndPoint;
            district.LmsAcademicSessionEndPoint = postedDistrict.LmsAcademicSessionEndPoint;

            district.SyncEnrollment       = postedDistrict.SyncEnrollment;
            district.SyncAcademicSessions = postedDistrict.SyncAcademicSessions;
            district.SyncClasses          = postedDistrict.SyncClasses;
            district.SyncCourses          = postedDistrict.SyncCourses;
            district.SyncOrgs             = postedDistrict.SyncOrgs;
            district.SyncUsers            = postedDistrict.SyncUsers;

            DistrictRepo.UpdateNextProcessingTime(district);

            district.Touch();

            await db.SaveChangesAsync();

            return(RedirectToDistrict(district.DistrictId));
        }