public string AutoInfo(DSinfo info) { DSRestPlayer player = null; lock (dblock) { player = _context.DSRestPlayers.FirstOrDefault(f => f.Name == info.Name); } string myreturn = ""; if (player != null) { //DEBUG //player.LastRep = new DateTime(2020, 4, 21); DateTime LastRep = DateTime.MinValue; if (info.LastRep.Length == 14) { int year = int.Parse(info.LastRep.Substring(0, 4)); int month = int.Parse(info.LastRep.Substring(4, 2)); int day = int.Parse(info.LastRep.Substring(6, 2)); int hour = int.Parse(info.LastRep.Substring(8, 2)); int min = int.Parse(info.LastRep.Substring(10, 2)); int sec = int.Parse(info.LastRep.Substring(12, 2)); LastRep = new DateTime(year, month, day, hour, min, sec); } Version dbversion = new Version(player.Version); Version clversion = new Version(info.Version); Version bpversion = new Version("2.0.0"); _logger.LogInformation($"db: {dbversion}; client: {clversion}"); if (clversion >= bpversion && dbversion < bpversion) { myreturn = "0"; } else if (player.LastRep == LastRep) { myreturn = "UpToDate"; } else { myreturn = player.LastRep.ToString("yyyyMMddHHmmss"); } } else { player = new DSRestPlayer(); player.Name = info.Name; player.Json = info.Json; player.Total = info.Total; player.Version = info.Version; myreturn = "0"; _context.DSRestPlayers.Add(player); } lock (dblock) { _context.SaveChanges(); } Infos[info.Name] = info; return(myreturn); }
public async Task <bool> GetAutoFile(string id, string myfile) { DSRestPlayer player = _context.DSRestPlayers.Include(p => p.Uploads).FirstOrDefault(f => f.Name == id); if (player == null) { return(false); } player.LastUpload = DateTime.UtcNow; string mypath = SharedDir + "/" + id; string mysum = SharedDir + "/sum/" + id + ".json"; if (!Directory.Exists(mypath)) { try { Directory.CreateDirectory(mypath); } catch (Exception e) { _logger.LogError("Could not create directory " + mypath + " " + e.Message); return(false); } } if (File.Exists(myfile)) { if (!File.Exists(mysum)) { File.Create(mysum).Dispose(); } string myjson = ""; return(await Task.Run(() => myjson = Decompress(new FileInfo(myfile), mypath, id, _logger)) .ContinueWith(task => { if (myjson == "") { return false; } if (File.Exists(myjson) && new FileInfo(myjson).Length > 0) { using (StreamWriter sw = File.AppendText(mysum)) { foreach (string line in File.ReadLines(myjson)) { if (!line.StartsWith(@"{")) { return false; } sw.WriteLine(line); dsreplay replay = null; try { replay = JsonSerializer.Deserialize <dsreplay>(line); if (replay != null) { DSReplay dsreplay = Map.Rep(replay); DSPlayer dsplayer = dsreplay.DSPlayer.FirstOrDefault(f => f.NAME == "player"); if (dsplayer != null) { dsplayer.NAME = id; } dsreplay.Upload = player.LastUpload; DSReplays.Add(dsreplay); player.Data++; } } catch (Exception e) { _logger.LogError("Could not Deserialize and map replay " + e.Message); } } } DSRestUpload upload = new DSRestUpload(); upload.Upload = player.LastUpload; upload.DSRestPlayer = player; _context.DSRestUploads.Add(upload); DSinfo info = Infos.FirstOrDefault(f => f.Key == id).Value; if (info != null) { DateTime LastRep = DateTime.MinValue; if (info.LastRep.Length == 14) { int year = int.Parse(info.LastRep.Substring(0, 4)); int month = int.Parse(info.LastRep.Substring(4, 2)); int day = int.Parse(info.LastRep.Substring(6, 2)); int hour = int.Parse(info.LastRep.Substring(8, 2)); int min = int.Parse(info.LastRep.Substring(10, 2)); int sec = int.Parse(info.LastRep.Substring(12, 2)); LastRep = new DateTime(year, month, day, hour, min, sec); } player.LastRep = LastRep; player.Json = info.Json; player.Total = info.Total; player.Version = info.Version; } lock (dblock) { _context.SaveChanges(); } InsertDSReplays(); return true; } else { return false; } })); } else { return(false); } }