Esempio n. 1
0
    /// <summary>
    /// The <see cref="PresenterModule.TrialChanged"/> event handler.
    ///   Stores the trial information into the database
    ///   and updates the live viewer with the new slide.
    /// </summary>
    /// <param name="sender">
    /// Source of the event.
    /// </param>
    /// <param name="e">
    /// A <see cref="TrialChangedEventArgs"/> with the event data.
    /// </param>
    private void ObjPresenterTrialChanged(object sender, TrialChangedEventArgs e)
    {
      // Set time critical values
      long currentTime = this.counterChangedTime;
      this.xScrollOffset = 0;
      this.yScrollOffset = 0;

      // If the last trial was a disabled trial (PreFixationSlide)
      // Only update start times
      if (e.FinishedTrial[e.FinishedTrial.Count - 1].IsDisabled)
      {
        // Update new trial
        this.currentTrialStarttime = currentTime - this.recordingStarttime;

        if (this.chbRecordAudio.Checked || this.chbRecordVideo.Checked)
        {
          this.currentTrialVideoStartTime = e.WebcamTime;
        }

        this.Invoke(this.delegateNewSlideAvailable);

        return;
      }

      if (e.FinishedTrial.Name != "DummyTrial")
      {
        // Update current trial
        this.precedingTrial = e.FinishedTrial;

        // When rawData list exceeds sample limit or this was the last trial
        // write the samples into the database
        if (this.rawDataLists[this.listCounter].Count > MINSAMPLESFORWRITINGTODATABASE || e.NextTrial == null)
        {
          // Stop recording if this was the last trial or cancelled
          if (e.NextTrial == null)
          {
            // Stop tracking
            this.currentTracker.Stop();

            // Give the presentation thread time to close.
            Application.DoEvents();
          }

          // switch to next raw data list for writing
          lock (this)
          {
            // Save copy to dataset table in new thread
            AsyncHelper.FireAndForget(
              new WaitCallback(StoreRecordsInDataSetTable),
              new DataToTable(this.rawDataLists[this.listCounter], this.subjectRawDataTable));

            // Clear list, cause its content was copied during creation of DataToTable
            this.rawDataLists[this.listCounter].Clear();

            this.listCounter++;
            if (this.listCounter == NUMWRITINGTHREADS)
            {
              this.listCounter = 0;
            }
          }
        }

        // Write new trial information
        var trialData = new TrialsData
                          {
                            SubjectName = this.currentTracker.Subject.SubjectName,
                            TrialName = this.precedingTrial.Name,
                            TrialSequence = this.trialSequenceCounter - 1,
                            TrialID = this.precedingTrial.ID,
                            Category = this.precedingTrial[0].Category,
                            TrialStartTime = this.currentTrialStarttime,
                            Duration =
                              (int)(currentTime - this.recordingStarttime - this.currentTrialStarttime)
                          };

        if (this.trialSequenceCounter > 0)
        {
          this.trialDataList.Add(trialData);
        }

        // Store usercam start event if applicable
        if (this.chbRecordAudio.Checked || this.chbRecordVideo.Checked)
        {
          var usercamVideoEvent = new MediaEvent
                                    {
                                      EventID = this.trialEventList.Count,
                                      Param = this.currentTrialVideoStartTime.ToString(CultureInfo.InvariantCulture),
                                      Task = MediaEventTask.Start,
                                      Time = 0,
                                      Type = EventType.Usercam,
                                      SubjectName = this.currentTracker.Subject.SubjectName,
                                      TrialSequence = this.trialSequenceCounter - 1
                                    };

          if (this.trialSequenceCounter > 0)
          {
            this.trialEventList.Add(usercamVideoEvent);
          }
        }

        // Store subjects response event
        var inputEvent = new InputEvent
                           {
                             EventID = this.trialEventList.Count,
                             SubjectName = this.currentTracker.Subject.SubjectName,
                             Task = InputEventTask.SlideChange,
                             Time = trialData.Duration,
                             TrialSequence = this.trialSequenceCounter - 1,
                             Type = EventType.Response
                           };

        if (e.Response != null)
        {
          inputEvent.Param = e.Response.ToString();
        }

        if (this.trialSequenceCounter >= 0)
        {
          this.trialEventList.Add(inputEvent);
        }
      }

      // Update new trial
      this.currentTrialStarttime = currentTime - this.recordingStarttime;

      if (this.chbRecordAudio.Checked || this.chbRecordVideo.Checked)
      {
        this.currentTrialVideoStartTime = e.WebcamTime;
      }

      // Update recorder modules viewer
      var updateLiveViewerThread = new Thread(this.NewSlideAvailable);
      updateLiveViewerThread.SetApartmentState(ApartmentState.STA);
      updateLiveViewerThread.Start();
    }
Esempio n. 2
0
 /// <summary>
 /// This method raises the <see cref="TrialChanged"/>
 ///   event by invoking the delegates.
 ///   It should be called when the current trial has changed.
 /// </summary>
 /// <param name="e">
 /// A <see cref="TrialChangedEventArgs"/> with the event data.
 /// </param>
 /// .
 private void OnTrialChanged(TrialChangedEventArgs e)
 {
   if (this.TrialChanged != null)
   {
     AsyncHelper.FireAndForget(this.TrialChanged, this, e);
   }
 }