private void backgroundWorker_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e) { // enable controls back to normal txtSourcePath.Enabled = true; txtDestinationURL.Enabled = true; btSourceFolder.Enabled = true; grpboxAuthentication.Enabled = true; ContextMenuLog.Enabled = true; MenuTools_Options.Enabled = true; MenuFile_ClearLogs.Enabled = true; MenuFile_SaveLog.Enabled = true; MenuFile_Print.Enabled = true; MenuFile_PrintPreview.Enabled = true; MenuFile_Exit.Enabled = true; MenuHelp_About.Enabled = true; // wrap up everything! LogStatus.SelectionFont = new Font("Lucida Console", 9f, FontStyle.Regular); LogStatus.SelectionColor = Color.DarkBlue; LogStatus.AppendText( // "\n\nImport Process Completed at " + String.Format("{0:MM-dd-yyyy - hh:mm:ss}", System.DateTime.Now) + "\n\n" + "\n\n" + (Settings.Default.OptionsSimulationMode ? "SIMULATION" : "Import") + " process Completed at " + System.DateTime.Now.ToString() + "\n\n" + "Folders Processed...: " + Last.TotalFolders.ToString() + "\n" + "Files Processed.....: " + Last.TotalFiles.ToString() + "\n" + "Files Renamed.......: " + Last.TotalFilesRenamed.ToString() + "\n" + "Files Skipped.......: " + Last.TotalFilesSkipped.ToString() + "\n" + "Files Overwritten...: " + Last.TotalFilesOverwritten + "\n" + "Failures............: " + Last.TotalFailures.ToString() + "\n" ); LogStatus.SelectionFont = new Font("Lucida Console", 9f, FontStyle.Regular); LogStatus.SelectionColor = Color.Blue;; TextWriter tw = new StreamWriter("Last Operation.rtf"); tw.WriteLine(LogStatus.Text); tw.Close(); StripProgressBar.Visible = false; btSourceFolder.Enabled = true; btUpload.Text = "Upload"; btUpload.Image = ((System.Drawing.Image)(Properties.Resources.Upload_Green_48x48)); if (Last.OperationAborted) { StatusLabel.Text = "The last operation was cancelled!"; } else { StatusLabel.Text = "Dishes are done!"; } }
private void backgroundWorker_ProgressChanged(object sender, ProgressChangedEventArgs e) { LogStatus.SelectionFont = Last.LogSelectionFont; LogStatus.SelectionColor = Last.LogSelectionColor; LogStatus.AppendText(Last.LogStatus); LogStatus.SelectionFont = new Font("Lucida Console", 9f, FontStyle.Regular); LogStatus.SelectionColor = Color.Blue; StatusLabel.Text = "Item: " + e.ProgressPercentage.ToString() + " of " + (Last.ComputedFiles + Last.ComputedFolders).ToString() + " - Processing " + Last.ComputedFileFolder; StripProgressBar.Value = e.ProgressPercentage; }
// ====================================================================================================== Button Upload private void btUpload_Click(object sender, EventArgs e) { if (btUpload.Text == "Cancel") { backgroundWorker.CancelAsync(); return; } if (txtDestinationURL.Text.Length > 0 && txtSourcePath.Text.Length > 0) { // // TO-DO: // // 1) regex to validate the URL: '/^(https?|http):\/\/.+$/igm' = catches the url at any format for http/https // if (!Uri.IsWellFormedUriString(txtDestinationURL.Text.Trim(), UriKind.RelativeOrAbsolute)) { } // disable controls to prevent unwanted interactions that may affect the current task txtSourcePath.Enabled = false; txtDestinationURL.Enabled = false; btSourceFolder.Enabled = false; grpboxAuthentication.Enabled = false; ContextMenuLog.Enabled = false; MenuTools_Options.Enabled = false; MenuFile_ClearLogs.Enabled = false; MenuFile_SaveLog.Enabled = false; MenuFile_Print.Enabled = false; MenuFile_PrintPreview.Enabled = false; MenuFile_Exit.Enabled = false; MenuHelp_About.Enabled = false; // reset the struct Last.OperationAborted = false; Last.LogStatus = ""; Last.LogSelectionFont = new Font("Lucida Console", 9f, FontStyle.Regular); Last.LogSelectionColor = Color.Blue; Last.ComputedFiles = 0; Last.ComputedFolders = 0; Last.ComputedFileFolder = ""; Last.TotalFolders = 0; Last.TotalFiles = 0; Last.TotalFilesRenamed = 0; Last.TotalFilesSkipped = 0; Last.TotalFilesOverwritten = 0; Last.TotalFailures = 0; Last.ListDir = ""; Last.ListRow = null; // modify the button enabling it to CANCEL the operation btUpload.Text = "Cancel"; btUpload.Image = ((System.Drawing.Image)(Properties.Resources.Upload_Cancel_48x48)); // // Returns Feedback for UI: // // - Compute the files // - Feeds the Progress Bar with numbers // - Fires the log // ComputeItems(txtSourcePath.Text.Trim(), 0); StripProgressBar.Visible = true; StripProgressBar.Maximum = Last.ComputedFiles + Last.ComputedFolders; LogStatus.SelectionFont = new Font("Lucida Console", 9f, FontStyle.Regular); LogStatus.SelectionColor = Color.DarkBlue; if (Settings.Default.OptionsSimulationMode) { LogStatus.AppendText("\n\nSimulation Import Process started at " + System.DateTime.Now.ToString() + "\n\n"); } else { LogStatus.AppendText("\n\nImport Process started at " + System.DateTime.Now.ToString() + "\n\n"); } // // start uploading files // backgroundWorker.RunWorkerAsync(); } }