public override Task <int> ExecuteAsync(CommandContext context, AddCommandSettings settings) { _settings.Subscriptions.Add(new AppSettings.Subscription() { Name = settings.Name, Endpoint = settings.Endpoint, Client = new AppSettings.Client() { Id = settings.ClientId, Secret = settings.ClientSecret } }); var directory = SettingsPathFactory.Path(); if (!Directory.Exists(directory)) { Directory.CreateDirectory(directory); } using (var file = File.CreateText(Path.Combine(directory, "appsettings.json"))) { var serializer = new JsonSerializer(); serializer.Serialize(file, _settings); } Console.WriteLine($"Configuration successfully added to subscription \"{settings.Name}\"."); return(Task.FromResult((int)StatusCodes.Success)); }
public override Task <int> ExecuteAsync(CommandContext context, RemoveCommandSettings settings) { var subscription = _settings.GetSubscription(settings.Name); _settings.Subscriptions.Remove(subscription); var directory = SettingsPathFactory.Path(); using (var file = File.CreateText(Path.Combine(directory, "appsettings.json"))) { var serializer = new JsonSerializer(); serializer.Serialize(file, _settings); } Console.WriteLine($"Subscription \"{settings.Name}\" configuration removed successfully."); return(Task.FromResult((int)StatusCodes.Success)); }
private static IConfigurationRoot CreateConfigurationRoot() => new ConfigurationBuilder() .SetBasePath(AppContext.BaseDirectory) .AddJsonFile(Path.Combine(SettingsPathFactory.Path(), "appsettings.json"), true) .Build();