/// <summary> /// Gets the github repo browser internally. Tries to pull the authentication service from memory since that should be a one-time thing. /// The transformation service should be separate in case there are multiple requests from the service and messages in flight. We don't want /// the result array being shared across requests. /// </summary> /// <returns>The github repo browser.</returns> /// <param name="org">Org.</param> /// <param name="config">Config.</param> /// <param name="memoryCache">Memory cache.</param> internal static IRepoBrowser GetGithubRepoBrowser(Organization org, RepoBrowserConfiguration config, IMemoryCache memoryCache) { // Authentication can be re-used string hashKey = ComputeHash(config.AuthType); // First check our cache for the value if (memoryCache != null && memoryCache.TryGetValue(hashKey, out IAuthenticationService authService)) { } else { authService = CreateObjectOfType <IAuthenticationService>(config.AuthType, config.AuthSettings); if (memoryCache != null) { memoryCache.Set(hashKey, authService); } } ITransformationService transformService = CreateObjectOfType <ITransformationService>(config.TransformType); HttpMessageHandler messageHandler = null; if (!string.IsNullOrEmpty(config.HttpMessageHandlerType)) { messageHandler = CreateObjectOfType <HttpMessageHandler>(config.HttpMessageHandlerType); } else { messageHandler = new HttpClientHandler(); } return(new GithubRepoBrowser(authService, transformService, messageHandler)); }
/// <summary> /// Creates the repo browsing interface. /// </summary> /// <returns>The search repository.</returns> /// <param name="organization">Organization.</param> /// <param name="config">Config.</param> public static IRepoBrowser CreateRepoBrowser(Organization organization, List <RepoBrowserConfiguration> config, IMemoryCache memoryCache) { if (organization.Repository == null) { throw new NullReferenceException("Organization must be configured with a repository."); } switch (organization.Repository.Type) { case RepositoryType.Github: RepoBrowserConfiguration finalConfig = config.FindLast((obj) => obj.TypeName == RepositoryType.Github); // Get the last instance of the Github repo definitions return(GetGithubRepoBrowser(organization, finalConfig, memoryCache)); default: throw new NotSupportedException("Repository type not currently supported: " + organization.Repository); } }