internal UpdateSolutionEvents(IVsSolutionBuildManager2 solutionBuildManager)
            {
                ThreadHelper.ThrowIfNotOnUIThread();

                _solutionBuildManager = solutionBuildManager;
                ErrorHandler.ThrowOnFailure(solutionBuildManager.AdviseUpdateSolutionEvents(this, out _cookie));
            }
        protected override void Initialize()
        {
            base.Initialize();

            //if invalid data, adjust it
            dataAdjuster.Adjust();

            // Get solution build manager
            sbm = ServiceProvider.GlobalProvider.GetService(typeof(SVsSolutionBuildManager)) as IVsSolutionBuildManager2;
            if (sbm != null)
            {
                sbm.AdviseUpdateSolutionEvents(this, out updateSolutionEventsCookie);
            }

            // Must hold a reference to the solution events object or the events wont fire, garbage collection related
            events         = GetDTE().Events.SolutionEvents;
            events.Opened += Solution_Opened;
            GetDTE().Events.BuildEvents.OnBuildBegin += Build_Begin;

            PrintLine("Build monitor initialized");
            PrintLine("Path to persist data: {0}", Settings.RepositoryPath);

            monitor.SolutionBuildFinished = b =>
            {
                Print("[{0}] Time Elapsed: {1} \t\t", b.SessionBuildCount, b.SolutionBuildTime.ToTime());
                PrintLine("Session build time: {0}\n", b.SessionMillisecondsElapsed.ToTime());
                PrintLine("Rebuild All: {0}\n", b.SolutionBuild.IsRebuildAll);
                System.Threading.Tasks.Task.Factory.StartNew(() => SaveToDatabase(b));
            };

            monitor.ProjectBuildFinished = b => PrintLine(" - {0}\t-- {1} --", b.MillisecondsElapsed.ToTime(), b.ProjectName);
            AnalyseBuildTimesCommand.Initialize(this);
        }
        internal void Register()
        {
            // Register this object to listen for IVsUpdateSolutionEvents
            IVsSolutionBuildManager2 buildManager = Package.GetService <SVsSolutionBuildManager, IVsSolutionBuildManager2>();

            if (buildManager == null)
            {
                throw Marshal.GetExceptionForHR(E_FAIL);
            }
            buildManager.AdviseUpdateSolutionEvents(this, out m_updateSolutionEventsCookie);

            // Register this object to listen for IVsSolutionEvents
            IVsSolution solution = Package.GetService <SVsSolution, IVsSolution>();

            if (solution == null)
            {
                throw Marshal.GetExceptionForHR(E_FAIL);
            }
            solution.AdviseSolutionEvents(this, out m_solutionEventsCookie);

            // Register this object to listen for IVsRunningDocTableEvents
            _runningDocTable = Package.GetService <SVsRunningDocumentTable, IVsRunningDocumentTable>();
            if (_runningDocTable == null)
            {
                throw Marshal.GetExceptionForHR(E_FAIL);
            }
            _runningDocTable.AdviseRunningDocTableEvents(this, out m_runningDocTableEventsCookie);
        }
        protected override void Initialize()
        {
            base.Initialize();

            //if invalid data, adjust it
            dataAdjuster.Adjust();

            // Get solution build manager
            sbm = ServiceProvider.GlobalProvider.GetService(typeof(SVsSolutionBuildManager)) as IVsSolutionBuildManager2;
            if (sbm != null)
            {
                sbm.AdviseUpdateSolutionEvents(this, out updateSolutionEventsCookie);
            }

            // Must hold a reference to the solution events object or the events wont fire, garbage collection related
            events = GetDTE().Events.SolutionEvents;
            events.Opened += Solution_Opened;

            PrintLine("Build monitor initialized");
            PrintLine("Path to persist data: {0}", Settings.RepositoryPath);

            monitor.SolutionBuildFinished = b =>
            {
                Print("[{0}] Time Elapsed: {1} \t\t", b.SessionBuildCount, b.SolutionBuildTime.ToTime());
                PrintLine("Session build time: {0}\n", b.SessionMillisecondsElapsed.ToTime());
            };

            monitor.ProjectBuildFinished = b => PrintLine(" - {0}\t-- {1} --", b.MillisecondsElapsed.ToTime(), b.ProjectName);
        }
