private void BtnEiUpdate_Click(object sender, EventArgs e) { Enabled = false; var tmp = btnEiUpdate.Text; btnEiUpdate.Text = "Updating ..."; btnEiUpdate.Update(); DialogResult res = DialogResult.OK; var progressBar = new LoadingBar("EI Update", (ct, invok, progress) => { do { try { EliteInsights.Update(initState, new Progress <double>(p => progress.Report(new ProgressMessage(p, "Update EI"))), ct).Wait(); } catch (OperationCanceledException ex) { Logger.Error("Manual EI update failed"); Logger.LogException(ex); res = MessageBox.Show("EI uppdate failed.\nMessage:\n" + ex.Message, "Error - EI Update", MessageBoxButtons.RetryCancel, MessageBoxIcon.Error, MessageBoxDefaultButton.Button1); } } while (res == DialogResult.Retry); }); progressBar.ShowDialog(this); btnEiUpdate.Text = tmp; Enabled = true; }
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 static async Task InitEliteInsights(IEliteInsightsSettings settings, IProxySettings proxySettings, IProgress <ProgressMessage> progress = null, CancellationToken cancellationToken = default) { progress?.Report(new ProgressMessage(0, "Init")); EliteInsights.Init(settings); await EliteInsights.UpdateNewestVersion(proxySettings, new Progress <double>(p => progress?.Report(new ProgressMessage((p * 0.2) + 0.05, "Checking for Update")))); var newVersion = EliteInsights.UpdateAviable(); if (EliteInsights.IsInstalled()) { Logger.Message($"Installed EI Version: {EliteInsights.LocalVersion}"); } else { Logger.Warn("EI not installed"); } if (newVersion) { Logger.Message("EI update available. New version: " + EliteInsights.NewestVersion); Logger.Message("Auto update EI: " + settings.AutoUpdateEI); if (settings.AutoUpdateEI || MessageBox.Show("New Version of EliteInsights is aviable\nUpdate now?", "EliteInsights Update", MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button1) == DialogResult.Yes) { progress?.Report(new ProgressMessage(0.25, "Starting Update")); try { await EliteInsights.Update(proxySettings, new Progress <double>(p => progress?.Report(new ProgressMessage((p * 0.70) + 0.25, $"Updating {p*100:.}%"))), cancellationToken); Logger.Message("Update EI completed"); } catch (OperationCanceledException e) { Logger.Warn("EI update failed"); Logger.LogException(e); if (!EliteInsights.IsInstalled()) { MessageBox.Show("Faild to install EliteInsights", "Missing EliteInsights installation", MessageBoxButtons.OK, MessageBoxIcon.Error); //TODO really crash here? Exit(ExitCode.EI_UPDATE_FATAL_ERROR); } } progress?.Report(new ProgressMessage(1, "Update Done")); } } }
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 }