/// <summary> /// Initializes a new instance of the VGScrollImage class. /// Clone Constructor. Creates new <see cref="VGImage"/> that is /// identical to the given <see cref="VGImage"/>. /// </summary> /// <param name="cloneImage"><see cref="VGImage"/> to clone</param> private VGScrollImage(VGScrollImage cloneImage) : base( cloneImage.ShapeDrawAction, cloneImage.Pen, cloneImage.Brush, cloneImage.Font, cloneImage.FontColor, cloneImage.Filename, cloneImage.Filepath, cloneImage.Layout, cloneImage.Alpha, cloneImage.Canvas, cloneImage.StyleGroup, cloneImage.Name, cloneImage.ElementGroup, false) { }
/// <summary> /// The web browser_ navigating lock. /// </summary> /// <param name="sender"> /// The sender. /// </param> /// <param name="e"> /// The e. /// </param> private void WebBrowserNavigatingLock(object sender, WebBrowserNavigatingEventArgs e) { try { // Get WebBrowser object var browser = sender as WebBrowser; // Check if website has frames which leads to multiple // calls to navigated for each frame if (this.isWebbrowserClicked) { // Reset flag to avoid multiple trial notifications on frame loading this.isWebbrowserClicked = false; // Disable navigation, if max browse depth is reached this.numberOfTimesNavigated++; if (this.numberOfTimesNavigated >= this.maxBrowseDepth) { if (browser != null) { browser.AllowNavigation = false; } } // Get slideshow var documentsSlideshow = Document.ActiveDocument.ExperimentSettings.SlideShow; // Make screenshot of newly navigated web page in // separate thread, if it is not already there. var screenshotFilename = BrowserDialog.GetFilenameFromUrl(e.Url); // WebsiteScreenshot.Instance.ScreenshotFilename = screenshotFilename; if (!this.currentBrowserTreeNode.UrlToID.ContainsKey(screenshotFilename)) { // This webpage has never been visited before, so get a new id // and create slide and slideshownode for the slideshow var newTrialId = Convert.ToInt32(documentsSlideshow.GetUnusedNodeID()); this.currentBrowserTreeNode.UrlToID.Add(screenshotFilename, newTrialId); // Create new trial var newName = Path.GetFileNameWithoutExtension(screenshotFilename); var newWebpageTrial = new Trial(newName, newTrialId); // Create VGScrollImageSlide var newWebpageSlide = (Slide)this.shownSlideContainer.Slide.Clone(); newWebpageSlide.Modified = true; if (!newWebpageSlide.IsThumbNull) { newWebpageSlide.Thumb.Dispose(); newWebpageSlide.Thumb = null; } newWebpageSlide.Name = newName; newWebpageSlide.ActiveXStimuli.Clear(); newWebpageSlide.VGStimuli.Clear(); var baseUrlScreenshot = new VGScrollImage( ShapeDrawAction.None, Pens.Transparent, Brushes.Black, SystemFonts.DefaultFont, Color.Black, Path.GetFileName(screenshotFilename), Document.ActiveDocument.ExperimentSettings.SlideResourcesPath, ImageLayout.None, 1f, Document.ActiveDocument.PresentationSize, VGStyleGroup.None, newWebpageSlide.Name, string.Empty); newWebpageSlide.VGStimuli.Add(baseUrlScreenshot); // Finish creating new trial newWebpageTrial.Add(newWebpageSlide); // Update trial lists with new trial TrialsIncludingNavigatedWebpages.Add(newWebpageTrial); // Now update slideshow with new trial // Create node var slideNode = new SlideshowTreeNode(newName); slideNode.Name = newTrialId.ToString(CultureInfo.InvariantCulture); slideNode.Slide = newWebpageSlide; // Add node to slideshow at browser tree node subgroup this.currentBrowserTreeNode.Nodes.Add(slideNode); documentsSlideshow.IsModified = true; Document.ActiveDocument.Modified = true; } if (this.getTimeMethod != null) { this.getTimeMethod(); } // Get the corrent trial ID // use the existing, if we have already a screenshot of this url var trialID = this.currentBrowserTreeNode.UrlToID[screenshotFilename]; var trialIndex = TrialsIncludingNavigatedWebpages.GetIndexOfTrialByID(trialID); var trial = TrialsIncludingNavigatedWebpages[trialIndex]; // Reset slide counter // but do not increase trial counter, otherwise // we would have wrong counting in CheckForSlideChange // instead note the trials added this.slideCounter = 0; this.trialsAdded++; // Send counter changed event to increase trial sequence // and update recorders control view this.OnCounterChanged(new CounterChangedEventArgs(trialID, this.slideCounter)); var webcamTime = this.userCamera != null ? this.userCamera.GetCurrentTime() : -1; var navigatedCondition = new NavigatedStopCondition(e.Url); this.OnTrialChanged( new TrialChangedEventArgs( this.shownSlideContainer.Trial, trial, navigatedCondition, "Webpage", this.trialCounter + this.trialsAdded, webcamTime)); // Update shown slide container this.shownSlideContainer.Trial = trial; this.shownSlideContainer.Slide = trial[0]; var fullFile = Path.Combine(Document.ActiveDocument.ExperimentSettings.SlideResourcesPath, screenshotFilename); if (!File.Exists(fullFile)) { // Create screenshot on Document completed event using // the filename stated above var navigateThread = new Thread(this.NavigateMirror); navigateThread.SetApartmentState(ApartmentState.STA); var parameters = new object[2]; parameters[0] = e; parameters[1] = fullFile; navigateThread.Start(parameters); } } } catch (Exception ex) { ExceptionMethods.HandleException(ex); } }
/// <summary> /// Initializes a new instance of the VGScrollImage class. /// Clone Constructor. Creates new <see cref="VGImage"/> that is /// identical to the given <see cref="VGImage"/>. /// </summary> /// <param name="cloneImage"><see cref="VGImage"/> to clone</param> private VGScrollImage(VGScrollImage cloneImage) : base( cloneImage.ShapeDrawAction, cloneImage.Pen, cloneImage.Brush, cloneImage.Font, cloneImage.FontColor, cloneImage.Filename, cloneImage.Filepath, cloneImage.Layout, cloneImage.Alpha, cloneImage.Canvas, cloneImage.StyleGroup, cloneImage.Name, cloneImage.ElementGroup, false) { }
/// <summary> /// Creates a new <see cref="Slide"/> with the /// properties defined on this dialog and creates a thumb for it. /// </summary> /// <returns>The new <see cref="Slide"/> to be added to the slideshow.</returns> private BrowserTreeNode GetBrowserSlide() { if (this.browserTreeNode == null) { this.browserTreeNode = new BrowserTreeNode(); } // Store category and name. this.browserTreeNode.Category = this.cbbCategory.Text; this.browserTreeNode.Text = this.txbName.Text; this.browserTreeNode.OriginURL = this.txbURL.Text; this.browserTreeNode.BrowseDepth = (int)this.nudBrowseDepth.Value; // Add standard stop condition if none is specified. if (this.lsbStopConditions.Items.Count == 0) { this.lsbStopConditions.Items.Add(new TimeStopCondition(SlideDesignModule.SLIDEDURATIONINS * 1000)); } Slide baseURLSlide = new Slide(); baseURLSlide.Category = this.cbbCategory.Text; baseURLSlide.Modified = true; baseURLSlide.Name = this.txbName.Text; baseURLSlide.PresentationSize = Document.ActiveDocument.PresentationSize; baseURLSlide.MouseCursorVisible = true; // Store Stop conditions foreach (StopCondition cond in this.lsbStopConditions.Items) { baseURLSlide.StopConditions.Add(cond); } Bitmap screenshot = WebsiteThumbnailGenerator.GetWebSiteScreenshot( this.txbURL.Text, Document.ActiveDocument.PresentationSize); string screenshotFilename = GetFilenameFromUrl(new Uri(this.txbURL.Text)); var filename = Path.Combine(Document.ActiveDocument.ExperimentSettings.SlideResourcesPath, screenshotFilename); screenshot.Save(filename, System.Drawing.Imaging.ImageFormat.Png); VGScrollImage baseURLScreenshot = new VGScrollImage( ShapeDrawAction.None, Pens.Transparent, Brushes.Black, SystemFonts.DefaultFont, Color.Black, Path.GetFileName(screenshotFilename), Document.ActiveDocument.ExperimentSettings.SlideResourcesPath, ImageLayout.None, 1f, Document.ActiveDocument.PresentationSize, VGStyleGroup.None, baseURLSlide.Name, string.Empty); baseURLSlide.VGStimuli.Add(baseURLScreenshot); this.browserTreeNode.Slide = baseURLSlide; // HtmlElementCollection es = webBrowser1.Document.GetElementsByTagName("a"); // if (es != null && es.Count != 0) // { // HtmlElement ele = es[0]; // //This line is optional, it only visually scolls the first link element into view // ele.ScrollIntoView(true); // ele.Focus(); // SendKeys.Send("{ENTER}"); // } return this.browserTreeNode; }