Esempio n. 5
0
        protected override void Initialize()
        {
            Trace.WriteLine(String.Format(CultureInfo.CurrentCulture, "Entering Initialize() of: {0}", this.ToString()));
            base.Initialize();

            try
            {
                errorList       = new VSTools.ErrorList.Pane(this);
                Log._.Received -= onLogReceived;
                Log._.Received += onLogReceived;

                initAppEvents();

                OleMenuCommandService mcs = (OleMenuCommandService)GetService(typeof(IMenuCommandService));

                // Build / <Main App>
                _menuItemMain         = new MenuCommand(_menuMainCallback, new CommandID(GuidList.MAIN_CMD_SET, (int)PkgCmdIDList.CMD_MAIN));
                _menuItemMain.Visible = false;
                mcs.AddCommand(_menuItemMain);

                // View / Other Windows / <Status Panel>
                mcs.AddCommand(new MenuCommand(_menuPanelCallback, new CommandID(GuidList.PANEL_CMD_SET, (int)PkgCmdIDList.CMD_PANEL)));

                // To listen events that fired as a IVsSolutionEvents
                spSolution = (IVsSolution)ServiceProvider.GlobalProvider.GetService(typeof(SVsSolution));
                spSolution.AdviseSolutionEvents(this, out _pdwCookieSolution);

                // To listen events that fired as a IVsUpdateSolutionEvents2
                spSolutionBM = (IVsSolutionBuildManager2)ServiceProvider.GlobalProvider.GetService(typeof(SVsSolutionBuildManager));
                spSolutionBM.AdviseUpdateSolutionEvents(this, out _pdwCookieSolutionBM);
            }
            catch (Exception ex)
            {
                string msg = string.Format("{0}\n{1}\n\n-----\n{2}",
                                           "Something went wrong -_-",
                                           "Try to restart IDE or reinstall current plugin in Extension Manager.",
                                           ex.ToString());

                Debug.WriteLine(msg);

                int        res;
                Guid       id      = Guid.Empty;
                IVsUIShell uiShell = (IVsUIShell)GetService(typeof(SVsUIShell));

                Microsoft.VisualStudio.ErrorHandler.ThrowOnFailure(
                    uiShell.ShowMessageBox(
                        0,
                        ref id,
                        "Initialize vsSolutionBuildEvent",
                        msg,
                        string.Empty,
                        0,
                        OLEMSGBUTTON.OLEMSGBUTTON_OK,
                        OLEMSGDEFBUTTON.OLEMSGDEFBUTTON_FIRST,
                        OLEMSGICON.OLEMSGICON_WARNING,
                        0,
                        out res));
            }
        }
        protected override async System.Threading.Tasks.Task InitializeAsync(CancellationToken cancellationToken, IProgress <ServiceProgressData> progress)
        {
            // Switches to the UI thread, which most of this package requires. Even joining the main thread here improves
            // the load time of the package, and it stops a warning popping up when you load vs2019 with the package installed.
            await JoinableTaskFactory.SwitchToMainThreadAsync(cancellationToken);

            await base.InitializeAsync(cancellationToken, progress);

            output = new OutputWindowWrapper(this);

            SettingsManager       settingsManager = new ShellSettingsManager(ServiceProvider.GlobalProvider);
            WritableSettingsStore settingsStore   = settingsManager.GetWritableSettingsStore(SettingsScope.UserSettings);

            Settings.Instance = new Settings(settingsStore);

            var factory    = new BuildFactory();
            var repository = new BuildRepository(Settings.Instance.RepositoryPath);

            monitor      = new BuildMonitor.Domain.Monitor(factory, repository);
            dataAdjuster = new DataAdjusterWithLogging(repository, output.WriteLine);

            //if invalid data, adjust it
            dataAdjuster.Adjust();


            // Get solution build manager
            sbm = ServiceProvider.GlobalProvider.GetService(typeof(SVsSolutionBuildManager)) as IVsSolutionBuildManager2;
            if (sbm != null)
            {
                sbm.AdviseUpdateSolutionEvents(this, out updateSolutionEventsCookie);
            }

            // Must hold a reference to the solution events object or the events wont fire, garbage collection related
            events         = GetDTE().Events.SolutionEvents;
            events.Opened += Solution_Opened;
            GetDTE().Events.BuildEvents.OnBuildBegin += Build_Begin;

            output.WriteLine("Build monitor initialized");
            output.WriteLine("Path to persist data: {0}", Settings.Instance.RepositoryPath);

            monitor.SolutionBuildFinished = b =>
            {
                output.Write("[{0}] Time Elapsed: {1} \t\t", b.SessionBuildCount, b.SolutionBuildTime.ToTime());
                output.WriteLine("Session build time: {0}\n", b.SessionMillisecondsElapsed.ToTime());
                output.WriteLine("Rebuild All: {0}\n", b.SolutionBuild.IsRebuildAll);
                //System.Threading.Tasks.Task.Factory.StartNew(() => SaveToDatabase(b));
            };

            monitor.ProjectBuildFinished = b => output.WriteLine(" - {0}\t-- {1} --", b.MillisecondsElapsed.ToTime(), b.ProjectName);

            // In vs 2017 and earlier, this event was always called, but in 2019 it isn't called if you open a solution on startup.
            // I imagine this is because the solution has already loaded before we connect to the events. To get over it we just
            // manually call the event here.
            Solution_Opened();

            AnalyseBuildTimesCommand.Initialize(this);
        }
Esempio n. 7
0
 public BuildEvents()
 {
     // Get solution build manager
     buildManager = ServiceProvider.GlobalProvider.GetService(typeof(SVsSolutionBuildManager)) as IVsSolutionBuildManager2;
     if (buildManager != null)
     {
         buildManager.AdviseUpdateSolutionEvents(this, out eventsCookie);
     }
 }
 private void HookBuildEvents()
 {
     // Get solution build manager
     sbm = ServiceProvider.GetService(typeof(SVsSolutionBuildManager)) as IVsSolutionBuildManager2;
     if (sbm != null)
     {
         sbm.AdviseUpdateSolutionEvents(this, out updateSolutionEventsCookie);
     }
 }
