コード例 #1
0
 public HomeController(IUnusedCourseBLL deletedCourseBll, ICourseSearchQueueBLL courseSearchQueueBll)
 {
     this.unusedCourseBLL      = deletedCourseBll;
     this.courseSearchQueueBll = courseSearchQueueBll;
 }
コード例 #2
0
 public UnusedCourseSearchManager(ICourseSearchQueueBLL courseSearchQueueBll, IUnusedCourseBLL unusedCourseBll, ISendEmailBLL sendEmailBll)
 {
     this.courseSearchQueueBll = courseSearchQueueBll;
     this.unusedCourseBll      = unusedCourseBll;
     this.sendEmailBll         = sendEmailBll;
 }
コード例 #3
0
 public HomeController(ICourseSearchQueueBLL courseSearchQueueBll, IHttpClientFactory httpClientFactory, IOptions <AppSettings> appSettings)
 {
     this.courseSearchQueueBll = courseSearchQueueBll;
     this.canvasRedshiftClient = httpClientFactory.CreateClient(HttpClientNames.CanvasRedshiftClient);
     this.appSettings          = appSettings.Value;
 }
コード例 #4
0
        static void ProcessCoursesPendingDeletion(IUnusedCourseBLL unusedCourseBll, ICourseSearchQueueBLL courseSearchQueueBll, ISendEmailBLL sendEmailBll)
        {
            DateTime deleteStartTimeStamp = DateTime.Now;

            var coursesPendingDeletion = unusedCourseBll.GetAll().Where(x => x.Status == CourseStatus.PendingDeletion).ToList();

            if (coursesPendingDeletion.Any())
            {
                var coursesByAccount = coursesPendingDeletion.GroupBy(x => x.AccountId);
                var coursesDeleted   = 0;
                var errors           = new List <string>();

                foreach (var courseList in coursesByAccount)
                {
                    var courseChunks = courseList.ToList().ChunkBy(MAXCOURSESTHATCANBEMODIFIED);
                    foreach (var courseChunk in courseChunks)
                    {
                        var courseIds = courseChunk.Select(x => x.CourseId);

                        var form = new MultipartFormDataContent();
                        foreach (var courseId in courseIds)
                        {
                            form.Add(new StringContent(courseId), "course_ids[]");
                        }
                        form.Add(new StringContent("delete"), "event");

                        var result = client.PutAsync($"accounts/{courseList.Key}/courses", form).GetAwaiter().GetResult();

                        if (result.IsSuccessStatusCode)
                        {
                            coursesDeleted += courseChunk.Count;

                            foreach (var unusedCourse in courseChunk)
                            {
                                unusedCourse.Status = CourseStatus.Deleted;
                            }

                            unusedCourseBll.UpdateRange(courseChunk);
                        }
                        else
                        {
                            string error = $"{(int)result.StatusCode}: {result.ReasonPhrase}. {result.RequestMessage.RequestUri}";
                            if (!errors.Contains(error))
                            {
                                errors.Add(error);
                            }
                        }
                    }
                }

                var deleteEndTimeStamp = DateTime.Now;

                var courseSearchQueueIds = coursesPendingDeletion.Select(x => x.CourseSearchQueueId).Distinct().ToList();

                foreach (var courseSearchQueueId in courseSearchQueueIds)
                {
                    // Send email if DELETE ALL was requested
                    var courseSearchQueue = courseSearchQueueBll.Get(courseSearchQueueId);
                    if (courseSearchQueue.DeleteAllRequested)
                    {
                        sendEmailBll.SendBatchDeleteCoursesCompletedEmailAsync(deleteStartTimeStamp,
                                                                               deleteEndTimeStamp, coursesDeleted, errors,
                                                                               courseSearchQueue.SubmittedByEmail).GetAwaiter().GetResult();

                        courseSearchQueue.DeleteAllRequested = false;
                        courseSearchQueueBll.Update(courseSearchQueue);
                    }
                }
            }
        }
コード例 #5
0
 public ReportController(ICourseSearchQueueBLL courseSearchQueueBll, IUnusedCourseBLL unusedCourseBll)
 {
     this.courseSearchQueueBll = courseSearchQueueBll;
     this.unusedCourseBll      = unusedCourseBll;
 }