Example #1
0
        /// <summary>
        /// Sets the property value.
        /// </summary>
        /// <param name="jolietDiscMaster">The joliet disc master.</param>
        /// <param name="propertyID">The property ID.</param>
        /// <param name="value">The value.</param>
        /// <exception cref="COMException"></exception>
        /// <exception cref="NoDevicePropertiesException"></exception>
        /// <exception cref="DiscMasterNotOpenedException"></exception>
        /// <exception cref="NoActiveFormatException"></exception>
        /// <exception cref="WrongFormatException"></exception>
        internal static void SetJolietPropertyValue( IJolietDiscMaster jolietDiscMaster, string propertyID, object value )
        {
            IPropertyStorage ppPropStg;
            PropSpec rgPropID;
            object newValue;

            try
            {
                jolietDiscMaster.GetJolietProperties( out ppPropStg );
            }
            catch ( COMException ex )
            {
                Trace.WriteLine( ex.Message + Environment.NewLine + ex.StackTrace );
                switch ( (uint) ex.ErrorCode )
                {
                    case ErrorCodes.IMAPI_E_DEVICE_NOPROPERTIES:
                        throw new NoDevicePropertiesException();
                    case ErrorCodes.IMAPI_E_NOTOPENED:
                        throw new DiscMasterNotOpenedException();
                    case ErrorCodes.IMAPI_E_NOACTIVEFORMAT:
                        throw new NoActiveFormatException();
                    case ErrorCodes.IMAPI_E_WRONGFORMAT:
                        throw new WrongFormatException();
                    default:
                        throw;
                }
            }
            newValue = value;
            rgPropID = new PropSpec();

            rgPropID.ulKind = PrpSpec.LPWStr;
            rgPropID.ID_or_LPWSTR = Marshal.StringToCoTaskMemUni( propertyID );

            try
            {
                ppPropStg.WriteMultiple( 1, ref rgPropID, ref newValue, 8 );
            }
            catch ( Exception ex )
            {
                Trace.WriteLine( string.Format( CultureInfo.CurrentCulture, "Error setting {0}.{1}{2}{3}{4}", propertyID,
                                                Environment.NewLine,
                                                ex.Message, Environment.NewLine, ex.StackTrace ) );
                throw;
            }
            finally
            {
                Marshal.FreeCoTaskMem( rgPropID.ID_or_LPWSTR );
            }

            try
            {
                jolietDiscMaster.SetJolietProperties( ppPropStg );
            }
            catch ( COMException ex )
            {
                Trace.WriteLine( ex.Message + Environment.NewLine + ex.StackTrace );
                switch ( (uint) ex.ErrorCode )
                {
                    case ErrorCodes.IMAPI_S_PROPERTIESIGNORED:
                        Trace.WriteLine( Resources.Error_Msg_IMAPI_S_PROPERTIESIGNORED );
                        break;
                    case ErrorCodes.IMAPI_E_DEVICE_NOPROPERTIES:
                        throw new NoDevicePropertiesException();
                    case ErrorCodes.IMAPI_E_NOTOPENED:
                        throw new DiscMasterNotOpenedException();
                    case ErrorCodes.IMAPI_E_NOACTIVEFORMAT:
                        throw new NoActiveFormatException();
                    case ErrorCodes.IMAPI_E_WRONGFORMAT:
                        throw new WrongFormatException();
                    default:
                        throw;
                }
            }
        }
Example #2
0
        /// <summary>
        /// Sets the property value.
        /// </summary>
        /// <param name="discRecorder">The disc recorder.</param>
        /// <param name="propertyID">The property ID.</param>
        /// <returns></returns>
        /// <exception cref="COMException"></exception>
        /// <exception cref="NoDevicePropertiesException"></exception>
        /// <exception cref="RecorderNotInitializedException"></exception>
        /// <exception cref="ArgumentNullException"></exception>
        internal static object GetDiscRecorderPropertyValue( IDiscRecorder discRecorder, string propertyID )
        {
            IPropertyStorage ppPropStg;
            PropSpec rgPropID;
            object rgPropVar;

            try
            {
                discRecorder.GetRecorderProperties( out ppPropStg );
            }
            catch ( COMException ex )
            {
                switch ( (uint) ex.ErrorCode )
                {
                    case ErrorCodes.IMAPI_E_DEVICE_NOPROPERTIES:
                        throw new NoDevicePropertiesException();
                    case ErrorCodes.IMAPI_E_NOTINITIALIZED:
                        throw new RecorderNotInitializedException();
                    default:
                        throw;
                }
            }

            rgPropID = new PropSpec();
            rgPropVar = null;
            rgPropID.ulKind = PrpSpec.LPWStr;
            rgPropID.ID_or_LPWSTR = Marshal.StringToCoTaskMemUni( propertyID );

            try
            {
                ppPropStg.ReadMultiple( 1, ref rgPropID, out rgPropVar );
            }
            catch ( COMException ce )
            {
                Trace.WriteLine( CultureInfo.CurrentCulture, "Error getting AudioGapSize." );
                Trace.WriteLine( string.Format( CultureInfo.CurrentCulture, "{0}{1}{2}", ce.Message, Environment.NewLine,
                                                ce.StackTrace ) );
                return -1;
            }
            finally
            {
                Marshal.FreeCoTaskMem( rgPropID.ID_or_LPWSTR );
            }

            try
            {
                return Int32.Parse( rgPropVar.ToString(), CultureInfo.CurrentCulture );
            }
            catch ( Exception ex )
            {
                Trace.WriteLine( ex.Message + Environment.NewLine + ex.StackTrace );
                return -1;
            }
        }