Пример #1
0
        public void OnConnection(object Application, ext_ConnectMode ConnectMode, object AddInInst, ref Array custom)
        {
            try
            {
                _vbe          = RootComWrapperFactory.GetVbeWrapper(Application);
                _addin        = RootComWrapperFactory.GetAddInWrapper(AddInInst);
                _addin.Object = this;

                VbeProvider.Initialize(_vbe);
                VbeNativeServices.HookEvents(_vbe);

#if DEBUG
                // FOR DEBUGGING/DEVELOPMENT PURPOSES, ALLOW ACCESS TO SOME VBETypeLibsAPI FEATURES FROM VBA
                _addin.Object = new VBEditor.ComManagement.TypeLibsAPI.VBETypeLibsAPI_Object(_vbe);
#endif

                switch (ConnectMode)
                {
                case ext_ConnectMode.ext_cm_Startup:
                    // normal execution path - don't initialize just yet, wait for OnStartupComplete to be called by the host.
                    break;

                case ext_ConnectMode.ext_cm_AfterStartup:
                    _isBeginShutdownExecuted = false;       //When we reconnect after having been unloaded, the variable might no longer have its initial value.
                    InitializeAddIn();
                    break;
                }
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
            }
        }
Пример #2
0
        public void OnConnection(object Application, ext_ConnectMode ConnectMode, object AddInInst, ref Array custom)
        {
            try
            {
                _vbe          = RootComWrapperFactory.GetVbeWrapper(Application);
                _addin        = RootComWrapperFactory.GetAddInWrapper(AddInInst);
                _addin.Object = this;

                _vbeNativeApi    = new VbeNativeApiAccessor();
                _beepInterceptor = new BeepInterceptor(_vbeNativeApi);
                VbeProvider.Initialize(_vbe, _vbeNativeApi, _beepInterceptor);
                VbeNativeServices.HookEvents(_vbe);

                SetAddInObject();

                switch (ConnectMode)
                {
                case ext_ConnectMode.ext_cm_Startup:
                    // normal execution path - don't initialize just yet, wait for OnStartupComplete to be called by the host.
                    break;

                case ext_ConnectMode.ext_cm_AfterStartup:
                    _isBeginShutdownExecuted = false;       //When we reconnect after having been unloaded, the variable might no longer have its initial value.
                    InitializeAddIn();
                    break;
                }
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
            }
        }
Пример #3
0
        private void ShutdownAddIn()
        {
            var currentDomain = AppDomain.CurrentDomain;

            try
            {
                _logger.Log(LogLevel.Info, "Rubberduck is shutting down.");
                _logger.Log(LogLevel.Trace, "Unhooking VBENativeServices events...");
                VbeNativeServices.UnhookEvents();
                VbeProvider.Terminate();

                _logger.Log(LogLevel.Trace, "Releasing dockable hosts...");

                using (var windows = _vbe.Windows)
                {
                    windows.ReleaseDockableHosts();
                }

                if (_app != null)
                {
                    _logger.Log(LogLevel.Trace, "Initiating App.Shutdown...");
                    _app.Shutdown();
                    _app = null;
                }

                if (_container != null)
                {
                    _logger.Log(LogLevel.Trace, "Disposing IoC container...");
                    _container.Dispose();
                    _container = null;
                }
            }
            catch (Exception e)
            {
                _logger.Error(e);
                _logger.Log(LogLevel.Warn, "Exception is swallowed.");
                //throw; // <<~ uncomment to crash the process
            }
            finally
            {
                try
                {
                    _logger.Log(LogLevel.Trace, "Disposing COM safe...");
                    ComSafeManager.DisposeAndResetComSafe();
                    _addin = null;
                    _vbe   = null;

                    _isInitialized = false;
                    _logger.Log(LogLevel.Info, "No exceptions were thrown.");
                }
                catch (Exception e)
                {
                    _logger.Error(e);
                    _logger.Log(LogLevel.Warn, "Exception disposing the ComSafe has been swallowed.");
                    //throw; // <<~ uncomment to crash the process
                }
                finally
                {
                    _logger.Log(LogLevel.Trace, "Unregistering AppDomain handlers....");
                    currentDomain.AssemblyResolve    -= LoadFromSameFolder;
                    currentDomain.UnhandledException -= HandlAppDomainException;
                    _logger.Log(LogLevel.Trace, "Done. Main Shutdown completed. Toolwindows follow. Quack!");
                    _isInitialized = false;
                }
            }
        }