Exemplo n.º 1
0
    /// <summary>
    ///   Starts a multiple dialog routine (fixations import assistant)
    ///   for reading fixation log files into OGAMAs database.
    /// </summary>
    public static void Start()//(MainForm mainWindow)
    {
      try
      {
        asciiSetting = new ASCIISettings();
        detectionSetting = new DetectionSettings();

        var objfrmImportAssistent = new ImportFixationsAssistentDialog();
        if (objfrmImportAssistent.ShowDialog() == DialogResult.OK)
        {
        OpenFile:
          if (asciiSetting.FileDialog.ShowDialog() == DialogResult.OK)
          {
            // Save filename
            string filename = asciiSetting.FileDialog.FileName;

            // Ask the user to use a settings file
            // and loads it into the importsettings, if true.
            AskforUsingSettingsFile();

            // Save import file
            asciiSetting.Filename = filename;

            // Set import mode
            detectionSetting.ImportType = ImportTypes.Fixations;

            var objfrmImportReadFile = new ImportParseFileDialog(ref asciiSetting);
          ReadFile:
            DialogResult resultRawData = objfrmImportReadFile.ShowDialog();
            if (resultRawData == DialogResult.OK)
            {
              var objfrmImportFixationsAssignColumns = new ImportFixationsAssignColumnsDialog();

            MakeAssignments:
              DialogResult resultAssign = objfrmImportFixationsAssignColumns.ShowDialog();
              if (resultAssign == DialogResult.OK)
              {
                var objfrmImportTrials = new ImportTrialsDialog(ref asciiSetting, ref detectionSetting);

                //CheckTrials:
                DialogResult resultTrials = objfrmImportTrials.ShowDialog();
                if (resultTrials == DialogResult.OK)
                {
                  //var objfrmImportImages = new ImportImagesDialog(ref asciiSetting, ref detectionSetting);

                  //DialogResult resultImages = objfrmImportImages.ShowDialog();
                  //if (resultImages == DialogResult.OK)
                  //{
                  if (InformationDialog.Show(
                    "Save ?",
                    "Would you like to save the import settings ?",
                    true,
                    MessageBoxIcon.Question) == DialogResult.Yes)
                  {
                    SaveImportSettings();
                  }

                  // Inform user about deletion.
                  string cleanupMessage = "If you continue the import process, " + Environment.NewLine + "all existing "
                                   + "gaze fixation data is deleted before the imported fixations "
                                   + "are written to the database.";
                  if (MessageBox.Show(
                    cleanupMessage,
                    Application.ProductName,
                    MessageBoxButtons.OKCancel,
                    MessageBoxIcon.Information) == DialogResult.Cancel)
                  {
                    return;
                  }

                  // Show import splash window
                  asciiSetting.WaitingSplash.RunWorkerAsync();

                  // Give some time to show the splash ...
                  Application.DoEvents();

                  // Read log file again, but complete
                  if (!GenerateOgamaFixationDataList(-1))
                  {
                    asciiSetting.WaitingSplash.CancelAsync();
                    return;
                  }

                  // Generate the trials
                  GenerateOgamaSubjectAndTrialList();

                  // Save the import into ogamas database and the mdf file.
                  var successful = SaveImportIntoTablesAndDB();

                  //// Create slideshow trials
                  //ImportRawData.GenerateOgamaSlideshowTrials(detectionSetting, mainWindow);

                  // Import has finished.
                  asciiSetting.WaitingSplash.CancelAsync();

                  // Inform user about success.
                  if (successful)
                  {
                    string message = "Fixation data successfully written to database.";// + Environment.NewLine +
                    //"Please don´t forget to move the stimuli images to the SlideResources subfolder" +
                    //"of the experiment, otherwise no images will be shown.";
                    ExceptionMethods.ProcessMessage("Success", message);
                  }
                  else
                  {
                    string message = "Import had errors. Some or all of the import data " +
                      "could not be written the database.";
                    ExceptionMethods.ProcessErrorMessage(message);
                  }
                  //}
                  //else if (resultImages == DialogResult.Cancel)
                  //{
                  //  goto CheckTrials;
                  //}
                }
                else if (resultTrials == DialogResult.Cancel)
                {
                  goto MakeAssignments;
                }
                else if (resultTrials == DialogResult.Abort)
                {

                }
              }
              else if (resultAssign == DialogResult.Cancel)
              {
                goto ReadFile;
              }
            }
            else if (resultRawData == DialogResult.Cancel)
            {
              goto OpenFile;
            }
          }
        }
      }
      catch (Exception ex)
      {
        string message = "Something failed during import." + Environment.NewLine
                         + "Please try again with other settings." + Environment.NewLine + "Error: " + ex.Message;
        ExceptionMethods.ProcessErrorMessage(message);

        if (asciiSetting.WaitingSplash.IsBusy)
        {
          asciiSetting.WaitingSplash.CancelAsync();
        }
      }
    }
Exemplo n.º 2
0
    ///////////////////////////////////////////////////////////////////////////////
    // Public methods                                                            //
    ///////////////////////////////////////////////////////////////////////////////
    #region Public Methods and Operators

    /// <summary>
    ///   Starts a multiple dialog routine for reading AOIs
    ///   from a log file into the programs database.
    /// </summary>
    public static void Start()
    {
      try
      {
        // Show assistant start screen with instructions
        var objfrmImportAssistent = new ImportAOIAssistentDialog();
        if (objfrmImportAssistent.ShowDialog() == DialogResult.OK)
        {
        // Show open file dialog
        OpenFile:
          if (asciiSettings.FileDialog.ShowDialog() == DialogResult.OK)
          {
            // Save import file
            asciiSettings.Filename = asciiSettings.FileDialog.FileName;

            // Show ascii file parse dialog with preview
            var objfrmImportReadFile = new ImportParseFileDialog(ref asciiSettings);
          ReadFile:
            DialogResult resultReadFile = objfrmImportReadFile.ShowDialog();
            if (resultReadFile == DialogResult.OK)
            {
              // Show assign columns dialog
              var objfrmImportAOIAssignColumns = new ImportAOIAssignColumnsDialog();

              DialogResult resultAssign = objfrmImportAOIAssignColumns.ShowDialog();
              if (resultAssign == DialogResult.OK)
              {
                // Show import splash window
                asciiSettings.WaitingSplash.RunWorkerAsync();

                // Give some time to show the splash ...
                Application.DoEvents();

                var columnHeaders = new List<string>();

                // Read import log file
                asciiSettings.Rows = FileImport.ParseFile(asciiSettings.Filename, -1, ref columnHeaders);

                // Convert log file to AOI
                GenerateOgamaAOIDataList();

                // Save the import into ogamas database and the mdf file.
                SaveImportIntoTablesAndDB();

                // Import has finished.
                asciiSettings.WaitingSplash.CancelAsync();

                // Inform user about success.
                string message = "AOI import data successfully written to database.";
                ExceptionMethods.ProcessMessage("Successfull", message);
              }
              else if (resultAssign == DialogResult.Cancel)
              {
                goto ReadFile;
              }
            }
            else if (resultReadFile == DialogResult.Cancel)
            {
              goto OpenFile;
            }
          }
        }
      }
      catch (Exception ex)
      {
        string message = "Something failed during import." + Environment.NewLine
                         + "Please try again with other settings. " + Environment.NewLine + "Error: " + ex.Message;
        ExceptionMethods.ProcessErrorMessage(message);

        // CleanUp
        if (asciiSettings.WaitingSplash.IsBusy)
        {
          asciiSettings.WaitingSplash.CancelAsync();
        }
      }
    }