Exemple #1
0
        /// <summary>
        /// Worker thread that Formats the Disc
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void backgroundFormatWorker_DoWork(object sender, DoWorkEventArgs e)
        {
            MsftDiscRecorder2    discRecorder    = null;
            MsftDiscFormat2Erase discFormatErase = null;
            BurnerMsg            burnerMsg       = new BurnerMsg(this);

            try
            {
                //
                // Create and initialize the IDiscRecorder2
                //
                discRecorder = new MsftDiscRecorder2();
                var activeDiscRecorder = (string)e.Argument;
                discRecorder.InitializeDiscRecorder(activeDiscRecorder);

                //
                // Create the IDiscFormat2Erase and set properties
                //
                discFormatErase = new MsftDiscFormat2Erase
                {
                    Recorder   = discRecorder,
                    ClientName = ClientName,
                    FullErase  = !quickFormat
                };

                //
                // Setup the Update progress event handler
                //
                discFormatErase.Update += discFormatErase_Update;

                //
                // Erase the media here
                //
                try
                {
                    discFormatErase.EraseMedia();
                    e.Result = 0;
                }
                catch (COMException ex)
                {
                    e.Result = ex.ErrorCode;
                    System.Diagnostics.Trace.WriteLine("IDiscFormat2.EraseMedia failed " + ex.Message);
                    burnerMsg.fase = Fase.FormattazioneFallita;
                    OnInviaStatoMasterizzazione(burnerMsg);
                }

                //
                // Remove the Update progress event handler
                //
                discFormatErase.Update -= discFormatErase_Update;

                //
                // Eject the media
                //
                if (ejectMedia)
                {
                    discRecorder.EjectMedia();
                }
                burnerMsg.fase = Fase.FormattazioneCompletata;
                OnInviaStatoMasterizzazione(burnerMsg);
            }
            catch (COMException exception)
            {
                //
                // If anything happens during the format, show the message
                //
                System.Diagnostics.Trace.WriteLine(exception.Message);
                burnerMsg.fase = Fase.FormattazioneFallita;
                OnInviaStatoMasterizzazione(burnerMsg);
            }
            finally
            {
                if (discRecorder != null)
                {
                    Marshal.ReleaseComObject(discRecorder);
                }

                if (discFormatErase != null)
                {
                    Marshal.ReleaseComObject(discFormatErase);
                }
            }
        }
Exemple #2
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)
        {
            MsftDiscRecorder2   discRecorder   = null;
            MsftDiscFormat2Data discFormatData = null;

            try
            {
                //
                // Create and initialize the IDiscRecorder2 object
                //
                discRecorder = new MsftDiscRecorder2();
                var burnData = (BurnData)e.Argument;
                discRecorder.InitializeDiscRecorder(burnData.uniqueRecorderId);

                //
                // Create and initialize the IDiscFormat2Data
                //
                discFormatData = new MsftDiscFormat2Data
                {
                    Recorder             = discRecorder,
                    ClientName           = ClientName,
                    ForceMediaToBeClosed = closeMedia
                };

                //
                // Set the verification level
                //
                var burnVerification = (IBurnVerification)discFormatData;
                burnVerification.BurnVerificationLevel = _verificationLevel;

                //
                // Check if media is blank, (for RW media)
                //
                object[] multisessionInterfaces = null;
                if (!discFormatData.MediaHeuristicallyBlank)
                {
                    multisessionInterfaces = discFormatData.MultisessionInterfaces;
                }

                //
                // Create the file system
                //
                IStream fileSystem;
                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;
                    BurnerMsg burnerMsg = new BurnerMsg(this);
                    burnerMsg.fase          = Fase.MasterizzazioneFallita;
                    burnerMsg.statusMessage = "IDiscFormat2Data.Write failed";
                    OnInviaStatoMasterizzazione(burnerMsg);
                    System.Diagnostics.Trace.WriteLine(ex.Message, "IDiscFormat2Data.Write failed");
                }
                finally
                {
                    if (fileSystem != null)
                    {
                        Marshal.FinalReleaseComObject(fileSystem);
                    }
                }

                //
                // remove the Update event handler
                //
                discFormatData.Update -= new DiscFormat2Data_EventHandler(discFormatData_Update);

                if (ejectMedia)
                {
                    discRecorder.EjectMedia();
                }
            }
            catch (COMException exception)
            {
                //
                // If anything happens during the format, show the message
                //
                System.Diagnostics.Trace.WriteLine("[Eccezione]: " + exception.Message);
                e.Result = exception.ErrorCode;
                BurnerMsg burnerMsg = new BurnerMsg(this);
                burnerMsg.fase          = Fase.MasterizzazioneFallita;
                burnerMsg.statusMessage = exception.Message;
                OnInviaStatoMasterizzazione(burnerMsg);
            }
            finally
            {
                if (discRecorder != null)
                {
                    Marshal.ReleaseComObject(discRecorder);
                }

                if (discFormatData != null)
                {
                    Marshal.ReleaseComObject(discFormatData);
                }
            }
        }