コード例 #1
0
        public string GetValueFor(string key)
        {
            var value = ConfigurationManager.AppSettings[key];

            if (value is null)
            {
                var editor = new ConfigurationFileEditor();

                var configErrorMessage = $"Configuration Error:\n" +
                                         $"The configuration could not retrieve the item: '{key}'\n" +
                                         $"Enter your desired value: (or type EXIT)";

                _logger.LogError(configErrorMessage);
                editor.WriteSetting(key, "REPLACE-ME");
                editor.Save();

                value = Console.ReadLine();

                if (value.Trim().ToLower() == "exit")
                {
                    Environment.Exit(0);
                }
                if (value.Trim().ToLower() == "i'm feeling lucky")
                {
                    value = $"{RandomString(24)}.{RandomString(6)}.{RandomString(27)}";
                    _logger.Log($"Let's try {value}. I have a good feeling about this one.");
                }

                editor.WriteSetting(key, value);
                editor.Save();
            }

            return(value);
        }
コード例 #2
0
 private void StoreSetting(KeyValuePair setting)
 {
     _editor.WriteSetting(setting);
     _editor.Save();
 }