/// <summary>
    ///   This method checks for assigning of all minimum relevant columns,
    ///   and returns false if some are missing.
    /// </summary>
    /// <returns>
    ///   <strong>True</strong> if successful, otherwise
    ///   <strong>false</strong>.
    /// </returns>
    private bool ValidateAssignments()
    {
      // Check for missing time column.
      if (ImportFixations.ASCIISettings.ColumnAssignments["StartTime"] == null
          || ImportFixations.ASCIISettings.ColumnAssignments["StartTime"] == string.Empty
          || ImportFixations.ASCIISettings.ColumnAssignments["PosX"] == null
          || ImportFixations.ASCIISettings.ColumnAssignments["PosX"] == string.Empty
          || ImportFixations.ASCIISettings.ColumnAssignments["PosY"] == null
          || ImportFixations.ASCIISettings.ColumnAssignments["PosY"] == string.Empty)
      {
        string message = "You have to define at least the trial id, start time, posx and posY columns ...";
        ExceptionMethods.ProcessMessage("Define columns", message);
        return false;
      }

      // If no subject column is specified show subject name dialog.
      if (ImportFixations.ASCIISettings.ColumnAssignments["SubjectName"] == null
          || ImportFixations.ASCIISettings.ColumnAssignments["SubjectName"] == string.Empty)
      {
        var dlg = new AskForSubjectNameDialog(true);
        dlg.SubjectName = ImportFixations.DetectionSetting.SubjectName;
        if (dlg.ShowDialog() == DialogResult.OK)
        {
          ImportFixations.DetectionSetting.SubjectName = dlg.SubjectName;
        }
        else
        {
          return false;
        }
      }

      return true;
    }
