Ejemplo n.º 1
0
        public override string Execute()
        {
            _engineConfig.Load().Wait();

            if (RemoveAll)
            {
                var configKeys     = _engineConfig.Configs.Keys.ToList();
                var removedConfigs = new List <string>();
                foreach (var key in configKeys)
                {
                    _engineConfig.RemoveValue(key);
                    removedConfigs.Add(key);
                }

                _engineConfig.Save().Wait();

                Logger.LogInformation($"Config values have been removed: {JsonConvert.SerializeObject(removedConfigs)}");

                return("Config values have been removed successfully.");
            }

            if (string.IsNullOrEmpty(ConfigName))
            {
                return("");
            }

            _engineConfig.RemoveValue(ConfigName);
            _engineConfig.Save().Wait();

            var message = $"Config \"{ConfigName}\" has been removed.";

            Logger.LogInformation(message);

            return(message);
        }
Ejemplo n.º 2
0
        public override string Execute()
        {
            if (!File.Exists(InputFile))
            {
                return($"File \"{InputFile}\" could not be found.");
            }

            _engineConfig.Load().Wait();

            var obj     = JObject.Parse(File.ReadAllText(InputFile));
            var configs = obj.ToObject <Dictionary <string, string> >();

            var addedConfigs    = new Dictionary <string, string>();
            var modifiedConfigs = new Dictionary <string, string>();

            foreach (var key in configs.Keys)
            {
                if (_engineConfig.Configs.ContainsKey(key))
                {
                    modifiedConfigs.Add(key, configs[key]);
                }
                else
                {
                    addedConfigs.Add(key, configs[key]);
                }

                _engineConfig.SetValue(key, configs[key]);
            }

            _engineConfig.Save().Wait();

            Logger.LogInformation($"Modified configs: {JsonConvert.SerializeObject(modifiedConfigs)}. Added configs: {JsonConvert.SerializeObject(addedConfigs)}");

            var sb = new StringBuilder("Configs have been imported.");

            if (modifiedConfigs.Any())
            {
                sb.AppendLine("- Modified:");
                foreach (var key in modifiedConfigs.Keys)
                {
                    sb.AppendLine($"  - {key}: {modifiedConfigs[key]}");
                }
            }

            if (addedConfigs.Any())
            {
                sb.AppendLine("- Added:");
                foreach (var key in addedConfigs.Keys)
                {
                    sb.AppendLine($"  - {key}: {addedConfigs[key]}");
                }
            }

            return(sb.ToString());
        }
Ejemplo n.º 3
0
        public override string Execute()
        {
            var message = "";

            _engineConfig.Load().Wait();

            if (!string.IsNullOrEmpty(ConfigName) && !string.IsNullOrEmpty(ConfigValue))
            {
                _engineConfig.SetValue(ConfigName, ConfigValue);
                _engineConfig.Save().Wait();

                var logMessage = $"The value of \"{ConfigName}\" has been set";
                message = $"{logMessage} to \"{ConfigValue}\".";

                if (ConfigName != CatapultEngineConfig.AuthorizationTokenKey)
                {
                    logMessage = message;
                }

                Logger.LogInformation(logMessage);
            }
            else if (!string.IsNullOrEmpty(ConfigName) || !string.IsNullOrEmpty(ConfigValue))
            {
                return(message);
            }
            else
            {
                Console.WriteLine("Please enter the value for each config item below, or press ENTER if no changes needed:");

                var configKeys      = _engineConfig.Configs.Keys.ToList();
                var modifiedConfigs = new Dictionary <string, string>();
                foreach (var key in configKeys)
                {
                    var isValueNeeded = true;
                    while (isValueNeeded)
                    {
                        System.Console.SetIn(new StreamReader(System.Console.OpenStandardInput(8192)));
                        var value = Console.GetString($"- {key} ({_engineConfig.GetValueOrDefault(key, "")}): ");

                        try
                        {
                            if (!string.IsNullOrEmpty(value))
                            {
                                _engineConfig.SetValue(key, value);

                                if (key == CatapultEngineConfig.AuthorizationTokenKey)
                                {
                                    modifiedConfigs.Add(key, "***");
                                }
                                else
                                {
                                    modifiedConfigs.Add(key, value);
                                }
                            }

                            isValueNeeded = false;
                        }
                        catch (Exception)
                        {
                            // do nothing, just repeat the input
                        }
                    }
                }

                _engineConfig.Save().Wait();

                message = "Config values have been saved successfully.";
                Logger.LogInformation($"Config values have been modified: {JsonConvert.SerializeObject(modifiedConfigs)}");
            }

            return(message);
        }