/// <summary> /// Instantiate the <c>MsDiscMasterObj</c> implementation, open /// it, create progress events and the recorder collection. /// </summary> /// <exception cref="COMException">if the <c>MsDiscMasterObj</c> implementation /// cannot be instantiated.</exception> /// <exception cref="DiscMasterAlreadyOpenedException"></exception> /// <exception cref="DiscMasterNotOpenedException"></exception> private void InitializeImapi() { _discMaster = IDiscMaster; try { _discMaster.Open(); } catch ( COMException ex ) { Trace.WriteLine( ex.Message + Environment.NewLine + ex.StackTrace ); if ( (uint) ex.ErrorCode == ErrorCodes.IMAPI_E_ALREADYOPEN ) { throw new DiscMasterAlreadyOpenedException(); } throw; } // Set up progress events _progressEvents = new DiscMasterProgressEvents( this ); IntPtr cookie = IntPtr.Zero; IDiscMasterProgressEvents iprgEvents = _progressEvents; try { _discMaster.ProgressAdvise( iprgEvents, out cookie ); } catch ( COMException ex ) { Trace.WriteLine( ex.Message + Environment.NewLine + ex.StackTrace ); if ( (uint) ex.ErrorCode == ErrorCodes.IMAPI_E_NOTOPENED ) { throw new DiscMasterNotOpenedException(); } throw; } _progressEvents.Cookie = cookie; // Recorders collection DiscRecorders = new DiscRecorderCollection( _discMaster ); }
/// <summary> /// Dispose(bool disposing) executes in two distinct scenarios. /// If disposing equals true, the method has been called directly /// or indirectly by a user's code. Managed and unmanaged resources /// can be disposed. /// </summary> /// <param name="disposing"> /// If disposing equals false, the method has been called by the /// runtime from inside the finalizer and you should not reference /// other objects. Only unmanaged resources can be disposed. /// </param> protected override void Dispose( bool disposing ) { // Check to see if Dispose has already been called. if ( disposing && !IsDisposed ) { // If disposing equals true, dispose all managed // and unmanaged resources. if ( _jolietDiscMaster != null ) { _jolietDiscMaster.Dispose(); } if ( _redbookDiscMaster != null ) { _redbookDiscMaster.Dispose(); } // Dispose managed resources. if ( _discMaster != null ) { if ( _progressEvents != null ) { try { _discMaster.ProgressUnadvise( _progressEvents.Cookie ); } catch ( COMException ex ) { if ( (uint) ex.ErrorCode == ErrorCodes.IMAPI_E_NOTOPENED ) { // do not throw an exception in the dispose. Trace.WriteLine( Resources.Error_Msg_IMAPI_E_NOTOPENED ); } Trace.WriteLine( ex.Message + Environment.NewLine + ex.StackTrace ); } _progressEvents.Dispose(); _progressEvents = null; } _discMaster.Close(); Marshal.ReleaseComObject( _discMaster ); _discMaster = null; } if ( DiscRecorders != null ) { DiscRecorders.Dispose(); } } base.Dispose( disposing ); }