Nextrek
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
53
54
55
56
57
58
|
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization.Formatters;
using System.Text;
using System.Threading.Tasks;
using Windows.Storage;
using Windows.System;
namespace SmartCharging
{
class Config
{
private static Config instance;
private const string CONFIG_FILE_PATH = "ms-appx:///config.json";
private Dictionary<string, string> configDictionary;
private async Task loadConfig()
{
if (this.configDictionary == null)
{
// StorageFolder storageFolder = Windows.Storage.ApplicationData.Current.LocalFolder;
//StorageFile configFile = await storageFolder.GetFileAsync(CONFIG_FILE_PATH);
StorageFile configFile = await StorageFile.GetFileFromApplicationUriAsync(new Uri(CONFIG_FILE_PATH));
string text = await Windows.Storage.FileIO.ReadTextAsync(configFile);
configDictionary = JsonConvert.DeserializeObject<Dictionary<string, string>>(text);
}
}
public async Task<string> getConfigValueByKey(string key)
{
await loadConfig();
return configDictionary[key];
}
public static Config Instance
{
get
{
if (instance == null)
{
instance = new Config();
}
return instance;
}
}
}
}
|
Revision |
Author |
Commited |
Message |
660
|
JMBauan
|
Thu 03 Sep, 2015 08:14:10 +0000 |
|