/// <summary> /// event-worker for JournalEventRecieved-event /// </summary> /// <param name="sender"></param> /// <param name="e"></param> void JournalEventRecieved(object sender, FileScanner.EDJournalScanner.JournalEventArgs e) { try { switch (e.EventType) { case FileScanner.EDJournalScanner.JournalEvent.Docked: if((!Program.actualCondition.System.EqualsNullOrEmpty(e.Data.Value<String>("StarSystem"))) || (!Program.actualCondition.Station.EqualsNullOrEmpty(e.Data.Value<String>("StationName")))) { if(Program.DBCon.getIniValue<Boolean>(IBESettingsView.DB_GROUPNAME, "AutoAdd_Visited", true.ToString(), false)) SaveEvent(DateTime.UtcNow, e.Data.Value<String>("StarSystem"), e.Data.Value<String>("StationName"), "", "", 0, 0, Program.CompanionIO.SGetCreditsTotal(), "Visited", ""); } else if(e.History.Find(x => ((x.EventType == FileScanner.EDJournalScanner.JournalEvent.Resurrect) && (e.History.IndexOf(x) < 2))) != null) { var resurrectEvent = e.History.Find(x => ((x.EventType == FileScanner.EDJournalScanner.JournalEvent.Resurrect) && (e.History.IndexOf(x) < 2))); SaveEvent(e.Data.Value<DateTime>("timestamp"), e.Data.Value<String>("StarSystem"), e.Data.Value<String>("StationName"), "", "", 0, 0, Program.CompanionIO.SGetCreditsTotal(), "Resurrect", String.Format("option: {0}\ncost: {1} cr.\nbankrupt = {2}", resurrectEvent.Data.Value<String>("Option"), resurrectEvent.Data.Value<Int32>("Cost"), resurrectEvent.Data.Value<Boolean>("Bankrupt") ? "yes" : "no")); } break; case FileScanner.EDJournalScanner.JournalEvent.FSDJump: if(Program.DBCon.getIniValue<Boolean>(IBESettingsView.DB_GROUPNAME, "AutoAdd_JumpedTo", true.ToString(), false)) { SaveEvent(e.Data.Value<DateTime>("timestamp"), e.Data.Value<String>("StarSystem"), "", "", "", 0, 0, Program.CompanionIO.SGetCreditsTotal(), "Jumped To", "", e.Data.Value<Double>("JumpDist")); } break; case FileScanner.EDJournalScanner.JournalEvent.Died: String killInfo= ""; IBECompanion.CompanionConverter cmpConverter = new IBECompanion.CompanionConverter(); if(e.Data.Value<String>("KillerName") != null) { killInfo = String.Format("killed by \t: {0}\n" + "ship \t: {1}\n" + "rank \t: {2}", (e.Data.Value<String>("KillerName_Localised") != null) ? e.Data.Value<String>("KillerName_Localised") : e.Data.Value<String>("KillerName"), cmpConverter.GetShipNameFromSymbol(Program.Data.BaseData.tbshipyardbase, e.Data.Value<String>("KillerShip")), e.Data.Value<String>("KillerRank")); } else if(e.Data.Value<Object>("Killers") != null) { killInfo = "killed by wing:\n"; Int32 counter = 1; foreach (JToken killerData in e.Data.SelectTokens("Killers.[*]")) { killInfo += String.Format("{4}{3}. \t{0}, \t{1}, \t{2}", killerData.Value<String>("Name"), cmpConverter.GetShipNameFromSymbol(Program.Data.BaseData.tbshipyardbase, killerData.Value<String>("Ship")), killerData.Value<String>("Rank"), counter, counter > 1 ? "\n":""); counter++; } } SaveEvent(e.Data.Value<DateTime>("timestamp"), Program.actualCondition.System, "", "", "", 0, 0, Program.CompanionIO.SGetCreditsTotal(), "Died", killInfo); break; case FileScanner.EDJournalScanner.JournalEvent.Resurrect: break; case FileScanner.EDJournalScanner.JournalEvent.Touchdown: if(Program.DBCon.getIniValue<Boolean>(IBESettingsView.DB_GROUPNAME, "AutoAdd_TouchDown", true.ToString(), false)) { SaveEvent(e.Data.Value<DateTime>("timestamp"), Program.actualCondition.System, "", "", "", 0, 0, Program.CompanionIO.SGetCreditsTotal(), "Touchdown", String.Format("landed on {0}{1}\n" + "long: {3}\n" + "lat : {2}", Program.actualCondition.Body, String.IsNullOrWhiteSpace(Program.actualCondition.BodyType) ? "" : " (" + Program.actualCondition.BodyType + ")", e.Data.Value<Double>("Latitude"), e.Data.Value<Double>("Longitude"))); } break; case FileScanner.EDJournalScanner.JournalEvent.Liftoff: if(Program.DBCon.getIniValue<Boolean>(IBESettingsView.DB_GROUPNAME, "AutoAdd_Liftoff", true.ToString(), false)) { SaveEvent(e.Data.Value<DateTime>("timestamp"), Program.actualCondition.System, "", "", "", 0, 0, Program.CompanionIO.SGetCreditsTotal(), "Liftoff", String.Format("liftoff from {0}{1}\n" + "long: {3}\n" + "lat : {2}", Program.actualCondition.Body, String.IsNullOrWhiteSpace(Program.actualCondition.BodyType) ? "" : " (" + Program.actualCondition.BodyType + ")", e.Data.Value<Double>("Latitude"), e.Data.Value<Double>("Longitude"))); } break; case FileScanner.EDJournalScanner.JournalEvent.Scan: if(Program.DBCon.getIniValue<Boolean>(IBESettingsView.DB_GROUPNAME, "AutoAdd_Scan", true.ToString(), false)) { TextHelper txtHelp = new TextHelper(); Font usedFont = m_GUI.dgvCommandersLog.Columns["notes"].DefaultCellStyle.Font != null ? m_GUI.dgvCommandersLog.Columns["notes"].DefaultCellStyle.Font : m_GUI.dgvCommandersLog.DefaultCellStyle.Font ; System.Text.StringBuilder data = new System.Text.StringBuilder(); System.Text.StringBuilder rings = new System.Text.StringBuilder(); Int32 fullLength = 170; if(e.Data.Value<Object>("StarType") != null) { data.AppendLine(String.Format("{0} : {1} (Star)", txtHelp.FixedLength("Name", usedFont, fullLength), e.Data.Value<String>("BodyName"))); data.AppendLine(String.Format("{0} : {1}", txtHelp.FixedLength("Type", usedFont, fullLength), e.Data.Value<String>("StarType"))); data.AppendLine(String.Format("{0} : {1:N1} ls", txtHelp.FixedLength("Distance", usedFont, fullLength), e.Data.Value<Double>("DistanceFromArrivalLS"))); if(!String.IsNullOrWhiteSpace(e.Data.Value<String>("Radius"))) data.AppendLine(String.Format("{0} : {1:N1} km", txtHelp.FixedLength("Radius", usedFont, fullLength), e.Data.Value<Double>("Radius"))); if(!String.IsNullOrWhiteSpace(e.Data.Value<String>("StellarMass"))) data.AppendLine(String.Format("{0} : {1:N1} stellar masses", txtHelp.FixedLength("Mass", usedFont, fullLength), e.Data.Value<Double>("StellarMass"))); if(!String.IsNullOrWhiteSpace(e.Data.Value<String>("Age_MY"))) data.AppendLine(String.Format("{0} : {1:N1} my", txtHelp.FixedLength("Age", usedFont, fullLength), e.Data.Value<Double>("Age_MY"))); if(!String.IsNullOrWhiteSpace(e.Data.Value<String>("SurfaceTemperature"))) data.AppendLine(String.Format("{0} : {1:N1}°K ( {2:N1}°C )", txtHelp.FixedLength("Temp.", usedFont, fullLength), e.Data.Value<Double>("SurfaceTemperature"), e.Data.Value<Double>("SurfaceTemperature") - 273.15)); } else { System.Text.StringBuilder materials = new System.Text.StringBuilder(); data.AppendLine(String.Format("{0} : {1} (Planet/Moon)", txtHelp.FixedLength("Name", usedFont, fullLength), e.Data.Value<String>("BodyName"))); data.AppendLine(String.Format("{0} : {1:N1} ls", txtHelp.FixedLength("Distance", usedFont, fullLength), e.Data.Value<Double>("DistanceFromArrivalLS"))); if(!String.IsNullOrWhiteSpace(e.Data.Value<String>("TerraformState"))) data.AppendLine(String.Format("{0} : {1}", txtHelp.FixedLength("Terraform", usedFont, fullLength), e.Data.Value<String>("TerraformState"))); if(!String.IsNullOrWhiteSpace(e.Data.Value<String>("PlanetClass"))) data.AppendLine(String.Format("{0} : {1}", txtHelp.FixedLength("Class", usedFont, fullLength), e.Data.Value<String>("PlanetClass"))); if(!String.IsNullOrWhiteSpace(e.Data.Value<String>("Atmosphere"))) data.AppendLine(String.Format("{0} : {1}", txtHelp.FixedLength("Atmosphere", usedFont, fullLength), e.Data.Value<String>("Atmosphere"))); if(!String.IsNullOrWhiteSpace(e.Data.Value<String>("Volcanism"))) data.AppendLine(String.Format("{0} : {1}", txtHelp.FixedLength("Volcanism", usedFont, fullLength), e.Data.Value<String>("Volcanism"))); if(!String.IsNullOrWhiteSpace(e.Data.Value<String>("SurfaceGravity"))) data.AppendLine(String.Format("{0} : {1:N2} g", txtHelp.FixedLength("Gravity", usedFont, fullLength), e.Data.Value<Double>("SurfaceGravity")/10.0)); if(!String.IsNullOrWhiteSpace(e.Data.Value<String>("SurfaceTemperature"))) data.AppendLine(String.Format("{0} : {1:N1}°K ( {2:N1}°C )", txtHelp.FixedLength("Temp.", usedFont, fullLength), e.Data.Value<Double>("SurfaceTemperature"), e.Data.Value<Double>("SurfaceTemperature") - 273.15)); if(!String.IsNullOrWhiteSpace(e.Data.Value<String>("SurfacePressure"))) data.AppendLine(String.Format("{0} : {1:N1} atm", txtHelp.FixedLength("Pressure", usedFont, fullLength), e.Data.Value<Double>("SurfacePressure") / 100000.0)); if((!String.IsNullOrWhiteSpace(e.Data.Value<String>("Landable"))) && e.Data.Value<Boolean>("Landable")) data.AppendLine(String.Format("{0} : {1}", txtHelp.FixedLength("Landable", usedFont, fullLength), e.Data.Value<Boolean>("Landable") ? "yes" : "no")); if (e.Data.Value<Object>("Materials") != null) { TextInfo textInfo = new CultureInfo("en-US", false).TextInfo; foreach (JProperty material in e.Data.SelectToken("Materials")) { if(materials.Length == 0) materials.AppendFormat(String.Format("\n{0} : ", txtHelp.FixedLength("Materials", usedFont, fullLength))); else materials.AppendFormat(", "); materials.AppendFormat("{0} : {1:N1}%", textInfo.ToTitleCase(material.Name), (Double)material.Value); } data.AppendLine(materials.ToString()); } } if(e.Data.Value<Object>("Rings") != null) { foreach (JObject ring in e.Data.SelectTokens("Rings.[*]")) { String classname = ring.Value<String>("RingClass").Replace("eRingClass_","") .Replace("Rich"," Rich") .Replace("Metal","Metall"); if(rings.Length == 0) rings.AppendLine(String.Format("\n{0} • {1} (Type: {2})", txtHelp.FixedLength("Belts", usedFont, 100), ring.Value<String>("Name"), classname)); else rings.AppendLine(String.Format("{0} • {1} (Type: {2})", txtHelp.FixedLength("", usedFont, 100), ring.Value<String>("Name"), classname)); } data.Append(rings); } SaveEvent(e.Data.Value<DateTime>("timestamp"), Program.actualCondition.System, "", "", "", 0, 0, Program.CompanionIO.SGetCreditsTotal(), "Scan", data.ToString()); } break; } } catch (Exception ex) { CErr.processError(ex, "Error while processing the JournalEventRecieved-event"); } }