Esempio n. 2
0
    /// <summary>
    ///   This method writes the data that is written in the lists during
    ///   recording to OGAMAs dataset.
    ///   If this could be successfully done the whole new data is
    ///   written to the database (SQL Database file).
    /// </summary>
    private void SaveRecordingIntoTablesAndDB()
    {
      try
      {
        // Set wait cursor until UI is reset
        Cursor.Current = Cursors.WaitCursor;

        string subject = this.currentTracker.Subject.SubjectName;

        if (subject == string.Empty)
        {
          var dialog = new AskForSubjectNameDialog(false);
          dialog.ShowDialog();
          subject = dialog.SubjectName;
        }

        this.bgwSaveSplash.RunWorkerAsync("Saving to database ...");

        // Creates an empty raw data table in the mdf database
        Queries.CreateRawDataTableInDB(subject);

        // Write RawDataTable into File with Bulk Statement
        Queries.WriteRawDataWithBulkStatement(subject, this.subjectRawDataTable);

        // Save subject information to dataset
        if (!Queries.WriteSubjectToDataSet(this.currentTracker.Subject))
        {
          throw new DataException("The new subject information could not be written into the dataset.");
        }

        // Save trial information to dataset
        if (!Queries.WriteTrialsDataListToDataSet(this.trialDataList))
        {
          throw new DataException("The new trials table could not be written into the dataset.");
        }

        // Save trial event information to dataset
        if (!Queries.WriteTrialEventsToDataSet(this.trialEventList))
        {
          throw new DataException("The new trials table could not be written into the dataset.");
        }

        Document.ActiveDocument.DocDataSet.EnforceConstraints = false;

        // Update subjects and trials table in the mdf database
        Document.ActiveDocument.DocDataSet.TrialEventsAdapter.Update(Document.ActiveDocument.DocDataSet.TrialEvents);
        Document.ActiveDocument.DocDataSet.TrialsAdapter.Update(Document.ActiveDocument.DocDataSet.Trials);
        Document.ActiveDocument.DocDataSet.SubjectsAdapter.Update(Document.ActiveDocument.DocDataSet.Subjects);

        Document.ActiveDocument.DocDataSet.AcceptChanges();
        Document.ActiveDocument.DocDataSet.CreateRawDataAdapters();

        Document.ActiveDocument.DocDataSet.EnforceConstraints = true;

        // Get trial data of current subject
        DataTable trialsTable = Document.ActiveDocument.DocDataSet.TrialsAdapter.GetDataBySubject(subject);

        // Hide splash
        this.bgwSaveSplash.CancelAsync();

        // Show new splash new info
        this.bgwCalcFixations.RunWorkerAsync("Calculating fixations ...");
        Application.DoEvents();

        // Calculate fixations
        var calculationObject = new FixationCalculation();
        calculationObject.CalcFixations(SampleType.Gaze, subject, trialsTable, null, null);
        calculationObject.CalcFixations(SampleType.Mouse, subject, trialsTable, null, null);

        this.bgwCalcFixations.CancelAsync();

        // Show the success information on the 
        // controllers screen
        var successDlg = new SavingSuccessDialog();
        Rectangle controllerBounds = PresentationScreen.GetControllerWorkingArea();
        successDlg.Location = new Point(
          controllerBounds.Width / 2 - successDlg.Width / 2,
          controllerBounds.Height / 2 - successDlg.Height / 2);
        successDlg.ShowDialog();
      }
      catch (Exception ex)
      {
        ExceptionMethods.HandleException(ex);

        // Hide saving splash.
        if (this.bgwSaveSplash.IsBusy)
        {
          this.bgwSaveSplash.CancelAsync();
        }

        // Hide fixation calculation splash.
        if (this.bgwCalcFixations.IsBusy)
        {
          this.bgwCalcFixations.CancelAsync();
        }

        // CleanUp
        // First reject changes (remove trial and subject table modifications)
        Document.ActiveDocument.DocDataSet.RejectChanges();

        Document.ActiveDocument.DocDataSet.EnforceConstraints = false;

        Document.ActiveDocument.DocDataSet.SubjectsAdapter.Update(Document.ActiveDocument.DocDataSet.Subjects);
        Document.ActiveDocument.DocDataSet.TrialsAdapter.Update(Document.ActiveDocument.DocDataSet.Trials);
        Document.ActiveDocument.DocDataSet.TrialEventsAdapter.Update(Document.ActiveDocument.DocDataSet.TrialEvents);

        // Remove eventually added raw data table in dataset
        if (Document.ActiveDocument.DocDataSet.Tables.Contains(this.currentTracker.Subject.SubjectName + "Rawdata"))
        {
          Document.ActiveDocument.DocDataSet.Tables.Remove(this.currentTracker.Subject.SubjectName + "Rawdata");
        }

        Document.ActiveDocument.DocDataSet.EnforceConstraints = true;

        // Remove raw data table in database file (.mdf)
        Queries.DeleteRawDataTableInDB(this.currentTracker.Subject.SubjectName);

        string filename = Path.Combine(
          Document.ActiveDocument.ExperimentSettings.ThumbsPath,
          this.currentTracker.Subject.SubjectName + ".avi");
        if (File.Exists(filename))
        {
          File.Delete(filename);
        }
      }
      finally
      {
        // Free resources
        this.trialEventList.Clear();
        this.trialDataList.Clear();
        this.subjectRawDataTable.Dispose();
      }
    }
    /// <summary>
    /// This method checks for assigning of all minimum relevant columns,
    /// and returns false if some are missing.
    /// </summary>
    /// <returns><strong>True</strong> if successful, otherwise
    /// <strong>false</strong>.</returns>
    private bool ValidateAssignments()
    {
      // Check for missing time column.
      if (ImportRawData.ASCIISettings.ColumnAssignments["Time"] == null ||
        ImportRawData.ASCIISettings.ColumnAssignments["Time"] == string.Empty)
      {
        ExceptionMethods.ProcessMessage("Time colum missing", "Please specify a time column, this is a required value ...");
        return false;
      }

      // Check for missing data column.
      if (ImportRawData.ASCIISettings.ColumnAssignments["PupilDiaX"] == string.Empty &&
        ImportRawData.ASCIISettings.ColumnAssignments["PupilDiaY"] == string.Empty &&
        ImportRawData.ASCIISettings.ColumnAssignments["GazePosX"] == string.Empty &&
        ImportRawData.ASCIISettings.ColumnAssignments["GazePosY"] == string.Empty &&
        ImportRawData.ASCIISettings.ColumnAssignments["MousePosX"] == string.Empty &&
        ImportRawData.ASCIISettings.ColumnAssignments["MousePosY"] == string.Empty)
      {
        string message = "Please specify a data column pair " + Environment.NewLine +
        "either for gaze position (x,y) and/or " + Environment.NewLine +
        "pupil diameter (x,y) and/or" + Environment.NewLine +
        "mouse position (x,y) ...";
        ExceptionMethods.ProcessMessage("Data colum missing", message);
        return false;
      }

      // If no subject column is specified show subject name dialog.
      if (ImportRawData.ASCIISettings.ColumnAssignments["SubjectName"] == null ||
        ImportRawData.ASCIISettings.ColumnAssignments["SubjectName"] == string.Empty)
      {
        AskForSubjectNameDialog dlg = new AskForSubjectNameDialog(false);
        dlg.SubjectName = ImportRawData.DetectionSetting.SubjectName;
        if (dlg.ShowDialog() == DialogResult.OK)
        {
          ImportRawData.DetectionSetting.SubjectName = dlg.SubjectName;
        }
        else
        {
          return false;
        }
      }

      return true;
    }