Esempio n. 9
0
 private void SubscribeToUpdateSolutionEvents()
 {
     // Get solution build manager
     _solutionBuildManager = ServiceProvider.GlobalProvider.GetService(typeof(SVsSolutionBuildManager)) as IVsSolutionBuildManager2;
     if (_solutionBuildManager != null)
     {
         _solutionBuildManager.AdviseUpdateSolutionEvents(this, out _updateSolutionEventsCookie);
     }
 }
Esempio n. 10
0
        /// <summary>
        /// Defines listeners for main events.
        /// </summary>
        private void adviseEvents()
        {
            // To listen events that fired as a IVsSolutionEvents
            spSolution = (IVsSolution)ServiceProvider.GlobalProvider.GetService(typeof(SVsSolution));
            spSolution.AdviseSolutionEvents(this, out _pdwCookieSolution);

            // To listen events that fired as a IVsUpdateSolutionEvents2
            spSolutionBM = (IVsSolutionBuildManager2)ServiceProvider.GlobalProvider.GetService(typeof(SVsSolutionBuildManager));
            spSolutionBM.AdviseUpdateSolutionEvents(this, out _pdwCookieSolutionBM);
        }
Esempio n. 11
0
            internal UpdateSolutionEvents(IVsSolutionBuildManager2 solutionBuildManager)
            {
                this.solutionBuildManager = solutionBuildManager;
                var hresult = solutionBuildManager.AdviseUpdateSolutionEvents(this, out cookie);

                if (hresult != 0)
                {
                    System.Runtime.InteropServices.Marshal.ThrowExceptionForHR(hresult);
                }
            }
Esempio n. 12
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();

            _solutionBuildManager =
                ServiceProvider.GlobalProvider.GetService(
                    typeof(SVsSolutionBuildManager)) as
                IVsSolutionBuildManager2;
            Throw.IfNull(_solutionBuildManager, "_solutionBuildManager");
            ErrorHandler.ThrowOnFailure(
                _solutionBuildManager.AdviseUpdateSolutionEvents(this,
                                                                 out _updateSolutionEventsCookie));
        }
Esempio n. 13
0
        private async Task EnsureBuildManagerInitializedAsync()
        {
            // Switch to UI thread for querying the build manager service.
            await _threadingService.SwitchToUIThread();

            if (_buildManager == null)
            {
                _buildManager = _serviceProvider.GetService <IVsSolutionBuildManager2, SVsSolutionBuildManager>();

                // Register for solution build events.
                _buildManager.AdviseUpdateSolutionEvents(this, out _solutionEventsCookie);
            }
        }
Esempio n. 14
0
        public BuildTracker(
            DTE2 vsInstance,
            IVsSolutionBuildManager2 buildManager,
            BuildRestartSettings settings
            )
        {
            Ensure.That(() => vsInstance).IsNotNull();
            Ensure.That(() => settings).IsNotNull();
            Ensure.That(() => buildManager).IsNotNull();

            _vsInstance   = vsInstance;
            _settings     = settings;
            _buildManager = buildManager;
            _buildManager.AdviseUpdateSolutionEvents(this, out uint pdwCookieSolutionBM);
        }
Esempio n. 15
0
        /*private void AddMetroResources()
         * {
         *  void AddResourceDict(string s)
         *  {
         *      Application.Current.Resources.MergedDictionaries.Add(new ResourceDictionary
         *      {
         *          Source = new Uri(s, UriKind.Absolute),
         *      });
         *  }
         *
         *  AddResourceDict(@"pack://*****:*****@"pack://application:,,,/MahApps.Metro;component/Styles/Fonts.xaml");
         *  AddResourceDict(@"pack://*****:*****@"pack://application:,,,/MahApps.Metro;component/Styles/Controls.Buttons.xaml");
         * }*/

        /// <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>
        /// <param name="cancellationToken">A cancellation token to monitor for initialization cancellation, which can occur when VS is shutting down.</param>
        /// <param name="progress">A provider for progress updates.</param>
        /// <returns>A task representing the async work of package initialization, or an already completed task if there is none. Do not return null from this method.</returns>
        protected override async Task InitializeAsync(CancellationToken cancellationToken, IProgress <ServiceProgressData> progress)
        {
            await base.InitializeAsync(cancellationToken, progress);

            // When initialized asynchronously, the current thread may be a background thread at this point.
            // Do any initialization that requires the UI thread after switching to the UI thread.
            await this.JoinableTaskFactory.SwitchToMainThreadAsync(cancellationToken);

            solutionBuildManager = (IVsSolutionBuildManager2)ServiceProvider.GlobalProvider.GetService(typeof(SVsSolutionBuildManager));
            Assumes.Present(solutionBuildManager);
            solutionBuildManager.AdviseUpdateSolutionEvents(this, out solutionBuildManagerCookie);

            dte = await ServiceProvider.GetGlobalServiceAsync(typeof(SDTE)) as DTE2;

            RegisterEditorFactory(new NetPrintsEditorFactory(this));
        }
