internal VSSolutionManager( IAsyncServiceProvider asyncServiceProvider, IProjectSystemCache projectSystemCache, NuGetProjectFactory projectSystemFactory, ICredentialServiceProvider credentialServiceProvider, IVsProjectAdapterProvider vsProjectAdapterProvider, ILogger logger, Lazy <ISettings> settings, INuGetFeatureFlagService featureFlagService, JoinableTaskContext joinableTaskContext) { Assumes.Present(asyncServiceProvider); Assumes.Present(projectSystemCache); Assumes.Present(projectSystemFactory); Assumes.Present(credentialServiceProvider); Assumes.Present(vsProjectAdapterProvider); Assumes.Present(logger); Assumes.Present(settings); Assumes.Present(featureFlagService); Assumes.Present(joinableTaskContext); _asyncServiceProvider = asyncServiceProvider; _projectSystemCache = projectSystemCache; _projectSystemFactory = projectSystemFactory; _credentialServiceProvider = credentialServiceProvider; _vsProjectAdapterProvider = vsProjectAdapterProvider; _logger = logger; _settings = settings; _featureFlagService = featureFlagService; _initLock = new NuGetLockService(joinableTaskContext); _dte = new(() => asyncServiceProvider.GetDTEAsync(), NuGetUIThreadHelper.JoinableTaskFactory); _asyncVSSolution = new(() => asyncServiceProvider.GetServiceAsync <SVsSolution, IVsSolution>(), NuGetUIThreadHelper.JoinableTaskFactory); }
public async Task <NuGet.Configuration.ICredentialService> GetCredentialServiceAsync() { // Initialize the credential providers. var credentialProviders = new List <ICredentialProvider>(); var dte = await _asyncServiceProvider.GetDTEAsync(); var webProxy = await _asyncServiceProvider.GetServiceAsync <SVsWebProxy, IVsWebProxy>(); TryAddCredentialProviders( credentialProviders, Strings.CredentialProviderFailed_VisualStudioAccountProvider, () => { var importer = new VsCredentialProviderImporter( dte, VisualStudioAccountProvider.FactoryMethod, (exception, failureMessage) => LogCredentialProviderError(exception, failureMessage)); return(importer.GetProviders()); }); TryAddCredentialProviders( credentialProviders, Strings.CredentialProviderFailed_VisualStudioCredentialProvider, () => { Debug.Assert(webProxy != null); return(new ICredentialProvider[] { new VisualStudioCredentialProvider(webProxy) }); }); await TryAddCredentialProvidersAsync( credentialProviders, Strings.CredentialProviderFailed_PluginCredentialProvider, async() => await(new SecurePluginCredentialProviderBuilder(PluginManager.Instance, canShowDialog: true, logger: NullLogger.Instance).BuildAllAsync()) ); if (PreviewFeatureSettings.DefaultCredentialsAfterCredentialProviders) { TryAddCredentialProviders( credentialProviders, Strings.CredentialProviderFailed_DefaultCredentialsCredentialProvider, () => { return(new ICredentialProvider[] { new DefaultCredentialsCredentialProvider() }); }); } // Initialize the credential service. var credentialService = new CredentialService(new AsyncLazy <IEnumerable <ICredentialProvider> >(() => System.Threading.Tasks.Task.FromResult((IEnumerable <ICredentialProvider>)credentialProviders)), nonInteractive: false, handlesDefaultCredentials: PreviewFeatureSettings.DefaultCredentialsAfterCredentialProviders); return(credentialService); }
private async Task InitializeAsync() { await NuGetUIThreadHelper.JoinableTaskFactory.SwitchToMainThreadAsync(); _vsSolution = await _asyncServiceProvider.GetServiceAsync <SVsSolution, IVsSolution>(); var dte = await _asyncServiceProvider.GetDTEAsync(); UserAgent.SetUserAgentString( new UserAgentStringBuilder(VSNuGetClientName).WithVisualStudioSKU(dte.GetFullVsVersionString())); HttpHandlerResourceV3.CredentialService = new Lazy <ICredentialService>(() => { return(NuGetUIThreadHelper.JoinableTaskFactory.Run(async() => { return await _credentialServiceProvider.GetCredentialServiceAsync(); })); }); TelemetryActivity.NuGetTelemetryService = new NuGetVSTelemetryService(); _vsMonitorSelection = await _asyncServiceProvider.GetServiceAsync <SVsShellMonitorSelection, IVsMonitorSelection>(); var solutionLoadedGuid = VSConstants.UICONTEXT.SolutionExistsAndFullyLoaded_guid; _vsMonitorSelection.GetCmdUIContextCookie(ref solutionLoadedGuid, out _solutionLoadedUICookie); uint cookie; var hr = _vsMonitorSelection.AdviseSelectionEvents(this, out cookie); ErrorHandler.ThrowOnFailure(hr); // Keep a reference to SolutionEvents so that it doesn't get GC'ed. Otherwise, we won't receive events. _solutionEvents = dte.Events.SolutionEvents; _solutionEvents.BeforeClosing += OnBeforeClosing; _solutionEvents.AfterClosing += OnAfterClosing; _solutionEvents.ProjectAdded += OnEnvDTEProjectAdded; _solutionEvents.ProjectRemoved += OnEnvDTEProjectRemoved; _solutionEvents.ProjectRenamed += OnEnvDTEProjectRenamed; var vSStd97CmdIDGUID = VSConstants.GUID_VSStandardCommandSet97.ToString("B"); var solutionSaveID = (int)VSConstants.VSStd97CmdID.SaveSolution; var solutionSaveAsID = (int)VSConstants.VSStd97CmdID.SaveSolutionAs; _solutionSaveEvent = dte.Events.CommandEvents[vSStd97CmdIDGUID, solutionSaveID]; _solutionSaveAsEvent = dte.Events.CommandEvents[vSStd97CmdIDGUID, solutionSaveAsID]; _solutionSaveEvent.BeforeExecute += SolutionSaveAs_BeforeExecute; _solutionSaveEvent.AfterExecute += SolutionSaveAs_AfterExecute; _solutionSaveAsEvent.BeforeExecute += SolutionSaveAs_BeforeExecute; _solutionSaveAsEvent.AfterExecute += SolutionSaveAs_AfterExecute; _projectSystemCache.CacheUpdated += NuGetCacheUpdate_After; }
public async Task <NuGet.Configuration.ICredentialService> GetCredentialServiceAsync() { // Initialize the credential providers. var credentialProviders = new List <ICredentialProvider>(); var dte = await _asyncServiceProvider.GetDTEAsync(); var webProxy = (IVsWebProxy)await _asyncServiceProvider.GetServiceAsync(typeof(SVsWebProxy)); TryAddCredentialProviders( credentialProviders, Strings.CredentialProviderFailed_VisualStudioAccountProvider, () => { var importer = new VsCredentialProviderImporter( dte, VisualStudioAccountProvider.FactoryMethod, (exception, failureMessage) => LogCredentialProviderError(exception, failureMessage)); return(importer.GetProviders()); }); TryAddCredentialProviders( credentialProviders, Strings.CredentialProviderFailed_VisualStudioCredentialProvider, () => { Debug.Assert(webProxy != null); return(new ICredentialProvider[] { new VisualStudioCredentialProvider(webProxy) }); }); if (PreviewFeatureSettings.DefaultCredentialsAfterCredentialProviders) { TryAddCredentialProviders( credentialProviders, Strings.CredentialProviderFailed_DefaultCredentialsCredentialProvider, () => { return(new ICredentialProvider[] { new DefaultCredentialsCredentialProvider() }); }); } // Initialize the credential service. var credentialService = new CredentialService(credentialProviders, nonInteractive: false); return(credentialService); }