private CachedLog HandelNewFile(string path) { var absolutPath = path; var bossID = GetBoss(path).ID; var date = File.GetCreationTime(absolutPath); var sizeKb = (int)Math.Ceiling(new FileInfo(absolutPath).Length / 1000.0); var newLog = new CachedLog(-1, bossID, absolutPath, null, null, null, sizeKb, date); newLog.ID = LogDBConnector.Insert(newLog.GetDBLog()); var taskName = newLog.BossName.Length > 17 ? newLog.BossName.Substring(0, Math.Min(17, newLog.BossName.Length)) + "..." : newLog.BossName; LogCache.Add(newLog); OnDataChanged(new EventArgs()); if (EnableAutoParsing && EnableAutoUpload) { ParseAndUpload(newLog.ID, $"{Language.Data.FooterProcessing} {taskName}"); } else if (EnableAutoParsing) { Parse(newLog.ID, $"{Language.Data.FooterParsing} {taskName}"); } else if (EnableAutoUpload) { Upload(newLog.ID, $"{Language.Data.FooterUploading} {taskName}"); } GC.Collect(); return(newLog); }
public DataTable GetData() { var data = LogDBConnector.GetAll(); var tabel = ListToDataTable.Convert(data); return(tabel); }
private void UpdateUnkowen(IProgress <double> progress = null) { progress?.Report(0); var logs = LogDBConnector.GetByBossIdWithPath(0); int i = 0; int count = logs.Count; foreach (var log in logs) { bool update = false; var id = GetBoss(log.EvtcPath).ID; if (id != 0) { update = true; log.BossID = id; } if (!File.Exists(log.EvtcPath)) { update = true; log.EvtcPath = null; } if (update) { LogDBConnector.Update(log); } progress?.Report((double)i++ / count); i++; } }
private CachedLog ParseJob(CachedLog log) { var localDataVersion = CacheLog(log.ID).DataVersion; if (!string.IsNullOrEmpty(log.HtmlPath) && localDataVersion >= CachedLog.CurrentDataVersion) { return(log); } if (string.IsNullOrEmpty(log.EvtcPath) || !File.Exists(log.EvtcPath)) { UpdateFilePaths(log); return(log); } var res = EliteInsights.Parse(log.EvtcPath); var html = res.Where(path => path.EndsWith(".html")).FirstOrDefault(); var json = res.Where(path => path.EndsWith(".json")).FirstOrDefault(); //Maybe Add corrupted flag if no output is generated if (res.Count == 0) { var ex = new Exception($"Could not parse the {log.BossName} log! ({log.SizeKb} kb)\n{log.EvtcPath}"); if (log.SizeKb >= 30) { throw ex; } Logger.LogException(ex); return(log); } if (!log.DataCorrected || localDataVersion < CachedLog.CurrentDataVersion) { var jsonStr = GP.ReadJsonFile(json); log.UpdateEi(jsonStr); if (string.IsNullOrWhiteSpace(log.JsonPath)) { var simpleLogJson = new SimpleLogJson(jsonStr); var newjson = json.Substring(0, json.Length - ".json".Length) + "_simple.json"; GP.WriteJsonFile(newjson, simpleLogJson.ToString()); log.JsonPath = newjson; } } log.HtmlPath = html; File.Delete(json); LogDBConnector.Update(log.GetDBLog()); return(log); }
private CachedLog UploadJob(CachedLog log) { var localDataVersion = CacheLog(log.ID).DataVersion; if (!string.IsNullOrEmpty(log.Link) && localDataVersion >= CachedLog.CurrentDataVersion) { return(log); } if (string.IsNullOrEmpty(log.EvtcPath) || !File.Exists(log.EvtcPath)) { UpdateFilePaths(log); return(log); } var response = DPSReport.UpladContent(log.EvtcPath); var jsonData = Newtonsoft.Json.Linq.JObject.Parse(response); if (jsonData.ContainsKey("Error")) { var ex = new Exception($"Could not upload the {log.BossName} log! ({log.SizeKb} kb)\n{log.EvtcPath}\n\nResponse: \"{(string)jsonData["Error"]}\""); if (log.SizeKb >= 30) { throw ex; } Logger.LogException(ex); return(log); } var link = (string)jsonData["permalink"]; if (!log.DataCorrected || localDataVersion < CachedLog.CurrentDataVersion) { response = DPSReport.GetEncounterDataPermalink(link); log.UpdateEi(response); if (string.IsNullOrWhiteSpace(log.JsonPath)) { var simpleLogJson = new SimpleLogJson(response); var evtcName = Path.GetFileName(log.EvtcPath); var newjson = EliteInsights.LogsPath + evtcName.Substring(0, evtcName.LastIndexOf('.')) + "_simple.json"; GP.WriteJsonFile(newjson, simpleLogJson.ToString()); log.JsonPath = newjson; } } log.Link = link; LogDBConnector.Update(log.GetDBLog()); return(log); }
public CachedLog QuickCacheLog(int id) { var log = LogCache.GetLog(id); if (log == null) { log = new CachedLog(LogDBConnector.GetByID(id)); LogCache.Add(log); } if (!File.Exists(log.EvtcPath)) { log.EvtcPath = null; LogDBConnector.Update(log.GetDBLog()); } return(log); }
private void CheckForNewLogs(IProgress <double> progress = null) { progress?.Report(0); var newestElement = LogDBConnector.GetNewest(); var min = newestElement?.Date.Subtract(new TimeSpan(1, 0, 0, 0)) ?? new DateTime(2000, 1, 1); var allFiles = Directory.EnumerateFiles(Settings.ArcLogsPath, "*.*", SearchOption.AllDirectories) .Where(file => file.EndsWith(".evtc") || file.EndsWith(".zevtc") || file.EndsWith(".evtc.zip")) .ToList(); List <DBLog> newLogs = FilterNewLogs(progress, min, allFiles); progress?.Report(0.95); if (newLogs.Count > 0) { LogDBConnector.InsertBulk(newLogs); } }
public void UpdateFilePaths(CachedLog log) { if (string.IsNullOrEmpty(log.EvtcPath) || !File.Exists(log.EvtcPath)) { log.EvtcPath = null; } if (string.IsNullOrEmpty(log.HtmlPath) || !File.Exists(log.HtmlPath)) { log.HtmlPath = null; } if (string.IsNullOrEmpty(log.JsonPath) || !File.Exists(log.JsonPath)) { log.JsonPath = null; } LogDBConnector.Update(log.GetDBLog()); }
private static void InitDB(IProgress <ProgressMessage> progress) { progress?.Report(new ProgressMessage(0, "Init")); string dbFilePaht = $@"{ Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData)}\LogUploader\LogDB.db"; LogDBConnector.DBConnectionString = $@"Data Source=""{dbFilePaht}""; Version=3;Connect Timeout=30"; try { progress?.Report(new ProgressMessage(0.25, "Connect")); var count = LogDBConnector.GetCount(); Logger.Message("DB found " + count + " entries"); } catch (System.Data.SQLite.SQLiteException) { //Create DB progress?.Report(new ProgressMessage(0.50, "Create")); Logger.Message("Creating DB"); LogDBConnector.CreateTable(); } progress?.Report(new ProgressMessage(1, "Done")); }
private List <DBLog> FilterNewLogs(IProgress <double> progress, DateTime min, List <string> allFiles) { var newLogs = new List <DBLog>(); var reportStep = 32; var numFiles = allFiles.Count; for (int i = 0; i < numFiles; i++) { if (i % reportStep == 0) { progress?.Report(0.95 * i / numFiles); } var path = allFiles[i]; var Fi = new FileInfo(path); if (Fi.LastWriteTime < min || LogDBConnector.GetByEvtcPaht(path).Count() != 0) { continue; } var id = GetBoss(path).ID; newLogs.Add(new DBLog(id, path, null, null, null, (int)Math.Ceiling(Fi.Length / 1000.0), Fi.LastWriteTime)); } return(newLogs); }
public int GetElementCount() { return(LogDBConnector.GetCount()); }
private CachedLog ReParseData(CachedLog log) { if (!log.DataCorrected) { return(ParseJob(log)); } if (!string.IsNullOrWhiteSpace(log.Link)) { var response = DPSReport.GetEncounterDataPermalink(log.Link); var simpleLogJson = new SimpleLogJson(response); if (!string.IsNullOrWhiteSpace(log.JsonPath)) { if (File.Exists(log.JsonPath)) { File.Delete(log.JsonPath); } } string name; if (!string.IsNullOrWhiteSpace(log.EvtcPath)) { name = log.EvtcPath.Substring(0, log.EvtcPath.LastIndexOf('.')).Split('\\').Last(); } else { name = log.Link.Split('/').Last(); } var newjson = EliteInsights.LogsPath + name + "_simple.json"; GP.WriteJsonFile(newjson, simpleLogJson.ToString()); log.JsonPath = newjson; LogDBConnector.Update(log.GetDBLog()); log.ApplySimpleLog(simpleLogJson); return(log); } if (!string.IsNullOrWhiteSpace(log.EvtcPath)) { if (!File.Exists(log.EvtcPath)) { UpdateFilePaths(log); return(log); } var res = EliteInsights.Parse(log.EvtcPath); var html = res.Where(path => path.EndsWith(".html")).FirstOrDefault(); var json = res.Where(path => path.EndsWith(".json")).FirstOrDefault(); if (res.Count == 0) { return(null); } if (!string.IsNullOrWhiteSpace(log.HtmlPath) && File.Exists(log.HtmlPath)) { File.Delete(log.HtmlPath); } if (!string.IsNullOrWhiteSpace(log.JsonPath) && File.Exists(log.JsonPath)) { File.Delete(log.HtmlPath); } if (!log.DataCorrected) { var jsonStr = GP.ReadJsonFile(json); log.UpdateEi(jsonStr); if (string.IsNullOrWhiteSpace(log.JsonPath)) { var simpleLogJson = new SimpleLogJson(jsonStr); var newjson = json.Substring(0, json.Length - ".json".Length) + "_simple.json"; GP.WriteJsonFile(newjson, simpleLogJson.ToString()); log.JsonPath = newjson; } } log.HtmlPath = html; File.Delete(json); LogDBConnector.Update(log.GetDBLog()); } return(null); // cannot upgrade data }