/// <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.LogMessageWriteLineFormat("SlowCheetah initalizing"); // Initialization logic this.LogMessageWriteLineFormat(string.Format(CultureInfo.CurrentCulture, "Entering Initialize() of: {0}", this.ToString())); this.errorListProvider = new ErrorListProvider(this); IVsSolutionBuildManager solutionBuildManager = this.GetService(typeof(SVsSolutionBuildManager)) as IVsSolutionBuildManager; solutionBuildManager.AdviseUpdateSolutionEvents(this, out this.solutionUpdateCookie); // Add our command handlers for menu (commands must exist in the .vsct file) OleMenuCommandService mcs = this.GetService(typeof(IMenuCommandService)) as OleMenuCommandService; if (mcs != null) { // create the command for the "Add Transform" query status menu item CommandID menuContextCommandID = new CommandID(Guids.GuidSlowCheetahCmdSet, (int)PkgCmdID.CmdIdAddTransform); OleMenuCommand menuCommand = new OleMenuCommand(this.OnAddTransformCommand, this.OnChangeAddTransformMenu, this.OnBeforeQueryStatusAddTransformCommand, menuContextCommandID); mcs.AddCommand(menuCommand); // create the command for the Preview Transform menu item menuContextCommandID = new CommandID(Guids.GuidSlowCheetahCmdSet, (int)PkgCmdID.CmdIdPreviewTransform); menuCommand = new OleMenuCommand(this.OnPreviewTransformCommand, this.OnChangePreviewTransformMenu, this.OnBeforeQueryStatusPreviewTransformCommand, menuContextCommandID); mcs.AddCommand(menuCommand); } }
/// <summary> /// Builds the specified project. /// </summary> public async Task <bool> BuildProjectAsync(SolutionItem project, BuildAction action = BuildAction.Build) { if (project?.Type != SolutionItemType.Project && project?.Type != SolutionItemType.VirtualProject) { return(false); } await ThreadHelper.JoinableTaskFactory.SwitchToMainThreadAsync(); IVsSolutionBuildManager svc = await VS.Services.GetSolutionBuildManagerAsync(); uint buildFlags = (uint)GetBuildFlags(action); project.GetItemInfo(out IVsHierarchy hierarchy, out _, out _); BuildObserver observer = new(hierarchy); ErrorHandler.ThrowOnFailure(svc.AdviseUpdateSolutionEvents(observer, out uint cookie)); try { ErrorHandler.ThrowOnFailure(svc.StartSimpleUpdateProjectConfiguration(hierarchy, null, null, buildFlags, 0, 0)); return(await observer.Result); } finally { svc.UnadviseUpdateSolutionEvents(cookie); } }
protected override void Initialize() { base.Initialize(); // Initialize common functionality Common.Initialize(this); taskListMenu = new RootMenu(); // Initialize fields tools = new Tools(); sharedTaskManagers = new List <TaskManager>(); // Attach to solution events solution = GetService(typeof(SVsSolution)) as IVsSolution; // if (solution == null) throw new NullReferenceException(); solution.AdviseSolutionEvents(this as IVsSolutionEvents, out solutionEventsCookie); // Attach to build events buildManager = GetService(typeof(SVsSolutionBuildManager)) as IVsSolutionBuildManager; // if (buildManager == null) throw new NullReferenceException(); buildManager.AdviseUpdateSolutionEvents(this, out buildManagerCookie); // Add a TaskManagerFactory service (this as System.ComponentModel.Design.IServiceContainer).AddService(typeof(ITaskManagerFactory), this, true); }
private static async Task AdviseSolutionEventsAsync() { await ThreadHelper.JoinableTaskFactory.SwitchToMainThreadAsync(); _solutionBuildManager = ServiceLocator.GetService <SVsSolutionBuildManager, IVsSolutionBuildManager>(); Assumes.Present(_solutionBuildManager); _solutionBuildManager.AdviseUpdateSolutionEvents(_solutionEventHandler, out _updateSolutionEventsCookie); }
/// <summary> /// Constructor. /// </summary> /// <param name="buildManager">IVsSolutionBuildManager service (for registering this object).</param> /// <param name="propertyKey">Key of the property to be modified during build.</param> /// <param name="newValue">Value during build for the property to be modified.</param> public SolutionBuildListener(IVsSolutionBuildManager buildManager, string propertyKey, string newValue) { this.buildManager = buildManager; this.propertyKey = propertyKey; this.newValue = newValue; this.oldValue = ProjectConfiguration.Instance.GetProperty(propertyKey); buildManager.AdviseUpdateSolutionEvents(this, out cookie); }
public VsUpdateSolutionEvents( IVsSolutionBuildManager buildManager, TaskCompletionSource<bool> taskSource) { _taskSource = taskSource; _buildManager = buildManager; Marshal.ThrowExceptionForHR( buildManager.AdviseUpdateSolutionEvents(this, out _cookie)); }
public VsUpdateSolutionEvents( IVsSolutionBuildManager buildManager, TaskCompletionSource <bool> taskSource) { _taskSource = taskSource; _buildManager = buildManager; Marshal.ThrowExceptionForHR( buildManager.AdviseUpdateSolutionEvents(this, out _cookie)); }
public UpdateSolutionEvents(Commands commands) { ThreadHelper.ThrowIfNotOnUIThread(); _commands = commands; // Subscribe to events IVsSolutionBuildManager buildManager = (IVsSolutionBuildManager)Package.GetGlobalService(typeof(SVsSolutionBuildManager)) ?? throw new ArgumentNullException(nameof(buildManager)); buildManager.AdviseUpdateSolutionEvents(this, out _cookie); }
public NunitView() { Assembly assembly = Assembly.GetExecutingAssembly(); emptyIcon = new Bitmap(assembly.GetManifestResourceStream("BubbleCloudorg.VisualNunit.Icons.Empty.png")); successIcon = new Bitmap(assembly.GetManifestResourceStream("BubbleCloudorg.VisualNunit.Icons.Success.png")); failureIcon = new Bitmap(assembly.GetManifestResourceStream("BubbleCloudorg.VisualNunit.Icons.Failure.png")); abortedIcon = new Bitmap(assembly.GetManifestResourceStream("BubbleCloudorg.VisualNunit.Icons.Aborted.png")); runIcon = new Bitmap(assembly.GetManifestResourceStream("BubbleCloudorg.VisualNunit.Icons.Run.png")); debugIcon = new Bitmap(assembly.GetManifestResourceStream("BubbleCloudorg.VisualNunit.Icons.Debug.png")); stopIcon = new Bitmap(assembly.GetManifestResourceStream("BubbleCloudorg.VisualNunit.Icons.Stop.png")); homeIcon = new Bitmap(assembly.GetManifestResourceStream("BubbleCloudorg.VisualNunit.Icons.Support.png")); InitializeComponent(); dataGridView1.AutoGenerateColumns = false; toolTip = new ToolTip(); toolTip.AutoPopDelay = 5000; toolTip.InitialDelay = 1000; toolTip.ReshowDelay = 500; toolTip.ShowAlways = true; runTestsButton.Image = runIcon; toolTip.SetToolTip(runTestsButton, "Run All or Selected Tests"); homeButton.Image = homeIcon; toolTip.SetToolTip(homeButton, "View Support Page"); statusButton.Image = emptyIcon; uint cookie; int result = 0; IVsSolution2 solutionService = (IVsSolution2)Package.GetGlobalService(typeof(SVsSolution)); result = solutionService.AdviseSolutionEvents(this, out cookie); Trace.WriteLine(string.Format(CultureInfo.CurrentCulture, "Added solution service event listener: {0}", result)); IVsSolutionBuildManager buildService = (IVsSolutionBuildManager)Package.GetGlobalService(typeof(SVsSolutionBuildManager)); result = buildService.AdviseUpdateSolutionEvents(this, out cookie); Trace.WriteLine(string.Format(CultureInfo.CurrentCulture, "Added build service event listener: {0}", result)); RefreshView(); }
public VsSolutionManager( ISolutionBrowser solutionBrowser, IVsMonitorSelection monitorSelection, IVsSolutionBuildManager solutionBuildManager, IDiagLog log) { ThreadHelper.ThrowIfNotOnUIThread(); this.solutionBrowser = solutionBrowser ?? throw new ArgumentNullException(nameof(solutionBrowser)); this.monitorSelection = monitorSelection ?? throw new ArgumentNullException(nameof(monitorSelection)); this.solutionBuildManager = solutionBuildManager ?? throw new ArgumentNullException(nameof(solutionBuildManager)); this.log = log ?? throw new ArgumentNullException(nameof(log)); // Advise to selection events (e.g. startup project changed) monitorSelection.AdviseSelectionEvents(this, out selectionEventsCookie); // Advise to update solution events (e.g. switched debug/release configuration) solutionBuildManager.AdviseUpdateSolutionEvents(this, out updateSolutionEventsCookie); }
public override void Initialize(ProjectSnapshotManagerBase projectManager) { _projectManager = projectManager; _projectManager.Changed += ProjectManager_Changed; _ = _joinableTaskContext.Factory.RunAsync(async() => { await _joinableTaskContext.Factory.SwitchToMainThreadAsync(); // Attach the event sink to solution update events. if (_services.GetService(typeof(SVsSolutionBuildManager)) is IVsSolutionBuildManager solutionBuildManager) { _solutionBuildManager = solutionBuildManager; // We expect this to be called only once. So we don't need to Unadvise. var hr = _solutionBuildManager.AdviseUpdateSolutionEvents(this, out _updateCookie); Marshal.ThrowExceptionForHR(hr); } }); }
/// <summary> /// Builds the solution. /// </summary> public async Task <bool> BuildSolutionAsync(BuildAction action = BuildAction.Build) { await ThreadHelper.JoinableTaskFactory.SwitchToMainThreadAsync(); IVsSolutionBuildManager svc = await VS.Services.GetSolutionBuildManagerAsync(); uint buildFlags = (uint)GetBuildFlags(action); BuildObserver observer = new(null); ErrorHandler.ThrowOnFailure(svc.AdviseUpdateSolutionEvents(observer, out uint cookie)); try { ErrorHandler.ThrowOnFailure(svc.StartSimpleUpdateSolutionConfiguration(buildFlags, 0, 0)); return(await observer.Result); } finally { svc.UnadviseUpdateSolutionEvents(cookie); } }
/// [connect with VS] private void ConnectWithVisualStudio() { bool connectedToSelectionEvents = false; bool connectedToUpdateSolutionEvents = false; // Advise to selection events (e.g. startup project changed) m_monitorSelection = Microsoft.VisualStudio.Shell.ServiceProvider.GlobalProvider. GetService(typeof(SVsShellMonitorSelection)) as IVsMonitorSelection; if (m_monitorSelection != null) { m_monitorSelection.AdviseSelectionEvents( this, out m_selectionEventsCookie); connectedToSelectionEvents = true; } else { WriteLine(1, "ConnectWithVisualStudio: GetService(SVsShellMonitorSelection) failed!"); } // Advise to update solution events (e.g. switched debug/release configuration) m_solutionBuildManager = Microsoft.VisualStudio.Shell.ServiceProvider.GlobalProvider. GetService(typeof(SVsSolutionBuildManager)) as IVsSolutionBuildManager; if (m_solutionBuildManager != null) { m_solutionBuildManager.AdviseUpdateSolutionEvents( this, out m_updateSolutionEventsCookie); connectedToUpdateSolutionEvents = true; } else { WriteLine(1, "ConnectWithVisualStudio: GetService(SVsSolutionBuildManager) failed!"); } if (connectedToSelectionEvents && connectedToUpdateSolutionEvents) { WriteLine(1, "ConnectWithVisualStudio succeeded"); } }
protected override void Initialize() { Common.Trace("Package intialize"); base.Initialize(); Common.Trace("Task manager.Initialize()"); // Initialize common functionality Common.Initialize(this); taskListMenu = new RootMenu(); // Initialize fields tools = new Tools(); sharedTaskManagers = new List <TaskManager>(); // Attach to solution events solution = GetService(typeof(SVsSolution)) as IVsSolution; if (solution == null) { Common.Log("Could not get solution"); } solution.AdviseSolutionEvents(this as IVsSolutionEvents, out solutionEventsCookie); // Attach to build events buildManager = GetService(typeof(SVsSolutionBuildManager)) as IVsSolutionBuildManager; if (buildManager == null) { Common.Log("Could not get build manager"); } buildManager.AdviseUpdateSolutionEvents(this, out buildManagerCookie); // Add a TaskManagerFactory service ITaskManagerFactory factory = this as ITaskManagerFactory; (this as System.ComponentModel.Design.IServiceContainer).AddService(typeof(ITaskManagerFactory), factory, true); // Set PID for msbuild tasks Environment.SetEnvironmentVariable("VSPID", System.Diagnostics.Process.GetCurrentProcess().Id.ToString()); }
// remember the latest OnQueryRemoveDirectories remove list //string[] _RemoveDirectoriesQueue = null; #region SccProvider Service initialization/unitialization public SccProviderService(SccProvider sccProvider) { Debug.Assert(null != sccProvider); _sccProvider = sccProvider; // Subscribe to solution events IVsSolution sol = (IVsSolution)_sccProvider.GetService(typeof(SVsSolution)); sol.AdviseSolutionEvents(this, out _vsSolutionEventsCookie); Debug.Assert(VSConstants.VSCOOKIE_NIL != _vsSolutionEventsCookie); // Subscribe to project documents IVsTrackProjectDocuments2 tpdService = (IVsTrackProjectDocuments2)_sccProvider.GetService(typeof(SVsTrackProjectDocuments)); tpdService.AdviseTrackProjectDocumentsEvents(this, out _tpdTrackProjectDocumentsCookie); Debug.Assert(VSConstants.VSCOOKIE_NIL != _tpdTrackProjectDocumentsCookie); // Subscribe to status events _sccStatusTracker.HGStatusChanged += new HGLib.HGStatusChangedEvent(SetNodesGlyphsDirty); IVsSolutionBuildManager buildManagerService = _sccProvider.GetService(typeof(SVsSolutionBuildManager)) as IVsSolutionBuildManager; buildManagerService.AdviseUpdateSolutionEvents(this, out _dwBuildManagerCooky); }
// ------------------------------------------------------ /// <summary> /// This method is called after the package is sited to perform any /// initialization that relies on Visual Studio services. /// </summary> protected override void Initialize() { base.Initialize(); // Add the command handlers for the menus and toolbars. OleMenuCommandService mcs = GetService( typeof(IMenuCommandService)) as OleMenuCommandService; if (mcs != null) { CommandID cmdID; // View / Other Windows / CxxTest Suites cmdID = new CommandID(Guids.CxxTestPackageCmdSet, (int)CommandIds.cmdidCxxTestViewWindow); mcs.AddCommand(new MenuCommand( new EventHandler(ShowCxxTestSuitesWindow_Invoked), cmdID)); // View / Other Windows / CxxTest Results cmdID = new CommandID(Guids.CxxTestPackageCmdSet, (int)CommandIds.cmdidCxxTestResultsWindow); mcs.AddCommand(new MenuCommand( new EventHandler(ShowCxxTestResultsWindow_Invoked), cmdID)); // <Solution Item> / Generate Test Suite... cmdID = new CommandID(Guids.CxxTestPackageCmdSet, (int)CommandIds.cmdidGenerateTests); mcs.AddCommand(new OleMenuCommand( new EventHandler(GenerateTests_Invoked), delegate { }, new EventHandler(GenerateTests_BeforeQueryStatus), cmdID)); } // Add the CxxTest and Dereferee includes and libraries paths to // the Visual C++ directories options if they're not already // there. AddIncludesAndLibrariesPaths(); // Initialize the solution build events listener. solutionBuildEvents = new SolutionBuildEventsHandler(); IVsSolutionBuildManager manager = (IVsSolutionBuildManager)GetService( typeof(SVsSolutionBuildManager)); manager.AdviseUpdateSolutionEvents( solutionBuildEvents, out solutionBuildCookie); // Listen for solution events. (We may want to switch this over to // VSIP interfaces in the future.) DTE dte = (DTE)GetService(typeof(DTE)); dte.Events.SolutionEvents.Opened += SolutionEvents_Opened; dte.Events.SolutionEvents.ProjectAdded += SolutionEvents_ProjectAdded; dte.Events.SolutionEvents.ProjectRemoved += SolutionEvents_ProjectRemoved; dte.Events.SolutionEvents.BeforeClosing += SolutionEvents_BeforeClosing; dte.Events.SolutionEvents.AfterClosing += SolutionEvents_AfterClosing; // Initialize the project documents tracking events handler. IVsTrackProjectDocuments2 trackDocs = GetTrackProjectDocuments(); trackProjectDocsEvents = new TrackProjectDocumentsEventsHandler(); trackDocs.AdviseTrackProjectDocumentsEvents( trackProjectDocsEvents, out trackProjectDocsCookie); // Initialize the debugger events handler. debuggerEvents = new DebuggerEventsHandler(); IVsDebugger debugger = (IVsDebugger)GetService(typeof(SVsShellDebugger)); debugger.AdviseDebuggerEvents(debuggerEvents, out debuggerCookie); }
private SolutionEventListener(IVsSolutionBuildManager solutionManager) { solutionManager.AdviseUpdateSolutionEvents(this, out var cookie); this.SubscriptionCookie = cookie; }
protected override void Initialize() { Common.Trace("Package intialize"); base.Initialize(); Common.Trace("Task manager.Initialize()"); // Initialize common functionality Common.Initialize(this); taskListMenu = new RootMenu(); // Initialize fields tools = new Tools(); sharedTaskManagers = new List<TaskManager>(); // Attach to solution events solution = GetService(typeof(SVsSolution)) as IVsSolution; if (solution == null) Common.Log("Could not get solution"); solution.AdviseSolutionEvents(this as IVsSolutionEvents, out solutionEventsCookie); // Attach to build events buildManager = GetService(typeof(SVsSolutionBuildManager)) as IVsSolutionBuildManager; if (buildManager == null) Common.Log("Could not get build manager"); buildManager.AdviseUpdateSolutionEvents(this, out buildManagerCookie); // Add a TaskManagerFactory service ITaskManagerFactory factory = this as ITaskManagerFactory; (this as System.ComponentModel.Design.IServiceContainer).AddService(typeof(ITaskManagerFactory), factory, true); // Set PID for msbuild tasks Environment.SetEnvironmentVariable( "VSPID", System.Diagnostics.Process.GetCurrentProcess().Id.ToString() ); }
protected override void Initialize() { base.Initialize(); // Initialize common functionality Common.Initialize(this); taskListMenu = new RootMenu(); // Initialize fields tools = new Tools(); sharedTaskManagers = new List<TaskManager>(); // Attach to solution events solution = GetService(typeof(SVsSolution)) as IVsSolution; // if (solution == null) throw new NullReferenceException(); solution.AdviseSolutionEvents(this as IVsSolutionEvents, out solutionEventsCookie); // Attach to build events buildManager = GetService(typeof(SVsSolutionBuildManager)) as IVsSolutionBuildManager; // if (buildManager == null) throw new NullReferenceException(); buildManager.AdviseUpdateSolutionEvents(this, out buildManagerCookie); // Add a TaskManagerFactory service (this as System.ComponentModel.Design.IServiceContainer).AddService(typeof(ITaskManagerFactory), this, true); }