12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152 |
- using System;
- using System.Collections.Generic;
- using System.Configuration;
- using System.Runtime.CompilerServices;
- namespace Rac.Tools
- {
- internal class ConfigAdapter
- {
- private readonly Dictionary<string, string> _dicConf;
- public ConfigAdapter(Dictionary<string, string> dicConf)
- {
- _dicConf = dicConf;
- }
- private string GetValue([CallerMemberName] string confKey = "")
- {
- return _dicConf.ContainsKey(confKey)
- ? _dicConf[confKey]
- : null;
- }
- private string[] GetValues([CallerMemberName] string confKey = "")
- {
- // ReSharper disable once ExplicitCallerInfoArgument
- return (GetValue(confKey) ?? "").Split(new[] { "\r\n", "\r", "\n" }, StringSplitOptions.RemoveEmptyEntries);
- }
- private int GetInt32Value([CallerMemberName] string confKey = "")
- {
- // ReSharper disable once ExplicitCallerInfoArgument
- var value = GetValue(confKey);
- if (int.TryParse(value, out var int32Value))
- {
- return int32Value;
- }
- throw new ConfigurationErrorsException($"Bad config {confKey}");
- }
- public string HomeUrl => GetValue();
- public string[] HostsInclude => GetValues();
- public string[] UrlPrefixExclude => GetValues();
- public int Parallel => GetInt32Value();
- public int OwsPort => GetInt32Value();
- public string DefaultCharset => GetValue();
- public string ExtractWebRoot => GetValue();
- }
- }
|