public OutputConsoleLogger( [Import(typeof(SVsServiceProvider))] IServiceProvider serviceProvider, IOutputConsoleProvider consoleProvider) { if (serviceProvider == null) { throw new ArgumentNullException(nameof(serviceProvider)); } if (consoleProvider == null) { throw new ArgumentNullException(nameof(consoleProvider)); } NuGetUIThreadHelper.JoinableTaskFactory.Run(async() => { await NuGetUIThreadHelper.JoinableTaskFactory.SwitchToMainThreadAsync(); ErrorListProvider = new ErrorListProvider(serviceProvider); _dte = serviceProvider.GetDTE(); _buildEvents = _dte.Events.BuildEvents; _buildEvents.OnBuildBegin += (_, __) => { ErrorListProvider.Tasks.Clear(); }; _solutionEvents = _dte.Events.SolutionEvents; _solutionEvents.AfterClosing += () => { ErrorListProvider.Tasks.Clear(); }; OutputConsole = consoleProvider.CreatePackageManagerConsole(); }); }
public OutputConsoleLogger( IAsyncServiceProvider asyncServiceProvider, IOutputConsoleProvider consoleProvider, Lazy <ErrorListTableDataSource> errorListDataSource) { if (asyncServiceProvider == null) { throw new ArgumentNullException(nameof(asyncServiceProvider)); } if (consoleProvider == null) { throw new ArgumentNullException(nameof(consoleProvider)); } ErrorListTableDataSource = errorListDataSource; NuGetUIThreadHelper.JoinableTaskFactory.Run(async() => { await NuGetUIThreadHelper.JoinableTaskFactory.SwitchToMainThreadAsync(); _dte = await asyncServiceProvider.GetDTEAsync(); _buildEvents = _dte.Events.BuildEvents; _buildEvents.OnBuildBegin += (_, __) => { ErrorListTableDataSource.Value.ClearNuGetEntries(); }; _solutionEvents = _dte.Events.SolutionEvents; _solutionEvents.AfterClosing += () => { ErrorListTableDataSource.Value.ClearNuGetEntries(); }; OutputConsole = consoleProvider.CreatePackageManagerConsole(); }); }
private void Initialize(IServiceProvider serviceProvider) { ThreadHelper.JoinableTaskFactory.Run(async() => { await ThreadHelper.JoinableTaskFactory.SwitchToMainThreadAsync(); _dte = (EnvDTE.DTE)serviceProvider.GetService(typeof(EnvDTE.DTE)); if (_dte != null) { _dteEvents = _dte.Events; _dteBuildEvents = _dteEvents.BuildEvents; _dteBuildEvents.OnBuildBegin += (scope, action) => StopCoverageProcess(); } if (serviceProvider.GetService(typeof(SVsShell)) is IVsShell shell) { var packageToBeLoadedGuid = new Guid(OutputToolWindowPackage.PackageGuidString); shell.LoadPackage(ref packageToBeLoadedGuid, out var package); var outputWindowInitializedFile = Path.Combine(FCCEngine.AppDataFolder, "outputWindowInitialized"); if (File.Exists(outputWindowInitializedFile)) { OutputToolWindowCommand.Instance.FindToolWindow(); } else { // for first time users, the window is automatically docked OutputToolWindowCommand.Instance.ShowToolWindow(); File.WriteAllText(outputWindowInitializedFile, string.Empty); } } }); }
/// <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 System.Threading.Tasks.Task InitializeAsync(CancellationToken cancellationToken, IProgress <ServiceProgressData> progress) { await base.InitializeAsync(cancellationToken, progress); VSColorTheme.ThemeChanged += _ => { System.Diagnostics.Debug.WriteLine("Theme changed."); ThemeHelper.RefreshThemeCache(); }; SolutionEvents.OnAfterOpenSolution += (s, args) => { Classifiers.SymbolMarkManager.Clear(); }; // 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 JoinableTaskFactory.SwitchToMainThreadAsync(cancellationToken); if ((Config.Instance.DisplayOptimizations & DisplayOptimizations.MainWindow) != 0) { WpfHelper.SetUITextRenderOptions(Application.Current.MainWindow, true); } _dteEvents = DTE2.Events; _buildEvents = _dteEvents.BuildEvents; _buildEvents.OnBuildBegin += BuildEvents_OnBuildBegin; _buildEvents.OnBuildDone += BuildEvents_OnBuildEnd; _buildEvents.OnBuildProjConfigDone += BuildEvents_OnBuildProjConfigDone; //_extenderCookie = DTE.ObjectExtenders.RegisterExtenderProvider(VSConstants.CATID.CSharpFileProperties_string, BuildBots.AutoReplaceExtenderProvider.Name, new BuildBots.AutoReplaceExtenderProvider()); //await Commands.SymbolFinderWindowCommand.InitializeAsync(this); Commands.ScreenshotCommand.Initialize(this); Commands.IncrementVsixVersionCommand.Initialize(this); Commands.NaviBarSearchDeclarationCommand.Initialize(this); }
public void populateDefaultVSComObjects() { VisualStudio_2010.Package = this; VisualStudio_2010.ErrorListProvider = new ErrorListProvider(this); VisualStudio_2010.IVsUIShell = this.getService <IVsUIShell>(); VisualStudio_2010.DTE2 = this.getService <EnvDTE.DTE, EnvDTE80.DTE2>(); VisualStudio_2010.OleMenuCommandService = this.getService <OleMenuCommandService>(); Events = VisualStudio_2010.DTE2.Events; BuildEvents = Events.BuildEvents; CommandEvents = Events.CommandEvents; DebuggerEvents = Events.DebuggerEvents; DocumentEvents = Events.DocumentEvents; DTEEvents = Events.DTEEvents; FindEvents = Events.FindEvents; MiscFilesEvents = Events.MiscFilesEvents; OutputWindowEvents = Events.OutputWindowEvents; SelectionEvents = Events.SelectionEvents; SolutionEvents = Events.SolutionEvents; SolutionItemsEvents = Events.SolutionItemsEvents; TaskListEvents = Events.TaskListEvents; TextEditorEvents = Events.TextEditorEvents; WindowEvents = Events.WindowEvents; BuildEvents.OnBuildBegin += (scope, action) => VisualStudio_2010.On_BuildBegin.invoke(); BuildEvents.OnBuildDone += (scope, action) => VisualStudio_2010.On_BuildDone.invoke(); BuildEvents.OnBuildProjConfigDone += (Project, ProjectConfig, Platform, SolutionConfig, Success) => { //@"On OnBuildProjConfigDone: project: {0} , ProjectConfig: {1} , Platform: {2}, SolutionConfig: {3} , Success: {4}".debug(Project,ProjectConfig, Platform, SolutionConfig,Success); if (Success) { VisualStudio_2010.On_ProjectBuild_OK.invoke(Project); } else { VisualStudio_2010.On_ProjectBuild_Failed.invoke(Project); } }; SolutionEvents.Opened += () => VisualStudio_2010.On_SolutionOpened.invoke(); DocumentEvents.DocumentOpened += (document) => VisualStudio_2010.on_DocumentOpened.invoke(document); DocumentEvents.DocumentClosing += (document) => VisualStudio_2010.on_DocumentClosing.invoke(document); DocumentEvents.DocumentSaved += (document) => VisualStudio_2010.on_DocumentSaved.invoke(document); DocumentEvents.DocumentOpening += (documentPath, readOnly) => VisualStudio_2010.on_DocumentOpening.invoke(documentPath, readOnly); TextEditorEvents.LineChanged += (startPoint, endPoint, hInt) => VisualStudio_2010.on_LineChanged.invoke(startPoint, endPoint); WindowEvents.WindowActivated += (windowGotFocus, windowLostFocus) => { if (windowGotFocus.Document.notNull()) { VisualStudio_2010.on_ActiveDocumentChange.invoke(windowGotFocus.Document); } }; }
async Task IVisualStudioShell.SubscribeToBuildBeginAsync(Action onBuildBegin) { await NuGetUIThreadHelper.JoinableTaskFactory.SwitchToMainThreadAsync(); var dte = await _dte.GetValueAsync(); _buildEvents = dte.Events.BuildEvents; _buildEvents.OnBuildBegin += (scope, action) => onBuildBegin(); }
private EnvDTE.BuildEvents GetBuildEvents() { if (_buildEvents == null) { EnvDTE.DTE dte = _serviceProvider.GetService(typeof(EnvDTE.DTE)) as EnvDTE.DTE; _buildEvents = dte.Events.BuildEvents; } return(_buildEvents); }
/// <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 System.Threading.Tasks.Task InitializeAsync(CancellationToken cancellationToken, IProgress <ServiceProgressData> progress) { await base.InitializeAsync(cancellationToken, progress); SolutionEvents.OnAfterOpenSolution += (s, args) => { Taggers.SymbolMarkManager.Clear(); }; // 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 JoinableTaskFactory.SwitchToMainThreadAsync(cancellationToken); if (Config.Instance.DisplayOptimizations.MatchFlags(DisplayOptimizations.CompactMenu)) { Controls.LayoutOverrider.CompactMenu(); } if (Config.Instance.DisplayOptimizations.MatchFlags(DisplayOptimizations.MainWindow)) { WpfHelper.SetUITextRenderOptions(Application.Current.MainWindow, true); } _dteEvents = DTE2.Events; _buildEvents = _dteEvents.BuildEvents; _buildEvents.OnBuildBegin += BuildEvents_OnBuildBegin; _buildEvents.OnBuildDone += BuildEvents_OnBuildEnd; _buildEvents.OnBuildProjConfigDone += BuildEvents_OnBuildProjConfigDone; //_extenderCookie = DTE.ObjectExtenders.RegisterExtenderProvider(VSConstants.CATID.CSharpFileProperties_string, BuildBots.AutoReplaceExtenderProvider.Name, new BuildBots.AutoReplaceExtenderProvider()); //Commands.SymbolFinderWindowCommand.Initialize(); Commands.ScreenshotCommand.Initialize(); Commands.GetContentTypeCommand.Initialize(); Commands.IncrementVsixVersionCommand.Initialize(); Commands.NaviBarSearchDeclarationCommand.Initialize(); if (Config.Instance.InitStatus != InitStatus.Normal) { Config.Instance.SaveConfig(Config.ConfigPath); // save the file to prevent this notification from reoccurrence new Commands.VersionInfoBar(this).Show(Config.Instance.InitStatus); if (Config.Instance.InitStatus == InitStatus.FirstLoad) { // automatically load theme when first load if (ThemeHelper.DocumentPageColor.ToWpfColor().IsDark()) { Config.LoadConfig(Config.DarkTheme, StyleFilters.All); } else { Config.LoadConfig(Config.LightTheme, StyleFilters.All); } } } Commands.SyntaxCustomizerWindowCommand.Initialize(); //ListEditorCommands(); }
private async System.Threading.Tasks.Task BuildProjectAsync(CancellationToken ct) { await ThreadHelper.JoinableTaskFactory.SwitchToMainThreadAsync(ct); _tcsBuildProject = new TaskCompletionSource <object>(); _buildEvents = DTE.Events.BuildEvents; // This is a COM wrapper and has to be declared at class level, or it will be garbage collected. _buildEvents.OnBuildDone += OnBuildDone; var solutionBuild = DTE.Solution.SolutionBuild; solutionBuild.BuildProject(solutionBuild.ActiveConfiguration.Name, VsProject.UniqueName); await _tcsBuildProject.Task; }
private EnvDTE.BuildEvents GetBuildEvents() { if (_buildEvents == null) { var dte = _serviceProvider.GetService(typeof(EnvDTE.DTE)) as EnvDTE.DTE; if (dte == null) { Debug.Fail("Failed to get DTE service."); return(null); } _buildEvents = dte.Events.BuildEvents; } return(_buildEvents); }
private void SubscribeToEvents() { _dteService = _serviceProvider.GetService(typeof(EnvDTE.DTE)) as EnvDTE.DTE; if(null != _dteService) { _buildEvents = _dteService.Events.BuildEvents; _windowEvents = _dteService.Events.WindowEvents; if(null != _buildEvents) { _buildEvents.OnBuildBegin += _buildEvents_OnBuildBegin; _buildEvents.OnBuildDone += _buildEvents_OnBuildDone; } if(null != _windowEvents) { _windowEvents.WindowActivated += _windowEvents_WindowActivated; } } }
private void InitializeWithSolutionAndDTEReady() { string path = System.Environment.GetFolderPath(System.Environment.SpecialFolder.MyDocuments); dte = (EnvDTE.DTE) this.GetService(typeof(EnvDTE.DTE)); if (dte != null && dte.Solution != null) { path = System.Environment.GetFolderPath(System.Environment.SpecialFolder.LocalApplicationData); path = System.IO.Path.Combine(path, "attachables", System.IO.Path.GetFileNameWithoutExtension(dte.Solution.FullName)); } if (!System.IO.Directory.Exists(path)) { System.IO.Directory.CreateDirectory(path); } RemindersContext.ConfigureDatabase(path); Manager = new ReminderManager(this); // Check due reminders once during startup. Manager.CheckTodoBy(); // Need to always have reference to avoid COM releasing. buildEvents = dte.Events.BuildEvents; buildEvents.OnBuildBegin += (scope, action) => { // Check due reminders when building. Manager.CheckTodoBy(); }; buildEvents.OnBuildDone += (scope, action) => { }; buildEvents.OnBuildProjConfigBegin += (project, config, platform, solutionConfig) => { }; buildEvents.OnBuildProjConfigDone += (project, config, platform, solutionConfig, success) => { }; }
protected override async Task InitializeAsync( CancellationToken cancellationToken, IProgress <ServiceProgressData> progress) { var componentModel = await GetServiceAsync(typeof(SComponentModel)) as IComponentModel; componentModel.DefaultCompositionService.SatisfyImportsOnce(this); _restoreWorker = new Lazy <ISolutionRestoreWorker>( () => componentModel.GetService <ISolutionRestoreWorker>()); _settings = new Lazy <ISettings>( () => componentModel.GetService <ISettings>()); _solutionManager = new Lazy <IVsSolutionManager>( () => componentModel.GetService <IVsSolutionManager>()); var lockService = new Lazy <INuGetLockService>( () => componentModel.GetService <INuGetLockService>()); var updateSolutionEvent = new VsUpdateSolutionEvent(lockService); // Don't use CPS thread helper because of RPS perf regression await ThreadHelper.JoinableTaskFactory.RunAsync(async() => { await ThreadHelper.JoinableTaskFactory.SwitchToMainThreadAsync(); var dte = (EnvDTE.DTE) await GetServiceAsync(typeof(SDTE)); _buildEvents = dte.Events.BuildEvents; _buildEvents.OnBuildBegin += BuildEvents_OnBuildBegin; UserAgent.SetUserAgentString( new UserAgentStringBuilder().WithVisualStudioSKU(dte.GetFullVsVersionString())); _solutionBuildManager = (IVsSolutionBuildManager5)await GetServiceAsync(typeof(SVsSolutionBuildManager)); Assumes.Present(_solutionBuildManager); _solutionBuildManager.AdviseUpdateSolutionEvents4(updateSolutionEvent, out _updateSolutionEventsCookie4); }); await SolutionRestoreCommand.InitializeAsync(this); await base.InitializeAsync(cancellationToken, progress); }
public VSProjectNode(VSProject package) { LogUtility.LogString("Entering Cosmos.VS.Package.VSProjectNode.ctor(VSProject)"); try { this.Package = package; var dte = (EnvDTE.DTE)((IServiceProvider)this.Package).GetService(typeof(EnvDTE.DTE)); buildEvents = dte.Events.BuildEvents; buildEvents.OnBuildProjConfigDone += buildEvents_OnBuildProjConfigDone; imageIndex = this.ImageHandler.ImageList.Images.Count; foreach (Image img in imageList.Images) { this.ImageHandler.AddImage(img); } } catch (Exception E) { LogUtility.LogException(E); } finally { LogUtility.LogString("Exiting Cosmos.VS.Package.VSProjectNode.ctor(VSProject)"); } }
private void SubscripeToEvents() { var events = MasterObjekt.Events; buildEvents = events.BuildEvents; commandEvents = events.CommandEvents; documentEvents = events.DocumentEvents; solutionEvents = events.SolutionEvents; buildEvents.OnBuildBegin += new EnvDTE._dispBuildEvents_OnBuildBeginEventHandler(BuildEvents_OnBuildBegin); buildEvents.OnBuildDone += new EnvDTE._dispBuildEvents_OnBuildDoneEventHandler(BuildEvents_OnBuildDone); commandEvents.AfterExecute += new EnvDTE._dispCommandEvents_AfterExecuteEventHandler(CommandEvents_AfterExecute); documentEvents.DocumentSaved += new EnvDTE._dispDocumentEvents_DocumentSavedEventHandler(DocumentEvents_DocumentSaved); solutionEvents.Opened += new EnvDTE._dispSolutionEvents_OpenedEventHandler(SolutionEvents_Opened); solutionEvents.ProjectAdded += new EnvDTE._dispSolutionEvents_ProjectAddedEventHandler(SolutionEvents_ProjectAdded); solutionEvents.ProjectRemoved += new EnvDTE._dispSolutionEvents_ProjectRemovedEventHandler(SolutionEvents_ProjectRemoved); solutionEvents.ProjectRenamed += new EnvDTE._dispSolutionEvents_ProjectRenamedEventHandler(SolutionEvents_ProjectRenamed); solutionEvents.Renamed += new EnvDTE._dispSolutionEvents_RenamedEventHandler(SolutionEvents_Renamed); solutionEvents.AfterClosing += new EnvDTE._dispSolutionEvents_AfterClosingEventHandler(SolutionEvents_AfterClosing); }
private void SubscribeToEvents() { _dteService = _serviceProvider.GetService(typeof(EnvDTE.DTE)) as EnvDTE.DTE; if (null != _dteService) { _buildEvents = _dteService.Events.BuildEvents; _windowEvents = _dteService.Events.WindowEvents; if (null != _buildEvents) { _buildEvents.OnBuildBegin += _buildEvents_OnBuildBegin; _buildEvents.OnBuildDone += _buildEvents_OnBuildDone; } if (null != _windowEvents) { _windowEvents.WindowActivated += _windowEvents_WindowActivated; } } }
protected override async System.Threading.Tasks.Task InitializeAsync(CancellationToken cancellationToken, IProgress <ServiceProgressData> progress) { using (var tidyLogWriter = new StreamWriter(TidyProcesLogsPath, false)) await tidyLogWriter.WriteLineAsync("Initialization has begun..."); await base.InitializeAsync(cancellationToken, progress); using (var tidyLogWriter = new StreamWriter(TidyProcesLogsPath, true)) await tidyLogWriter.WriteLineAsync("Base has initialized"); await ThreadHelper.JoinableTaskFactory.SwitchToMainThreadAsync(cancellationToken); using (var tidyLogWriter = new StreamWriter(TidyProcesLogsPath, true)) await tidyLogWriter.WriteLineAsync("Switched to main thread"); App.Initialize(GetDialogPage(typeof(OptionsPage)) as OptionsPage); using (var tidyLogWriter = new StreamWriter(TidyProcesLogsPath, true)) await tidyLogWriter.WriteLineAsync("App initialized"); Instance = this; var componentModel = (IComponentModel) await GetServiceAsync(typeof(SComponentModel)).ConfigureAwait(true); if (componentModel != null) { VsWorkspace = componentModel.GetService <VisualStudioWorkspace>(); } using (var tidyLogWriter = new StreamWriter(TidyProcesLogsPath, true)) { if (componentModel == null) { await tidyLogWriter.WriteLineAsync("component Model is null"); } else { await tidyLogWriter.WriteLineAsync("component has value"); } } // Add our command handlers for menu (commands must exist in the .vsct file) var menuCommandService = await GetServiceAsync(typeof(IMenuCommandService)).ConfigureAwait(true) as OleMenuCommandService; if (null != menuCommandService) { new ActionCustomCodeCleanup(menuCommandService).SetupCommands(); } using (var tidyLogWriter = new StreamWriter(TidyProcesLogsPath, true)) { if (menuCommandService == null) { await tidyLogWriter.WriteLineAsync("menu Command Service is null"); } else { await tidyLogWriter.WriteLineAsync("menu Command Service has value"); } } // Hook up event handlers events = App.Dte.Events; buildEvent = events.BuildEvents; docEvents = events.DocumentEvents; solEvents = events.SolutionEvents; buildEvent.OnBuildBegin += BuildEvent_OnBuildBegin; docEvents.DocumentSaved += DocEvents_DocumentSaved; solEvents.Opened += delegate { App.Initialize(GetDialogPage(typeof(OptionsPage)) as OptionsPage); }; using (var tidyLogWriter = new StreamWriter(TidyProcesLogsPath, true)) await tidyLogWriter.WriteLineAsync("Initialization has finished..."); }
private void SubscripeToEvents() { var events = GetDTE2().Events; buildEvents = events.BuildEvents; commandEvents = events.CommandEvents; documentEvents = events.DocumentEvents; solutionEvents = events.SolutionEvents; buildEvents.OnBuildDone += new EnvDTE._dispBuildEvents_OnBuildDoneEventHandler(BuildEvents_OnBuildDone); commandEvents.AfterExecute += new EnvDTE._dispCommandEvents_AfterExecuteEventHandler(CommandEvents_AfterExecute); documentEvents.DocumentSaved += new EnvDTE._dispDocumentEvents_DocumentSavedEventHandler(DocumentEvents_DocumentSaved); solutionEvents.Opened += new EnvDTE._dispSolutionEvents_OpenedEventHandler(SolutionEvents_Opened); solutionEvents.ProjectAdded += new EnvDTE._dispSolutionEvents_ProjectAddedEventHandler(SolutionEvents_ProjectAdded); solutionEvents.ProjectRemoved += new EnvDTE._dispSolutionEvents_ProjectRemovedEventHandler(SolutionEvents_ProjectRemoved); solutionEvents.ProjectRenamed += new EnvDTE._dispSolutionEvents_ProjectRenamedEventHandler(SolutionEvents_ProjectRenamed); solutionEvents.Renamed += new EnvDTE._dispSolutionEvents_RenamedEventHandler(SolutionEvents_Renamed); solutionEvents.AfterClosing += new EnvDTE._dispSolutionEvents_AfterClosingEventHandler(SolutionEvents_AfterClosing); }
private EnvDTE.BuildEvents GetBuildEvents() { if (_buildEvents == null) { var dte = _serviceProvider.GetService(typeof(EnvDTE.DTE)) as EnvDTE.DTE; if (dte == null) { Debug.Fail("Failed to get DTE service."); return null; } _buildEvents = dte.Events.BuildEvents; } return _buildEvents; }
private EnvDTE.BuildEvents GetBuildEvents() { if (_buildEvents == null) { EnvDTE.DTE dte = _serviceProvider.GetService(typeof(EnvDTE.DTE)) as EnvDTE.DTE; _buildEvents = dte.Events.BuildEvents; } return _buildEvents; }