// Called on a New Entry, by EDDiscoveryController:NewEntry, to add an journal entry in public HistoryEntry AddJournalEntry(JournalEntry je, Action <string> logerror) // always return he { HistoryEntry prev = GetLast; bool journalupdate = false; HistoryEntry he = HistoryEntry.FromJournalEntry(je, prev, true, out journalupdate); if (journalupdate) { JournalFSDJump jfsd = je as JournalFSDJump; if (jfsd != null) { JournalEntry.UpdateEDSMIDPosJump(jfsd.Id, he.System, !jfsd.HasCoordinate && he.System.HasCoordinate, jfsd.JumpDist); } } using (SQLiteConnectionUser conn = new SQLiteConnectionUser()) { he.ProcessWithUserDb(je, prev, this, conn); // let some processes which need the user db to work cashledger.Process(je, conn); he.Credits = cashledger.CashTotal; Tuple <ShipInformation, ModulesInStore> ret = shipinformationlist.Process(je, conn); he.ShipInformation = ret.Item1; he.StoredModules = ret.Item2; he.MissionList = missionlistaccumulator.Process(je, he.System, he.WhereAmI, conn); } historylist.Add(he); if (je.EventTypeID == JournalTypeEnum.Scan) { JournalScan js = je as JournalScan; JournalLocOrJump jl; HistoryEntry jlhe; if (!starscan.AddScanToBestSystem(js, Count - 1, EntryOrder, out jlhe, out jl)) { // Ignore scans where the system name has been changed // Also ignore belt clusters if (jl == null || (jl.StarSystem.Equals(jlhe.System.name, StringComparison.InvariantCultureIgnoreCase) && !js.BodyDesignation.ToLowerInvariant().Contains(" belt cluster "))) { logerror("Cannot add scan to system - alert the EDDiscovery developers using either discord or Github (see help)" + Environment.NewLine + "Scan object " + js.BodyName + " in " + he.System.name); } } } return(he); }
public void FillEDSM(HistoryEntry syspos, SystemClassDB edsmsys = null, bool reload = false, SQLiteConnectionUser uconn = null) // call to fill in ESDM data for entry, and also fills in all others pointing to the system object { if (syspos.System.status == SystemStatusEnum.EDSC || (!reload && syspos.System.id_edsm == -1)) // if set already, or we tried and failed.. { return; } List <HistoryEntry> alsomatching = new List <HistoryEntry>(); foreach (HistoryEntry he in historylist) // list of systems in historylist using the same system object { if (Object.ReferenceEquals(he.System, syspos.System)) { alsomatching.Add(he); } } if (edsmsys == null) // if we found it externally, do not find again { edsmsys = FindEDSM(syspos, reload: reload); } if (edsmsys != null) { foreach (HistoryEntry he in alsomatching) // list of systems in historylist using the same system object { bool updateedsmid = he.System.id_edsm <= 0; bool updatepos = (he.EntryType == JournalTypeEnum.FSDJump || he.EntryType == JournalTypeEnum.Location) && !syspos.System.HasCoordinate && edsmsys.HasCoordinate; if (updatepos || updateedsmid) { JournalEntry.UpdateEDSMIDPosJump(he.Journalid, edsmsys, updatepos, -1, uconn); // update pos and edsmid, jdist not updated } he.System = edsmsys; } } else { foreach (HistoryEntry he in alsomatching) // list of systems in historylist using the same system object { he.System.id_edsm = -1; // can't do it } } }
public static HistoryList LoadHistory(EDJournalClass journalmonitor, Func <bool> cancelRequested, Action <int, string> reportProgress, string NetLogPath = null, bool ForceNetLogReload = false, bool ForceJournalReload = false, int CurrentCommander = Int32.MinValue, bool Keepuievents = true) { HistoryList hist = new HistoryList(); EDCommander cmdr = null; if (CurrentCommander >= 0) { cmdr = EDCommander.GetCommander(CurrentCommander); journalmonitor.ParseJournalFiles(() => cancelRequested(), (p, s) => reportProgress(p, s), forceReload: ForceJournalReload); // Parse files stop monitor.. if (NetLogPath != null) { string errstr = null; NetLogClass.ParseFiles(NetLogPath, out errstr, EliteConfigInstance.InstanceConfig.DefaultMapColour, () => cancelRequested(), (p, s) => reportProgress(p, s), ForceNetLogReload, currentcmdrid: CurrentCommander); } } reportProgress(-1, "Resolving systems"); List <JournalEntry> jlist = JournalEntry.GetAll(CurrentCommander).OrderBy(x => x.EventTimeUTC).ThenBy(x => x.Id).ToList(); List <Tuple <JournalEntry, HistoryEntry> > jlistUpdated = new List <Tuple <JournalEntry, HistoryEntry> >(); using (SQLiteConnectionSystem conn = new SQLiteConnectionSystem()) { HistoryEntry prev = null; JournalEntry jprev = null; foreach (JournalEntry je in jlist) { if (MergeEntries(jprev, je)) // if we merge.. we may have updated info, so reprint. { jprev.FillInformation(out prev.EventSummary, out prev.EventDescription, out prev.EventDetailedInfo); // need to keep this up to date.. continue; } if (je.IsUIEvent && !Keepuievents) // filter out any UI events { //System.Diagnostics.Debug.WriteLine("**** Filter out " + je.EventTypeStr + " on " + je.EventTimeLocal.ToString()); continue; } bool journalupdate = false; HistoryEntry he = HistoryEntry.FromJournalEntry(je, prev, out journalupdate, conn, cmdr); prev = he; jprev = je; hist.historylist.Add(he); if (journalupdate) { jlistUpdated.Add(new Tuple <JournalEntry, HistoryEntry>(je, he)); Debug.WriteLine("Queued update requested {0} {1}", he.System.EDSMID, he.System.Name); } } } if (jlistUpdated.Count > 0) { reportProgress(-1, "Updating journal entries"); using (SQLiteConnectionUser conn = new SQLiteConnectionUser(utc: true)) { using (DbTransaction txn = conn.BeginTransaction()) { foreach (Tuple <JournalEntry, HistoryEntry> jehe in jlistUpdated) { JournalEntry je = jehe.Item1; HistoryEntry he = jehe.Item2; double dist = (je is JournalFSDJump) ? (je as JournalFSDJump).JumpDist : 0; bool updatecoord = (je is JournalLocOrJump) ? (!(je as JournalLocOrJump).HasCoordinate && he.System.HasCoordinate) : false; Debug.WriteLine("Push update {0} {1} to JE {2} HE {3}", he.System.EDSMID, he.System.Name, je.Id, he.Indexno); JournalEntry.UpdateEDSMIDPosJump(je.Id, he.System, updatecoord, dist, conn, txn); } txn.Commit(); } } } // now database has been updated due to initial fill, now fill in stuff which needs the user database hist.CommanderId = CurrentCommander; hist.ProcessUserHistoryListEntries(h => h.ToList()); // here, we update the DBs in HistoryEntry and any global DBs in historylist return(hist); }
private void FillInSystemFromDBInt(HistoryEntry syspos, ISystem edsmsys, SQLiteConnectionUser uconn, DbTransaction utn) // call to fill in ESDM data for entry, and also fills in all others pointing to the system object { List <HistoryEntry> alsomatching = new List <HistoryEntry>(); foreach (HistoryEntry he in historylist) // list of systems in historylist using the same system object { if (Object.ReferenceEquals(he.System, syspos.System)) { alsomatching.Add(he); } } if (edsmsys != null) { ISystem oldsys = syspos.System; bool updateedsmid = oldsys.EDSMID <= 0 && edsmsys.EDSMID > 0; bool updatesyspos = !oldsys.HasCoordinate && edsmsys.HasCoordinate; bool updatename = oldsys.HasCoordinate && edsmsys.HasCoordinate && oldsys.Distance(edsmsys) < 0.1 && !String.Equals(edsmsys.Name, oldsys.Name, StringComparison.InvariantCultureIgnoreCase) && edsmsys.UpdateDate > syspos.EventTimeUTC; ISystem newsys = new SystemClass { Name = updatename ? edsmsys.Name : oldsys.Name, X = updatesyspos ? edsmsys.X : oldsys.X, Y = updatesyspos ? edsmsys.Y : oldsys.Y, Z = updatesyspos ? edsmsys.Z : oldsys.Z, EDSMID = updateedsmid ? edsmsys.EDSMID : oldsys.EDSMID, SystemAddress = oldsys.SystemAddress ?? edsmsys.SystemAddress, Allegiance = oldsys.Allegiance == EDAllegiance.Unknown ? edsmsys.Allegiance : oldsys.Allegiance, Government = oldsys.Government == EDGovernment.Unknown ? edsmsys.Government : oldsys.Government, Population = oldsys.Government == EDGovernment.Unknown ? edsmsys.Population : oldsys.Population, PrimaryEconomy = oldsys.PrimaryEconomy == EDEconomy.Unknown ? edsmsys.PrimaryEconomy : oldsys.PrimaryEconomy, Security = oldsys.Security == EDSecurity.Unknown ? edsmsys.Security : oldsys.Security, State = oldsys.State == EDState.Unknown ? edsmsys.State : oldsys.State, Faction = oldsys.Faction ?? edsmsys.Faction, CommanderCreate = edsmsys.CommanderCreate, CommanderUpdate = edsmsys.CommanderUpdate, CreateDate = edsmsys.CreateDate, EDDBID = edsmsys.EDDBID, EDDBUpdatedAt = edsmsys.EDDBUpdatedAt, GridID = edsmsys.GridID, NeedsPermit = edsmsys.NeedsPermit, RandomID = edsmsys.RandomID, UpdateDate = edsmsys.UpdateDate, SystemNote = edsmsys.SystemNote, status = SystemStatusEnum.EDSM }; foreach (HistoryEntry he in alsomatching) // list of systems in historylist using the same system object { bool updatepos = (he.EntryType == JournalTypeEnum.FSDJump || he.EntryType == JournalTypeEnum.Location) && updatesyspos; if (updatepos || updateedsmid) { JournalEntry.UpdateEDSMIDPosJump(he.Journalid, edsmsys, updatepos, -1, uconn, utn); // update pos and edsmid, jdist not updated } he.System = newsys; } } else { foreach (HistoryEntry he in alsomatching) // list of systems in historylist using the same system object { he.System.EDSMID = -1; // can't do it } } }
public static HistoryList LoadHistory(EDJournalClass journalmonitor, Func <bool> cancelRequested, Action <int, string> reportProgress, string NetLogPath = null, bool ForceNetLogReload = false, bool ForceJournalReload = false, bool CheckEdsm = false, int CurrentCommander = Int32.MinValue) { HistoryList hist = new HistoryList(); EDCommander cmdr = null; if (CurrentCommander >= 0) { cmdr = EDCommander.GetCommander(CurrentCommander); journalmonitor.ParseJournalFiles(() => cancelRequested(), (p, s) => reportProgress(p, s), forceReload: ForceJournalReload); // Parse files stop monitor.. if (NetLogPath != null) { string errstr = null; NetLogClass.ParseFiles(NetLogPath, out errstr, EliteConfigInstance.InstanceConfig.DefaultMapColour, () => cancelRequested(), (p, s) => reportProgress(p, s), ForceNetLogReload, currentcmdrid: CurrentCommander); } } reportProgress(-1, "Resolving systems"); List <JournalEntry> jlist = JournalEntry.GetAll(CurrentCommander).OrderBy(x => x.EventTimeUTC).ThenBy(x => x.Id).ToList(); List <Tuple <JournalEntry, HistoryEntry> > jlistUpdated = new List <Tuple <JournalEntry, HistoryEntry> >(); using (SQLiteConnectionSystem conn = new SQLiteConnectionSystem()) { HistoryEntry prev = null; foreach (JournalEntry inje in jlist) { foreach (JournalEntry je in hist.ProcessJournalEntry(inje)) { bool journalupdate = false; HistoryEntry he = HistoryEntry.FromJournalEntry(je, prev, CheckEdsm, out journalupdate, conn, cmdr); prev = he; hist.historylist.Add(he); if (journalupdate) { jlistUpdated.Add(new Tuple <JournalEntry, HistoryEntry>(je, he)); } } } } if (jlistUpdated.Count > 0) { reportProgress(-1, "Updating journal entries"); using (SQLiteConnectionUser conn = new SQLiteConnectionUser(utc: true)) { using (DbTransaction txn = conn.BeginTransaction()) { foreach (Tuple <JournalEntry, HistoryEntry> jehe in jlistUpdated) { JournalEntry je = jehe.Item1; HistoryEntry he = jehe.Item2; JournalFSDJump jfsd = je as JournalFSDJump; if (jfsd != null) { JournalEntry.UpdateEDSMIDPosJump(jfsd.Id, he.System, !jfsd.HasCoordinate && he.System.HasCoordinate, jfsd.JumpDist, conn, txn); } } txn.Commit(); } } } // now database has been updated due to initial fill, now fill in stuff which needs the user database hist.CommanderId = CurrentCommander; hist.ProcessUserHistoryListEntries(h => h.ToList()); // here, we update the DBs in HistoryEntry and any global DBs in historylist hist.SendEDSMStatusInfo(hist.GetLast, true); return(hist); }