示例#1
0
 /// <summary>
 /// Handles the FormClosing event of the MainForm control.
 /// </summary>
 /// <param name="sender">The source of the event.</param>
 /// <param name="e">The <see cref="System.Windows.Forms.FormClosingEventArgs"/> instance containing the event data.</param>
 /// <remarks>Documented by Dev02, 2008-04-10</remarks>
 private void MainForm_FormClosing(object sender, FormClosingEventArgs e)
 {
     if (BusinessLayer.WorkingThreadActive)
     {
         BusinessLayer.AbortWorkingThread();
     }
 }
示例#2
0
        /// <summary>
        /// Handles the Click event of the buttonStart control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param>
        /// <remarks>Documented by Dev02, 2008-03-17</remarks>
        private void buttonStart_Click(object sender, EventArgs e)
        {
            if (BusinessLayer.WorkingThreadActive)
            {
                BusinessLayer.AbortWorkingThread();
                return;
            }

            textBoxLog.Clear();
            tracelistener.LogMessages.Clear();

            //check if input file exists
            if (!File.Exists(textBoxLearningModule.Text))
            {
                BusinessLayer.AddLog("The specified learning module file cannot be found");
                return;
            }

            //check if any audio fields are selected
            if (listViewPlaybackSequence.Items.Count == 0)
            {
                BusinessLayer.AddLog("Please select at least one field for the playback sequence");
                return;
            }

            IDictionary dictionary = null;

            try
            {
                AudioBookOptions options = new AudioBookOptions();

                //add mono/stereo selection to options
                options.Stereo = radioButtonStereo.Checked;

                //add selected fields to the options
                foreach (ListViewItem lvi in listViewPlaybackSequence.Items)
                {
                    MediaField mediafield = lvi.Tag as MediaField;
                    if (mediafield != null)
                    {
                        options.MediaFields.Add(mediafield);
                    }
                }

                //check for valid file paths
                FileInfo dictionaryfile = null, audiobook = null;
                try
                {
                    dictionaryfile = new FileInfo(textBoxLearningModule.Text);
                    audiobook      = new FileInfo(textBoxAudiobook.Text);
                    if (string.IsNullOrEmpty(audiobook.Extension))
                    {
                        BusinessLayer.AddLog("Please enter a valid extension for the target audiobook file");
                        return;
                    }
                }
                catch
                {
                    BusinessLayer.AddLog("The specified file paths are not valid. Please check your input");
                    return;
                }

                //save file paths to settings as recent files
                Settings.Default.RecentLearningModule = dictionaryfile.FullName;
                Settings.Default.RecentAudioBook      = audiobook.FullName;
                Settings.Default.Save();

                //open learning module and start audio book generation
                try
                {
                    ConnectionStringStruct       css  = new ConnectionStringStruct(DatabaseType.MsSqlCe, dictionaryfile.FullName);
                    MLifter.DAL.Interfaces.IUser user = UserFactory.Create((GetLoginInformation)MLifter.Controls.LoginForm.OpenLoginForm, css, (DataAccessErrorDelegate) delegate { return; }, this);
                    css.LmId = User.GetIdOfLearningModule(dictionaryfile.FullName, user);
                    user.ConnectionString = css;
                    dictionary            = user.Open();
                }
                catch (System.IO.IOException)
                {
                    BusinessLayer.AddLog("The Learning Module file could not be accessed. Please make sure that it is not open within another program (e.g. MemoryLifter)");
                    return;
                }
                catch (System.Xml.XmlException)
                {
                    BusinessLayer.AddLog("The Learning Module file does not seem to be in a valid format");
                    return;
                }
                catch (ProtectedLearningModuleException)
                {
                    BusinessLayer.AddLog("The Learning Module could not be opened: It is content protected");
                    return;
                }
                catch (Exception exp)
                {
                    BusinessLayer.AddLog("The Learning Module file could not be opened:" + Environment.NewLine + exp.Message);
                    return;
                }
                buttonStart.Text = "Cancel";
                BusinessLayer.GenerateAudioBook(dictionary, audiobook, options, codecs);
            }
            catch (Exception exp)
            {
                BusinessLayer.AddLog("Audio book generation exception happened: " + Environment.NewLine + exp.ToString());
                return;
            }
            finally
            {
                if (dictionary != null)
                {
                    dictionary.Dispose();
                }
            }
        }