Esempio n. 1
0
        /// <summary>
        /// Initialization of the package; this method is called right after the package is sited, so this is the place
        /// where you can put all the initialization code that rely on services provided by VisualStudio.
        /// </summary>
        protected override void Initialize()
        {
            base.Initialize();

            this.logger.Debug("Initializing...");

            var visualStudioProcess = Process.GetCurrentProcess();

            this.otherApplicationFocusedHandlerReference = this.HandleOtherApplicationFocused;
            this.currentInstanceFocusedHandlerReference  = this.HandleCurrentInstanceFocused;
            this.otherApplicationFocusedHookHandle       = WindowsEventHooker.SetWinEventHook(3, 3, IntPtr.Zero, this.otherApplicationFocusedHandlerReference, 0, 0, SetWinEventHookFlags.WINEVENT_OUTOFCONTEXT | SetWinEventHookFlags.WINEVENT_SKIPOWNPROCESS);
            this.currentInstanceFocusedHookHandle        = WindowsEventHooker.SetWinEventHook(3, 3, IntPtr.Zero, this.currentInstanceFocusedHandlerReference, (uint)visualStudioProcess.Id, 0, SetWinEventHookFlags.WINEVENT_OUTOFCONTEXT);

            try
            {
                var dte = (DTE)this.GetService(typeof(DTE));

                this.solutionEvents = dte.Events.SolutionEvents;
                this.solutionEvents.BeforeClosing += this.HandleBeforeClosingSolution;
            }
            catch (Exception e)
            {
                this.logger.Error(e, "Could not hook visual studio closing event.");
            }

            this.logger.Debug("Initialized...");
        }
        /// <summary>
        /// Initialization of the package; this method is called right after the package is sited, so this is the place
        /// where you can put all the initialization code that rely on services provided by VisualStudio.
        /// </summary>
        protected override void Initialize()
        {
            this.GetLogger().LogInformation(this.GetPackageName(), "Initializing.");
            base.Initialize();

            try
            {
                var visualStudioProcess = Process.GetCurrentProcess();
                this.otherApplicationFocusedHandlerReference = this.HandleOtherApplicationFocused;
                this.currentInstanceFocusedHandlerReference  = this.HandleCurrentInstanceFocused;
                this.otherApplicationFocusedHookHandle       = WindowsEventHooker.SetWinEventHook(3, 3, IntPtr.Zero, this.otherApplicationFocusedHandlerReference, 0, 0, SetWinEventHookFlags.WINEVENT_OUTOFCONTEXT | SetWinEventHookFlags.WINEVENT_SKIPOWNPROCESS);
                this.currentInstanceFocusedHookHandle        = WindowsEventHooker.SetWinEventHook(3, 3, IntPtr.Zero, this.currentInstanceFocusedHandlerReference, (uint)visualStudioProcess.Id, 0, SetWinEventHookFlags.WINEVENT_OUTOFCONTEXT);

                var dte = (DTE)this.GetService(typeof(DTE));

                this.solutionEvents = dte.Events.SolutionEvents;
                this.solutionEvents.BeforeClosing += this.HandleBeforeClosingSolution;
                this.solutionEvents.Opened        += this.HandleSolutionOpened;

                this.GetLogger().LogInformation(this.GetPackageName(), "Initialized.");
            }
            catch (Exception exception)
            {
                this.GetLogger().LogError(this.GetPackageName(), "Exception during initialization", exception);
            }
        }
Esempio n. 3
0
        protected override void Dispose(bool disposing)
        {
            this.logger.Debug("disposing package");

            WindowsEventHooker.UnhookWinEvent(this.currentInstanceFocusedHookHandle);
            this.currentInstanceFocusedHandlerReference = null;

            WindowsEventHooker.UnhookWinEvent(this.otherApplicationFocusedHookHandle);
            this.otherApplicationFocusedHandlerReference = null;

            base.Dispose(disposing);

            this.logger.Debug("disposed package");
        }
        protected override void Dispose(bool disposing)
        {
            this.GetLogger().LogInformation(this.GetPackageName(), "Disposing.");

            WindowsEventHooker.UnhookWinEvent(this.currentInstanceFocusedHookHandle);
            this.currentInstanceFocusedHandlerReference = null;

            WindowsEventHooker.UnhookWinEvent(this.otherApplicationFocusedHookHandle);
            this.otherApplicationFocusedHandlerReference = null;

            this.GetLogger().LogInformation(this.GetPackageName(), "Disposed.");

            base.Dispose(disposing);
        }
        /// <summary>
        /// Initialization of the package; this method is called right after the package is sited, so this is the place
        /// where you can put all the initialization code that rely on services provided by VisualStudio.
        /// </summary>
        protected override void Initialize()
        {
            base.Initialize();

            this.logger.Debug("Initializing...");

            var visualStudioProcess = Process.GetCurrentProcess();
            this.otherApplicationFocusedHandlerReference = this.HandleOtherApplicationFocused;
            this.currentInstanceFocusedHandlerReference = this.HandleCurrentInstanceFocused;
            this.otherApplicationFocusedHookHandle = WindowsEventHooker.SetWinEventHook(3, 3, IntPtr.Zero, this.otherApplicationFocusedHandlerReference, 0, 0, SetWinEventHookFlags.WINEVENT_OUTOFCONTEXT | SetWinEventHookFlags.WINEVENT_SKIPOWNPROCESS);
            this.currentInstanceFocusedHookHandle = WindowsEventHooker.SetWinEventHook(3, 3, IntPtr.Zero, this.currentInstanceFocusedHandlerReference, (uint)visualStudioProcess.Id, 0, SetWinEventHookFlags.WINEVENT_OUTOFCONTEXT);

            try
            {
                var dte = (DTE)this.GetService(typeof(DTE));

                this.solutionEvents = dte.Events.SolutionEvents;
                this.solutionEvents.BeforeClosing += this.HandleBeforeClosingSolution;
            }
            catch (Exception e)
            {
                this.logger.Error(e, "Could not hook visual studio closing event.");
            }

            this.logger.Debug("Initialized...");
        }
        protected override void Dispose(bool disposing)
        {
            this.logger.Debug("disposing package");

            WindowsEventHooker.UnhookWinEvent(this.currentInstanceFocusedHookHandle);
            this.currentInstanceFocusedHandlerReference = null;

            WindowsEventHooker.UnhookWinEvent(this.otherApplicationFocusedHookHandle);
            this.otherApplicationFocusedHandlerReference = null;

            base.Dispose(disposing);

            this.logger.Debug("disposed package");
        }