public void RunQueuedUpdates() { try { var coursesPendingDeletion = unusedCourseBll.GetAll().Where(x => x.Status == CourseStatus.PendingDeletion).ToList(); if (coursesPendingDeletion.Any()) { var coursesClient = new CoursesClient(); foreach (var course in coursesPendingDeletion) { if (coursesClient.DeleteCourse(course.CourseId).Result) { course.Status = CourseStatus.Deleted; unusedCourseBll.Update(course); } } } } catch (Exception ex) { FileLogger.Log("RunQueuedUpdates :: " + ex.ToString()); } }
public static async Task <List <ICourseLink> > ExtractCourses() { await CoursesClient.LazyRefresh(); var coursesPageText = await CoursesClient.SessionClient.GetStringAsyncHttp(CoursesProfileAllCoursesUrl); CoursesClient.FindSessKey(coursesPageText); var doc = new HtmlDocument(); doc.LoadHtml(coursesPageText); var coursesLinksNodes = doc.DocumentNode.SelectNodes(XPathFilterProfileCoursesLinks); var coursesLinksTasks = coursesLinksNodes .Where(l => Regex.IsMatch(l.InnerText, CurrentSemesterCourseLongFormNameRegex)) .Select(async(l, _) => { var longName = ExtractName(l); var url = ExtractHref(l); string shortName; using (var courseHtml = await CoursesClient.SessionClient.GetStreamAsyncHttp(url)) { shortName = LazyHtmlParser.FindShortNameInHtml(courseHtml); shortName = CleanName(shortName, true); } return(new CourseLink($"{shortName,-8}{longName}", url)); }); var coursesLinks = await Task.WhenAll(coursesLinksTasks); SharedVars.Courses = coursesLinks.ToList <ICourseLink>(); return(SharedVars.Courses); }
public static async Task <int> ExtractSemestersCount() { await CoursesClient.LazyRefresh(); var profileHtml = await CoursesClient.SessionClient.GetStringAsyncHttp(CoursesProfileAllCoursesUrl); var doc = new HtmlDocument(); doc.LoadHtml(profileHtml); var coursesLinks = doc.DocumentNode.SelectNodes(XPathFilterProfileCoursesLinks); var semestersCount = SemesterCoursesLongFormNameRegex .Reverse() .Select(pair => new { Number = pair.Key, Courses = coursesLinks .Where(node => Regex.IsMatch(node.InnerText, pair.Value)) }) .First(semester => semester.Courses.Any()) .Number; return(semestersCount); }
static void Main(string[] args) { CoursesClient CC = new CoursesClient("NetTcpBinding_ICourses"); for (int i = 0; i < 1; i++) { Console.WriteLine("Enter record:"); CC.AddToCourses(new Course() { CourseId = int.Parse(Console.ReadLine()), CourseName = Console.ReadLine() }); } GetCourses(CC); CC.Close(); CC = new CoursesClient("NetTcpBinding_ICourses"); for (int i = 0; i < 1; i++) { Console.WriteLine("Enter record:"); CC.AddToCourses(new Course() { CourseId = int.Parse(Console.ReadLine()), CourseName = Console.ReadLine() }); } GetCourses(CC); Console.ReadLine(); }
private static void GetCourses(CoursesClient CC) { Console.WriteLine(); foreach (var item in CC.ListCourses()) { Console.WriteLine("CourseId:{0} CourseName:{1}", item.CourseId, item.CourseName); } }
async Task LoadCourse() { var departmentsTask = DepartmentsClient.Get(); var courseTask = CoursesClient.GetDetails(CourseID); Departments = await departmentsTask; Course = await courseTask; }
public static async Task Init() { Console.OutputEncoding = Encoding.UTF8; await CoursesClient.LazyRefresh(); SharedVars.CurrentSemesterNumber = await CoursesExtractor.ExtractSemestersCount(); }
private static void GetCourses(CoursesClient coursesClient) { Console.WriteLine(); foreach (var course in coursesClient.ListCourse()) { Console.WriteLine($"CourseId: {course.CourseId}, CourseName: {course.CourseName}"); } }
private async Task ExtractExternalUrlAndTitle() { await CoursesClient.LazyRefresh(); using (var html = await CoursesClient.SessionClient.GetStreamAsyncHttp(Url)) { var title = LazyHtmlParser.FindTitleInHtml(html); Title = title; IsTitleExtracted = true; } }
public async Task <ActionResult> Index(HomeViewModel viewModel) { if (ModelState.IsValid) { var courseIds = new List <string>(); using (var reader = new StreamReader(Request.Files["CoursesDataFile"].InputStream)) { while (!reader.EndOfStream) { var line = await reader.ReadLineAsync(); Regex validator = new Regex(@"^[0-9]+$"); var id = line.Split(',')[0]; if (!validator.IsMatch(id)) { ModelState.AddModelError(nameof(HomeViewModel.CoursesDataFile), "There was a problem while reading the input file. Please make sure that the file chosen contains a comma delimited list and has an extension of csv."); return(View(viewModel)); } courseIds.Add(id); } } var client = new CoursesClient(); var accountClient = new AccountsClient(); try { var account = accountClient.Get <Account>(viewModel.CanvasAccountId); foreach (var id in courseIds) { await client.MoveCourse(id, viewModel.CanvasAccountId); } } catch (Exception ex) { ModelState.AddModelError(nameof(viewModel.CanvasAccountId), ex); return(View(viewModel)); } viewModel.Notify = true; } return(View(viewModel)); }
static void Main(string[] args) { //var coursesClient = new CoursesClient("BasicHttpBinding_ICourses"); // Not support session var coursesClient = new CoursesClient("NetTcpBinding_ICourses"); //support session //coursesClient.AddToCourse(new Course{CourseId = 1, CourseName = "Asp.Net"}); //coursesClient.AddToCourse(new Course{CourseId = 2, CourseName = "Ado.Net"}); //coursesClient.AddToCourse(new Course{CourseId = 2, CourseName = "C#.Net" }); //GetCourses(coursesClient); //Enumerable.Range(0, 3).ToList().ForEach(i => //{ // Console.WriteLine($"Enter Record {i + 1}"); // coursesClient.AddToCourse(new Course(){CourseId = int.Parse(Console.ReadLine()), CourseName = Console.ReadLine()}); //}); //GetCourses(coursesClient); //coursesClient.AddToCourse(new Course { CourseId = 1, CourseName = "Asp.Net" }); //coursesClient.AddToCourse(new Course { CourseId = 2, CourseName = "Ado.Net" }); //coursesClient.AddToCourse(new Course { CourseId = 2, CourseName = "C#.Net" }); //Thread.Sleep(5000); //GetCourses(coursesClient); coursesClient.AddToCourse(new Course { CourseId = 1, CourseName = "Asp.Net" }); GetCourses(coursesClient); // 세션이 끝나면 객체를 새로 만들어줘야 한다. coursesClient = new CoursesClient("NetTcpBinding_ICourses"); //support session coursesClient.AddToCourse(new Course { CourseId = 1, CourseName = "Asp.Net" }); GetCourses(coursesClient); Console.ReadKey(); }
protected override async Task GetAndSaveFile(string filename) { await CoursesClient.LazyRefresh(); ReportProgress(0, 1024); var html = await ExtractMainHtml(); ReportProgress(html.Length / 2.0, html.Length); var pdf = GeneratePdf(html); ReportProgress(pdf.Length * 0.9, pdf.Length); File.WriteAllBytes(filename, pdf); ReportProgress(pdf.Length, pdf.Length); }
static void Main(string[] args) { CoursesClient CC = new CoursesClient("NetTcpBinding_ICourses"); CC.AddToCourses(new Course() { CourseId = int.Parse(Console.ReadLine()), CourseName = Console.ReadLine() }); GetCourses(CC); CC = new CoursesClient("NetTcpBinding_ICourses"); CC.AddToCourses(new Course() { CourseId = int.Parse(Console.ReadLine()), CourseName = Console.ReadLine() }); GetCourses(CC); Console.ReadLine(); }
private async Task ExtractExternalUrlAndTitle() { await CoursesClient.LazyRefresh(); // Go to url as clicked on courses using (var coursesResponse = await CoursesClient.SessionClient.GetHeadersAsyncHttp(Url)) { var externalResponse = coursesResponse; // if redirected to courses, grab url workaround, get title from there if (coursesResponse.RequestMessage.RequestUri.Host == CoursesClient.SessionClient.BaseAddress.Host) { using (var coursesHtml = await coursesResponse.Content.ReadAsStreamAsync()) { var urlWorkaround = LazyHtmlParser.FindUrlWorkaroundInHtml(coursesHtml); ExternalUrl = urlWorkaround; // Go to url as clicked on workaround url externalResponse = await CoursesClient.SessionClient.GetHeadersAsyncHttp(urlWorkaround); } } // else redirected to external link, just save it else { var url = coursesResponse.RequestMessage.RequestUri.ToString(); ExternalUrl = url; } using (externalResponse) { using (var externalHtml = await externalResponse.Content.ReadAsStreamAsync()) { var title = LazyHtmlParser.FindTitleInHtml(externalHtml); Title = title; AreExternalUrlAndTitleExtracted = true; } } } }
protected override async Task GetAndSaveFile(string filename) { await CoursesClient.LazyRefresh(); CoursesClient.AddEvent(DownloadProgressTracker); // we request headers because otherwise the file is first put into memory so we lose the whole point of streams // since we are using ReadAsStreamAsync, nothing is loaded into memory // although we can't use HeadersResponse from previously because that way we can't track progress using (var file = await CoursesClient.SessionClient.GetHeadersAsyncHttp(DownloadUrl)) { using (var fileStream = File.Create(filename)) { using (var content = await file.Content.ReadAsStreamAsync()) { await content.CopyToAsync(fileStream); await fileStream.FlushAsync(); } } } CoursesClient.RemoveEvent(DownloadProgressTracker); }
public async Task Download(string[] middlePath) { await CoursesClient.LazyRefresh(); await GetNameFromUrlNow(); string filename; switch (SharedVars.NamingMethod) { case NamingMethod.CoursesName: filename = FileFromCourses.FileNameAndExtensionOnly; break; case NamingMethod.UrlName: filename = FileFromUrl.FileNameAndExtensionOnly; break; default: filename = FileFromUrl.FileNameAndExtensionOnly; break; } var filepath = FileNameHelpers.FullyPrepareFile(filename, middlePath); FileFromUrl.FullPathAndFileAndExtension = FileFromCourses.FullPathAndFileAndExtension = filepath; var fileInfo = new FileInfo(filepath); if (!fileInfo.Directory?.Exists ?? false) { fileInfo.Directory.Create(); } await GetAndSaveFile(filepath); }
public static void Dispose() { CoursesClient.Dispose(); }
public HomeController(ILogger <HomeController> logger, CoursesClient client) { _logger = logger; this.client = client; }
public async Task OnSaveClick() { var updated = await CoursesClient.Update(Course); UriHelper.NavigateTo("/courses"); }
public static async Task <List <ISection> > ExtractSectionsForCourse(ICourseLink courseLink) { await CoursesClient.LazyRefresh(); var coursePageText = await CoursesClient.SessionClient.GetStringAsyncHttp(courseLink.Url); CoursesClient.FindSessKey(coursePageText); var doc = new HtmlDocument(); doc.LoadHtml(coursePageText); var headersLinks = doc.DocumentNode.SelectNodes(XPathFilterLinksHeadersFolders); SharedVars.Sections = new List <ISection>(); var currentSection = new Section(); SharedVars.Sections.Add(currentSection); foreach (var headerLink in headersLinks) { var itemType = TryGetItemType(headerLink); string innerText = null; string href = null; if (itemType != ItemType.Header) { innerText = headerLink.Descendants().First(d => d.Name == "#text").InnerText.DecodeHtml(); href = headerLink.Attributes.First(l => l.Name == "href").Value; } switch (itemType) { case ItemType.Header: var headerName = headerLink.InnerText.DecodeHtml(); var headerTag = headerLink.OriginalName; var headerId = FindIdFromAncestors(headerLink); currentSection = new Section(new Header(headerName, headerTag, headerId), courseLink); SharedVars.Sections.Add(currentSection); break; case ItemType.File: currentSection.Links.Add(new FileLink(innerText, href, currentSection)); break; case ItemType.Folder: currentSection.Links.Add(new FolderLink(innerText, href, currentSection)); break; case ItemType.Url: currentSection.Links.Add(new ExternalLink(innerText, href, currentSection)); break; case ItemType.Page: currentSection.Links.Add(new PageLink(innerText, href, currentSection)); break; default: throw new ArgumentOutOfRangeException(); } } SharedVars.Sections = SharedVars.Sections.Where(s => s.Links.Any()).ToList(); return(SharedVars.Sections); }
/// <summary> /// A Course Shell is an unpublished course that has no content or activity /// </summary> private bool IsUnusedCourse(Course course) { var client = new CoursesClient(); var courseWithSyllabus = client.GetWithSyllabusBody(course.Id).Result; if (!string.IsNullOrWhiteSpace(courseWithSyllabus.SyllabusBody)) { return(false); } var enrollments = client.GetEnrollments(course.Id).Result; if (enrollments.Any(x => x.LastActivityAt != null)) { return(false); } var assignments = client.GetCourseAssignments(course.Id).Result; if (assignments.Any()) { return(false); } var modules = client.GetCourseModules(course.Id).Result; if (modules.Any()) { return(false); } var files = client.GetCourseFiles(course.Id).Result; if (files.Any()) { return(false); } var pages = client.GetCoursePages(course.Id).Result; if (pages.Any()) { return(false); } var discussions = client.GetCourseDiscussions(course.Id).Result; if (discussions.Any()) { return(false); } var quizzes = client.GetCourseQuizzes(course.Id).Result; if (quizzes.Any()) { return(false); } return(true); }
private static async Task HandleLogOutAction() { CoursesClient.Dispose(); await CoursesDownloaderManual.Init(); }
private static void HandleCloseAction() { CoursesClient.Dispose(); }
private static void HandleTempUserLogOutAction() { CoursesClient.TempLogOutUser(); }
private static async Task HandleTempUserLogInAction() { await CoursesClient.TempLogInUser(); await CoursesDownloaderManual.Init(); }
async Task LoadCourses() { Courses = await CoursesClient.Get(); }