Example #1
0
    /// <summary>
    /// This method opens experiment settings dialog and saves changes to Document.ActiveDocument.ExperimentSettings
    /// </summary>
    public static void ShowExperimentSettingsDialog()
    {
      if (Document.ActiveDocument != null)
      {
        ExperimentSettingsDialog popUpDlg = new ExperimentSettingsDialog();

        // Update dialog with settings not needed because it reads the current
        // settings of the Document singleton by itself
        // show dialog
        if (popUpDlg.ShowDialog() == DialogResult.OK)
        {
          // Read dialogs changes
          Document.ActiveDocument.ExperimentSettings = popUpDlg.ExperimentSettings;
          Document.ActiveDocument.Modified = true;
        }
      }
    }
Example #2
0
    /// <summary>
    /// The <see cref="Control.Click"/> event handler
    /// for the <see cref="ToolStripMenuItem"/> <see cref="mnuFileNewExperiment"/>
    /// Creates new experiment through creating new database and
    /// asks for stimulus path and screen size.
    /// </summary>
    /// <param name="sender">Source of the event</param>
    /// <param name="e">An empty <see cref="EventArgs"/></param>
    private void mnuFileNewExperiment_Click(object sender, EventArgs e)
    {
      if (Document.ActiveDocument == null)
      {
        // Show new experiment storage dialog.
        NewExperiment objfrmNewExperimentDlg = new NewExperiment();
        if (objfrmNewExperimentDlg.ShowDialog() != DialogResult.OK)
        {
          return;
        }

        this.Cursor = Cursors.WaitCursor;

        string newExperimentFolder = Path.Combine(
          objfrmNewExperimentDlg.ParentFolder,
          objfrmNewExperimentDlg.ExperimentName);

        string newExperimentName = objfrmNewExperimentDlg.ExperimentName;
        string newExperimentFilename = Path.Combine(newExperimentFolder, newExperimentName + ".oga");

        Document.ActiveDocument = new Document();
        ExperimentSettings newSettings = new ExperimentSettings();

        // Show new experiment properties dialog.
        ExperimentSettingsDialog popUpDlg = new ExperimentSettingsDialog();
        if (popUpDlg.ShowDialog() == DialogResult.OK)
        {
          newSettings = popUpDlg.ExperimentSettings;
          newSettings.DocumentPath = newExperimentFolder;
          newSettings.Name = newExperimentName;
          newSettings.UpdateVersion();
        }
        else
        {
          return;
        }

        // Show loading splash screen
        this.bgwLoad.RunWorkerAsync();
        Application.DoEvents();

        Directory.CreateDirectory(newExperimentFolder);
        Directory.CreateDirectory(newSettings.ThumbsPath);
        Directory.CreateDirectory(newSettings.DatabasePath);
        Directory.CreateDirectory(newSettings.SlideResourcesPath);

        Document.ActiveDocument.ExperimentSettings = newSettings;

        string sqliteSource = Application.StartupPath + "\\DataSet\\OgamaDatabaseTemplate.db";
        if (File.Exists(sqliteSource))
        {
          string sqliteDBDestination = newSettings.DatabaseSQLiteFile;

          bool overwrite = false;
          bool skip = false;
          if (File.Exists(sqliteDBDestination))
          {
            // Hide loading splash screen
            this.bgwLoad.CancelAsync();

            if (MessageBox.Show(
              "Overwrite existing Database File " + Environment.NewLine + sqliteDBDestination,
              Application.ProductName,
                MessageBoxButtons.YesNo,
                MessageBoxIcon.Question) == DialogResult.Yes)
            {
              overwrite = true;
            }
            else
            {
              skip = true;
            }

            // Show loading splash screen again
            this.bgwLoad.RunWorkerAsync();
            Application.DoEvents();
          }

          try
          {
            if (!skip)
            {
              File.Copy(sqliteSource, sqliteDBDestination, overwrite);
            }
          }
          catch (ArgumentException ex)
          {
            ExceptionMethods.ProcessErrorMessage(ex.Message);
          }
          catch (IOException ex)
          {
            ExceptionMethods.ProcessErrorMessage(ex.Message);
          }
          catch (NotSupportedException ex)
          {
            ExceptionMethods.ProcessErrorMessage(ex.Message);
          }
          catch (UnauthorizedAccessException ex)
          {
            ExceptionMethods.ProcessErrorMessage(ex.Message);
          }
          catch (Exception ex)
          {
            ExceptionMethods.HandleException(ex);
          }

          if (!Document.ActiveDocument.SaveDocument(newExperimentFilename, this.bgwLoad))
          {
            ExceptionMethods.ProcessErrorMessage("Couldn't create document");
            this.ChangeMenuItems(false);
            if (Document.ActiveDocument != null)
            {
              this.CleanUpDocument();
            }
          }
          else
          {
            if (!Document.ActiveDocument.LoadSQLData(this.bgwLoad))
            {
              ExceptionMethods.ProcessErrorMessage("Couldn't create document, because database loading failed.");
              this.ChangeMenuItems(false);
              if (Document.ActiveDocument != null)
              {
                this.CleanUpDocument();
              }
            }
            else
            {
              this.contextPanel.Init();
              RecentFilesList.List.Add(newExperimentFilename);
            }

            // Hide loading splash screen
            this.bgwLoad.CancelAsync();

            if (Document.ActiveDocument != null)
            {
              this.ShowTaskChooseDialog();
              this.ChangeMenuItems(true);
            }
          }
        }
        else
        {
          // DataBaseSourceFile does not exist in the expected directory
          string message = "Could not find DataBaseTemplate File:" + Environment.NewLine;
          message += sqliteSource;
          message += Environment.NewLine + "Please make sure the File OgamaDatabaseTemplate.db (supplied with the application installation) is in the directory listed before and try again.";

          ExceptionMethods.ProcessErrorMessage(message);
        }

        // Hide loading splash screen
        this.bgwLoad.CancelAsync();
      }
      else
      {
        // mDocument.ActiveDocument!=null
        string message = "Couldn't create new experiment, because there is one already open." +
          Environment.NewLine + "Please close it using File -> Close Experiment.";
        ExceptionMethods.ProcessErrorMessage(message);
      }

      this.Cursor = Cursors.Default;
    }