Esempio n. 16
0
        protected override void Initialize()
        {
            base.Initialize();

            output = new OutputWindowWrapper(this);

            SettingsManager       settingsManager = new ShellSettingsManager(ServiceProvider.GlobalProvider);
            WritableSettingsStore settingsStore   = settingsManager.GetWritableSettingsStore(SettingsScope.UserSettings);

            Settings.Instance = new Settings(settingsStore);

            var factory    = new BuildFactory();
            var repository = new BuildRepository(Settings.Instance.RepositoryPath);

            monitor      = new Monitor(factory, repository);
            dataAdjuster = new DataAdjusterWithLogging(repository, output.WriteLine);

            //if invalid data, adjust it
            dataAdjuster.Adjust();


            // Get solution build manager
            sbm = ServiceProvider.GlobalProvider.GetService(typeof(SVsSolutionBuildManager)) as IVsSolutionBuildManager2;
            if (sbm != null)
            {
                sbm.AdviseUpdateSolutionEvents(this, out updateSolutionEventsCookie);
            }

            // Must hold a reference to the solution events object or the events wont fire, garbage collection related
            events         = GetDTE().Events.SolutionEvents;
            events.Opened += Solution_Opened;
            GetDTE().Events.BuildEvents.OnBuildBegin += Build_Begin;

            output.WriteLine("Build monitor initialized");
            output.WriteLine("Path to persist data: {0}", Settings.Instance.RepositoryPath);

            monitor.SolutionBuildFinished = b =>
            {
                output.Write("[{0}] Time Elapsed: {1} \t\t", b.SessionBuildCount, b.SolutionBuildTime.ToTime());
                output.WriteLine("Session build time: {0}\n", b.SessionMillisecondsElapsed.ToTime());
                output.WriteLine("Rebuild All: {0}\n", b.SolutionBuild.IsRebuildAll);
                //System.Threading.Tasks.Task.Factory.StartNew(() => SaveToDatabase(b));
            };

            monitor.ProjectBuildFinished = b => output.WriteLine(" - {0}\t-- {1} --", b.MillisecondsElapsed.ToTime(), b.ProjectName);
            AnalyseBuildTimesCommand.Initialize(this);
        }
Esempio n. 17
0
        protected override async Task InitializeAsync(CancellationToken cancellationToken, IProgress <ServiceProgressData> progress)
        {
            if (!Directory.Exists(GetLogFileRoot()))
            {
                Directory.CreateDirectory(GetLogFileRoot());
            }

            // When initialized asynchronously, the current thread may be a background thread at this point.
            // Do any initialization that requires the UI thread after switching to the UI thread.
            await this.JoinableTaskFactory.SwitchToMainThreadAsync(cancellationToken);

            _solutionService = await GetServiceAsync(typeof(SVsSolutionBuildManager)) as IVsSolutionBuildManager2;

            if (_solutionService != null)
            {
                _solutionService.AdviseUpdateSolutionEvents(this, out _cookieHandle);
            }
        }
Esempio n. 18
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();
            ActivateBuildOrderPaneCmd.Initialize(this);

            // Get solution build manager
            _solutionBuildManager = ServiceProvider.GlobalProvider.GetService(typeof(SVsSolutionBuildManager)) as IVsSolutionBuildManager2;
            if (_solutionBuildManager != null)
            {
                _solutionBuildManager.AdviseUpdateSolutionEvents(this, out _updateSolutionEventsCookie);
            }

            _outputWindow = (IVsOutputWindow)GetService(typeof(SVsOutputWindow));
            if (_outputWindow != null)
            {
                _outputWindow.GetPane(VSConstants.OutputWindowPaneGuid.SortedBuildOutputPane_guid, out _buildOrderPane);
            }
        }
Esempio n. 19
0
		public BuildTracker(
			DTE2 vsInstance,
			IVsSolutionBuildManager2 buildManager,
			BuildHelperSettings settings,
			WinHelper winHelper)
		{
			Ensure.That(() => vsInstance).IsNotNull();
			Ensure.That(() => settings).IsNotNull();
			Ensure.That(() => winHelper).IsNotNull();
			Ensure.That(() => buildManager).IsNotNull();

			m_VsInstance = vsInstance;
			m_Settings = settings;
			m_WinHelper = winHelper;

			uint pdwCookieSolutionBM;
			m_BuildManager = buildManager;
			m_BuildManager.AdviseUpdateSolutionEvents(this, out pdwCookieSolutionBM);
		}
