-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathConfigurationRequest.cs
More file actions
52 lines (45 loc) · 1.65 KB
/
ConfigurationRequest.cs
File metadata and controls
52 lines (45 loc) · 1.65 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
using System;
using System.Configuration;
using System.Globalization;
using System.Linq;
using m3md2;
namespace KeyboardMaster
{
internal class ConfigurationRequest
{
internal static IDictonary GetDictonary()
{
StaticVariables.LanguageDictonary = (LanguageDictonary)Enum.Parse(typeof(LanguageDictonary), GetValueByKey("Lang"));
return StaticVariables.LanguageDictonary switch
{
LanguageDictonary.RU => new RuDictonary(),
LanguageDictonary.EN => new EnDictonary(),
_ => throw new ArgumentException("В конфигурации обнаружено неожиданное значение"),
};
}
private static void WriteValueByKey(string key, string value)
{
var appSettings = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
var item = Array.Find(appSettings.AppSettings.Settings.OfType<KeyValueConfigurationElement>().ToArray(), x => x.Key == key);
item.Value = value;
appSettings.Save(ConfigurationSaveMode.Minimal);
ConfigurationManager.RefreshSection("appSettings");
}
private static string GetValueByKey(string key)
{
return ConfigurationManager.AppSettings.Get(key);
}
internal static string GetTime()
{
return GetValueByKey("Time");
}
internal static void SaveDictonary(string v)
{
WriteValueByKey("Lang", v);
}
internal static void SaveTime(string text)
{
WriteValueByKey("Time", text);
}
}
}