/// <summary> /// Retrieve the CPS enabled JoinableTaskFactory for the current version of Visual Studio. /// This overrides the default VsTaskLibraryHelper.ServiceInstance JTF. /// </summary> public static void SetJoinableTaskFactoryFromService(IProjectServiceAccessor projectServiceAccessor) { if (projectServiceAccessor == null) { throw new ArgumentNullException(nameof(projectServiceAccessor)); } if (_joinableTaskFactory == null) { _joinableTaskFactory = new Lazy <JoinableTaskFactory>(() => { #if VS14 // Use IThreadHandling.AsyncPump for Visual Studio 2015 ProjectService projectService = projectServiceAccessor.GetProjectService(); IThreadHandling threadHandling = projectService.Services.ThreadingPolicy; return(threadHandling.AsyncPump); #else // Use IProjectService for Visual Studio 2017 var projectService = projectServiceAccessor.GetProjectService(); return(projectService.Services.ThreadingPolicy.JoinableTaskFactory); #endif }, // This option helps avoiding deadlocks caused by CPS trying to create ProjectServiceHost // PublicationOnly mode lets parallel threads execute value factory method without // being blocked on each other. // It is correct behavior in this case as the value factory provides the same value // each time it is called and Lazy is used just for caching the value for perf reasons. LazyThreadSafetyMode.PublicationOnly); } }
public T?GetExport <T>(string projectFilePath) where T : class { Requires.NotNullOrEmpty(projectFilePath, nameof(projectFilePath)); IProjectService projectService = _projectServiceAccessor.GetProjectService(); UnconfiguredProject?project = projectService?.LoadedUnconfiguredProjects .FirstOrDefault(x => string.Equals(x.FullPath, projectFilePath, StringComparisons.Paths)); return(project?.Services.ExportProvider.GetExportedValueOrDefault <T>()); }
public T GetExport <T>(string projectFilePath) where T : class { if (string.IsNullOrEmpty(projectFilePath)) { throw new ArgumentNullException(nameof(projectFilePath)); } IProjectService projectService = _projectServiceAccessor.GetProjectService(); UnconfiguredProject project = projectService?.LoadedUnconfiguredProjects .FirstOrDefault(x => x.FullPath.Equals(projectFilePath, StringComparison.OrdinalIgnoreCase)); return(project?.Services.ExportProvider.GetExportedValueOrDefault <T>()); }
/// <summary> /// Retrieve the CPS enabled JoinableTaskFactory for the current version of Visual Studio. /// This overrides the default VsTaskLibraryHelper.ServiceInstance JTF. /// </summary> public static void SetJoinableTaskFactoryFromService(IProjectServiceAccessor projectServiceAccessor) { if (projectServiceAccessor == null) { throw new ArgumentNullException(nameof(projectServiceAccessor)); } if (_joinableTaskFactory == null) { _joinableTaskFactory = new Lazy <JoinableTaskFactory>(() => { #if VS14 // Use IThreadHandling.AsyncPump for Visual Studio 2015 ProjectService projectService = projectServiceAccessor.GetProjectService(); IThreadHandling threadHandling = projectService.Services.ThreadingPolicy; return(threadHandling.AsyncPump); #else // Use IProjectService for Visual Studio 2017 IProjectService projectService = projectServiceAccessor.GetProjectService(); return(projectService.Services.ThreadingPolicy.JoinableTaskFactory); #endif }); } }
protected override void Handle() { var projectService = _projectServiceAccessor.GetProjectService(); var lastLoadedProject = projectService.LoadedUnconfiguredProjects.LastOrDefault(); var initialPath = lastLoadedProject != null?lastLoadedProject.GetProjectDirectory() : Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments); var file = _appShell.BrowseForFileOpen(IntPtr.Zero, Resources.WorkspaceFileFilter, initialPath, Resources.LoadWorkspaceTitle); if (file == null) { return; } LoadWorkspace(_rSession, file).DoNotWait(); }
protected override void Handle() { var projectService = _projectServiceAccessor.GetProjectService(); var lastLoadedProject = projectService.LoadedUnconfiguredProjects.LastOrDefault(); var initialPath = lastLoadedProject != null?lastLoadedProject.GetProjectDirectory() : Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments); var file = _shell.FileDialog().ShowSaveFileDialog(Resources.WorkspaceFileFilter, initialPath, Resources.SaveWorkspaceAsTitle); if (file == null) { return; } SaveWorkspace(file).DoNotWait(); }
public void Search(IRelationshipSearchParameters parameters, Action <ISearchResult> resultAccumulator) { Requires.NotNull(parameters, nameof(parameters)); Requires.NotNull(resultAccumulator, nameof(resultAccumulator)); if (_providers.Length == 0) { // No providers registered return; } if (!parameters.Options.SearchExternalItems) { // Consider the dependencies tree as containing 'external items', allowing the // tree to be excluded from search results via this option. return; } using var context = new DependenciesTreeSearchContext(parameters, resultAccumulator); _joinableTaskContext.Factory.Run(SearchSolutionAsync); Task SearchSolutionAsync() { // Search projects concurrently return(Task.WhenAll(_projectServiceAccessor.GetProjectService().LoadedUnconfiguredProjects.Select(SearchProjectAsync))); } async Task SearchProjectAsync(UnconfiguredProject unconfiguredProject) { IUnconfiguredProjectVsServices? projectVsServices = unconfiguredProject.Services.ExportProvider.GetExportedValue <IUnconfiguredProjectVsServices>(); IActiveConfigurationGroupService?configurationGroupService = unconfiguredProject.Services.ExportProvider.GetExportedValue <IActiveConfigurationGroupService>(); IProjectTree?dependenciesNode = projectVsServices?.ProjectTree.CurrentTree?.FindChildWithFlags(DependencyTreeFlags.DependenciesRootNode); if (projectVsServices != null && dependenciesNode != null && configurationGroupService is IActiveConfigurationGroupService2 activeConfigurationGroupService) { IConfigurationGroup <ConfiguredProject> configuredProjects = await activeConfigurationGroupService.GetActiveLoadedConfiguredProjectGroupAsync(); var projectContext = new DependenciesTreeProjectSearchContext(context, unconfiguredProject, dependenciesNode, _hierarchyItemManager, projectVsServices, _relationProvider); // Search providers concurrently await Task.WhenAll(_providers.Select(provider => provider.SearchAsync(projectContext))); } } }
public static void SetJoinableTaskFactoryFromService(IProjectServiceAccessor projectServiceAccessor) { Requires.NotNull(projectServiceAccessor, nameof(projectServiceAccessor)); if (_joinableTaskFactory == null) { _joinableTaskFactory = new Lazy <JoinableTaskFactory>(() => { // Use IProjectService for Visual Studio 2017 var projectService = projectServiceAccessor.GetProjectService(); return(projectService.Services.ThreadingPolicy.JoinableTaskFactory); }, // This option helps avoiding deadlocks caused by CPS trying to create ProjectServiceHost // PublicationOnly mode lets parallel threads execute value factory method without // being blocked on each other. // It is correct behavior in this case as the value factory provides the same value // each time it is called and Lazy is used just for caching the value for perf reasons. LazyThreadSafetyMode.PublicationOnly); } }
public Task InitializeAsync(IAsyncServiceProvider asyncServiceProvider) { IMissingSetupComponentRegistrationService missingWorkloadRegistrationService = _projectServiceAccessor .GetProjectService() .Services .ExportProvider .GetExport <IMissingSetupComponentRegistrationService>() .Value; return(missingWorkloadRegistrationService.InitializeAsync()); }
protected QueryDataProviderBase(IProjectServiceAccessor projectServiceAccessor) { _projectService = new Lazy <IProjectService2>( () => (IProjectService2)projectServiceAccessor.GetProjectService(), System.Threading.LazyThreadSafetyMode.PublicationOnly); }
public ReferenceCleanupService(IProjectServiceAccessor projectServiceAccessor) { _projectService = new Lazy <IProjectService2>( () => (IProjectService2)projectServiceAccessor.GetProjectService(), LazyThreadSafetyMode.PublicationOnly); }
public Task InitializeAsync(IAsyncServiceProvider asyncServiceProvider) { // Need to use the CPS export provider to get the dotnet compatibility detector IDotNetCoreProjectCompatibilityDetector dotNetCoreCompatibilityDetector = _projectServiceAccessor .GetProjectService() .Services .ExportProvider .GetExport <IDotNetCoreProjectCompatibilityDetector>() .Value; return(dotNetCoreCompatibilityDetector.InitializeAsync()); }