Exemple #1
0
    /// <summary>
    /// Displays the form and aligns it to the center of the <paramref name="form"/>. Afterwards the given <see cref="BackgroundWorker"/> is run.
    /// </summary>
    /// <param name="form">The form to which center the <see cref="FormProgressBackground"/> form should be aligned to.</param>
    /// <param name="worker">A background worker to run upon displaying the form.</param>
    /// <param name="staticStatusText">A text to be shown as a static title describing the process.</param>
    /// <param name="statusLabelText">A text to display the progress percentage in the status label of the form. One place holder for the progress percentage must be reserved (i.e. {0}).</param>
    /// <returns>True if the <see cref="BackgroundWorker"/> instance was successfully run; otherwise false.</returns>
    public static bool Execute(Form form, BackgroundWorker worker, string staticStatusText, string statusLabelText)
    {
        if (formProgressBackground != null || worker == null)
        {
            return(false);
        }

        statusText                            = statusLabelText;
        backgroundWorker                      = worker;
        formProgressBackground                = new FormProgressBackground();
        formProgressBackground.Left           = form.Left + (form.Width - formProgressBackground.Width) / 2;
        formProgressBackground.Top            = form.Top + (form.Height - formProgressBackground.Height) / 2;
        formProgressBackground.lbStatus.Text  = string.Format(statusLabelText, 0);
        formProgressBackground.lbLoading.Text = staticStatusText;
        backgroundWorker.ProgressChanged     += BackgroundWorker_ProgressChanged;
        backgroundWorker.RunWorkerCompleted  += BackgroundWorker_RunWorkerCompleted;
        var result = formProgressBackground.ShowDialog() == DialogResult.OK;

        backgroundWorker.ProgressChanged    -= BackgroundWorker_ProgressChanged;
        backgroundWorker.RunWorkerCompleted -= BackgroundWorker_RunWorkerCompleted;

        using (formProgressBackground)
        {
            formProgressBackground = null;
        }

        using (worker)
        {
            // dispose of the BackgroundWorker class instance..
        }

        return(result);
    }
Exemple #2
0
        private void BtUpdateFileLocation_Click(object sender, EventArgs e)
        {
            FormProgressBackground.Execute(this,
                                           DatabaseDataMigrate.UpdateSongLocations(fbdDirectory, Connection),
                                           DBLangEngine.GetMessage("msgDatabaseUpdate", "Database update|A message describing that the software is updating it's database."),
                                           DBLangEngine.GetMessage("msgProgressPercentage",
                                                                   "Progress: {0} %|A message describing some operation progress in percentage."));

            // indicate to the user that a software restart is required..
            tbRestartRequired.Visible = true;

            // indicate that the application should be restarted after the operation..
            FormMain.RestartRequired = true;
        }
Exemple #3
0
        private void BtDeleteNonExistingSongs_Click(object sender, EventArgs e)
        {
            if (MessageBox.Show(
                    DBLangEngine.GetMessage("msgQueryUserDeleteNonExistingSongs",
                                            "Really delete non-existing files from the database?|A message requesting for user confirmation to delete non-existing files from the database."),
                    DBLangEngine.GetMessage("msgConfirmation",
                                            "Confirm|Used in a dialog title to ask for a confirmation to do something"),
                    MessageBoxButtons.YesNo, MessageBoxIcon.Information, MessageBoxDefaultButton.Button2) ==
                DialogResult.Yes)
            {
                // indicate to the user that a software restart is required..
                tbRestartRequired.Visible = true;

                FormProgressBackground.Execute(this,
                                               DatabaseDataMigrate.DeleteNonExistingSongs(Connection),
                                               DBLangEngine.GetMessage("msgDatabaseUpdate", "Database update|A message describing that the software is updating it's database."),
                                               DBLangEngine.GetMessage("msgProgressPercentage",
                                                                       "Progress: {0} %|A message describing some operation progress in percentage."));

                // indicate that the application should be restarted after the operation..
                FormMain.RestartRequired = true;
            }
        }
Exemple #4
0
    /// <summary>
    /// Copies the queue files into a given directory and optionally converts the files to MP3 format.
    /// </summary>
    /// <param name="queueIdentifier">The database ID number for the queue.</param>
    /// <param name="toFolder">The folder to copy the files to.</param>
    /// <param name="connection">A reference to a <see cref="SQLiteConnection"/> class instance.</param>
    /// <param name="convertToMp3">A value indicating whether to convert the file to a MP3 format.</param>
    /// <param name="staticStatusText">A text to be shown as a static title describing the process.</param>
    /// <param name="statusLabelText">A text to display the progress percentage in the status label of the form. One place holder for the progress percentage must be reserved (i.e. {0}).</param>
    /// <param name="outputBitRate">A bit rate for an MP3 file if a file is requested to be converted into a MP3 format.</param>
    /// <param name="parentForm">the parent form to which the progress dialog should be aligned to the center of.</param>
    public static void RunWithDialog(Form parentForm, int queueIdentifier, string toFolder,
                                     SQLiteConnection connection, bool convertToMp3, string staticStatusText, string statusLabelText,
                                     int outputBitRate = 256000)
    {
        worker = new BackgroundWorker {
            WorkerReportsProgress = true, WorkerSupportsCancellation = true
        };
        queueIndex     = queueIdentifier;
        toPath         = toFolder;
        conn           = connection;
        toMp3          = convertToMp3;
        bitRate        = outputBitRate;
        form           = parentForm;
        worker.DoWork += Worker_DoWork;
        FormProgressBackground.Execute(form, worker, staticStatusText, statusLabelText);

        worker.DoWork -= Worker_DoWork;

        using (worker)
        {
            worker = null;
        }
    }