Beispiel #1
0
 private void openToolStripMenuItem_Click(object sender, EventArgs e)
 {
     if (openSampleDialog.ShowDialog() == DialogResult.OK)
     {
         try
         {
             // TODO: May want to separately handle a failure in LoadSample, although there's not much that could go wrong
             Sample sample = SampleStorage.Load(openSampleDialog.FileName);
             DiscardCurrentSample();
             LoadSample(sample);
         }
         catch (Exception ex)
         {
             FormatAndShowException(ex, Resources.Could_not_open_sample_file_at, openSampleDialog.FileName);
         }
     }
 }
Beispiel #2
0
        /// <summary>
        ///     Pop up a save dialog and try to save the current _sample.
        /// </summary>
        /// <returns>The result of the save dialog, or <see cref="DialogResult.Cancel" /> when an exception occurred.</returns>
        /// <remarks>
        ///     Handling the exception here rather than passing it on the the caller doesn't seem quite right, but limits code
        ///     duplication.
        /// </remarks>
        private DialogResult SaveSample()
        {
            DialogResult result = sampleSaveFileDialog.ShowDialog();

            if (result == DialogResult.OK)
            {
                try
                {
                    // TODO: More detailed information in sample saving error message
                    SampleStorage.Save(sampleSaveFileDialog.FileName, _sample);
                }
                catch (Exception ex)
                {
                    FormatAndShowException(ex, Resources.Could_not_save_sample_to, sampleSaveFileDialog.FileName);
                    return(DialogResult.Cancel);
                }
            }
            return(result);
        }