예제 #1
0
 internal static IEnumerable <string> ReadDatasetURLs(string dataset)
 {
     if (Datasets.Contains(dataset))
     {
         foreach (var line in FilesManager.ReadLinesFromEmbeddedFile("Dataset." + dataset + "_urls.csv"))
         {
             if (line.StartsWith('"'))
             {
                 yield return(line.Substring(1, line.Length - 2));
             }
             else
             {
                 yield return(line);
             }
         }
     }
 }
예제 #2
0
        public MainPage()
        {
            this.InitializeComponent();

            // Output folder link => clipboard
            var outputPath = FilesManager.GetOutputFolderPath();
            var cbData     = new DataPackage();

            cbData.SetText(outputPath);
            Clipboard.SetContent(cbData);

            // Initialize URLs list and navigate to next URL
            urlsToCapture = URLsSource.ReadDatasetURLs(DATASET).ToList();
            counter       = STARTCOUNTER - 1;
            if (STARTCOUNTER == 1)
            {
                counter = FilesManager.GetLastSavedCounter();
            }
            NavigateToNextUrl(this, null);
        }
예제 #3
0
 private async void CaptureScreenshotsAndNavigateToNextURL(object sender, RoutedEventArgs e)
 {
     do
     {
         try
         {
             await DoCaptureScreenshots();
             await DoNavigateToNextUrl();
         }
         catch (Exception ex)
         {
             if (INTERACTIVE)
             {
                 var md = new MessageDialog(ex.Message);
                 await md.ShowAsync();
             }
             else
             {
                 FilesManager.WriteTextToFileAsync(counter.ToString("D5") + "_error.log", ex.Message);
             }
         }
     }while (!INTERACTIVE);
 }
예제 #4
0
        private async Task DoCaptureScreenshots()
        {
            // Get unique file name for the current URL
            var fileName = await JavascriptInterop.GetUniqueFileNameFromURLAsync(webview);

            fileName = counter.ToString("D5") + "_" + fileName;

            if (currentErrorStatus != WebErrorStatus.Unknown)
            {
                var errorString  = Enum.GetName(typeof(WebErrorStatus), currentErrorStatus);
                var errorMessage = "Error navigating to " + currentURL + " => " + errorString;
                if (INTERACTIVE)
                {
                    var md = new MessageDialog(errorMessage);
                    await md.ShowAsync();
                }
                else
                {
                    FilesManager.WriteTextToFileAsync(fileName + "_error.log", errorMessage);
                }
            }
            else
            {
                // Get view and content dimensions
                var viewDimensions    = ScreenCapture.GetViewDimensions(webview);
                var contentDimensions = await ScreenCapture.GetContentDimensionsAsync(webview);

                // Resize view to content size
                ScreenCapture.SetViewDimensions(webview, contentDimensions);

                // Capture a screenshot
                await ScreenCapture.CreateAndSaveScreenshotAsync(webview, capture, null, warmup : true); // necessary because sometimes screenshot alters layout

                await ScreenCapture.CreateAndSaveScreenshotAsync(webview, capture, fileName);

                try
                {
                    // Capture a description of all chars/words/lines/blocks bounding boxes
                    // Draw all these bounding boxes on the screen
                    var pageElementsTree = await ScreenCapture.CreateAndSaveTextBoundingBoxes(webview, fileName);

                    // Capture a new screenshot
                    await ScreenCapture.CreateAndSaveScreenshotAsync(webview, captureBoxes, fileName, "boxes");
                }
                catch (Exception e)
                {
                    if (INTERACTIVE)
                    {
                        var md = new MessageDialog(e.Message);
                        await md.ShowAsync();
                    }
                    else
                    {
                        FilesManager.WriteTextToFileAsync(fileName + "_error.log", e.Message);
                    }
                }

                if (INTERACTIVE)
                {
                    // Reset view to its original size
                    ScreenCapture.SetViewDimensions(webview, viewDimensions);
                }
                else
                {
                    // Choose random width for next image
                    viewDimensions.width = ScreenCapture.GetRandowWidth();
                    ScreenCapture.SetViewDimensions(webview, viewDimensions);
                }
            }
        }
예제 #5
0
 static JavascriptInterop()
 {
     javascriptDefinitions = FilesManager.ReadStringFromEmbeddedFile(JS_FILE_PATH);
 }