Add Json.Net and separate out Statistics Configuration file

Import Json.Net since it's difficult for SimpleJson to deal with nested type.
This commit is contained in:
icylogic
2015-09-03 14:08:35 +08:00
parent a30cb166a5
commit 4e1b140dd9
10 changed files with 132 additions and 71 deletions
@@ -1,8 +1,12 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Reflection;
using Shadowsocks.Controller;
using Shadowsocks.Controller.Strategy;
using SimpleJson;
using Newtonsoft.Json;
namespace Shadowsocks.Model
{
@@ -17,6 +21,41 @@ namespace Shadowsocks.Model
private int _dataCollectionMinutes;
private int _repeatTimesNum;
private const string ConfigFile = "statistics-config.json";
public static StatisticsStrategyConfiguration Load()
{
try
{
var content = File.ReadAllText(ConfigFile);
var configuration = JsonConvert.DeserializeObject<StatisticsStrategyConfiguration>(content);
return configuration;
}
catch (FileNotFoundException e)
{
return new StatisticsStrategyConfiguration();
}
catch (Exception e)
{
Logging.LogUsefulException(e);
return new StatisticsStrategyConfiguration();
}
}
public static void Save(StatisticsStrategyConfiguration configuration)
{
try
{
var content = JsonConvert.SerializeObject(configuration, Formatting.Indented);
File.WriteAllText(ConfigFile, content);
}
catch (Exception e)
{
Logging.LogUsefulException(e);
}
}
public Dictionary<string, float> Calculations;
public StatisticsStrategyConfiguration()