Esempio n. 20
0
        protected override void Initialize()
        {
            base.Initialize();

            IVsSolution pSolution  = GetService(typeof(SVsSolution)) as IVsSolution;
            object      objLoadMgr = this; //the class that implements IVsSolutionManager

            pSolution.SetProperty((int)__VSPROPID4.VSPROPID_ActiveSolutionLoadManager, objLoadMgr);

            uint id = 0;

            pSolution.AdviseSolutionEvents(this, out id);

            //if invalid data, adjust it
            dataAdjuster.Adjust();

            // Get solution build manager
            sbm = ServiceProvider.GlobalProvider.GetService(typeof(SVsSolutionBuildManager)) as IVsSolutionBuildManager2;

            if (sbm != null)
            {
                sbm.AdviseUpdateSolutionEvents(this, out updateSolutionEventsCookie);
            }

            // Must hold a reference to the solution events object or the events wont fire, garbage collection related
            events = GetDTE().Events.SolutionEvents;


            events.Opened += Solution_Opened;

            PrintLine("Build monitor initialized");
            PrintLine("Path to persist data: {0}", Settings.RepositoryPath);

            monitor.SolutionBuildFinished = b =>
            {
                Print("[{0}] Time Elapsed: {1}ms  \t\t", b.SessionBuildCount, b.SolutionBuildTime);
                PrintLine("Session build time: {0}ms\n", b.SessionMillisecondsElapsed);
                new SendBuildCompleteGrowlNotification(b.SolutionName, new TimeSpan(b.SolutionBuildTime)).Execute();
            };

            monitor.ProjectBuildFinished = b => PrintLine(" - {0}ms\t-- {1} --", b.MillisecondsElapsed, b.ProjectName);
        }
Esempio n. 21
0
        public BuildTracker(
            DTE2 vsInstance,
            IVsSolutionBuildManager2 buildManager,
            BuildHelperSettings settings,
            ServiceHelper serviceHelper,
            ProcessHelper processHelper)
        {
            Ensure.That(() => vsInstance).IsNotNull();
            Ensure.That(() => settings).IsNotNull();
            Ensure.That(() => serviceHelper).IsNotNull();
            Ensure.That(() => processHelper).IsNotNull();
            Ensure.That(() => buildManager).IsNotNull();

            m_VsInstance    = vsInstance;
            m_Settings      = settings;
            m_ServiceHelper = serviceHelper;
            m_ProcessHelper = processHelper;
            m_BuildManager  = buildManager;
            m_BuildManager.AdviseUpdateSolutionEvents(this, out uint pdwCookieSolutionBM);
        }
        /// <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();

            // Get solution
            solution = ServiceProvider.GlobalProvider.GetService(typeof(SVsSolution)) as IVsSolution2;
            if (solution != null)
            {
                // Get count of any currently loaded projects
                object count;
                solution.GetProperty((int)__VSPROPID.VSPROPID_ProjectCount, out count);
                //totalProjects = (int)count;

                // Register for solution events
                solution.AdviseSolutionEvents(this, out solutionEventsCookie);
            }

            // Get solution build manager
            sbm = ServiceProvider.GlobalProvider.GetService(typeof(SVsSolutionBuildManager)) as IVsSolutionBuildManager2;
            sbm?.AdviseUpdateSolutionEvents(this, out updateSolutionEventsCookie);
        }
