private static ISimpleClient BuildClient() { ServiceCollection services = new ServiceCollection(); IClientBuilder builder = services.AddBackBlazeB2(); //This is a commercial feature builder.CoreBuilder.UsePooledClients(); //This is a commercial feature builder.CoreBuilder.UseProfileManager() .BindConfigToDefaultProfile() .UseConsoleSetup() .UseDataProtection(); //This is a commercial feature IServiceProvider serviceProvider = services.BuildServiceProvider(); IProfileManager profileManager = serviceProvider.GetRequiredService <IProfileManager>(); IProfile? profile = profileManager.GetDefaultProfile(); if (profile == null) { IProfileSetup setup = serviceProvider.GetRequiredService <IProfileSetup>(); setup.SetupDefaultProfile(); } return(serviceProvider.GetRequiredService <ISimpleClient>()); }
private static ISimpleClient BuildClient(IWebProxy?proxy = null) { //Create the dependency injection container ServiceCollection services = new ServiceCollection(); //We use Microsoft.Extensions.Logging to log to the console services.AddLogging(x => x.AddConsole()); //Here we create a core client. It has no network driver at this point. ICoreBuilder coreBuilder = SimpleS3CoreServices.AddSimpleS3Core(services); //We want to use HttpClientFactory as the HTTP driver IHttpClientBuilder httpBuilder = coreBuilder.UseHttpClientFactory(); //Add a default timeout and retry policy httpBuilder.UseDefaultHttpPolicy(); //If you set a proxy, this is where it gets added if (proxy != null) { httpBuilder.UseProxy(proxy); } //This adds the S3Client service. This service combines ObjectClient, MultipartClient and BucketClient into a single client. Makes it easier for new people to use the library. coreBuilder.UseAmazonS3(); //Here we add the profile manager. It is a profile system that persist your credentials to disk in a very secure way. coreBuilder.UseProfileManager() .BindConfigToDefaultProfile() //We can either name the profile (so you can have more than one) or use the default one. .UseConsoleSetup(); //This adds a service that ask you to setup your profile if it does not exist. //Finally we build the service provider and return the S3Client IServiceProvider serviceProvider = services.BuildServiceProvider(); IProfileManager profileManager = serviceProvider.GetRequiredService <IProfileManager>(); IProfile? profile = profileManager.GetDefaultProfile(); if (profile == null) { IProfileSetup setup = serviceProvider.GetRequiredService <IProfileSetup>(); setup.SetupDefaultProfile(); } return(serviceProvider.GetRequiredService <ISimpleClient>()); }
public static IProfile SetupDefaultProfile(this IProfileSetup setup, bool persist = true) { return(setup.SetupProfile(ProfileManager.DefaultProfile, persist)); }