public static void Load(this SampleConfiguration configuration, IDictionary <string, string> settings = null) { var configPath = new LocalFileManager().GetJsonPath <SampleConfiguration>(); if (!configPath.Exists && settings == null) { throw new InvalidOperationException($"Either add {configPath.FullName} or pass a Dictionary<string, string> with Account, Project and AuthToken set."); } if (configPath.Exists) { var target = Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), "configuration.json"); configPath.CopyTo(target, true); } new ConfigurationBuilder() .AddJsonFile("configuration.json", true) .AddInMemoryCollection(settings) .Build() .Bind(configuration); }
public static IServiceCollection AddSampleForgeServices(this IServiceCollection serviceCollection, SampleConfiguration configuration = null) { serviceCollection.AddSingleton <ILocalFileManager, LocalFileManager>(); if (configuration == null) { serviceCollection.AddSingleton(new SampleConfiguration()); } else { serviceCollection.AddSingleton(configuration); } serviceCollection.AddSingleton <IForgeDataClient, ForgeDataClient>(); serviceCollection.AddSingleton <IForgeDerivativeClient, ForgeDerivativeClient>(); serviceCollection.AddSingleton <IForgeIssueClient, ForgeIssueClient>(); serviceCollection.AddTransient <SampleConfigurationDelegatingHandler>(); serviceCollection.AddHttpClient <IIndexClient, IndexClient>((provider, options) => options.BaseAddress = provider.GetRequiredService <SampleConfiguration>().ModelSetIndexApiBasePath) .AddSampleConfigurationDelegatingHandler(); serviceCollection.AddHttpClient <IModelSetClient, ModelSetClient>((provider, options) => options.BaseAddress = provider.GetRequiredService <SampleConfiguration>().ModelSetApiBasePath) .AddSampleConfigurationDelegatingHandler(); serviceCollection.AddHttpClient <IClashClient, ClashClient>((provider, options) => options.BaseAddress = provider.GetRequiredService <SampleConfiguration>().ModelSetClashApiBasePath) .AddSampleConfigurationDelegatingHandler(); serviceCollection.AddSingleton <ITokenManager, TokenManager>(); serviceCollection.AddSingleton <IIndexFieldCache, IndexFieldCache>(); serviceCollection.AddSingleton <IModelSetIndex, ModelSetIndex>(); return(serviceCollection); }
public static Uri ModelDerivativePath(this SampleConfiguration config, string path) => new Uri(config.ModelDerivativeBasePath, path);
public static Uri IssueManagementPath(this SampleConfiguration config, string path) => new Uri(config.IssueManagementBasePath, path);
protected ForgeClientBase(SampleConfiguration configuraiton) => Configuration = configuraiton;