예제 #1
0
        //========================================================================================
        // Constructors
        //========================================================================================

        /// <summary>
        /// Initialize class static fields.
        /// </summary>

        static Interaction()
        {
            enabledEvent  = new _IiTunesEvents_OnCOMCallsEnabledEventEventHandler(DoEnabledEvent);
            disabledEvent = new _IiTunesEvents_OnCOMCallsDisabledEventEventHandler(DoDisabledEvent);

            reset = new ManualResetEvent(true);

            isConnected = false;
        }
예제 #2
0
        //========================================================================================
        // Constructors
        //========================================================================================

        /// <summary>
        /// Initialize class static fields.
        /// </summary>

        static Interaction()
        {
            enabledEvent  = DoEnabledEvent;
            disabledEvent = DoDisabledEvent;

            reset = new ManualResetEvent(true);

            isConnected = false;
        }
예제 #3
0
        //========================================================================================
        // Constructors
        //========================================================================================

        /// <summary>
        /// Initialize class static fields.
        /// </summary>

        static Interaction()
        {
            enabledEvent  = new _IiTunesEvents_OnCOMCallsEnabledEventEventHandler(DoEnabledEvent);
            disabledEvent = new _IiTunesEvents_OnCOMCallsDisabledEventEventHandler(DoDisabledEvent);

            itunes = new iTunesAppClass();
            itunes.OnCOMCallsEnabledEvent  += enabledEvent;
            itunes.OnCOMCallsDisabledEvent += disabledEvent;

            reset = new ManualResetEvent(true);
        }
예제 #4
0
        /// <summary>
        /// Dispose of this instance, optionally exiting iTunes.
        /// </summary>
        /// <param name="finalRelease"><b>true</b> to exit iTunes.</param>

        public void Dispose(bool finalRelease)
        {
            if (!isDisposed)
            {
                // invoke Cleanup on behalf of the derived class
                Cleanup(finalRelease);

                if (isPrimaryController)
                {
                    isConnected = false;

                    if (itunes != null)
                    {
                        try
                        {
                            itunes.OnCOMCallsDisabledEvent -= disabledEvent;
                            itunes.OnCOMCallsEnabledEvent  -= enabledEvent;
                        }
                        catch (InvalidComObjectException)
                        {
                            // RCW may be released already... why?
                        }

                        disabledEvent = null;
                        enabledEvent  = null;

                        if (finalRelease)
                        {
                            try
                            {
                                itunes.Quit();
                            }
                            catch
                            {
                                // no-op
                            }
                            finally
                            {
                                Release(itunes);
                                itunes = null;
                            }
                        }

                        reset.Set();
                        reset.Close();
                        reset = null;
                    }
                }

                isDisposed = true;
                GC.SuppressFinalize(this);
            }
        }
예제 #5
0
        /// <summary>
        /// Dispose of this instance; do not override.
        /// </summary>

        public void Dispose()
        {
            if (!isDisposed)
            {
                // invoke Cleanup on behalf of the derived class
                Cleanup();

                if (isPrimaryController)
                {
                    isConnected = false;

                    if (itunes != null)
                    {
                        itunes.OnCOMCallsDisabledEvent -= disabledEvent;
                        itunes.OnCOMCallsEnabledEvent  -= enabledEvent;
                        disabledEvent = null;
                        enabledEvent  = null;

                        try
                        {
                            itunes.Quit();
                        }
                        catch
                        {
                            // no-op
                        }
                        finally
                        {
                            Release(itunes);
                            itunes = null;
                        }

                        reset.Set();
                        reset.Close();
                        reset = null;
                    }
                }

                isDisposed = true;
                GC.SuppressFinalize(this);
            }
        }