Esempio n. 23
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>
        /// <param name="cancellationToken">A cancellation token to monitor for initialization cancellation, which can occur when VS is shutting down.</param>
        /// <param name="progress">A provider for progress updates.</param>
        /// <returns>A task representing the async work of package initialization, or an already completed task if there is none. Do not return null from this method.</returns>
        protected override async Task InitializeAsync(CancellationToken cancellationToken, IProgress <ServiceProgressData> progress)
        {
            // When initialized asynchronously, the current thread may be a background thread at this point.
            // Do any initialization that requires the UI thread after switching to the UI thread.
            await this.JoinableTaskFactory.SwitchToMainThreadAsync(cancellationToken);

            await VSBuildTimeReportWindowCommand.InitializeAsync(this);

            // Get solution build manager
            _sbm = ServiceProvider.GlobalProvider.GetService(typeof(SVsSolutionBuildManager)) as IVsSolutionBuildManager2;
            if (_sbm != null)
            {
                _sbm.AdviseUpdateSolutionEvents(this, out _);
            }

            // Must hold a reference to the solution events object or the events wont fire, garbage collection related
            _events         = GetDTE().Events.SolutionEvents;
            _events.Opened += Solution_Opened;

            LoadAndInitializeBuildSession();
        }
        /// <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 initilaization code that rely on services provided by VisualStudio.
        /// </summary>
        protected override void Initialize()
        {
            Trace.WriteLine (string.Format(CultureInfo.CurrentCulture, "Entering Initialize() of: {0}", this.ToString()));
            base.Initialize();

            // Get solution build manager
            _buildManager = ServiceProvider.GlobalProvider.GetService(typeof(SVsSolutionBuildManager)) as IVsSolutionBuildManager2;

            if (_buildManager != null)
                _buildManager.AdviseUpdateSolutionEvents(this, out _solutionBuildEventsCookie);
        }
        /// <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();

            // Add our command handlers for menu (commands must exist in the .vsct file)
            OleMenuCommandService mcs = GetService(typeof(IMenuCommandService)) as OleMenuCommandService;
            if (null != mcs)
            {
                // Create the command for the tool window
                CommandID toolwndCommandID = new CommandID(GuidList.guidProgressBarCmdSet, (int)PkgCmdIDList.cmdidProgressBar);
                MenuCommand menuToolWin = new MenuCommand(ShowToolWindow, toolwndCommandID);
                mcs.AddCommand(menuToolWin);
            }

            // Get shell object
            vsShell = ServiceProvider.GlobalProvider.GetService(typeof(SVsShell)) as IVsShell;
            if (vsShell != null)
            {
                // Initialize VisualEffects values, so themes can determine if various effects are supported by the environment
                object effectsAllowed;
                if (ErrorHandler.Succeeded(vsShell.GetProperty((int)__VSSPROPID4.VSSPROPID_VisualEffectsAllowed, out effectsAllowed)))
                {
                    // VSSPROPID_VisualEffectsAllowed is a VT_I4 property, so casting to int should be safe
                    Debug.Assert(effectsAllowed is int, "VSSPROPID_VisualEffectsAllowed should be of type int");
                    this.visualEffectsAllowed = (int)effectsAllowed;
                }
                else
                {
                    Debug.Fail("Failed to get the VSSPROPID_VisualEffectsAllowed property value.");
                }

                // Subscribe to shell property changes to update VisualEffects values if the user modifies the settings
                vsShell.AdviseShellPropertyChanges(this, out shellPropertyChangesCookie);
            }

            // Get solution
            solution = ServiceProvider.GlobalProvider.GetService(typeof(SVsSolution)) as IVsSolution2;
            if (solution != null)
            {
                // Get count of any currently loaded projects
                object count;
                solution.GetProperty((int)__VSPROPID.VSPROPID_ProjectCount, out count);
                totalProjects = (int)count;

                // Register for solution events
                solution.AdviseSolutionEvents(this, out solutionEventsCookie);
            }

            // Get solution build manager
            sbm = ServiceProvider.GlobalProvider.GetService(typeof(SVsSolutionBuildManager)) as IVsSolutionBuildManager2;
            if (sbm != null)
            {
                sbm.AdviseUpdateSolutionEvents(this, out updateSolutionEventsCookie);
            }

            // Get tool window
            if (toolWindow == null)
            {
                toolWindow = this.FindToolWindow(typeof(BuildProgressToolWindow), 0, true) as BuildProgressToolWindow;
            }

            // Set initial value of EffectsEnabled in tool window
            toolWindow.EffectsEnabled = visualEffectsAllowed != 0;
        }
Esempio n. 26
0
        /// <summary>
        /// Defines listeners for main events.
        /// </summary>
        private void adviseEvents()
        {
            // To listen events that fired as a IVsSolutionEvents
            spSolution = (IVsSolution)ServiceProvider.GlobalProvider.GetService(typeof(SVsSolution));
            spSolution.AdviseSolutionEvents(this, out _pdwCookieSolution);

            // To listen events that fired as a IVsUpdateSolutionEvents2
            spSolutionBM = (IVsSolutionBuildManager2)ServiceProvider.GlobalProvider.GetService(typeof(SVsSolutionBuildManager));
            spSolutionBM.AdviseUpdateSolutionEvents(this, out _pdwCookieSolutionBM);
        }
Esempio n. 27
0
 public BuildService([Import(typeof(SVsServiceProvider))] IServiceProvider serviceProvider)
 {
     buildManager = serviceProvider.GetService <SVsSolutionBuildManager, IVsSolutionBuildManager2>();
     buildManager.AdviseUpdateSolutionEvents(this, out updateSolutionEventsCookie);
 }
        private void InitializePackage()
        {
            // Get shell object
            vsShell = ServiceProvider.GlobalProvider.GetService(typeof(SVsShell)) as IVsShell;

            // Get solution
            solution = ServiceProvider.GlobalProvider.GetService(typeof(SVsSolution)) as IVsSolution2;
            if (solution != null)
            {
                // Get count of any currently loaded projects
                object count;
                solution.GetProperty((int)__VSPROPID.VSPROPID_ProjectCount, out count);
                var totalProjects = (int)count;

                // Register for solution events
                solution.AdviseSolutionEvents(this, out solutionEventsCookie);
            }

            // Get solution build manager
            sbm = ServiceProvider.GlobalProvider.GetService(typeof(SVsSolutionBuildManager)) as IVsSolutionBuildManager2;
            if (sbm != null)
            {
                sbm.AdviseUpdateSolutionEvents(this, out updateSolutionEventsCookie);
            }

            /*
            // Get build manager
            bm = ServiceProvider.GlobalProvider.GetService(typeof (IVsSolutionBuildManager)) as IVsSolutionBuildManager;
            if (bm != null)
            {
                //bm.AdviseUpdateSolutionEvents(this, out someCookie);
            }
            */

            /*
            mon = ServiceProvider.GlobalProvider.GetService(typeof (IVsMonitorSelection)) as IVsMonitorSelection;
            IVsMultiItemSelect mms;
            IntPtr ppHier, ppSc;
            uint ppmms = VSConstants.VSITEMID_SELECTION;
            mon.GetCurrentSelection(out ppHier, out ppmms, out mms, out ppSc);
            IVsHierarchy hierarchy = Marshal.GetTypedObjectForIUnknown(ppHier, typeof(IVsHierarchy)) as IVsHierarchy;
            */

            //hier = ServiceProvider.GlobalProvider.GetService(typeof(IVsHierarchy)) as IVsHierarchy;

            _applicationObject = (DTE)GetService(typeof(DTE));
            //            string solutionDir = System.IO.Path.GetDirectoryName(_applicationObject.Solution.FullName);

            /*
            var doc = _applicationObject.ActiveDocument;
            var projectItem = doc.ProjectItem;
            var project = projectItem.ContainingProject;
            var evalProject = Microsoft.Build.Evaluation.ProjectCollection.GlobalProjectCollection.LoadProject(project.FullName);
            var execProject = evalProject.CreateProjectInstance();
            */
        }
