tools/VsIdeHostAdapter/TargetAddIn/HostSide/VsIdeHostAddin.cs
/// <summary>Implements the OnConnection method of the IDTExtensibility2 interface. Receives notification that the Add-in is being loaded.</summary>
/// <param term='application'>Root object of the host application.</param>
/// <param term='connectMode'>Describes how the Add-in is being loaded.</param>
/// <param term='addInInst'>Object representing this Add-in.</param>
/// <seealso class='IDTExtensibility2' />
Implements the OnConnection method of the IDTExtensibility2 interface. Receives notification that the Add-in is being loaded.
Root object of the host application.
Describes how the Add-in is being loaded.
Object representing this Add-in.
Implements the OnConnection method of the IDTExtensibility2 interface . Receives notification that the Add - in is being loaded . Root object of the host application . Describes how the Add - in is being loaded . Object representing this Add - in .
[CLSCompliant(false)]
        [SuppressMessage("Microsoft.Naming", "CA1725:ParameterNamesShouldMatchBaseDeclaration", MessageId = "0#")]
        [SuppressMessage("Microsoft.Naming", "CA1725:ParameterNamesShouldMatchBaseDeclaration", MessageId = "1#")]
        [SuppressMessage("Microsoft.Naming", "CA1725:ParameterNamesShouldMatchBaseDeclaration", MessageId = "2#")]
        public void OnConnection(object application, ext_ConnectMode connectMode, object addInInst, ref Array custom)
        {
            Trace.WriteLine(string.Format(
                CultureInfo.InvariantCulture,
                "[pid={0,4}, tid={1,2}, {2:yyyy}/{2:MM}/{2:dd} {2:HH}:{2:mm}:{2:ss}.{2:fff}] VsIdeTestHostAddin.OnConnection", 
                System.Diagnostics.Process.GetCurrentProcess().Id, 
                System.Threading.Thread.CurrentThread.ManagedThreadId, 
                DateTime.Now));
            if (RegistrySettings.LookupRegistrySetting<int>("EnableDebugBreak", 0) == 1)
            {
                System.Diagnostics.Debugger.Break();
            }
            if (connectMode == ext_ConnectMode.ext_cm_UISetup ||    
                connectMode == ext_ConnectMode.ext_cm_Startup ||    
                connectMode == ext_ConnectMode.ext_cm_AfterStartup) 
            {
                try
                {
                    lock (m_hostLock)   
                    {
                        DTE2 dteApplication = (DTE2)application;
                        Debug.Assert(dteApplication != null, "OnConnect: (DTE2)application = null!");
                        if (!m_hostInitialized) 
                        {
                            m_applicationObject = dteApplication;
                            SetupChannels();
                            InitHostSide();
                            m_hostInitialized = true;
                            m_hostInitializedEvent.Set();
                        }
                    }
                    if (m_debugger == null)
                    {
                        m_debugger = new VsIdeHostDebugger(m_applicationObject.DTE);
                        RemotingServices.Marshal(m_debugger, VsIdeHostSession.RemoteObjectName);
                    }
                }
                catch (Exception ex)
                {
                    Debug.Fail("Addin.OnConnection: " + ex.ToString());
                    throw;
                }
            }
        }
[ CLSCompliant ( false ) ] [ SuppressMessage ( " " , " " , MessageId = " " ) ] [ SuppressMessage ( " " , " " , MessageId = " " ) ] [ SuppressMessage ( " " , " " , MessageId = " " ) ] public void OnConnection ( object application , ext_ConnectMode connectMode , object addInInst , ref Array custom ) { Trace . WriteLine ( string . Format ( CultureInfo . InvariantCulture , " " , System . Diagnostics . Process . GetCurrentProcess ( ) . Id , System . Threading . Thread . CurrentThread . ManagedThreadId , DateTime . Now ) ) ; if ( RegistrySettings . LookupRegistrySetting < int > ( " " , 0 ) == 1 ) { System . Diagnostics . Debugger . Break ( ) ; } if ( connectMode == ext_ConnectMode . ext_cm_UISetup || connectMode == ext_ConnectMode . ext_cm_Startup || connectMode == ext_ConnectMode . ext_cm_AfterStartup ) { try { lock ( m_hostLock ) { DTE2 dteApplication = ( DTE2 ) application ; Debug . Assert ( dteApplication != null , " " ) ; if ( ! m_hostInitialized ) { m_applicationObject = dteApplication ; SetupChannels ( ) ; InitHostSide ( ) ; m_hostInitialized = true ; m_hostInitializedEvent . Set ( ) ; } } if ( m_debugger == null ) { m_debugger = new VsIdeHostDebugger ( m_applicationObject . DTE ) ; RemotingServices . Marshal ( m_debugger , VsIdeHostSession . RemoteObjectName ) ; } } catch ( Exception ex ) { Debug . Fail ( " " + ex . ToString ( ) ) ; throw ; } } }
<summary>Implements the OnConnection method of the IDTExtensibility2 interface.
<summary > Implements the OnConnection method of the IDTExtensibility2 interface .
// The idea about connection modes is to make sure we are initialized // after 1st OnConnection is called. Because this is when VS thinks that // addin is ready and returns it to outside. // When VS sets up UI for Addin. // When VS is started. // When loading from Tools->Addin Manager. // Protect from calling with different modes at the same time. // When loading from Tools->Addin Manager. // Marshal the object to serve debug requests from the adapter. // This does not have to be done inside the lock.
application
object
connectMode
ext_ConnectMode
addInInst
object
Array
ref