Esempio n. 1
0
 public static void Save(TrafficStatistics instance)
 {
     try
     {
         string filename = Utils.GetTempPath(TRAFFIC_STATISTICS_FILE);
         using (StreamWriter sw = new StreamWriter(File.Open(filename, FileMode.Create)))
         {
             string jsonString = JsonConvert.SerializeObject(instance, Formatting.Indented);
             sw.Write(jsonString);
             sw.Flush();
         }
     }
     catch (IOException e)
     {
         Console.Error.WriteLine(e);
     }
 }
Esempio n. 2
0
 public static TrafficStatistics Load()
 {
     try
     {
         string            filename = Utils.GetTempPath(TRAFFIC_STATISTICS_FILE);
         string            content  = File.ReadAllText(filename);
         TrafficStatistics instance = JsonConvert.DeserializeObject <TrafficStatistics>(content);
         return(instance);
     }
     catch (Exception e)
     {
         if (!(e is FileNotFoundException))
         {
             Logging.LogUsefulException(e);
         }
         return(new TrafficStatistics());
     }
 }