Esempio n. 29
0
        /////////////////////////////////////////////////////////////////////////////
        // Overriden Package Implementation
        #region Package Members

        /// <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();

            // Add our command handlers for menu (commands must exist in the .vsct file)
            OleMenuCommandService mcs = GetService(typeof(IMenuCommandService)) as OleMenuCommandService;

            if (null != mcs)
            {
                // Create the command for the tool window
                CommandID   toolwndCommandID = new CommandID(GuidList.guidProgressBarCmdSet, (int)PkgCmdIDList.cmdidProgressBar);
                MenuCommand menuToolWin      = new MenuCommand(ShowToolWindow, toolwndCommandID);
                mcs.AddCommand(menuToolWin);
            }

            // Get shell object
            vsShell = ServiceProvider.GlobalProvider.GetService(typeof(SVsShell)) as IVsShell;
            if (vsShell != null)
            {
                // Initialize VisualEffects values, so themes can determine if various effects are supported by the environment
                object effectsAllowed;
                if (ErrorHandler.Succeeded(vsShell.GetProperty((int)__VSSPROPID4.VSSPROPID_VisualEffectsAllowed, out effectsAllowed)))
                {
                    // VSSPROPID_VisualEffectsAllowed is a VT_I4 property, so casting to int should be safe
                    Debug.Assert(effectsAllowed is int, "VSSPROPID_VisualEffectsAllowed should be of type int");
                    this.visualEffectsAllowed = (int)effectsAllowed;
                }
                else
                {
                    Debug.Fail("Failed to get the VSSPROPID_VisualEffectsAllowed property value.");
                }

                // Subscribe to shell property changes to update VisualEffects values if the user modifies the settings
                vsShell.AdviseShellPropertyChanges(this, out shellPropertyChangesCookie);
            }

            // Get solution
            solution = ServiceProvider.GlobalProvider.GetService(typeof(SVsSolution)) as IVsSolution2;
            if (solution != null)
            {
                // Get count of any currently loaded projects
                object count;
                solution.GetProperty((int)__VSPROPID.VSPROPID_ProjectCount, out count);
                totalProjects = (int)count;

                // Register for solution events
                solution.AdviseSolutionEvents(this, out solutionEventsCookie);
            }

            // Get solution build manager
            sbm = ServiceProvider.GlobalProvider.GetService(typeof(SVsSolutionBuildManager)) as IVsSolutionBuildManager2;
            if (sbm != null)
            {
                sbm.AdviseUpdateSolutionEvents(this, out updateSolutionEventsCookie);
            }

            // Get tool window
            if (toolWindow == null)
            {
                toolWindow = this.FindToolWindow(typeof(BuildProgressToolWindow), 0, true) as BuildProgressToolWindow;
            }

            // Set initial value of EffectsEnabled in tool window
            toolWindow.EffectsEnabled = visualEffectsAllowed != 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();
              ActivateBuildOrderPaneCmd.Initialize(this);

              // Get solution build manager
              _solutionBuildManager = ServiceProvider.GlobalProvider.GetService(typeof(SVsSolutionBuildManager)) as IVsSolutionBuildManager2;
              if (_solutionBuildManager != null)
            _solutionBuildManager.AdviseUpdateSolutionEvents(this, out _updateSolutionEventsCookie);

              _outputWindow = (IVsOutputWindow)GetService(typeof(SVsOutputWindow));
              if (_outputWindow != null)
              {
            _outputWindow.GetPane(VSConstants.OutputWindowPaneGuid.SortedBuildOutputPane_guid, out _buildOrderPane);
              }
        }
        protected override void Initialize()
        {
            Trace.WriteLine(String.Format(CultureInfo.CurrentCulture, "Entering Initialize() of: {0}", this.ToString()));
            base.Initialize();

            try
            {
                initAppEvents();

                OleMenuCommandService mcs = (OleMenuCommandService)GetService(typeof(IMenuCommandService));

                // Build / <Main App>
                _menuItemMain = new MenuCommand(_menuMainCallback, new CommandID(GuidList.MAIN_CMD_SET, (int)PkgCmdIDList.CMD_MAIN));
                _menuItemMain.Visible = false;
                mcs.AddCommand(_menuItemMain);

                // View / Other Windows / <Status Panel>
                mcs.AddCommand(new MenuCommand(_menuPanelCallback, new CommandID(GuidList.PANEL_CMD_SET, (int)PkgCmdIDList.CMD_PANEL)));

                // To listen events that fired as a IVsSolutionEvents
                spSolution = (IVsSolution)ServiceProvider.GlobalProvider.GetService(typeof(SVsSolution));
                spSolution.AdviseSolutionEvents(this, out _pdwCookieSolution);

                // To listen events that fired as a IVsUpdateSolutionEvents2
                spSolutionBM = (IVsSolutionBuildManager2)ServiceProvider.GlobalProvider.GetService(typeof(SVsSolutionBuildManager));
                spSolutionBM.AdviseUpdateSolutionEvents(this, out _pdwCookieSolutionBM);
            }
            catch(Exception ex)
            {
                string msg = string.Format("{0}\n{1}\n\n-----\n{2}",
                                "Something went wrong -_-",
                                "Try to restart IDE or reinstall current plugin in Extension Manager.",
                                ex.ToString());

                Log.Fatal(msg);

                int res;
                Guid id = Guid.Empty;
                IVsUIShell uiShell = (IVsUIShell)GetService(typeof(SVsUIShell));

                Microsoft.VisualStudio.ErrorHandler.ThrowOnFailure(
                    uiShell.ShowMessageBox(
                           0,
                           ref id,
                           "Initialize vsSolutionBuildEvent",
                           msg,
                           string.Empty,
                           0,
                           OLEMSGBUTTON.OLEMSGBUTTON_OK,
                           OLEMSGDEFBUTTON.OLEMSGDEFBUTTON_FIRST,
                           OLEMSGICON.OLEMSGICON_WARNING,
                           0,
                           out res));
            }
        }