예제 #6
0
        public void iTunes()
        {
            itunes = new iTunesAppClass();

            aboutToPromptUserToQuitEvent = new _IiTunesEvents_OnAboutToPromptUserToQuitEventEventHandler(itunes_OnAboutToPromptUserToQuitEvent);
            cOMCallsDisabledEvent        = new _IiTunesEvents_OnCOMCallsDisabledEventEventHandler(itunes_OnCOMCallsDisabledEvent);
            cOMCallsEnabledEvent         = new _IiTunesEvents_OnCOMCallsEnabledEventEventHandler(itunes_OnCOMCallsEnabledEvent);
            databaseChangedEvent         = new _IiTunesEvents_OnDatabaseChangedEventEventHandler(itunes_OnDatabaseChangedEvent);
            playerPlayEvent = new _IiTunesEvents_OnPlayerPlayEventEventHandler(itunes_OnPlayerPlayEvent);
            playerPlayingTrackChangedEvent = new _IiTunesEvents_OnPlayerPlayingTrackChangedEventEventHandler(itunes_OnPlayerPlayingTrackChangedEvent);
            playerStopEvent           = new _IiTunesEvents_OnPlayerStopEventEventHandler(itunes_OnPlayerStopEvent);
            quittingEvent             = new _IiTunesEvents_OnQuittingEventEventHandler(itunes_OnQuittingEvent);
            soundVolumeChangedEvent   = new _IiTunesEvents_OnSoundVolumeChangedEventEventHandler(itunes_OnSoundVolumeChangedEvent);
            userInterfaceEnabledEvent = new _IiTunesEvents_OnUserInterfaceEnabledEventEventHandler(itunes_OnUserInterfaceEnabledEvent);

            // NOTE: did not see any difference in maintaining these individual handler variables
            // as opposed to unregistering -= new handlers in the OnAboutToPromptToQuit handler

            itunes.OnAboutToPromptUserToQuitEvent += aboutToPromptUserToQuitEvent;
            itunes.OnCOMCallsDisabledEvent        += cOMCallsDisabledEvent;
            itunes.OnCOMCallsEnabledEvent         += cOMCallsEnabledEvent;
            itunes.OnDatabaseChangedEvent         += databaseChangedEvent;
            itunes.OnPlayerPlayEvent += playerPlayEvent;
            itunes.OnPlayerPlayingTrackChangedEvent += playerPlayingTrackChangedEvent;
            itunes.OnPlayerStopEvent           += playerStopEvent;
            itunes.OnQuittingEvent             += quittingEvent;
            itunes.OnSoundVolumeChangedEvent   += soundVolumeChangedEvent;
            itunes.OnUserInterfaceEnabledEvent += userInterfaceEnabledEvent;

            AllProps(itunes);

            reset = new ManualResetEvent(false);

            // waiting for iTunes to quit
            reset.WaitOne();
        }
예제 #7
0
        public void iTunes()
        {
            itunes = new iTunesAppClass();

            aboutToPromptUserToQuitEvent = new _IiTunesEvents_OnAboutToPromptUserToQuitEventEventHandler(itunes_OnAboutToPromptUserToQuitEvent);
            cOMCallsDisabledEvent = new _IiTunesEvents_OnCOMCallsDisabledEventEventHandler(itunes_OnCOMCallsDisabledEvent);
            cOMCallsEnabledEvent = new _IiTunesEvents_OnCOMCallsEnabledEventEventHandler(itunes_OnCOMCallsEnabledEvent);
            databaseChangedEvent = new _IiTunesEvents_OnDatabaseChangedEventEventHandler(itunes_OnDatabaseChangedEvent);
            playerPlayEvent = new _IiTunesEvents_OnPlayerPlayEventEventHandler(itunes_OnPlayerPlayEvent);
            playerPlayingTrackChangedEvent = new _IiTunesEvents_OnPlayerPlayingTrackChangedEventEventHandler(itunes_OnPlayerPlayingTrackChangedEvent);
            playerStopEvent = new _IiTunesEvents_OnPlayerStopEventEventHandler(itunes_OnPlayerStopEvent);
            quittingEvent = new _IiTunesEvents_OnQuittingEventEventHandler(itunes_OnQuittingEvent);
            soundVolumeChangedEvent = new _IiTunesEvents_OnSoundVolumeChangedEventEventHandler(itunes_OnSoundVolumeChangedEvent);
            userInterfaceEnabledEvent = new _IiTunesEvents_OnUserInterfaceEnabledEventEventHandler(itunes_OnUserInterfaceEnabledEvent);

            // NOTE: did not see any difference in maintaining these individual handler variables
            // as opposed to unregistering -= new handlers in the OnAboutToPromptToQuit handler

            itunes.OnAboutToPromptUserToQuitEvent += aboutToPromptUserToQuitEvent;
            itunes.OnCOMCallsDisabledEvent += cOMCallsDisabledEvent;
            itunes.OnCOMCallsEnabledEvent += cOMCallsEnabledEvent;
            itunes.OnDatabaseChangedEvent += databaseChangedEvent;
            itunes.OnPlayerPlayEvent += playerPlayEvent;
            itunes.OnPlayerPlayingTrackChangedEvent += playerPlayingTrackChangedEvent;
            itunes.OnPlayerStopEvent += playerStopEvent;
            itunes.OnQuittingEvent += quittingEvent;
            itunes.OnSoundVolumeChangedEvent += soundVolumeChangedEvent;
            itunes.OnUserInterfaceEnabledEvent += userInterfaceEnabledEvent;

            AllProps(itunes);

            reset = new ManualResetEvent(false);

            // waiting for iTunes to quit
            reset.WaitOne();
        }