public void Given_PdfFile_Expect_Extracted_Content() { string pdfFileToTest = Path.Combine(TestContext.CurrentContext.TestDirectory, TestHelper.PdfToTest); var mediaParser = new MediaParser(); var metaData = new Dictionary <string, string>(); string extractedText = mediaParser.ParseMediaText(pdfFileToTest, WriteToConsole, out metaData); Assert.IsTrue(extractedText.Contains("PowerShell")); }
public Entities(CoreTweet.Entities cEntities, CoreTweet.Entities cExtendedEntities) { var mediaList = MediaParser.Parse(cEntities, cExtendedEntities); HashTags = new List <HashtagEntity>(); Media = new List <MediaEntity>(); Urls = new List <UrlEntity>(); UserMentions = new List <UserMentionEntity>(); if (cEntities == null) { return; } foreach (var fMedia in mediaList) { Media.Add(new MediaEntity(fMedia, this)); } if (cEntities.HashTags != null) { foreach (var cHashTag in cEntities.HashTags) { HashTags.Add(new HashtagEntity(cHashTag)); } } if (cEntities.Urls != null) { foreach (var cUrl in cEntities.Urls) { Urls.Add(new UrlEntity(cUrl)); } } if (cEntities.UserMentions != null) { foreach (var cUserMention in cEntities.UserMentions) { UserMentions.Add(new UserMentionEntity(cUserMention)); } } if (cEntities.Media != null) { Urls.Add(new UrlEntity(cEntities.Media.First())); } else if (cExtendedEntities?.Media != null) { Urls.Add(new UrlEntity(cExtendedEntities.Media.First())); } }
public void SetMediaText(String value, Boolean throwOnError) { _media.Clear(); var media = MediaParser.Parse(value); if (media != null) { _media.AddRange(media); } else if (throwOnError) { throw new DomException(DomError.Syntax); } if (_media.Count == 0) { _media.Add(new CssMedium(CssKeywords.All, inverse: true, exclusive: false)); } }
public Entities(IEnumerable <Mastonet.Entities.Attachment> cAttachments, IEnumerable <Mastonet.Entities.Mention> cMentions, IEnumerable <Mastonet.Entities.Tag> cTags, IEnumerable <string> cUrls, string cContent) { var mediaList = MediaParser.Parse(cAttachments, cContent); HashTags = new List <HashtagEntity>(); Media = new List <MediaEntity>(); Urls = new List <UrlEntity>(); UserMentions = new List <UserMentionEntity>(); foreach (var fMedia in mediaList) { Media.Add(new MediaEntity(fMedia, this)); } if (cTags != null) { foreach (var cHashTag in cTags) { HashTags.Add(new HashtagEntity(cHashTag)); } } if (cUrls != null) { foreach (var cUrl in cUrls) { Urls.Add(new UrlEntity(cUrl)); } } if (cMentions != null) { foreach (var cUserMention in cMentions) { UserMentions.Add(new UserMentionEntity(cUserMention)); } } DeficientEntity = true; }
public void Given_Large_No_Of_Docs_Expect_No_Out_Of_Memory_Exceptions_Thrown(int noOfDocs) { string pdfFileToTest = Path.Combine(TestContext.CurrentContext.TestDirectory, TestHelper.PdfToTest); var totalTimer = new Stopwatch(); var mediaParser = new MediaParser(); var metaData = new Dictionary <string, string>(); totalTimer.Start(); for (int i = 0; i < noOfDocs; i++) { Assert.That(() => mediaParser.ParseMediaText(pdfFileToTest, WriteToConsole, out metaData), Throws.Nothing); } totalTimer.Stop(); Console.WriteLine(totalTimer.ElapsedTicks); totalTimer.DisposeIfDisposable(); }
{ //Object to review the current webpage for the user and hold the data. Is reset whenever they click the CreateReport button. public PageReviewer() { A11yReviewer = new A11yParser(); MediaReviewer = new MediaParser(); LinkReviewer = new LinkParser("None"); }
private void CreateReport(object sender, DoWorkEventArgs e) { try { this.Dispatcher.Invoke(() => { var template = MainWindow.AppWindow.Template; var control = (LoadingSpinner)template.FindName("spinner", MainWindow.AppWindow); control.Visibility = Visibility.Visible; }); var s = new System.Diagnostics.Stopwatch(); s.Start(); this.Dispatcher.Invoke(() => { Run run = new Run($"Generating Report\n") { Foreground = System.Windows.Media.Brushes.Cyan }; TerminalOutput.Inlines.Add(run); }); if (CanvasApi.CurrentDomain == null || CanvasApi.CurrentDomain == "") { this.Dispatcher.Invoke(() => { MessageBox.Show("No domain chosen."); }); return; } var text = this.Dispatcher.Invoke(() => { return(CourseID.Text); }); if (text == null) { this.Dispatcher.Invoke(() => { MessageBox.Show("No course ID found."); }); return; } CourseInfo course; bool directory = false; LinkParser ParseForLinks = null; //Need to declare this early as it is only set if it is a directory if (int.TryParse(text, out int id)) { //It is an ID, create course info with new id var this.Dispatcher.Invoke(() => { Run run = new Run($"Loading canvas information\n") { Foreground = System.Windows.Media.Brushes.Green }; TerminalOutput.Inlines.Add(run); }); course = new CourseInfo(id); } else { //Just send it in as a string path after running basic find replace on directory this.Dispatcher.Invoke(() => { Run run = new Run($"Running basic Find Replace on directory\n") { Foreground = System.Windows.Media.Brushes.Green }; TerminalOutput.Inlines.Add(run); }); var script = File.ReadAllText(MainWindow.panelOptions.PowershellScriptDir + @"\FindReplace.ps1"); script = "param($path, $backupDir)process{\n" + script + "\n}"; var posh = PowerShell.Create(); posh.AddScript(script).AddArgument(text).AddArgument(MainWindow.panelOptions.CourseBackupDir); posh.Invoke(); Dispatcher.Invoke(() => { Run run = new Run($"Find Replace on {text} finished.\nBack up can be found at {MainWindow.panelOptions.CourseBackupDir}\n") { Foreground = System.Windows.Media.Brushes.Cyan }; TerminalOutput.Inlines.Add(run); }); course = new CourseInfo(text); directory = true; ParseForLinks = new LinkParser(course.CourseIdOrPath); } this.Dispatcher.Invoke(() => { Run run = new Run($"Created course object\n") { Foreground = System.Windows.Media.Brushes.Green }; TerminalOutput.Inlines.Add(run); }); if (course == null || course.CourseCode == null) { e.Result = "Could not find course. ID was entered wrong or canvas needs time to cool down ...\n"; return; } this.Dispatcher.Invoke(() => { Run run = new Run($"Beginning to parse pages\n") { Foreground = System.Windows.Media.Brushes.Green }; TerminalOutput.Inlines.Add(run); }); A11yParser ParseForA11y = new A11yParser(); MediaParser ParseForMedia = new MediaParser(); var options = new ParallelOptions { MaxDegreeOfParallelism = -1 }; Parallel.ForEach(course.PageHtmlList, options, page => { ParseForA11y.ProcessContent(page); ParseForMedia.ProcessContent(page); if (directory) { ParseForLinks.ProcessContent(page); } }); this.Dispatcher.Invoke(() => { Run run = new Run($"Finished parsing pages, creating file\n") { Foreground = System.Windows.Media.Brushes.Green }; TerminalOutput.Inlines.Add(run); }); var file_name_extention = ((CanvasApi.CurrentDomain == "Directory") ? System.IO.Path.GetPathRoot(text) + "Drive" : CanvasApi.CurrentDomain).Replace(":\\", ""); CreateExcelReport GenReport = new CreateExcelReport(MainWindow.panelOptions.ReportPath + $"\\ARC_{course.CourseCode.Replace(",", "").Replace(":", "")}_{file_name_extention}.xlsx"); GenReport.CreateReport(ParseForA11y.Data, ParseForMedia.Data, ParseForLinks?.Data); s.Stop(); ParseForMedia.Chrome.Quit(); if (ParseForA11y.Data.Count() > int.Parse(File.ReadAllText(MainWindow.panelOptions.HighScorePath))) { File.WriteAllText(MainWindow.panelOptions.HighScorePath, ParseForA11y.Data.Count().ToString()); Dispatcher.Invoke(() => { HighScoreBox.Text = "HighScore: " + File.ReadAllText(MainWindow.panelOptions.HighScorePath); }); } MainWindow.a11YRepair.SetCourse(course); e.Result = $"Report generated.\nTime taken: {s.Elapsed.ToString(@"hh\:mm\:ss")} for {course.PageHtmlList.Count()} pages\n"; }catch (Exception ex) { e.Result = ex.Message + '\n' + ex.ToString() + '\n' + ex.StackTrace; } }