Ejemplo n.º 1
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);
                    }
                }
            }
        }
Ejemplo n.º 2
0
 public UnusedCourseSearchManager(ICourseSearchQueueBLL courseSearchQueueBll, IUnusedCourseBLL unusedCourseBll, ISendEmailBLL sendEmailBll)
 {
     this.courseSearchQueueBll = courseSearchQueueBll;
     this.unusedCourseBll      = unusedCourseBll;
     this.sendEmailBll         = sendEmailBll;
 }
Ejemplo n.º 3
0
        static void ProcessCoursesPendingReactivation(IUnusedCourseBLL unusedCourseBll, ISendEmailBLL sendEmailBll)
        {
            var coursesPendingReactivation = unusedCourseBll.GetAll().Where(x => x.Status == CourseStatus.PendingReactivation).ToList();

            foreach (var unusedCourse in coursesPendingReactivation)
            {
                var form = new MultipartFormDataContent();
                form.Add(new StringContent(unusedCourse.CourseId), "course_ids[]");
                form.Add(new StringContent("undelete"), "event");

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

                if (result.IsSuccessStatusCode)
                {
                    // TODO: This call return an asyncronous task url internal to Canvas.  Need to get the url and wait for it to be completed
                    unusedCourse.Status = CourseStatus.Active;
                    unusedCourseBll.Update(unusedCourse);
                }
            }
        }