/// <summary>
        /// Determines whether two <see cref="NavigatedStopCondition"/> instances are equal.
        /// </summary>
        /// <param name="obj">The <see cref="Object"/> to compare with the current
        /// <see cref="NavigatedStopCondition"/>.</param>
        /// <returns><strong>True</strong> if the specified Object is equal
        /// to the current <see cref="KeyStopCondition"/>; otherwise, <strong>false</strong>. </returns>
        public override bool Equals(object obj)
        {
            if (obj is NavigatedStopCondition)
            {
                NavigatedStopCondition nsc = (NavigatedStopCondition)obj;
                if (nsc.link == this.Link)
                {
                    return(true);
                }
            }

            return(false);
        }
Beispiel #2
0
    /// <summary>
    /// Overridden <see cref="TypeConverter.ConvertFrom(ITypeDescriptorContext,CultureInfo,object)"/>
    /// Converts the given value to the type of this converter.</summary>
    /// <param name="context">An <see cref="ITypeDescriptorContext"/> that 
    /// provides a format context.</param>
    /// <param name="culture">The <see cref="CultureInfo"/> to use as the current culture.</param>
    /// <param name="value">The <see cref="Object"/> to convert.</param>
    /// <returns>An <strong>Object</strong> that represents the converted value.
    /// In this implementation that can be any <see cref="StopCondition"/></returns>
    public override object ConvertFrom(
      ITypeDescriptorContext context,
      CultureInfo culture,
      object value)
    {
      if (value is string)
      {
        try
        {
          if (value.ToString() == string.Empty)
          {
            return null;
          }

          // Old Ogama V1.1 versions supplied "None" for the Response when there was no response
          // Convert them to null.
          if (value.ToString() == "None")
          {
            return null;
          }

          // Old Ogama V1.1 versions supplied "Left" for a left mouse response
          if (value.ToString() == "Left")
          {
            return new MouseStopCondition(MouseButtons.Left, false, string.Empty, null, Point.Empty);
          }

          // Old Ogama V1.1 versions supplied "Right" for a right mouse response
          if (value.ToString() == "Right")
          {
            return new MouseStopCondition(MouseButtons.Right, false, string.Empty, null, Point.Empty);
          }

          string s = (string)value;
          int colon = s.IndexOf(':');
          int point = s.IndexOf('.');
          int target = s.IndexOf("target");
          int parenthesisOpen = s.IndexOf('(');
          int parenthesisClose = s.IndexOf(')');

          if (colon != -1)
          {
            StopCondition stopCondition = null;

            string type = s.Substring(0, colon).Trim();
            if (type == "Time")
            {
              string duration = s.Substring(colon + 1, s.Length - colon - 3).Trim();
              stopCondition = new TimeStopCondition(Convert.ToInt32(duration));
            }
            else if (type == "Key")
            {
              string key = s.Substring(colon + 1, point > -1 ? point - colon - 1 : s.Length - colon - 1).Trim();
              if (key == "any key")
              {
                stopCondition = new KeyStopCondition(Keys.None, false, null);
              }
              else
              {
                stopCondition = new KeyStopCondition((Keys)Enum.Parse(typeof(Keys), key), false, null);
              }
            }
            else if (type.Contains("Mouse"))
            {
              string button = MouseButtons.None.ToString();
              Point location = Point.Empty;

              // Older versions (Ogama 1.X) did not write the location in parenthesises.
              if (parenthesisOpen == -1)
              {
                button = s.Substring(colon + 1).Trim();
                int space = button.IndexOf(" ");
                if (space != -1)
                {
                  button = button.Substring(0, space);
                }

                // Do not set location because it is not known
              }
              else
              {
                button = s.Substring(colon + 1, parenthesisOpen - colon - 1).Trim();
                location = ObjectStringConverter.StringToPoint(s.Substring(parenthesisOpen, parenthesisClose - parenthesisOpen));
              }

              stopCondition = new MouseStopCondition(
                (MouseButtons)Enum.Parse(typeof(MouseButtons), button), false, string.Empty, null, location);

              if (button == "any mouse button")
              {
                ((MouseStopCondition)stopCondition).CanBeAnyInputOfThisType = true;
              }

              if (target != -1)
              {
                int colon2 = button.IndexOf(':');
                if (colon2 != -1)
                {
                  string targetName = button.Substring(colon2).Trim();
                  ((MouseStopCondition)stopCondition).Target = targetName;
                }
                else
                {
                  ((MouseStopCondition)stopCondition).Target = "Any";
                }
              }
            }
            else if (type == "http")
            {
              stopCondition = new NavigatedStopCondition(new Uri(s));
            }

            // Parse correct answer.
            if (s.Contains("."))
            {
              if (s.Contains("Correct"))
              {
                stopCondition.IsCorrectResponse = true;
              }
              else
              {
                stopCondition.IsCorrectResponse = false;
              }
            }

            // Parse trial ID of links.
            if (s.Contains("-"))
            {
              int sharp = s.IndexOf('#');
              if (sharp != -1)
              {
                string trialIDString = s.Substring(sharp).Trim();
                int trialID = 0;
                if (int.TryParse(trialIDString, out trialID))
                {
                  ((InputStopCondition)stopCondition).TrialID = trialID;
                }
              }
            }

            return stopCondition;
          }
          else if (value.ToString().Contains("Left"))
          {
            Point location = ObjectStringConverter.StringToPoint(s.Substring(parenthesisOpen, parenthesisClose - parenthesisOpen));
            MouseStopCondition stopCondition = new MouseStopCondition(MouseButtons.Left, false, string.Empty, null, location);
            return stopCondition;
          }
          else if (value.ToString().Contains("Right"))
          {
            Point location = ObjectStringConverter.StringToPoint(s.Substring(parenthesisOpen, parenthesisClose - parenthesisOpen));
            MouseStopCondition stopCondition = new MouseStopCondition(MouseButtons.Right, false, string.Empty, null, location);
            return stopCondition;
          }
        }
        catch
        {
          throw new ArgumentException(
              " '" + (string)value + "' could not be converted to StopCondition type.");
        }
      }

      return base.ConvertFrom(context, culture, value);
    }
