コード例 #1
0
 public static ServerTransferTotal Load()
 {
     try
     {
         ServerTransferTotal config;
         if (File.Exists(LogFile))
         {
             config = new ServerTransferTotal
             {
                 Servers = JsonUtils.Deserialize <Dictionary <string, ServerTrans> >(File.ReadAllText(LogFile))
             };
         }
         else
         {
             config = new ServerTransferTotal();
         }
         config.Init();
         return(config);
     }
     catch (FileNotFoundException)
     {
         // ignored
     }
     catch (Exception e)
     {
         Console.WriteLine(e);
     }
     return(new ServerTransferTotal());
 }
コード例 #2
0
 public static void Save(ServerTransferTotal config, List <Server> servers = null)
 {
     try
     {
         if (servers != null)
         {
             config.Servers = config.Servers
                              .Where(pair => servers.Exists(server => server.Id == pair.Key))
                              .ToDictionary(pair => pair.Key, pair => pair.Value);
         }
         var jsonString = JsonUtils.Serialize(config.Servers, true);
         Utils.WriteAllTextAsync(LogFile, jsonString);
     }
     catch (IOException e)
     {
         Console.Error.WriteLine(e);
     }
 }