Esempio n. 1
0
        public RpsPlayerStatsDataModel ReadStatsJson(ulong DiscordId)
        {
            var filePath = FilePaths.BuildFilePath($"{DiscordId}.json");

            if (CheckFileExists(filePath))
            {
                var obj = JsonConvert.DeserializeObject <RpsPlayerStatsDataModel>(File.ReadAllText(filePath));

                return(obj);
            }
            else
            {
                return(null);
            }
        }
Esempio n. 2
0
 public void SaveStatsJson(List <RpsPlayerStatsDataModel> ListStats)
 {
     try
     {
         foreach (var item in ListStats)
         {
             var filePath = FilePaths.BuildFilePath($"{item.DiscordId}.json");
             var readFile = ReadStatsJson(item.DiscordId);
             if (readFile == null)
             {
                 using (var file = File.CreateText(filePath))
                 {
                     var serializer = new JsonSerializer
                     {
                         Formatting = Formatting.Indented
                     };
                     serializer.Serialize(file, item);
                 }
             }
             else
             {
                 using (var file = File.CreateText(filePath))
                 {
                     var serializer = new JsonSerializer
                     {
                         Formatting = Formatting.Indented
                     };
                     serializer.Serialize(file, UpdateStatsJson(readFile, item));
                 }
             }
         }
     }
     catch (Exception e)
     {
         Console.WriteLine(e);
         throw;
     }
 }