protected override WebHookData.Field GenerateField(CachedLog log)
        {
            if (Settings.OnlyPostUploaded && string.IsNullOrWhiteSpace(log.Link))
            {
                return(null);
            }
            var name  = $"{log.Date:HH\\:mm}";
            var value = $"{(log.Succsess ? Language.Data.Succsess : Language.Data.Fail)}";

            if (log.DataCorrected)
            {
                value += $"\n";
                if (log.IsCM)
                {
                    value += $"\nCM";
                }
                value += $"\n{Language.Data.MiscDiscordPostGenDuration}: {log.Duration.ToString(Language.Current == eLanguage.DE ? "mm':'ss','fff" : "mm':'ss'.'fff")}";
                value += $"\n{Language.Data.MiscDiscordPostGenHpLeft}: {log.RemainingHealth:0.00'%'}";
                value += $"\n{Language.Data.MiscDiscordPostGenGroupDPS}: {log.PlayersNew.Select(p => p.DpsAll).Sum()}";
                value += $"\n{Language.Data.MiscDiscordPostGenTopDPS}: {log.PlayersNew.Max(p2 => p2.DpsAll)} ({log.PlayersNew.Where(p => p.DpsAll == log.PlayersNew.Max(p2 => p2.DpsAll)).First().Account})";
            }
            if (!string.IsNullOrWhiteSpace(log.Link))
            {
                value += $"\n[dps.report]({ log.Link})";
            }
            return(new WebHookData.Field(name, value, true));
        }
Example #2
0
 public Encounter(TeamComp tc, CachedLog log, Raid r)
 {
     TC         = tc;
     Boss       = tc.Encounter;
     Players    = GetPlayersFromLog(log.PlayersNew, r, tc.Encounter);
     tc.Success = log.Succsess;
 }
        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);
        }
Example #4
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 static void AddBoss(Raid raid, Boss boss, CachedLog log)
        {
            var players = new List <Position>();
            var tc      = new TeamComp(-1, boss, log.IsCM, players, log.Succsess);

            raid.Bosses.Add(tc);
        }
        private static void InsertLog(Raid raid, CachedLog log)
        {
            var boss = Boss.GetByID(log.BossID);

            if (boss.RaidOrgaPlusID == -1 || raid.ExistsBoss(boss, log.IsCM))
            {
                return;
            }
            AddBoss(raid, boss, log);
        }
        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);
        }
Example #8
0
        protected override WebHookData.Field GenerateField(CachedLog log)
        {
            if (Settings.OnlyPostUploaded && string.IsNullOrWhiteSpace(log.Link))
            {
                return(null);
            }
            string name = log.Succsess ? MiscData.EmoteRaidKill : MiscData.EmoteRaidWipe;

            name += Boss.GetByID(log.BossID).DiscordEmote;
            name += " " + log.BossName;
            if (log.IsCM)
            {
                name += " CM";
            }

            string value = "";

            value += log.Date.ToString("HH':'mm");
            if (log.DataCorrected)
            {
                value += $" - {log.Duration.Minutes}m {log.Duration.Seconds}s";
            }
            value += "\n";


            if (!string.IsNullOrWhiteSpace(log.Link))
            {
                value += $"[dps.report]({log.Link})";
            }
            else
            {
                value += Language.Data.MiscDiscordPostGenNoLink;
            }

            if (log.DataCorrected)
            {
                var subGroups = log.PlayersNew.GroupBy(p => p.Group).OrderBy(g => g.Key);
                foreach (var grop in subGroups)
                {
                    value += "\n";
                    foreach (var player in grop.OrderBy(p => p.Profession.Name))
                    {
                        value += player.Profession.Emote;
                    }
                }
            }

            return(new WebHookData.Field(name, value, true));
        }
        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);
        }
Example #10
0
        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);
        }
Example #11
0
 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());
 }
Example #12
0
        private CachedLog ParseAndUploadJob(CachedLog log)
        {
            var parse  = Task.Run(() => ParseJob(log));
            var upload = Task.Run(() => UploadJob(log));

            try
            {
                Task.WaitAll(parse, upload);
            }
            catch (AggregateException e)
            {
                throw new AggregateException($"{e.InnerExceptions.Count()} Exeptions occured\n" +
                                             $"First:\n" +
                                             $"{e.InnerExceptions.FirstOrDefault()?.Message}\n" +
                                             $"{e.InnerExceptions.FirstOrDefault()?.StackTrace}", e.InnerExceptions);
            }
            //ParseJob(log);
            //UploadJob(log);
            return(log);
        }
Example #13
0
        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
        }
Example #14
0
 protected abstract WebHookData.Field GenerateField(CachedLog log);
Example #15
0
 public ParsedData(CachedLog log, WebHookData.Field field)
 {
     Log   = log;
     Field = field;
 }