public async Task InitLogUploaderLogic(SettingsData settings, bool eap, bool eau, IProgress <ProgressMessage> progress = null)
        {
            progress?.Report(new ProgressMessage(0, "Init"));
            Settings          = settings;
            DPSReport         = new DPSReport(Settings, settings.UserToken);
            EnableAutoParsing = settings.EnableAutoParse || eap;
            EnableAutoUpload  = settings.EnableAutoUpload || eau;

            progress?.Report(new ProgressMessage(0.01, "Webhooks"));
            WebHookDB = Settings.WebHookDB;


            progress?.Report(new ProgressMessage(0.03, "Starting worker"));
            WorkerCTS = new CancellationTokenSource();
            Worker    = new JobQueue <CachedLog>(WorkerCTS.Token, "LogProcessing JobQueue");
            InitJobQueueEvents(Worker);

            progress?.Report(new ProgressMessage(0.05, "Starting worker"));
            WatchDogCTS  = new CancellationTokenSource();
            WatchDogTask = RunWatchDog(settings.ArcLogsPath, WatchDogCTS);

            progress?.Report(new ProgressMessage(0.06, "RO+"));
            await Task.Run(() => LoadTermine(new Progress <ProgressMessage>(p => progress?.Report(new ProgressMessage((0.24 * p.Percent) + 0.06, "RO+ " + p.Message)))));

            await Task.Run(() => UpdateUnkowen(new Progress <double>(p => progress?.Report(new ProgressMessage(0.3 + (p * 0.2), "Updating Local Files Old")))));

            await Task.Run(() => CheckForNewLogs(new Progress <double>(p => progress?.Report(new ProgressMessage(0.5 + (p * 0.5), "Updating Local Files New")))));
        }
Example #2
0
        protected virtual WebHookData.Field GenerateSingleBossField(CachedLog log, DPSReport remot = null)
        {
            if (Settings.OnlyPostUploaded && string.IsNullOrWhiteSpace(log.Link))
            {
                return(null);
            }
            string name  = $"{log.Date:HH\\:mm}";
            string value = $"{(log.Succsess ? Language.Data.Succsess : Language.Data.Fail)}";

            if (log.IsCM)
            {
                value = $"CM " + value;
            }
            if (log.DataCorrected)
            {
                value += $" - {log.Duration:mm':'ss}";
            }
            if (!string.IsNullOrWhiteSpace(log.Link))
            {
                value += $"\n[dps.report]({ log.Link})";
            }
            var field = new WebHookData.Field(name, value, true);

            return(field);
        }
        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);
        }
        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
        }