Esempio n. 32
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()
        {
            Trace.WriteLine(string.Format(CultureInfo.CurrentCulture, "Entering Initialize() of: {0}", this.ToString()));
            base.Initialize();

            // Get solution
            solution = ServiceProvider.GlobalProvider.GetService(typeof(SVsSolution)) as IVsSolution2;
            if (solution != null)
            {
                // Get count of any currently loaded projects
                object count;
                solution.GetProperty((int)__VSPROPID.VSPROPID_ProjectCount, out count);

                // Register for solution events
                solution.AdviseSolutionEvents(this, out solutionEventsCookie);
            }

            // Get solution build manager
            sbm = ServiceProvider.GlobalProvider.GetService(typeof(SVsSolutionBuildManager)) as IVsSolutionBuildManager2;
            if (sbm != null)
            {
                sbm.AdviseUpdateSolutionEvents(this, out updateSolutionEventsCookie);
            }
        }
Esempio n. 33
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()
        {
            Trace.WriteLine(string.Format(CultureInfo.CurrentCulture, "Entering Initialize() of: {0}", this.ToString()));
            base.Initialize();

            // Add our command handlers for menu (commands must exist in the .vsct file)
            OleMenuCommandService mcs = GetService(typeof(IMenuCommandService)) as OleMenuCommandService;
            if(null != mcs)
            {
                // Create the command for the menu item.
                CommandID menuCommandID = new CommandID(GuidList.guidMetaCmdSet1, (int)PkgCmdIDList.cmdidMetaUIContext1);
                OleMenuCommand menuItem = new OleMenuCommand(BuildProfileCallback, menuCommandID);
                menuItem.BeforeQueryStatus += uiContex1Cmd_BeforeQueryStatus;
                mcs.AddCommand(menuItem);

                menuCommandID = new CommandID(GuidList.guidMetaCmdSet2, (int)PkgCmdIDList.cmdidMetaUIContext1);
                menuItem = new OleMenuCommand(BuildProfileCallback, menuCommandID);
                menuItem.BeforeQueryStatus += uiContex1Cmd_BeforeQueryStatus;
                mcs.AddCommand(menuItem);

                menuCommandID = new CommandID(GuidList.guidMetaCmdSet2, (int)PkgCmdIDList.cmdidMetaUIContext2);
                menuItem = new OleMenuCommand(TemplateProfileCallback, menuCommandID);
                menuItem.BeforeQueryStatus += uiContex2Cmd_BeforeQueryStatus;
                mcs.AddCommand(menuItem);
            }

            // Get shell object
            vsShell = ServiceProvider.GlobalProvider.GetService(typeof(SVsShell)) as IVsShell;
            if(vsShell != null)
                vsShell.AdviseShellPropertyChanges(this, out shellPropertyChangesCookie);

            // Get solution
            solution = ServiceProvider.GlobalProvider.GetService(typeof(SVsSolution)) as IVsSolution2;
            if(solution != null)
            {
                // Get count of any currently loaded projects
                object count;
                solution.GetProperty((int)__VSPROPID.VSPROPID_ProjectCount, out count);

                // Register for solution events
                solution.AdviseSolutionEvents(this, out solutionEventsCookie);
            }

            // Get solution build manager
            sbm = ServiceProvider.GlobalProvider.GetService(typeof(SVsSolutionBuildManager)) as IVsSolutionBuildManager2;
            if(sbm != null)
                sbm.AdviseUpdateSolutionEvents(this, out updateSolutionEventsCookie);
        }