Esempio n. 1
0
        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));
        }
Esempio n. 2
0
        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));
        }
Esempio n. 3
0
 private static IConfigurationRoot CreateConfigurationRoot()
 => new ConfigurationBuilder()
 .SetBasePath(AppContext.BaseDirectory)
 .AddJsonFile(Path.Combine(SettingsPathFactory.Path(), "appsettings.json"), true)
 .Build();