/// <summary> /// Method which reads JSON file /// </summary> /// <param name="filePath"> - a path to a file</param> private void ReadJsonFile(string filePath) { //debug string for current JSONStringLine string JSONStringLine = ""; FileStream fileStream = null; StreamReader reader = null; try { fileStream = File.Open(filePath, FileMode.Open, FileAccess.Read, FileShare.ReadWrite); reader = new StreamReader(fileStream); EDEvent currentEvent = null; while (!reader.EndOfStream) { try { JSONStringLine = reader.ReadLine(); if (JSONStringLine.Equals("")) //if line contains nothing skips line and reads next { continue; } currentEvent = JsonConvert.DeserializeObject <EDEvent>(JSONStringLine, new JsonSerializerSettings { ContractResolver = new CamelCasePropertyNamesContractResolver() }); if (currentEvent != null) { //reads only if corverter corverts JSON FILE DetectThargoidKill(currentEvent, JSONStringLine); } } catch (JsonReaderException ex) { log.Debug("JSONReader exception occured", ex); continue; } } } catch (Exception) { log4net.GlobalContext.Properties["Prop1"] = JSONStringLine; log.Error($"Unknown error while reading file {filePath}"); throw; } finally { //closes stream and reader in case of some unknown error if (fileStream != null) { fileStream.Close(); } if (reader != null) { reader.Close(); } } }
/// <summary> /// Reads JSON file from selected line /// </summary> /// <param name="filePath">Path to file</param> /// <param name="line">Line number from which reader starts reading</param> /// <param name="firstRun">Line number from which reader starts reading</param> /// <returns>Line number where reader ended</returns> private int ReadJsonFile(string filePath, int line, bool firstRun) { //debug string for current JSONStringLine string JSONStringLine = ""; FileStream fileStream = null; StreamReader reader = null; try { fileStream = File.Open(filePath, FileMode.Open, FileAccess.Read, FileShare.ReadWrite); reader = new StreamReader(fileStream); EDEvent currentEvent = null; //skips the lines that previous readers have red for (int i = 1; i < line; i++) { reader.ReadLine(); } while (!reader.EndOfStream) { try { JSONStringLine = reader.ReadLine(); if (JSONStringLine.Equals("")) //if line contains nothing skips line and reads next { continue; } currentEvent = JsonConvert.DeserializeObject <EDEvent>(JSONStringLine, new JsonSerializerSettings { ContractResolver = new CamelCasePropertyNamesContractResolver() }); if (currentEvent != null) { //reads only if corverter corverts JSON FILE if (DetectThargoidKill(currentEvent, JSONStringLine, out string ThargoidType) && ScreenShotBool == true && firstRun == false) { ScreenShoter.MakeScreenShot(ThargoidType); } } line++; } catch (JsonReaderException ex) { log.Debug("JSONReader exception occured", ex); continue; } } return(line); } catch (Exception) { log4net.GlobalContext.Properties["Prop1"] = JSONStringLine; log.Error($"Unknown error while reading file {filePath}"); throw; } finally { //closes stream and reader in case of some unknown error if (fileStream != null) { fileStream.Close(); } if (reader != null) { reader.Close(); } } }
/// <summary> /// Checks if Json String line contains thargoid kill, returns name of Thargoid killed if true /// </summary> /// <param name="e1">converted JSON text to class</param> /// <param name="JSONStringLine">JSON text</param> /// <param name="ThargoidType">name of thargoid type</param> /// <returns>true on thargoid kill, false on no kill</returns> private bool DetectThargoidKill(EDEvent e1, string JSONStringLine, out string ThargoidType) { bool killDetected = false; ThargoidType = "No kill"; ThargoidKillEvent kill; if ([email protected]("FactionKillBond")) { kill = JsonConvert.DeserializeObject <ThargoidKillEvent>(JSONStringLine, new JsonSerializerSettings { ContractResolver = new CamelCasePropertyNamesContractResolver() }); if (kill.AwardingFaction == null || kill.VictimFaction == null) { log.Debug($"Faulty line passed to DetectThargoidKill. AwardingFaction and VictimFaction are null\r\n Text of line - {JSONStringLine}"); } else if (kill.AwardingFaction.Equals(@"$faction_PilotsFederation;") || kill.VictimFaction.Equals(@"$faction_Thargoid;")) { int caseSwitch = kill.Reward; switch (caseSwitch) { case 10000: Counter.Scout++; //Method wont change boolean killDetected, because Scout screenshots are not interesting but it is counted break; case 80000: //Price for scouts in journals since Oddysey Counter.Scout++; //Method wont change boolean killDetected, because Scout screenshots are not interesting but it is counted break; case 2000000: Counter.Cyclops++; killDetected = true; ThargoidType = $"Cyclops{DateTime.UtcNow.ToString("dd-MM-HH-mm-ss")}"; //format of datetime day-month-hour-minutes-seconds break; case 8000000: //Price for Cyclops in journals since Oddysey Counter.Cyclops++; killDetected = true; ThargoidType = $"Cyclops{DateTime.UtcNow.ToString("dd-MM-HH-mm-ss")}"; //format of datetime day-month-hour-minutes-seconds break; case 6000000: Counter.Basillisk++; killDetected = true; ThargoidType = $"Basillisk{DateTime.UtcNow.ToString("dd-MM-HH-mm-ss")}"; break; case 24000000: //Price for Basillisks in journals since Oddysey Counter.Basillisk++; killDetected = true; ThargoidType = $"Basillisk{DateTime.UtcNow.ToString("dd-MM-HH-mm-ss")}"; break; case 10000000: Counter.Medusa++; killDetected = true; ThargoidType = $"Medusa{DateTime.UtcNow.ToString("dd-MM-HH-mm-ss")}"; break; case 40000000: //Price for Medusaws in journals since Oddysey Counter.Medusa++; killDetected = true; ThargoidType = $"Medusa{DateTime.UtcNow.ToString("dd-MM-HH-mm-ss")}"; break; case 15000000: Counter.Hydra++; killDetected = true; ThargoidType = $"Hydra{DateTime.UtcNow.ToString("dd-MM-HH-mm-ss")}"; break; case 60000000: //Price for Hydras in journals since Oddysey Counter.Hydra++; killDetected = true; ThargoidType = $"Hydra{DateTime.UtcNow.ToString("dd-MM-HH-mm-ss")}"; break; default: Counter.Unknown++; log.Info($"NEW THARGOID TYPE - Found unknown new type of thargoid. Credits for kill: {kill.Reward}"); killDetected = true; ThargoidType = $"Unknown{DateTime.UtcNow.ToString("dd-MM-HH-mm-ss")}"; break; } } } return(killDetected); }
/// <summary> /// Detects thargoid kill from EDEvent class /// </summary> /// <param name="e1">converted JSON text to class</param> /// <param name="JSONStringLine">JSON text</param> private void DetectThargoidKill(EDEvent e1, string JSONStringLine) { ThargoidKillEvent kill; if ([email protected]("FactionKillBond")) { kill = JsonConvert.DeserializeObject <ThargoidKillEvent>(JSONStringLine, new JsonSerializerSettings { ContractResolver = new CamelCasePropertyNamesContractResolver() }); if (kill.AwardingFaction == null || kill.VictimFaction == null) { log.Debug($"Faulty line passed to DetectThargoidKill. AwardingFaction and VictimFaction are null\r\n Text of line - {JSONStringLine}"); } else if (kill.AwardingFaction.Equals(@"$faction_PilotsFederation;") || kill.VictimFaction.Equals(@"$faction_Thargoid;")) { int caseSwitch = kill.Reward; switch (caseSwitch) { case 10000: Counter.Scout++; break; case 80000: //Price for scouts in journals since Oddysey Counter.Scout++; //Method wont change boolean killDetected, because Scout screenshots are not interesting but it is counted break; case 2000000: Counter.Cyclops++; break; case 8000000: //Price for Cyclops in journals since Oddysey Counter.Cyclops++; break; case 6000000: Counter.Basillisk++; break; case 24000000: //Price for Basillisks in journals since Oddysey Counter.Basillisk++; break; case 10000000: Counter.Medusa++; break; case 40000000: //Price for Medusaws in journals since Oddysey Counter.Medusa++; break; case 15000000: Counter.Hydra++; break; case 60000000: //Price for Hydras in journals since Oddysey Counter.Hydra++; break; default: Counter.Unknown++; log.Info($"NEW THARGOID TYPE - Found unknown new type of thargoid. Credits for kill: {kill.Reward}"); break; } } } }