示例#1
0
        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();
            }

            // 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.
            if (connectMode == ext_ConnectMode.ext_cm_UISetup ||    // When VS sets up UI for Addin.
                connectMode == ext_ConnectMode.ext_cm_Startup ||    // When VS is started.
                connectMode == ext_ConnectMode.ext_cm_AfterStartup) // When loading from Tools->Addin Manager.
            {
                try
                {
                    lock (m_hostLock)   // Protect from calling with different modes at the same time.
                    {
                        DTE2 dteApplication = (DTE2)application;
                        Debug.Assert(dteApplication != null, "OnConnect: (DTE2)application = null!");

                        if (!m_hostInitialized) // When loading from Tools->Addin Manager.
                        {
                            m_applicationObject = dteApplication;

                            SetupChannels();

                            InitHostSide();

                            m_hostInitialized = true;
                            m_hostInitializedEvent.Set();
                        }
                    }

                    // Marshal the object to serve debug requests from the adapter.
                    // This does not have to be done inside the lock.
                    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;
                }
            }
        }
        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();
            }

            // 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.
            if (connectMode == ext_ConnectMode.ext_cm_UISetup ||    // When VS sets up UI for Addin.
                connectMode == ext_ConnectMode.ext_cm_Startup ||    // When VS is started.
                connectMode == ext_ConnectMode.ext_cm_AfterStartup) // When loading from Tools->Addin Manager.
            {
                try
                {
                    lock (m_hostLock)   // Protect from calling with different modes at the same time.
                    {
                        DTE2 dteApplication = (DTE2)application;
                        Debug.Assert(dteApplication != null, "OnConnect: (DTE2)application = null!");

                        if (!m_hostInitialized) // When loading from Tools->Addin Manager.
                        {
                            m_applicationObject = dteApplication;

                            SetupChannels();

                            InitHostSide();

                            m_hostInitialized = true;
                            m_hostInitializedEvent.Set();
                        }
                    }

                    // Marshal the object to serve debug requests from the adapter.
                    // This does not have to be done inside the lock.
                    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;
                }
            }
        }