async Task <object> CreateService(IAsyncServiceContainer container, CancellationToken cancellationToken, Type serviceType) { if (serviceType == null) { return(null); } if (serviceType == typeof(IUIProvider)) { var result = new GitHubServiceProvider(this); await result.Initialize(); return(result); } else if (serviceType == typeof(IMenuProvider)) { var sp = await GetServiceAsync(typeof(IUIProvider)) as IUIProvider; return(new MenuProvider(sp)); } else if (serviceType == typeof(IUsageTracker)) { var uiProvider = await GetServiceAsync(typeof(IUIProvider)) as IUIProvider; return(new UsageTracker(uiProvider)); } // go the mef route else { var sp = await GetServiceAsync(typeof(IUIProvider)) as IUIProvider; return(sp.TryGetService(serviceType)); } }
async Task <object> CreateService(IAsyncServiceContainer container, CancellationToken cancellationToken, Type serviceType) { if (serviceType == null) { return(null); } if (container != this) { return(null); } if (serviceType == typeof(IGitHubServiceProvider)) { //var sp = await GetServiceAsync(typeof(SVsServiceProvider)) as IServiceProvider; var result = new GitHubServiceProvider(this, this); await result.Initialize(); return(result); } else if (serviceType == typeof(ILoginManager)) { // These services are got through MEF and we will take a performance hit if ILoginManager is requested during // InitializeAsync. TODO: We can probably make LoginManager a normal MEF component rather than a service. var serviceProvider = await GetServiceAsync(typeof(IGitHubServiceProvider)) as IGitHubServiceProvider; var keychain = serviceProvider.GetService <IKeychain>(); var oauthListener = serviceProvider.GetService <IOAuthCallbackListener>(); // HACK: We need to make sure this is run on the main thread. We really // shouldn't be injecting a view model concern into LoginManager - this // needs to be refactored. See #1398. var lazy2Fa = new Lazy <ITwoFactorChallengeHandler>(() => ThreadHelper.JoinableTaskFactory.Run(async() => { await ThreadHelper.JoinableTaskFactory.SwitchToMainThreadAsync(); return(serviceProvider.GetService <ITwoFactorChallengeHandler>()); })); return(new LoginManager( keychain, lazy2Fa, oauthListener, ApiClientConfiguration.ClientId, ApiClientConfiguration.ClientSecret, ApiClientConfiguration.RequiredScopes, ApiClientConfiguration.AuthorizationNote, ApiClientConfiguration.MachineFingerprint)); } else if (serviceType == typeof(IMenuProvider)) { var sp = await GetServiceAsync(typeof(IGitHubServiceProvider)) as IGitHubServiceProvider; return(new MenuProvider(sp)); } else if (serviceType == typeof(IUsageService)) { var sp = await GetServiceAsync(typeof(IGitHubServiceProvider)) as IGitHubServiceProvider; var environment = new Rothko.Environment(); return(new UsageService(sp, environment)); } else if (serviceType == typeof(IUsageTracker)) { await ThreadHelper.JoinableTaskFactory.SwitchToMainThreadAsync(); var usageService = await GetServiceAsync(typeof(IUsageService)) as IUsageService; var serviceProvider = await GetServiceAsync(typeof(IGitHubServiceProvider)) as IGitHubServiceProvider; return(new UsageTracker(serviceProvider, usageService)); } else if (serviceType == typeof(IVSGitExt)) { var vsVersion = ApplicationInfo.GetHostVersionInfo().FileMajorPart; return(VSGitExtFactory.Create(vsVersion, this)); } else if (serviceType == typeof(IGitHubToolWindowManager)) { return(this); } // go the mef route else { var sp = await GetServiceAsync(typeof(IGitHubServiceProvider)) as IGitHubServiceProvider; return(sp.TryGetService(serviceType)); } }
async Task <object> CreateService(IAsyncServiceContainer container, CancellationToken cancellationToken, Type serviceType) { if (serviceType == null) { return(null); } if (container != this) { return(null); } if (serviceType == typeof(IGitHubServiceProvider)) { //var sp = await GetServiceAsync(typeof(SVsServiceProvider)) as IServiceProvider; var result = new GitHubServiceProvider(this, this); await result.Initialize(); return(result); } else if (serviceType == typeof(ILoginManager)) { var serviceProvider = await GetServiceAsync(typeof(IGitHubServiceProvider)) as IGitHubServiceProvider; var loginCache = serviceProvider.GetService <ILoginCache>(); var twoFaHandler = serviceProvider.GetService <ITwoFactorChallengeHandler>(); return(new LoginManager( loginCache, twoFaHandler, ApiClientConfiguration.ClientId, ApiClientConfiguration.ClientSecret, ApiClientConfiguration.AuthorizationNote, ApiClientConfiguration.MachineFingerprint)); } else if (serviceType == typeof(IMenuProvider)) { var sp = await GetServiceAsync(typeof(IGitHubServiceProvider)) as IGitHubServiceProvider; return(new MenuProvider(sp)); } else if (serviceType == typeof(IUsageTracker)) { await ThreadHelper.JoinableTaskFactory.SwitchToMainThreadAsync(); var serviceProvider = await GetServiceAsync(typeof(IGitHubServiceProvider)) as IGitHubServiceProvider; var usageService = serviceProvider.GetService <IUsageService>(); return(new UsageTracker(serviceProvider, usageService)); } else if (serviceType == typeof(IUIProvider)) { var sp = await GetServiceAsync(typeof(IGitHubServiceProvider)) as IGitHubServiceProvider; return(new UIProvider(sp)); } else if (serviceType == typeof(IGitHubToolWindowManager)) { return(this); } // go the mef route else { var sp = await GetServiceAsync(typeof(IGitHubServiceProvider)) as IGitHubServiceProvider; return(sp.TryGetService(serviceType)); } }
async Task <object> CreateService(IAsyncServiceContainer container, CancellationToken cancellationToken, Type serviceType) { if (serviceType == null) { return(null); } if (container != this) { return(null); } if (serviceType == typeof(IGitHubServiceProvider)) { //var sp = await GetServiceAsync(typeof(SVsServiceProvider)) as IServiceProvider; var result = new GitHubServiceProvider(this, this); await result.Initialize(); return(result); } else if (serviceType == typeof(ILoginManager)) { // These services are got through MEF and we will take a performance hit if ILoginManager is requested during // InitializeAsync. TODO: We can probably make LoginManager a normal MEF component rather than a service. var serviceProvider = await GetServiceAsync(typeof(IGitHubServiceProvider)) as IGitHubServiceProvider; Assumes.Present(serviceProvider); var keychain = serviceProvider.GetService <IKeychain>(); var oauthListener = serviceProvider.GetService <IOAuthCallbackListener>(); // HACK: We need to make sure this is run on the main thread. We really // shouldn't be injecting a view model concern into LoginManager - this // needs to be refactored. See #1398. #pragma warning disable VSTHRD011 // Use AsyncLazy<T> var lazy2Fa = new Lazy <ITwoFactorChallengeHandler>(() => JoinableTaskFactory.Run(async() => { await JoinableTaskFactory.SwitchToMainThreadAsync(); return(serviceProvider.GetService <ITwoFactorChallengeHandler>()); })); #pragma warning restore VSTHRD011 // Use AsyncLazy<T> return(new LoginManager( keychain, lazy2Fa, oauthListener, ApiClientConfiguration.ClientId, ApiClientConfiguration.ClientSecret, ApiClientConfiguration.MinimumScopes, ApiClientConfiguration.RequestedScopes, ApiClientConfiguration.AuthorizationNote, ApiClientConfiguration.MachineFingerprint)); } else if (serviceType == typeof(IUsageService)) { var sp = await GetServiceAsync(typeof(IGitHubServiceProvider)) as IGitHubServiceProvider; Assumes.Present(sp); var environment = new Rothko.Environment(); return(new UsageService(sp, environment, ThreadHelper.JoinableTaskContext)); } else if (serviceType == typeof(IUsageTracker)) { var usageService = await GetServiceAsync(typeof(IUsageService)) as IUsageService; var serviceProvider = await GetServiceAsync(typeof(IGitHubServiceProvider)) as IGitHubServiceProvider; var settings = await GetServiceAsync(typeof(IPackageSettings)) as IPackageSettings; Assumes.Present(usageService); Assumes.Present(serviceProvider); Assumes.Present(settings); // Only use Visual Studio Telemetry on VS 2017 and above await JoinableTaskFactory.SwitchToMainThreadAsync(cancellationToken); var dte = await GetServiceAsync(typeof(EnvDTE.DTE)) as EnvDTE.DTE; Assumes.Present(dte); var vsTelemetry = new Version(dte.Version) >= new Version(15, 0); return(new UsageTracker(serviceProvider, usageService, settings, ThreadHelper.JoinableTaskContext, vsTelemetry)); } else if (serviceType == typeof(IVSGitExt)) { var vsVersion = ApplicationInfo.GetHostVersionInfo().FileMajorPart; return(new VSGitExtFactory(vsVersion, this, GitService.GitServiceHelper, ThreadHelper.JoinableTaskContext).Create()); } else if (serviceType == typeof(IGitHubToolWindowManager)) { return(this); } else if (serviceType == typeof(IPackageSettings)) { await JoinableTaskFactory.SwitchToMainThreadAsync(); var sp = new ServiceProvider(Services.Dte as Microsoft.VisualStudio.OLE.Interop.IServiceProvider); return(new PackageSettings(sp)); } else if (serviceType == typeof(ITippingService)) { return(new TippingService(this)); } // go the mef route else { var sp = await GetServiceAsync(typeof(IGitHubServiceProvider)) as IGitHubServiceProvider; Assumes.Present(sp); return(sp.TryGetService(serviceType)); } }
async Task <object> CreateService(IAsyncServiceContainer container, CancellationToken cancellationToken, Type serviceType) { if (serviceType == null) { return(null); } if (container != this) { return(null); } if (serviceType == typeof(IGitHubServiceProvider)) { //var sp = await GetServiceAsync(typeof(SVsServiceProvider)) as IServiceProvider; var result = new GitHubServiceProvider(this, this); await result.Initialize(); return(result); } else if (serviceType == typeof(ILoginManager)) { var serviceProvider = await GetServiceAsync(typeof(IGitHubServiceProvider)) as IGitHubServiceProvider; var keychain = serviceProvider.GetService <IKeychain>(); // HACK: We need to make sure this is run on the main thread. We really // shouldn't be injecting a view model concern into LoginManager - this // needs to be refactored. See #1398. var lazy2Fa = new Lazy <ITwoFactorChallengeHandler>(() => ThreadHelper.JoinableTaskFactory.Run(async() => { await ThreadHelper.JoinableTaskFactory.SwitchToMainThreadAsync(); return(serviceProvider.GetService <ITwoFactorChallengeHandler>()); })); return(new LoginManager( keychain, lazy2Fa, ApiClientConfiguration.ClientId, ApiClientConfiguration.ClientSecret, ApiClientConfiguration.AuthorizationNote, ApiClientConfiguration.MachineFingerprint)); } else if (serviceType == typeof(IMenuProvider)) { var sp = await GetServiceAsync(typeof(IGitHubServiceProvider)) as IGitHubServiceProvider; return(new MenuProvider(sp)); } else if (serviceType == typeof(IUsageTracker)) { await ThreadHelper.JoinableTaskFactory.SwitchToMainThreadAsync(); var serviceProvider = await GetServiceAsync(typeof(IGitHubServiceProvider)) as IGitHubServiceProvider; var usageService = serviceProvider.GetService <IUsageService>(); return(new UsageTracker(serviceProvider, usageService)); } else if (serviceType == typeof(IGitHubToolWindowManager)) { return(this); } // go the mef route else { var sp = await GetServiceAsync(typeof(IGitHubServiceProvider)) as IGitHubServiceProvider; return(sp.TryGetService(serviceType)); } }