Beispiel #3
0
    /// <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>
        /// Overridden <see cref="TypeConverter.ConvertFrom(ITypeDescriptorContext,CultureInfo,object)"/>
        /// Converts the given value to the type of this converter.</summary>
        /// <param name="context">An <see cref="ITypeDescriptorContext"/> that
        /// provides a format context.</param>
        /// <param name="culture">The <see cref="CultureInfo"/> to use as the current culture.</param>
        /// <param name="value">The <see cref="Object"/> to convert.</param>
        /// <returns>An <strong>Object</strong> that represents the converted value.
        /// In this implementation that can be any <see cref="StopCondition"/></returns>
        public override object ConvertFrom(
            ITypeDescriptorContext context,
            CultureInfo culture,
            object value)
        {
            if (value is string)
            {
                try
                {
                    if (value.ToString() == string.Empty)
                    {
                        return(null);
                    }

                    // Old Ogama V1.1 versions supplied "None" for the Response when there was no response
                    // Convert them to null.
                    if (value.ToString() == "None")
                    {
                        return(null);
                    }

                    // Old Ogama V1.1 versions supplied "Left" for a left mouse response
                    if (value.ToString() == "Left")
                    {
                        return(new MouseStopCondition(MouseButtons.Left, false, string.Empty, null, Point.Empty));
                    }

                    // Old Ogama V1.1 versions supplied "Right" for a right mouse response
                    if (value.ToString() == "Right")
                    {
                        return(new MouseStopCondition(MouseButtons.Right, false, string.Empty, null, Point.Empty));
                    }

                    string s                = (string)value;
                    int    colon            = s.IndexOf(':');
                    int    point            = s.IndexOf('.');
                    int    target           = s.IndexOf("target");
                    int    parenthesisOpen  = s.IndexOf('(');
                    int    parenthesisClose = s.IndexOf(')');

                    if (colon != -1)
                    {
                        StopCondition stopCondition = null;

                        string type = s.Substring(0, colon).Trim();
                        if (type == "Time")
                        {
                            string duration = s.Substring(colon + 1, s.Length - colon - 3).Trim();
                            stopCondition = new TimeStopCondition(Convert.ToInt32(duration));
                        }
                        else if (type == "Key")
                        {
                            string key = s.Substring(colon + 1, point > -1 ? point - colon - 1 : s.Length - colon - 1).Trim();
                            if (key == "any key")
                            {
                                stopCondition = new KeyStopCondition(Keys.None, false, null);
                            }
                            else
                            {
                                stopCondition = new KeyStopCondition((Keys)Enum.Parse(typeof(Keys), key), false, null);
                            }
                        }
                        else if (type.Contains("Mouse"))
                        {
                            string button   = MouseButtons.None.ToString();
                            Point  location = Point.Empty;

                            // Older versions (Ogama 1.X) did not write the location in parenthesises.
                            if (parenthesisOpen == -1)
                            {
                                button = s.Substring(colon + 1).Trim();
                                int space = button.IndexOf(" ");
                                if (space != -1)
                                {
                                    button = button.Substring(0, space);
                                }

                                // Do not set location because it is not known
                            }
                            else
                            {
                                button   = s.Substring(colon + 1, parenthesisOpen - colon - 1).Trim();
                                location = ObjectStringConverter.StringToPoint(s.Substring(parenthesisOpen, parenthesisClose - parenthesisOpen));
                            }

                            stopCondition = new MouseStopCondition(
                                (MouseButtons)Enum.Parse(typeof(MouseButtons), button), false, string.Empty, null, location);

                            if (button == "any mouse button")
                            {
                                ((MouseStopCondition)stopCondition).CanBeAnyInputOfThisType = true;
                            }

                            if (target != -1)
                            {
                                int colon2 = button.IndexOf(':');
                                if (colon2 != -1)
                                {
                                    string targetName = button.Substring(colon2).Trim();
                                    ((MouseStopCondition)stopCondition).Target = targetName;
                                }
                                else
                                {
                                    ((MouseStopCondition)stopCondition).Target = "Any";
                                }
                            }
                        }
                        else if (type == "http")
                        {
                            stopCondition = new NavigatedStopCondition(new Uri(s));
                        }

                        // Parse correct answer.
                        if (s.Contains("."))
                        {
                            if (s.Contains("Correct"))
                            {
                                stopCondition.IsCorrectResponse = true;
                            }
                            else
                            {
                                stopCondition.IsCorrectResponse = false;
                            }
                        }

                        // Parse trial ID of links.
                        if (s.Contains("-"))
                        {
                            int sharp = s.IndexOf('#');
                            if (sharp != -1)
                            {
                                string trialIDString = s.Substring(sharp).Trim();
                                int    trialID       = 0;
                                if (int.TryParse(trialIDString, out trialID))
                                {
                                    ((InputStopCondition)stopCondition).TrialID = trialID;
                                }
                            }
                        }

                        return(stopCondition);
                    }
                    else if (value.ToString().Contains("Left"))
                    {
                        Point location = ObjectStringConverter.StringToPoint(s.Substring(parenthesisOpen, parenthesisClose - parenthesisOpen));
                        MouseStopCondition stopCondition = new MouseStopCondition(MouseButtons.Left, false, string.Empty, null, location);
                        return(stopCondition);
                    }
                    else if (value.ToString().Contains("Right"))
                    {
                        Point location = ObjectStringConverter.StringToPoint(s.Substring(parenthesisOpen, parenthesisClose - parenthesisOpen));
                        MouseStopCondition stopCondition = new MouseStopCondition(MouseButtons.Right, false, string.Empty, null, location);
                        return(stopCondition);
                    }
                }
                catch
                {
                    throw new ArgumentException(
                              " '" + (string)value + "' could not be converted to StopCondition type.");
                }
            }

            return(base.ConvertFrom(context, culture, value));
        }
Beispiel #5
0
 /// <summary>
 /// Initializes a new instance of the NavigatedStopCondition class.
 /// Clone Constructor.
 /// </summary>
 /// <param name="cloneCondition">The <see cref="NavigatedStopCondition"/>
 /// to be cloned.</param>
 public NavigatedStopCondition(NavigatedStopCondition cloneCondition)
   : base(cloneCondition)
 {
   this.link = cloneCondition.Link;
 }
 /// <summary>
 /// Initializes a new instance of the NavigatedStopCondition class.
 /// Clone Constructor.
 /// </summary>
 /// <param name="cloneCondition">The <see cref="NavigatedStopCondition"/>
 /// to be cloned.</param>
 public NavigatedStopCondition(NavigatedStopCondition cloneCondition)
     : base(cloneCondition)
 {
     this.link = cloneCondition.Link;
 }