public VsPathContextProviderTests(DispatcherThreadFixture fixture) { Assumes.Present(fixture); _jtf = fixture.JoinableTaskFactory; NuGetUIThreadHelper.SetCustomJoinableTaskFactory(_jtf); }
protected override void OnStartup(System.Windows.StartupEventArgs e) { base.OnStartup(e); var mainThread = Thread.CurrentThread; var synchronizationContext = SynchronizationContext.Current; NuGetUIThreadHelper.SetCustomJoinableTaskFactory(mainThread, synchronizationContext); var sp = new ServiceProvider(); ServiceLocator.InitializePackageServiceProvider(sp); var host = sp.HostProvider?.CreateHost(async: false); host.ActivePackageSource = "All"; var commandExpansion = sp.CommandExpansionProvider?.Create(host); var console = new StandaloneConsole(); host.Initialize(console); Task.Run(async() => { var listener = new ConsoleListener(host, commandExpansion); await listener.RunAsync(console).ConfigureAwait(false); }); }
public bool TryCreateNuGetProject(EnvDTE.Project dteProject, ProjectSystemProviderContext context, out NuGetProject result) { if (dteProject == null) { throw new ArgumentNullException(nameof(dteProject)); } if (context == null) { throw new ArgumentNullException(nameof(context)); } ThreadHelper.ThrowIfNotOnUIThread(); result = null; var project = new EnvDTEProjectAdapter(dteProject); if (!project.IsLegacyCSProjPackageReferenceProject) { return(false); } // Lazy load the CPS enabled JoinableTaskFactory for the UI. NuGetUIThreadHelper.SetJoinableTaskFactoryFromService(ProjectServiceAccessor.Value as ProjectSystem.IProjectServiceAccessor); result = new LegacyCSProjPackageReferenceProject( project, VsHierarchyUtility.GetProjectId(dteProject)); return(true); }
private INuGetProjectServices CreateCoreProjectSystemServices( IVsProjectAdapter vsProjectAdapter, IComponentModel componentModel) { // Lazy load the CPS enabled JoinableTaskFactory for the UI. NuGetUIThreadHelper.SetJoinableTaskFactoryFromService(ProjectServiceAccessor.Value as ProjectSystem.IProjectServiceAccessor); return(new VsManagedLanguagesProjectSystemServices(vsProjectAdapter, componentModel)); }
public ProjectKNuGetProjectTests(DispatcherThreadFixture fixture) { Assumes.Present(fixture); _jtf = fixture.JoinableTaskFactory; NuGetUIThreadHelper.SetCustomJoinableTaskFactory(_jtf); }
public CpsPackageReferenceProjectProviderTests(DispatcherThreadFixture fixture) { Assumes.Present(fixture); _jtf = fixture.JoinableTaskFactory; NuGetUIThreadHelper.SetCustomJoinableTaskFactory(_jtf); }
public InfiniteScrollListTests() { #pragma warning disable VSSDK005 // Avoid instantiating JoinableTaskContext _joinableTaskContext = new JoinableTaskContext(Thread.CurrentThread, SynchronizationContext.Current); #pragma warning restore VSSDK005 // Avoid instantiating JoinableTaskContext NuGetUIThreadHelper.SetCustomJoinableTaskFactory(_joinableTaskContext.Factory); }
public NuGetLockServiceTests(DispatcherThreadFixture fixture) { Assumes.Present(fixture); _jtf = fixture.JoinableTaskFactory; _lockService = new NuGetLockService(fixture.JoinableTaskFactory.Context); NuGetUIThreadHelper.SetCustomJoinableTaskFactory(_jtf); Assert.False(_lockService.IsLockHeld); }
public NuGetUITests() { #pragma warning disable VSSDK005 // Avoid instantiating JoinableTaskContext _joinableTaskContext = new JoinableTaskContext(Thread.CurrentThread, SynchronizationContext.Current); #pragma warning restore VSSDK005 // Avoid instantiating JoinableTaskContext NuGetUIThreadHelper.SetCustomJoinableTaskFactory(_joinableTaskContext.Factory); _testDirectory = TestDirectory.Create(); }
public SolutionRestoreBuildHandlerTests(DispatcherThreadFixture fixture) { Assumes.Present(fixture); _jtf = fixture.JoinableTaskFactory; #pragma warning disable VSSDK005 // Avoid instantiating JoinableTaskContext var joinableTaskContext = new JoinableTaskContext(Thread.CurrentThread, SynchronizationContext.Current); #pragma warning restore VSSDK005 // Avoid instantiating JoinableTaskContext NuGetUIThreadHelper.SetCustomJoinableTaskFactory(_jtf); }
public NuGetProjectManagerServiceTests(DispatcherThreadFixture dispatcherThreadFixture) { Assert.NotNull(dispatcherThreadFixture); _projectContext = new TestNuGetProjectContext(); _services = new Dictionary <Type, Task <object> >() { { typeof(INuGetProjectContext), Task.FromResult <object>(_projectContext) } }; ServiceLocator.InitializePackageServiceProvider(this); NuGetUIThreadHelper.SetCustomJoinableTaskFactory(dispatcherThreadFixture.JoinableTaskFactory); }
public PackageItemListViewModelTests(DispatcherThreadFixture fixture, ITestOutputHelper output, LocalPackageSearchMetadataFixture testData) { _testData = testData; _testInstance = new PackageItemListViewModel() { PackageReader = _testData.TestData.PackageReader, }; _output = output; Assumes.Present(fixture); _jtf = fixture.JoinableTaskFactory; NuGetUIThreadHelper.SetCustomJoinableTaskFactory(_jtf); }
private void CreatePackageManagerControl() { _container = Initialize(); // This method is called from MainWindow's constructor. Current thread is the main thread var mainThread = Thread.CurrentThread; var synchronizationContext = SynchronizationContext.Current; NuGetUIThreadHelper.SetCustomJoinableTaskFactory(mainThread, synchronizationContext); Title = "NuGet Standalone UI"; Height = 800; Width = 1000; var repositoryProvider = new SourceRepositoryProvider(_settings, Repository.Provider.GetVisualStudio()); var settings = new DefaultSettings(); var testSolutionManager = new TestSolutionManager(@"c:\temp\test"); var projectA = testSolutionManager.AddNewMSBuildProject("projectA"); //var projectB = testSolutionManager.AddNewMSBuildProject("projectB"); //var projectC = testSolutionManager.AddProjectKProject("projectK"); var projectBuildIntegrated = testSolutionManager.AddBuildIntegratedProject("BuildIntProj", NuGetFramework.Parse("net46")); var projects = new[] { projectBuildIntegrated }; var packageRestoreManager = new PackageRestoreManager( repositoryProvider, settings, testSolutionManager); var contextFactory = new StandaloneUIContextFactory( repositoryProvider, testSolutionManager, settings, packageRestoreManager: packageRestoreManager, optionsPage: null); var context = contextFactory.Create(@"c:\temp\test\settings.txt", projects); var uiController = _uiServiceFactory.Create( context, new NuGetUIProjectContext(new StandaloneUILogger(_textBox, _scrollViewer), _sourceControlManagerProvider, _commonOperations)); var model = new PackageManagerModel(uiController, context, isSolution: false, editorFactoryGuid: Guid.Empty); model.SolutionName = "test solution"; _packageManagerControl = new PackageManagerControl(model, _settings, new SimpleSearchBoxFactory(), vsShell: null); layoutGrid.Children.Add(_packageManagerControl); }
public DetailControlModelTestBase(LocalPackageSearchMetadataFixture testData) { _testData = testData; var testVersion = new NuGetVersion(0, 0, 1); _testViewModel = new PackageItemListViewModel() { PackageReader = _testData.TestData.PackageReader, Version = testVersion, InstalledVersion = testVersion, }; #pragma warning disable VSSDK005 // Avoid instantiating JoinableTaskContext _joinableTaskContext = new JoinableTaskContext(Thread.CurrentThread, SynchronizationContext.Current); #pragma warning restore VSSDK005 // Avoid instantiating JoinableTaskContext NuGetUIThreadHelper.SetCustomJoinableTaskFactory(_joinableTaskContext.Factory); }
public V3DetailControlModelTestBase(V3PackageSearchMetadataFixture testData) { _testData = testData; // The versions pre-baked into the view model provide data for the first step of metadata extraction // which fails (null) in a V3 scenario--they need to be extracted using a metadata provider (below) var testVersion = new NuGetVersion(0, 0, 1); var testVersions = new List <VersionInfo>() { new VersionInfo(new NuGetVersion(0, 0, 1)), new VersionInfo(new NuGetVersion(0, 0, 2)) }; _testViewModel = new PackageItemListViewModel() { Version = testVersion, Versions = new Lazy <Task <IEnumerable <VersionInfo> > >(() => Task.FromResult <IEnumerable <VersionInfo> >(testVersions)), InstalledVersion = testVersion, }; var resourceProvider = new MockNuGetResourceProvider(); var metadataResource = new MockPackageMetadataResource(_testData.TestData); var repository = new MockSourceRepository <PackageMetadataResource>( new PackageSource("nuget.psm.test"), new List <INuGetResourceProvider>() { resourceProvider }, metadataResource); var repositories = new List <SourceRepository>() { repository }; _metadataProvider = new MultiSourcePackageMetadataProvider( repositories, optionalLocalRepository: null, optionalGlobalLocalRepositories: null, logger: new Mock <ILogger>().Object); #pragma warning disable VSSDK005 // Avoid instantiating JoinableTaskContext _joinableTaskContext = new JoinableTaskContext(Thread.CurrentThread, SynchronizationContext.Current); #pragma warning restore VSSDK005 // Avoid instantiating JoinableTaskContext NuGetUIThreadHelper.SetCustomJoinableTaskFactory(_joinableTaskContext.Factory); }
/// <summary> /// Tries to create an instance of <see cref="NuGetProject"/> by calling registered /// providers in predefined order. /// </summary> /// <param name="vsProjectAdapter">A project adapter.</param> /// <param name="context">Project context</param> /// <param name="result">New project instance when <code>true</code> is returned. /// Otherwise - <code>null</code>.</param> /// <returns><code>true</code> when new project instance has been successfully created.</returns> public async Task <NuGetProject> TryCreateNuGetProjectAsync( IVsProjectAdapter vsProjectAdapter, ProjectProviderContext context) { Assumes.Present(vsProjectAdapter); Assumes.Present(context); await _threadingService.JoinableTaskFactory.SwitchToMainThreadAsync(); if (vsProjectAdapter.VsHierarchy != null && VsHierarchyUtility.IsCPSCapabilityComplaint(vsProjectAdapter.VsHierarchy)) { // Lazy load the CPS enabled JoinableTaskFactory for the UI. NuGetUIThreadHelper.SetJoinableTaskFactoryFromService(ProjectServiceAccessor.Value as IProjectServiceAccessor); } var exceptions = new List <Exception>(); foreach (var provider in _providers) { try { var nuGetProject = await provider.TryCreateNuGetProjectAsync( vsProjectAdapter, context, forceProjectType : false); if (nuGetProject != null) { return(nuGetProject); } } catch (Exception e) { // Ignore failures. If this method returns null, the problem falls // into one of the other NuGet project types. exceptions.Add(e); } } exceptions.ForEach(e => _logger.LogError(e.ToString())); return(null); }
/// <summary> /// Creates an instance of <see cref="NuGetProject"/> of desired type. /// </summary> /// <typeparam name="TProject">Type of project to create.</typeparam> /// <param name="vsProjectAdapter">Project adapter</param> /// <param name="optionalContext">Optional context for project creation. Not all of providers require it.</param> /// <returns>Instance of <see cref="NuGetProject"/> or null if failed.</returns> /// <remarks>The factory will identify a provider corresponding to given project type and will attempt to force create the project of desired type.</remarks> public async Task <TProject> CreateNuGetProjectAsync <TProject>( IVsProjectAdapter vsProjectAdapter, ProjectProviderContext optionalContext = null) where TProject : NuGetProject { Assumes.Present(vsProjectAdapter); await _threadingService.JoinableTaskFactory.SwitchToMainThreadAsync(); var provider = _providers .FirstOrDefault(p => typeof(TProject).TypeHandle.Equals(p.ProjectType)); if (provider == null) { return(null); } if (vsProjectAdapter.VsHierarchy != null && VsHierarchyUtility.IsCPSCapabilityComplaint(vsProjectAdapter.VsHierarchy)) { // Lazy load the CPS enabled JoinableTaskFactory for the UI. NuGetUIThreadHelper.SetJoinableTaskFactoryFromService(ProjectServiceAccessor.Value as IProjectServiceAccessor); } try { var nuGetProject = await provider.TryCreateNuGetProjectAsync( vsProjectAdapter, optionalContext, forceProjectType : true); if (nuGetProject != null) { return(nuGetProject as TProject); } } catch (Exception e) { _logger.LogError(e.ToString()); } return(null); }
public UIActionEngineTests(GlobalServiceProvider sp) { sp.Reset(); NuGetUIThreadHelper.SetCustomJoinableTaskFactory(ThreadHelper.JoinableTaskFactory); }
public NuGetFeatureFlagServiceTests(GlobalServiceProvider sp) { sp.Reset(); _globalProvider = sp; NuGetUIThreadHelper.SetCustomJoinableTaskFactory(ThreadHelper.JoinableTaskFactory); }
public bool TryCreateNuGetProject( IVsProjectAdapter vsProject, ProjectProviderContext context, bool forceProjectType, out NuGetProject result) { Assumes.Present(vsProject); Assumes.Present(context); ThreadHelper.ThrowIfNotOnUIThread(); result = null; // The project must be an IVsHierarchy. var hierarchy = vsProject.VsHierarchy; if (hierarchy == null) { return(false); } // Check if the project is not CPS capable or if it is CPS capable then it does not have TargetFramework(s), if so then return false if (!hierarchy.IsCapabilityMatch("CPS")) { return(false); } var buildProperties = vsProject.BuildProperties; // read MSBuild property RestoreProjectStyle, TargetFramework, and TargetFrameworks var restoreProjectStyle = buildProperties.GetPropertyValue(ProjectBuildProperties.RestoreProjectStyle); var targetFramework = buildProperties.GetPropertyValue(ProjectBuildProperties.TargetFramework); var targetFrameworks = buildProperties.GetPropertyValue(ProjectBuildProperties.TargetFrameworks); // check for RestoreProjectStyle property is set and if not set to PackageReference then return false if (!(string.IsNullOrEmpty(restoreProjectStyle) || restoreProjectStyle.Equals(PackageReference, StringComparison.OrdinalIgnoreCase))) { return(false); } // check whether TargetFramework or TargetFrameworks property is set, else return false else if (string.IsNullOrEmpty(targetFramework) && string.IsNullOrEmpty(targetFrameworks)) { return(false); } // Lazy load the CPS enabled JoinableTaskFactory for the UI. NuGetUIThreadHelper.SetJoinableTaskFactoryFromService(ProjectServiceAccessor.Value as IProjectServiceAccessor); var projectNames = vsProject.ProjectNames; var fullProjectPath = vsProject.FullProjectPath; var unconfiguredProject = GetUnconfiguredProject(vsProject.Project); var projectServices = new NetCoreProjectSystemServices(vsProject, _componentModel.Value); result = new NetCorePackageReferenceProject( vsProject.ProjectName, vsProject.CustomUniqueName, fullProjectPath, _projectSystemCache, vsProject, unconfiguredProject, projectServices, vsProject.ProjectId); return(true); }
public InfiniteScrollListTests() { var joinableTaskContext = new JoinableTaskContext(Thread.CurrentThread, SynchronizationContext.Current); NuGetUIThreadHelper.SetCustomJoinableTaskFactory(joinableTaskContext.Factory); }
public bool TryCreateNuGetProject(EnvDTE.Project dteProject, ProjectSystemProviderContext context, out NuGetProject result) { if (dteProject == null) { throw new ArgumentNullException(nameof(dteProject)); } if (context == null) { throw new ArgumentNullException(nameof(context)); } ThreadHelper.ThrowIfNotOnUIThread(); result = null; // The project must be an IVsHierarchy. var hierarchy = VsHierarchyUtility.ToVsHierarchy(dteProject); if (hierarchy == null) { return(false); } // Check if the project is not CPS capable or if it is CPS capable then it does not have TargetFramework(s), if so then return false if (!hierarchy.IsCapabilityMatch("CPS")) { return(false); } var buildPropertyStorage = hierarchy as IVsBuildPropertyStorage; // read MSBuild property RestoreProjectStyle, TargetFramework, and TargetFrameworks var restoreProjectStyle = VsHierarchyUtility.GetMSBuildProperty(buildPropertyStorage, RestoreProjectStyle); var targetFramework = VsHierarchyUtility.GetMSBuildProperty(buildPropertyStorage, TargetFramework); var targetFrameworks = VsHierarchyUtility.GetMSBuildProperty(buildPropertyStorage, TargetFrameworks); // check for RestoreProjectStyle property is set and if not set to PackageReference then return false if (!(string.IsNullOrEmpty(restoreProjectStyle) || restoreProjectStyle.Equals(ProjectStyle.PackageReference.ToString(), StringComparison.OrdinalIgnoreCase))) { return(false); } // check whether TargetFramework or TargetFrameworks property is set, else return false else if (string.IsNullOrEmpty(targetFramework) && string.IsNullOrEmpty(targetFrameworks)) { return(false); } // Lazy load the CPS enabled JoinableTaskFactory for the UI. NuGetUIThreadHelper.SetJoinableTaskFactoryFromService(ProjectServiceAccessor.Value as IProjectServiceAccessor); var projectNames = ProjectNames.FromDTEProject(dteProject); var fullProjectPath = EnvDTEProjectInfoUtility.GetFullProjectPath(dteProject); var unconfiguredProject = GetUnconfiguredProject(dteProject); result = new CpsPackageReferenceProject( dteProject.Name, EnvDTEProjectInfoUtility.GetCustomUniqueName(dteProject), fullProjectPath, _projectSystemCache, dteProject, unconfiguredProject, VsHierarchyUtility.GetProjectId(dteProject)); return(true); }