/// <summary> /// Event receives notification from the Burn thread of an event /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void backgroundBurnWorker_ProgressChanged(object sender, ProgressChangedEventArgs e) { //int percent = e.ProgressPercentage; BurnData burnData = (BurnData)e.UserState; if (burnData.task == BURN_MEDIA_TASK.BURN_MEDIA_TASK_FILE_SYSTEM) { labelStatusText.Text = burnData.statusMessage; } else if (burnData.task == BURN_MEDIA_TASK.BURN_MEDIA_TASK_WRITING) { switch (burnData.currentAction) { case IMAPI_FORMAT2_DATA_WRITE_ACTION.IMAPI_FORMAT2_DATA_WRITE_ACTION_VALIDATING_MEDIA: labelStatusText.Text = "Validating current media..."; break; case IMAPI_FORMAT2_DATA_WRITE_ACTION.IMAPI_FORMAT2_DATA_WRITE_ACTION_FORMATTING_MEDIA: labelStatusText.Text = "Formatting media..."; break; case IMAPI_FORMAT2_DATA_WRITE_ACTION.IMAPI_FORMAT2_DATA_WRITE_ACTION_INITIALIZING_HARDWARE: labelStatusText.Text = "Initializing hardware..."; break; case IMAPI_FORMAT2_DATA_WRITE_ACTION.IMAPI_FORMAT2_DATA_WRITE_ACTION_CALIBRATING_POWER: labelStatusText.Text = "Optimizing laser intensity..."; break; case IMAPI_FORMAT2_DATA_WRITE_ACTION.IMAPI_FORMAT2_DATA_WRITE_ACTION_WRITING_DATA: long writtenSectors = burnData.lastWrittenLba - burnData.startLba; if (writtenSectors > 0 && burnData.sectorCount > 0) { int percent = (int)((100 * writtenSectors) / burnData.sectorCount); labelStatusText.Text = string.Format("Progress: {0}%", percent); statusProgressBar.Value = percent; } else { labelStatusText.Text = "Progress 0%"; statusProgressBar.Value = 0; } break; case IMAPI_FORMAT2_DATA_WRITE_ACTION.IMAPI_FORMAT2_DATA_WRITE_ACTION_FINALIZATION: labelStatusText.Text = "Finalizing writing..."; break; case IMAPI_FORMAT2_DATA_WRITE_ACTION.IMAPI_FORMAT2_DATA_WRITE_ACTION_COMPLETED: labelStatusText.Text = "Completed!"; break; } } }
private string StatusWriting(BurnData burnData) { long writtenSectors = burnData.LastWrittenLba - burnData.StartLba; if (writtenSectors > 0 && burnData.SectorCount > 0) { var percent = (int)((100 * writtenSectors) / burnData.SectorCount); statusProgressBar.Value = percent; return(string.Format("Progress: {0}%", percent)); } else { statusProgressBar.Value = 0; return("Progress 0%"); } }
/// <summary> /// The thread that does the burning of the media /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void backgroundBurnWorker_DoWork(object sender, DoWorkEventArgs e) { // // Create and initialize the IDiscRecorder2 object // MsftDiscRecorder2 discRecorder = new MsftDiscRecorder2(); BurnData burnData = (BurnData)e.Argument; discRecorder.InitializeDiscRecorder(burnData.uniqueRecorderId); discRecorder.AcquireExclusiveAccess(true, m_clientName); // // Create and initialize the IDiscFormat2Data // MsftDiscFormat2Data discFormatData = new MsftDiscFormat2Data(); discFormatData.Recorder = discRecorder; discFormatData.ClientName = m_clientName; discFormatData.ForceMediaToBeClosed = checkBoxCloseMedia.Checked; // // Check if media is blank, (for RW media) // object[] multisessionInterfaces = null; if (!discFormatData.MediaHeuristicallyBlank) { multisessionInterfaces = discFormatData.MultisessionInterfaces; } // // Create the file system // IStream fileSystem = null; if (!CreateMediaFileSystem(discRecorder, multisessionInterfaces, out fileSystem)) { e.Result = -1; return; } // // add the Update event handler // discFormatData.Update += new DiscFormat2Data_EventHandler(discFormatData_Update); // // Write the data here // try { discFormatData.Write(fileSystem); e.Result = 0; } catch (COMException ex) { e.Result = ex.ErrorCode; MessageBox.Show(ex.Message, "IDiscFormat2Data.Write failed", MessageBoxButtons.OK, MessageBoxIcon.Stop); } // // remove the Update event handler // discFormatData.Update -= new DiscFormat2Data_EventHandler(discFormatData_Update); if (this.checkBoxEject.Checked) { discRecorder.EjectMedia(); } discRecorder.ReleaseExclusiveAccess(); }
public FileManager(BackgroundWorker backgroundBurnWorke) { _burnData = new BurnData(); this.backgroundBurnWorker = backgroundBurnWorke; this.files = new List <IMediaItem>(); }