Exemplo n.º 1
0
        public static void TestJournal()
        {
            foreach (string s in Enum.GetNames(typeof(EliteDangerousCore.JournalTypeEnum)))
            //string s = "EDDItemSet";
            {
                string json = "{ \"timestamp\":\"2017-04-05T11:16:19Z\", \"event\":\"" + s + "\" }";

                System.Diagnostics.Debug.WriteLine("Event " + s + ":");

                EliteDangerousCore.JournalEntry j = EliteDangerousCore.JournalEntry.CreateJournalEntry(json);

                Debug.Assert(j.Icon != null);

                string summary, info, detailed;
                j.FillInformation(out summary, out info, out detailed);

                Conditions.ConditionVariables vars = new Conditions.ConditionVariables();
                vars.AddPropertiesFieldsOfClass(j, "EventClass_", new Type[] { typeof(System.Drawing.Bitmap), typeof(Newtonsoft.Json.Linq.JObject) }, 5);      //depth seems good enough

                int n = 0;
                foreach (string cv in vars.NameList)
                {
                    if (n++ >= 1)
                    {
                        System.Diagnostics.Debug.Write(",");
                    }

                    System.Diagnostics.Debug.Write(cv);
                }

                System.Diagnostics.Debug.WriteLine("");
            }
        }
Exemplo n.º 2
0
        private void buttonExt1_Click(object sender, EventArgs e)
        {
            System.IO.StreamReader filejr = new System.IO.StreamReader(textBoxFile.Text);
            string   line;
            string   system = "";
            StarScan ss     = new StarScan();

            Dictionary <string, string> items = new Dictionary <string, string>();

            while ((line = filejr.ReadLine()) != null)
            {
                if (line.Equals("END"))
                {
                    break;
                }
                //System.Diagnostics.Trace.WriteLine(line);

                if (line.Length > 0)
                {
                    JObject jo = (JObject)JObject.Parse(line);

                    //JSONPrettyPrint jpp = new JSONPrettyPrint(EliteDangerous.JournalFieldNaming.StandardConverters(), "event;timestamp", "_Localised", (string)jo["event"]);
                    //string s = jpp.PrettyPrintStr(line, 80);
                    //System.Diagnostics.Trace.WriteLine(s);

                    EliteDangerousCore.JournalEntry je = EliteDangerousCore.JournalEntry.CreateJournalEntry(line);
                    //System.Diagnostics.Trace.WriteLine(je.EventTypeStr);

                    if (je.EventTypeID == EliteDangerousCore.JournalTypeEnum.Location)
                    {
                        EliteDangerousCore.JournalEvents.JournalLocOrJump jl = je as EliteDangerousCore.JournalEvents.JournalLocOrJump;
                        system = jl.StarSystem;
                    }
                    else if (je.EventTypeID == EliteDangerousCore.JournalTypeEnum.FSDJump)
                    {
                        EliteDangerousCore.JournalEvents.JournalFSDJump jfsd = je as EliteDangerousCore.JournalEvents.JournalFSDJump;
                        system = jfsd.StarSystem;
                    }
                    else if (je.EventTypeID == EliteDangerousCore.JournalTypeEnum.Scan)
                    {
                        //ss.Process(je as EliteDangerousCore.JournalEvents.JournalScan, new EliteDangerousCore.SystemClass(system));
                    }
                }
            }
        }
Exemplo n.º 3
0
        public static HistoryEntryStatus Update(HistoryEntryStatus prev, JournalEntry je, string curStarSystem)
        {
            if (prev == null)
            {
                prev = new HistoryEntryStatus();
            }

            switch (je.EventTypeID)
            {
            case JournalTypeEnum.Location:
                JournalLocation jloc = je as JournalLocation;
                TravelStateType t    = jloc.Docked ? TravelStateType.Docked : (jloc.Latitude.HasValue ? TravelStateType.Landed : TravelStateType.NormalSpace);

                return(new HistoryEntryStatus(prev)         // Bodyapproach copy over we should be in the same state as last..
                {
                    TravelState = t,
                    MarketId = jloc.MarketID,
                    BodyID = jloc.BodyID,
                    BodyType = jloc.BodyType,
                    BodyName = jloc.Body,
                    Wanted = jloc.Wanted,
                    StationName = jloc.StationName.Alt(null),          // if empty string, set to null
                    StationType = jloc.StationType.Alt(null),
                    StationFaction = jloc.StationFaction,              // may be null
                });

            case JournalTypeEnum.CarrierJump:
                var jcj = (je as JournalCarrierJump);
                return(new HistoryEntryStatus(prev)         // we are docked on a carrier
                {
                    TravelState = TravelStateType.Docked,
                    MarketId = jcj.MarketID,
                    BodyID = jcj.BodyID,
                    BodyType = jcj.BodyType,
                    BodyName = jcj.Body,
                    Wanted = jcj.Wanted,
                    StationName = jcj.StationName.Alt(null),           // if empty string, set to null
                    StationType = jcj.StationType.Alt(null),
                });

            case JournalTypeEnum.FSDJump:
                var jfsd = (je as JournalFSDJump);
                return(new HistoryEntryStatus(prev)
                {
                    TravelState = TravelStateType.Hyperspace,
                    MarketId = null,
                    BodyID = -1,
                    BodyType = "Star",
                    BodyName = jfsd.StarSystem,
                    Wanted = jfsd.Wanted,
                    StationName = null,
                    StationType = null,
                    BodyApproached = false,
                    StationFaction = null,     // to ensure
                });

            case JournalTypeEnum.LoadGame:
                JournalLoadGame jlg        = je as JournalLoadGame;
                bool            isbuggy    = ShipModuleData.IsSRV(jlg.ShipFD);
                string          shiptype   = isbuggy ? prev.ShipType : jlg.Ship;
                string          shiptypefd = isbuggy ? prev.ShipTypeFD : jlg.ShipFD;
                int             shipid     = isbuggy ? prev.ShipID : jlg.ShipId;

                return(new HistoryEntryStatus(prev)  // Bodyapproach copy over we should be in the same state as last..
                {
                    OnCrewWithCaptain = null,        // can't be in a crew at this point
                    GameMode = jlg.GameMode,         // set game mode
                    Group = jlg.Group,               // and group, may be empty
                    TravelState = (jlg.StartLanded || isbuggy) ? TravelStateType.Landed : prev.TravelState,
                    ShipType = shiptype,
                    ShipID = shipid,
                    ShipTypeFD = shiptypefd,
                    StationFaction = null,     // to ensure
                });

            case JournalTypeEnum.Docked:
                JournalDocked jdocked = (JournalDocked)je;
                //System.Diagnostics.Debug.WriteLine("{0} Station {1} {2}", jdocked.EventTimeUTC, jdocked.StationName, jdocked.Faction);
                return(new HistoryEntryStatus(prev)
                {
                    TravelState = TravelStateType.Docked,
                    MarketId = jdocked.MarketID,
                    Wanted = jdocked.Wanted,
                    StationName = jdocked.StationName,
                    StationType = jdocked.StationType,
                    StationFaction = jdocked.Faction,
                });

            case JournalTypeEnum.Undocked:
                return(new HistoryEntryStatus(prev)
                {
                    TravelState = TravelStateType.NormalSpace,
                    MarketId = null,
                    StationName = null,
                    StationType = null,
                    StationFaction = null,     // to clear
                });

            case JournalTypeEnum.Touchdown:
                if (((JournalTouchdown)je).PlayerControlled == true)            // can get this when not player controlled
                {
                    return(new HistoryEntryStatus(prev)
                    {
                        TravelState = TravelStateType.Landed,
                    });
                }
                else
                {
                    return(prev);
                }

            case JournalTypeEnum.Liftoff:
                if (((JournalLiftoff)je).PlayerControlled == true)             // can get this when not player controlled
                {
                    return(new HistoryEntryStatus(prev)
                    {
                        TravelState = TravelStateType.NormalSpace,
                    });
                }
                else
                {
                    return(prev);
                }

            case JournalTypeEnum.SupercruiseExit:
                JournalSupercruiseExit jsexit = (JournalSupercruiseExit)je;
                return(new HistoryEntryStatus(prev)
                {
                    TravelState = TravelStateType.NormalSpace,
                    BodyName = (prev.BodyApproached) ? prev.BodyName : jsexit.Body,
                    BodyType = (prev.BodyApproached) ? prev.BodyType : jsexit.BodyType,
                    BodyID = (prev.BodyApproached) ? prev.BodyID : jsexit.BodyID,
                });

            case JournalTypeEnum.SupercruiseEntry:
                return(new HistoryEntryStatus(prev)
                {
                    TravelState = TravelStateType.Hyperspace,
                    BodyName = !prev.BodyApproached ? curStarSystem : prev.BodyName,
                    BodyType = !prev.BodyApproached ? "Star" : prev.BodyType,
                    BodyID = !prev.BodyApproached ? -1 : prev.BodyID,
                });

            case JournalTypeEnum.ApproachBody:
                JournalApproachBody jappbody = (JournalApproachBody)je;
                return(new HistoryEntryStatus(prev)
                {
                    BodyApproached = true,
                    BodyType = jappbody.BodyType,
                    BodyName = jappbody.Body,
                    BodyID = jappbody.BodyID,
                });

            case JournalTypeEnum.ApproachSettlement:
                JournalApproachSettlement jappsettlement = (JournalApproachSettlement)je;
                return(new HistoryEntryStatus(prev)
                {
                    BodyApproached = true,
                    BodyType = jappsettlement.BodyType,
                    BodyName = jappsettlement.BodyName,
                    BodyID = jappsettlement.BodyID,
                });

            case JournalTypeEnum.LeaveBody:
                JournalLeaveBody jlbody = (JournalLeaveBody)je;
                return(new HistoryEntryStatus(prev)
                {
                    BodyApproached = false,
                    BodyType = "Star",
                    BodyName = curStarSystem,
                    BodyID = -1,
                });

            case JournalTypeEnum.StartJump:
                if (prev.TravelState != TravelStateType.Hyperspace)     // checking we are into hyperspace, we could already be if in a series of jumps
                {
                    return(new HistoryEntryStatus(prev)
                    {
                        TravelState = TravelStateType.Hyperspace,
                    });
                }
                else
                {
                    return(prev);
                }

            case JournalTypeEnum.ShipyardBuy:
                return(new HistoryEntryStatus(prev)
                {
                    ShipID = -1,
                    ShipType = ((JournalShipyardBuy)je).ShipType      // BUY does not have ship id, but the new entry will that is written later - journals 8.34
                });

            case JournalTypeEnum.ShipyardNew:
                JournalShipyardNew jsnew = (JournalShipyardNew)je;
                return(new HistoryEntryStatus(prev)
                {
                    ShipID = jsnew.ShipId,
                    ShipType = jsnew.ShipType,
                    ShipTypeFD = jsnew.ShipFD,
                });

            case JournalTypeEnum.ShipyardSwap:
                JournalShipyardSwap jsswap = (JournalShipyardSwap)je;
                return(new HistoryEntryStatus(prev)
                {
                    ShipID = jsswap.ShipId,
                    ShipType = jsswap.ShipType,
                    ShipTypeFD = jsswap.ShipFD,
                });

            case JournalTypeEnum.JoinACrew:
                return(new HistoryEntryStatus(prev)
                {
                    OnCrewWithCaptain = ((JournalJoinACrew)je).Captain
                });

            case JournalTypeEnum.QuitACrew:
                return(new HistoryEntryStatus(prev)
                {
                    OnCrewWithCaptain = null
                });

            case JournalTypeEnum.Died:
                return(new HistoryEntryStatus(prev)
                {
                    BodyName = "Unknown",
                    BodyID = -1,
                    BodyType = "Unknown",
                    StationName = "Unknown",
                    StationType = "Unknown",
                    MarketId = null,
                    TravelState = TravelStateType.Docked,
                    OnCrewWithCaptain = null,
                    BodyApproached = false,         // we have to clear this, we can't tell if we are going back to another place..
                });

            case JournalTypeEnum.Loadout:
                var jloadout = (JournalLoadout)je;
                if (!ShipModuleData.IsSRV(jloadout.ShipFD))         // just double checking!
                {
                    return(new HistoryEntryStatus(prev)
                    {
                        ShipID = jloadout.ShipId,
                        ShipType = jloadout.Ship,
                        ShipTypeFD = jloadout.ShipFD,
                    });
                }
                else
                {
                    return(prev);
                }

            default:
                return(prev);
            }
        }
Exemplo n.º 4
0
        public void ProcessWithUserDb(JournalEntry je, HistoryEntry prev, HistoryList hl)      // called after above with a USER connection
        {
            MaterialCommodity = MaterialCommoditiesList.Process(je, prev?.MaterialCommodity);

            snc = SystemNoteClass.GetSystemNote(Journalid, IsFSDJump, System);       // may be null
        }
Exemplo n.º 5
0
        public void ProcessWithUserDb(JournalEntry je, HistoryEntry prev, HistoryList hl, SQLiteConnectionUser conn)      // called after above with a USER connection
        {
            materialscommodities = MaterialCommoditiesList.Process(je, prev?.materialscommodities, conn, EliteConfigInstance.InstanceConfig.ClearMaterials, EliteConfigInstance.InstanceConfig.ClearCommodities);

            snc = SystemNoteClass.GetSystemNote(Journalid, IsFSDJump, System);       // may be null
        }
Exemplo n.º 6
0
        public static HistoryEntry FromJournalEntry(JournalEntry je, HistoryEntry prev, out bool journalupdate, SQLiteConnectionSystem conn = null)
        {
            ISystem isys    = prev == null ? new SystemClass("Unknown") : prev.System;
            int     indexno = prev == null ? 1 : prev.Indexno + 1;

            journalupdate = false;

            if (je.EventTypeID == JournalTypeEnum.Location || je.EventTypeID == JournalTypeEnum.FSDJump)
            {
                JournalLocOrJump jl = je as JournalLocOrJump;

                ISystem newsys;

                if (jl != null && jl.HasCoordinate)       // LAZY LOAD IF it has a co-ord.. the front end will when it needs it
                {
                    newsys = new SystemClass(jl.StarSystem, jl.StarPos.X, jl.StarPos.Y, jl.StarPos.Z)
                    {
                        EDSMID         = jl.EdsmID < 0 ? 0 : jl.EdsmID, // pass across the EDSMID for the lazy load process.
                        Faction        = jl.Faction,
                        Government     = jl.EDGovernment,
                        PrimaryEconomy = jl.EDEconomy,
                        Security       = jl.EDSecurity,
                        Population     = jl.Population ?? 0,
                        State          = jl.EDState,
                        Allegiance     = jl.EDAllegiance,
                        UpdateDate     = jl.EventTimeUTC,
                        status         = SystemStatusEnum.EDDiscovery,
                        SystemAddress  = jl.SystemAddress,
                    };

                    // If it was a new system, pass the coords back to the StartJump
                    if (prev != null && prev.journalEntry is JournalStartJump)
                    {
                        prev.System = newsys;       // give the previous startjump our system..
                    }
                }
                else
                {
                    // NOTE Rob: 09-JAN-2018 I've removed the Jumpstart looking up a system by name since they were using up lots of lookup time during history reading.
                    // This is used for pre 2.2 systems without co-ords, which now should be limited.
                    // JumpStart still gets the system when the FSD loc is processed, see above.
                    // Jumpstart was also screwing about with the EDSM ID fill in which was broken.  This is now working again.

                    // Default one
                    newsys        = new SystemClass(jl.StarSystem);
                    newsys.EDSMID = je.EdsmID;

                    ISystem s = SystemCache.FindSystem(newsys, conn); // has no co-ord, did we find it?

                    if (s != null)                                    // found a system..
                    {
                        if (jl != null && jl.HasCoordinate)           // if journal Loc, and journal has a star position, use that instead of EDSM..
                        {
                            s.X = Math.Round(jl.StarPos.X * 32.0) / 32.0;
                            s.Y = Math.Round(jl.StarPos.Y * 32.0) / 32.0;
                            s.Z = Math.Round(jl.StarPos.Z * 32.0) / 32.0;
                        }

                        //Debug.WriteLine("HistoryList found system {0} {1}", s.id_edsm, s.name);
                        newsys = s;

                        if (jl != null && je.EdsmID <= 0 && newsys.EDSMID > 0) // only update on a JL..
                        {
                            journalupdate = true;
                            Debug.WriteLine("HE EDSM ID update requested {0} {1}", newsys.EDSMID, newsys.Name);
                        }
                    }
                    else
                    {
                        newsys.EDSMID = -1;        // mark as checked but not found
                    }
                }

                JournalFSDJump jfsd = je as JournalFSDJump;

                if (jfsd != null)
                {
                    if (jfsd.JumpDist <= 0 && isys.HasCoordinate && newsys.HasCoordinate) // if no JDist, its a really old entry, and if previous has a co-ord
                    {
                        jfsd.JumpDist = isys.Distance(newsys);                            // fill it out here

                        if (jfsd.JumpDist > 0)
                        {
                            journalupdate = true;
                            Debug.WriteLine("Je Jump distance update(3) requested {0} {1} {2}", newsys.EDSMID, newsys.Name, jfsd.JumpDist);
                        }
                    }
                }

                isys = newsys;
            }

            HistoryEntry he = new HistoryEntry
            {
                Indexno      = indexno,
                journalEntry = je,
                System       = isys,
                EntryStatus  = HistoryEntryStatus.Update(prev?.EntryStatus, je, isys.Name)
            };

            if (prev != null)
            {
                if (prev.StopMarker)                 // if we had a stop marker previously, means the next one needs to clear the counters
                {
                    he.isTravelling         = false; // still travelling if its a start marker
                    he.TravelledDistance    = 0;
                    he.TravelledSeconds     = new TimeSpan(0);
                    he.TravelledMissingjump = 0;
                    he.Travelledjumps       = 0;
                }
                else
                {
                    he.isTravelling         = prev.isTravelling;
                    he.TravelledDistance    = prev.TravelledDistance;
                    he.TravelledSeconds     = prev.TravelledSeconds;
                    he.TravelledMissingjump = prev.TravelledMissingjump;
                    he.Travelledjumps       = prev.Travelledjumps;
                }
            }

            if (he.StartMarker)           // start marker, start travelling
            {
                he.isTravelling = true;
            }

            if (he.isTravelling)
            {
                if (he.IsFSDJump && !he.MultiPlayer)   // if jump, and not multiplayer..
                {
                    double dist = ((JournalFSDJump)je).JumpDist;
                    if (dist <= 0)
                    {
                        he.TravelledMissingjump++;
                    }
                    else
                    {
                        he.TravelledDistance += dist;
                        he.Travelledjumps++;
                    }
                }

                if (prev != null)
                {
                    TimeSpan diff = he.EventTimeUTC.Subtract(prev.EventTimeUTC);

                    if (he.EntryType != JournalTypeEnum.LoadGame && diff < new TimeSpan(2, 0, 0))   // time between last entry and load game is not real time
                    {
                        he.TravelledSeconds += diff;
                    }
                }
            }

            return(he);
        }
Exemplo n.º 7
0
 static public bool IsUIEventType(JournalEntry j)
 {
     return(j is JournalMusic);
 }
        // given a list of files to reparse, read them and store to db or fire them back (and set firebacklastn to make it work)

        public void ProcessDetectedNewFiles(List <EDJournalReader> readersToUpdate, Action <int, string> updateProgress,
                                            Action <JournalEntry, int, int, int, int> fireback = null, int firebacklastn = 0)
        {
            for (int i = 0; i < readersToUpdate.Count; i++)
            {
                EDJournalReader reader = readersToUpdate[i];

                List <JournalEntry> entries  = new List <JournalEntry>();
                List <UIEvent>      uievents = new List <UIEvent>();
                bool readanything            = reader.ReadJournal(entries, uievents, historyrefreshparsing: true); // this may create new commanders, and may write to the TLU

                if (fireback != null)
                {
                    if (readanything)               // need to update TLU pos if read anything
                    {
                        reader.TravelLogUnit.Update();
                    }

                    if (i >= readersToUpdate.Count - firebacklastn) // if within fireback window
                    {
                        for (int e = 0; e < entries.Count; e++)
                        {
                            //System.Diagnostics.Debug.WriteLine("Fire {0} {1} {2} {3} {4} {5}", entries[e].CommanderId, i, readersToUpdate.Count, e, entries.Count, entries[e].EventTypeStr );
                            fireback(entries[e], i, readersToUpdate.Count, e, entries.Count);
                        }
                    }
                }
                else
                {
                    UserDatabase.Instance.ExecuteWithDatabase(cn =>
                    {
                        // only lookup TLUs if there is actually anything to compare against
                        ILookup <DateTime, JournalEntry> existing = entries.Count > 0 ? JournalEntry.GetAllByTLU(reader.ID, cn.Connection).ToLookup(e => e.EventTimeUTC) : null;

                        //System.Diagnostics.Trace.WriteLine(BaseUtils.AppTicks.TickCountLap("PJF"), i + " into db");

                        using (DbTransaction tn = cn.Connection.BeginTransaction())
                        {
                            foreach (JournalEntry jre in entries)
                            {
                                //System.Diagnostics.Trace.WriteLine(string.Format("--- Check {0} {1} Existing {2} : {3}", jre.EventTimeUTC, jre.EventTypeStr, existing[jre.EventTimeUTC].Count(), jre.GetJson().ToString()));

                                if (!existing[jre.EventTimeUTC].Any(e => JournalEntry.AreSameEntry(jre, e, cn.Connection, ent1jo: jre.GetJson(cn.Connection, tn))))
                                {
                                    //foreach (var x in existing[jre.EventTimeUTC]) { System.Diagnostics.Trace.WriteLine(string.Format(" passed vs {0} Deepequals {1}", x.GetJson().ToString(), x.GetJson().DeepEquals(jre.GetJson()))); }

                                    BaseUtils.JSON.JObject jo = jre.GetJson(cn.Connection, tn);
                                    jre.Add(jo, cn.Connection, tn);

                                    //System.Diagnostics.Trace.WriteLine(string.Format("Write Journal to db {0} {1}", jre.EventTimeUTC, jre.EventTypeStr));
                                }
                                else
                                {
                                    //System.Diagnostics.Trace.WriteLine(string.Format("Duplicate Journal to db {0} {1}", jre.EventTimeUTC, jre.EventTypeStr));
                                }
                            }

                            if (readanything)
                            {
                                reader.TravelLogUnit.Update(cn.Connection, tn);
                            }

                            tn.Commit();
                        }
                    });
                }

                updateProgress((i + 1) * 100 / readersToUpdate.Count, reader.FullName);

                lastnfi = reader;
            }

            updateProgress(-1, "");
        }
Exemplo n.º 9
0
        // inhistoryrefreshparse = means reading history in batch mode
        // returns null if journal line is bad or its a repeat.. It does not throw
        private JournalEntry ProcessLine(string line, bool inhistoryrefreshparse)
        {
            //   System.Diagnostics.Debug.WriteLine("Line in '" + line + "'");
            int cmdrid = TravelLogUnit.CommanderId.HasValue  ? TravelLogUnit.CommanderId.Value  : -2; //-1 is hidden, -2 is never shown

            if (line.Length == 0)
            {
                return(null);
            }

            JObject jo = JObject.Parse(line, JToken.ParseOptions.AllowTrailingCommas | JToken.ParseOptions.CheckEOL); // parse, null if failed

            if (jo == null)                                                                                           // decode failed, gently return null
            {
                System.Diagnostics.Trace.WriteLine($"{TravelLogUnit.FullName} Bad journal line: {line}");
                return(null);
            }

            JournalEntry je = null;

            try
            {           // use a try block in case anything in the creation goes t**s up
                je = JournalEntry.CreateJournalEntry(jo, true);
            }
            catch
            {
                je = null;
            }

            if (je == null)
            {
                System.Diagnostics.Trace.WriteLine($"{TravelLogUnit.FullName} Bad journal creation: {line}");
                return(null);
            }

            bool toosoon = false;

            if (je.EventTypeID == JournalTypeEnum.Fileheader)
            {
                JournalEvents.JournalFileheader header = (JournalEvents.JournalFileheader)je;

                if ((header.Beta && !EliteConfigInstance.InstanceOptions.DisableBetaCommanderCheck) || EliteConfigInstance.InstanceOptions.ForceBetaOnCommander) // if beta, and not disabled, or force beta
                {
                    TravelLogUnit.Type |= TravelLogUnit.BetaMarker;
                }

                if (header.Part > 1)
                {
                    // if we have a last continued, and its header parts match, and it has a commander, and its not too different in time..
                    if (lastcontinued != null && lastcontinued.Part == header.Part && lastcontinued.CommanderId >= 0 &&
                        Math.Abs(header.EventTimeUTC.Subtract(lastcontinued.EventTimeUTC).TotalSeconds) < 5)
                    {
                        cmdrid = lastcontinued.CommanderId;
                        TravelLogUnit.CommanderId = lastcontinued.CommanderId;      // copy commander across.
                    }
                    else
                    {           // this only works if you have a history... EDD does.
                        JournalEvents.JournalContinued contd = JournalEntry.GetLast <JournalEvents.JournalContinued>(je.EventTimeUTC.AddSeconds(1), e => e.Part == header.Part);

                        // Carry commander over from previous log if it ends with a Continued event.
                        if (contd != null && Math.Abs(header.EventTimeUTC.Subtract(contd.EventTimeUTC).TotalSeconds) < 5 && contd.CommanderId >= 0)
                        {
                            cmdrid = lastcontinued.CommanderId;
                            TravelLogUnit.CommanderId = contd.CommanderId;
                        }
                    }
                }
            }
            else if (je.EventTypeID == JournalTypeEnum.Continued)
            {
                lastcontinued = je as JournalEvents.JournalContinued;       // save.. we are getting a new file soon
            }
            else if (je.EventTypeID == JournalTypeEnum.LoadGame)
            {
                var    jlg     = je as JournalEvents.JournalLoadGame;
                string newname = jlg.LoadGameCommander;

                if ((TravelLogUnit.Type & TravelLogUnit.BetaMarker) == TravelLogUnit.BetaMarker)
                {
                    newname = "[BETA] " + newname;
                }

                EDCommander commander = EDCommander.GetCommander(newname);

                if (commander == null)
                {
                    // in the default condition, we have a hidden commander, and first Cmdr. Jameson.
                    commander = EDCommander.GetListCommanders().FirstOrDefault();
                    if (EDCommander.NumberOfCommanders == 2 && commander != null && commander.Name == "Jameson (Default)")
                    {
                        commander.Name     = newname;
                        commander.EdsmName = newname;
                        EDCommander.Update(new List <EDCommander> {
                            commander
                        }, false);
                    }
                    else
                    {
                        commander = EDCommander.Create(name: newname, journalpath: EDJournalUIScanner.GetDefaultJournalDir().Equals(TravelLogUnit.Path) ? "" : TravelLogUnit.Path);
                    }
                }

                commander.FID = jlg.FID;

                cmdrid = commander.Nr;

                if (!TravelLogUnit.CommanderId.HasValue)        // we do not need to write to DB the TLU at this point, since we read something the upper layers will do that
                {
                    TravelLogUnit.CommanderId = cmdrid;
                    //System.Diagnostics.Trace.WriteLine(string.Format("TLU {0} updated with commander {1} at {2}", TravelLogUnit.Path, cmdrid, TravelLogUnit.Size));
                }
            }
            else if (je is ISystemStationEntry && ((ISystemStationEntry)je).IsTrainingEvent)
            {
                //System.Diagnostics.Trace.WriteLine($"{filename} Training detected:\n{line}");
                return(null);
            }

            if (je is IAdditionalFiles)
            {
                if ((je as IAdditionalFiles).ReadAdditionalFiles(TravelLogUnit.Path, inhistoryrefreshparse, ref jo) == false)     // if failed
                {
                    return(null);
                }
            }

            if (je is JournalEvents.JournalShipyard)                // when going into shipyard
            {
                toosoon      = lastshipyard != null && lastshipyard.Yard.Equals((je as JournalEvents.JournalShipyard).Yard);
                lastshipyard = je as JournalEvents.JournalShipyard;
            }
            else if (je is JournalEvents.JournalStoredShips)        // when going into shipyard
            {
                toosoon = laststoredships != null && CollectionStaticHelpers.Equals(laststoredships.ShipsHere, (je as JournalEvents.JournalStoredShips).ShipsHere) &&
                          CollectionStaticHelpers.Equals(laststoredships.ShipsRemote, (je as JournalEvents.JournalStoredShips).ShipsRemote);
                laststoredships = je as JournalEvents.JournalStoredShips;
            }
            else if (je is JournalEvents.JournalStoredModules)      // when going into outfitting
            {
                toosoon           = laststoredmodules != null && CollectionStaticHelpers.Equals(laststoredmodules.ModuleItems, (je as JournalEvents.JournalStoredModules).ModuleItems);
                laststoredmodules = je as JournalEvents.JournalStoredModules;
            }
            else if (je is JournalEvents.JournalOutfitting)         // when doing into outfitting
            {
                toosoon        = lastoutfitting != null && lastoutfitting.ItemList.Equals((je as JournalEvents.JournalOutfitting).ItemList);
                lastoutfitting = je as JournalEvents.JournalOutfitting;
            }
            else if (je is JournalEvents.JournalMarket)
            {
                toosoon    = lastmarket != null && lastmarket.Equals(je as JournalEvents.JournalMarket);
                lastmarket = je as JournalEvents.JournalMarket;
            }
            else if (je is JournalEvents.JournalCargo)
            {
                var cargo = je as JournalEvents.JournalCargo;
                if (lastcargo != null)
                {
                    toosoon = lastcargo.SameAs(cargo);     // if exactly the same, swallow.
                    System.Diagnostics.Debug.WriteLine("Cargo vs last " + toosoon);
                }
                lastcargo = cargo;
            }
            else if (je is JournalEvents.JournalUndocked || je is JournalEvents.JournalLoadGame)             // undocked, Load Game, repeats are cleared
            {
                lastshipyard      = null;
                laststoredmodules = null;
                lastoutfitting    = null;
                laststoredmodules = null;
                laststoredships   = null;
                lastcargo         = null;
                cqc = (je is JournalEvents.JournalLoadGame) && ((JournalEvents.JournalLoadGame)je).GameMode == null;
            }
            else if (je is JournalEvents.JournalMusic)
            {
                var music = je as JournalEvents.JournalMusic;

                if (music.MusicTrackID == JournalEvents.EDMusicTrackEnum.CQC || music.MusicTrackID == JournalEvents.EDMusicTrackEnum.CQCMenu)
                {
                    cqc = true;
                }
            }
            else if (je is JournalEvents.JournalNavRoute)
            {
                var route = je as JournalEvents.JournalNavRoute;

                if (lastnavroute != null && (route.EventTimeUTC == lastnavroute.EventTimeUTC || route.EventTimeUTC == lastnavroute.EventTimeUTC.AddSeconds(1)))
                {
                    toosoon = true;
                }

                lastnavroute = route;
            }

            if (toosoon)                                                // if seeing repeats, remove
            {
                // System.Diagnostics.Debug.WriteLine("**** Remove as dup " + je.EventTypeStr);
                return(null);
            }

            if (cqc)  // Ignore events if in CQC
            {
                return(null);
            }

            je.SetTLUCommander(TravelLogUnit.ID, cmdrid);

            return(je);
        }
Exemplo n.º 10
0
        // History load system, read DB for entries and make a history up

        public static HistoryList LoadHistory(Action <string> reportProgress,
                                              int CurrentCommander,
                                              int fullhistoryloaddaylimit, string essentialitems
                                              )
        {
            HistoryList hist = new HistoryList();

            Trace.WriteLine(BaseUtils.AppTicks.TickCountLapDelta("HLL", true).Item1 + " History Load");

            reportProgress("Reading Database");

            List <JournalEntry> jlist;       // returned in date ascending, oldest first order.

            if (fullhistoryloaddaylimit > 0)
            {
                var list = (essentialitems == nameof(JournalEssentialEvents.JumpScanEssentialEvents)) ? JournalEssentialEvents.JumpScanEssentialEvents :
                           (essentialitems == nameof(JournalEssentialEvents.JumpEssentialEvents)) ? JournalEssentialEvents.JumpEssentialEvents :
                           (essentialitems == nameof(JournalEssentialEvents.NoEssentialEvents)) ? JournalEssentialEvents.NoEssentialEvents :
                           (essentialitems == nameof(JournalEssentialEvents.FullStatsEssentialEvents)) ? JournalEssentialEvents.FullStatsEssentialEvents :
                           JournalEssentialEvents.EssentialEvents;

                jlist = JournalEntry.GetAll(CurrentCommander,
                                            ids: list,
                                            allidsafterutc: DateTime.UtcNow.Subtract(new TimeSpan(fullhistoryloaddaylimit, 0, 0, 0))
                                            );
            }
            else
            {
                jlist = JournalEntry.GetAll(CurrentCommander);
            }

            Trace.WriteLine(BaseUtils.AppTicks.TickCountLapDelta("HLL").Item1 + " Journals read from DB");

            reportProgress("Creating History");

            HistoryEntry hprev = null;

            foreach (JournalEntry je in jlist)
            {
                if (MergeEntries(hprev?.journalEntry, je))        // if we merge, don't store into HE
                {
                    continue;
                }

                // Clean up "UnKnown" systems from EDSM log
                if (je is JournalFSDJump && ((JournalFSDJump)je).StarSystem == "UnKnown")
                {
                    JournalEntry.Delete(je.Id);
                    continue;
                }

                if (je is EliteDangerousCore.JournalEvents.JournalMusic)      // remove music.. not shown.. now UI event. remove it for backwards compatibility
                {
                    //System.Diagnostics.Debug.WriteLine("**** Filter out " + je.EventTypeStr + " on " + je.EventTimeLocal.ToString());
                    continue;
                }

                HistoryEntry he = HistoryEntry.FromJournalEntry(je, hprev);     // create entry

                he.UpdateMaterialsCommodities(je, hprev?.MaterialCommodity);    // update material commodities BEFORE we possibly remove entries, as Cargo is one of the removal options
                Debug.Assert(he.MaterialCommodity != null);

                if (CheckForRemoval(he, hprev))                                 // check here to see if we want to remove the entry.. can move this lower later, but at first point where we have the data
                {
                    continue;
                }

                hist.historylist.Add(he);                                       // now add it to the history

                hprev = he;
            }

            Trace.WriteLine(BaseUtils.AppTicks.TickCountLapDelta("HLL").Item1 + " History List Created");
            reportProgress("Analysing History");

            for (int i = 0; i < hist.historylist.Count; i++)
            {
                HistoryEntry he = hist.historylist[i];
                JournalEntry je = he.journalEntry;

                he.UpdateStats(je, hist.statisticsaccumulator, he.StationFaction);
                he.UpdateSystemNote();

                hist.CashLedger.Process(je);            // update the ledger
                he.Credits = hist.CashLedger.CashTotal;

                hist.Shipyards.Process(je);
                hist.Outfitting.Process(je);

                Tuple <ShipInformation, ModulesInStore> ret = hist.ShipInformationList.Process(je, he.WhereAmI, he.System);  // the ships
                he.UpdateShipInformation(ret.Item1);
                he.UpdateShipStoredModules(ret.Item2);

                he.UpdateMissionList(hist.MissionListAccumulator.Process(je, he.System, he.WhereAmI));

                AddToVisitsScan(hist, i, null);          // add to scan but don't complain if can't add
            }

            //for (int i = hist.Count - 10; i < hist.Count; i++)  System.Diagnostics.Debug.WriteLine("Hist {0} {1} {2}", hist[i].EventTimeUTC, hist[i].Indexno , hist[i].EventSummary);

            // now database has been updated due to initial fill, now fill in stuff which needs the user database

            Trace.WriteLine(BaseUtils.AppTicks.TickCountLapDelta("HLL").Item1 + " Anaylsis End");

            hist.CommanderId = CurrentCommander;

#if LISTSCANS
            {
                using (var fileout = new System.IO.StreamWriter(@"c:\code\scans.csv"))
                {
                    fileout.WriteLine($"System,0,fullname,ownname,customname,bodyname,bodydesignation, bodyid,parentlist");
                    foreach (var sn in hist.StarScan.ScansSortedByName())
                    {
                        foreach (var body in sn.Bodies)
                        {
                            string pl = body.ScanData?.ParentList();

                            fileout.WriteLine($"{sn.System.Name},0, {body.FullName},{body.OwnName},{body.CustomName},{body.ScanData?.BodyName},{body.ScanData?.BodyDesignation},{body.BodyID},{pl}");
                        }
                    }
                }
            }
#endif

            return(hist);
        }
Exemplo n.º 11
0
        // 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, out journalupdate); // we may check edsm for this entry

            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;

                shipyards.Process(je, conn);
                outfitting.Process(je, conn);

                Tuple <ShipInformation, ModulesInStore> ret = shipinformationlist.Process(je, conn, he.WhereAmI, he.System);
                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);
                    }
                }
            }
            else if (je is IBodyNameAndID)
            {
                JournalLocOrJump jl;
                HistoryEntry     jlhe;
                starscan.AddBodyToBestSystem((IBodyNameAndID)je, Count - 1, EntryOrder, out jlhe, out jl);
            }

            return(he);
        }
Exemplo n.º 12
0
        static public void ParseFiles(string datapath, out string error, int defaultMapColour,
                                      Func <bool> cancelRequested, Action <int, string> updateProgress,
                                      bool forceReload, int currentcmdrid)
        {
            error = null;

            if (datapath == null)
            {
                error = "Netlog directory not set!";
                return;
            }

            if (!Directory.Exists(datapath))   // if logfiles directory is not found
            {
                error = "Netlog directory is not present!";
                return;
            }

            // list of systems in journal, sorted by time
            List <JournalLocOrJump> vsSystemsEnts = JournalEntry.GetAll(currentcmdrid).OfType <JournalLocOrJump>().OrderBy(j => j.EventTimeUTC).ToList();

            // order by file write time so we end up on the last one written
            FileInfo[] allFiles = Directory.EnumerateFiles(datapath, "netLog.*.log", SearchOption.AllDirectories).Select(f => new FileInfo(f)).OrderBy(p => p.LastWriteTime).ToArray();

            List <NetLogFileReader> readersToUpdate = new List <NetLogFileReader>();
            List <TravelLogUnit>    tlutoadd        = new List <TravelLogUnit>();

            for (int i = 0; i < allFiles.Length; i++)
            {
                FileInfo fi = allFiles[i];

                var reader = OpenFileReader(fi.FullName, currentcmdrid);

                if (reader.ID == 0)            // if not present, add to commit add list
                {
                    tlutoadd.Add(reader.TravelLogUnit);
                }

                if (forceReload)        // Force a reload of the travel log
                {
                    reader.Pos = 0;
                }

                if (reader.Pos != fi.Length || i == allFiles.Length - 1)  // File not already in DB, or is the last one
                {
                    readersToUpdate.Add(reader);
                }
            }

            if (tlutoadd.Count > 0)                      // now, on spinning rust, this takes ages for 600+ log files first time, so transaction it
            {
                UserDatabase.Instance.ExecuteWithDatabase(cn =>
                {
                    using (DbTransaction txn = cn.Connection.BeginTransaction())
                    {
                        foreach (var tlu in tlutoadd)
                        {
                            tlu.Add(cn.Connection, txn);
                        }

                        txn.Commit();
                    }
                });
            }

            for (int i = 0; i < readersToUpdate.Count; i++)
            {
                UserDatabase.Instance.ExecuteWithDatabase(cn =>
                {
                    int ji = 0;

                    NetLogFileReader reader = readersToUpdate[i];
                    updateProgress(i * 100 / readersToUpdate.Count, reader.TravelLogUnit.FullName);

                    var systems = JournalEntry.GetAllByTLU(reader.ID, cn.Connection).OfType <JournalLocOrJump>().ToList();
                    var last    = systems.LastOrDefault();  // find last system recorded for this TLU, may be null if no systems..

                    using (DbTransaction tn = cn.Connection.BeginTransaction())
                    {
                        var ienum = reader.ReadSystems(last, cancelRequested, currentcmdrid);
                        System.Diagnostics.Debug.WriteLine("Scanning TLU " + reader.ID + " " + reader.FullName);

                        foreach (JObject jo in ienum)
                        {
                            jo["EDDMapColor"] = defaultMapColour;

                            JournalLocOrJump je = new JournalFSDJump(jo);
                            je.SetTLUCommander(reader.TravelLogUnit.ID, currentcmdrid);

                            while (ji < vsSystemsEnts.Count && vsSystemsEnts[ji].EventTimeUTC < je.EventTimeUTC)
                            {
                                ji++;   // move to next entry which is bigger in time or equal to ours.
                            }

                            JournalLocOrJump prev = (ji > 0 && (ji - 1) < vsSystemsEnts.Count) ? vsSystemsEnts[ji - 1] : null;
                            JournalLocOrJump next = ji < vsSystemsEnts.Count ? vsSystemsEnts[ji] : null;

                            bool previssame = (prev != null && prev.StarSystem.Equals(je.StarSystem, StringComparison.CurrentCultureIgnoreCase) && (!prev.HasCoordinate || !je.HasCoordinate || (prev.StarPos - je.StarPos).LengthSquared < 0.01));
                            bool nextissame = (next != null && next.StarSystem.Equals(je.StarSystem, StringComparison.CurrentCultureIgnoreCase) && (!next.HasCoordinate || !je.HasCoordinate || (next.StarPos - je.StarPos).LengthSquared < 0.01));

                            // System.Diagnostics.Debug.WriteLine("{0} {1} {2}", ji, vsSystemsEnts[ji].EventTimeUTC, je.EventTimeUTC);

                            if (!(previssame || nextissame))
                            {
                                je.Add(jo, cn.Connection, tn);
                                System.Diagnostics.Debug.WriteLine("Add {0} {1}", je.EventTimeUTC, jo.ToString());
                            }
                        }

                        reader.TravelLogUnit.Update(cn.Connection, tn);

                        tn.Commit();
                    }

                    if (updateProgress != null)
                    {
                        updateProgress((i + 1) * 100 / readersToUpdate.Count, reader.TravelLogUnit.FullName);
                    }
                });
            }
        }
Exemplo n.º 13
0
        static public void ParseFiles(string datapath, out string error, int defaultMapColour, Func <bool> cancelRequested, Action <int, string> updateProgress, bool forceReload = false, Dictionary <string, NetLogFileReader> netlogreaders = null, int currentcmdrid = -1)
        {
            error = null;

            if (datapath == null)
            {
                error = "Netlog directory not set!";
                return;
            }

            if (!Directory.Exists(datapath))   // if logfiles directory is not found
            {
                error = "Netlog directory is not present!";
                return;
            }

            if (netlogreaders == null)
            {
                netlogreaders = new Dictionary <string, NetLogFileReader>();
            }

            if (currentcmdrid < 0)
            {
                currentcmdrid = EDCommander.CurrentCmdrID;
            }

            // TLUs
            List <TravelLogUnit> tlus = TravelLogUnit.GetAll();
            Dictionary <string, TravelLogUnit>            netlogtravelogUnits  = tlus.Where(t => t.type == 1).GroupBy(t => t.Name).Select(g => g.First()).ToDictionary(t => t.Name);
            Dictionary <long, string>                     travellogunitid2name = netlogtravelogUnits.Values.ToDictionary(t => t.id, t => t.Name);
            Dictionary <string, List <JournalLocOrJump> > vsc_lookup           = JournalEntry.GetAll().OfType <JournalLocOrJump>().GroupBy(v => v.TLUId).Where(g => travellogunitid2name.ContainsKey(g.Key)).ToDictionary(g => travellogunitid2name[g.Key], g => g.ToList());

            // list of systems in journal, sorted by time
            List <JournalLocOrJump> vsSystemsEnts = JournalEntry.GetAll(currentcmdrid).OfType <JournalLocOrJump>().OrderBy(j => j.EventTimeUTC).ToList();

            // order by file write time so we end up on the last one written
            FileInfo[] allFiles = Directory.EnumerateFiles(datapath, "netLog.*.log", SearchOption.AllDirectories).Select(f => new FileInfo(f)).OrderBy(p => p.LastWriteTime).ToArray();

            List <NetLogFileReader> readersToUpdate = new List <NetLogFileReader>();

            for (int i = 0; i < allFiles.Length; i++)
            {
                FileInfo fi = allFiles[i];

                var reader = OpenFileReader(fi, netlogtravelogUnits, vsc_lookup, netlogreaders);

                if (!netlogtravelogUnits.ContainsKey(reader.TravelLogUnit.Name))
                {
                    netlogtravelogUnits[reader.TravelLogUnit.Name] = reader.TravelLogUnit;
                    reader.TravelLogUnit.Add();
                }

                if (!netlogreaders.ContainsKey(reader.TravelLogUnit.Name))
                {
                    netlogreaders[reader.TravelLogUnit.Name] = reader;
                }

                if (forceReload)
                {
                    // Force a reload of the travel log
                    reader.TravelLogUnit.Size = 0;
                }

                if (reader.filePos != fi.Length || i == allFiles.Length - 1)  // File not already in DB, or is the last one
                {
                    readersToUpdate.Add(reader);
                }
            }

            for (int i = 0; i < readersToUpdate.Count; i++)
            {
                using (SQLiteConnectionUser cn = new SQLiteConnectionUser(utc: true))
                {
                    int ji = 0;

                    NetLogFileReader reader = readersToUpdate[i];
                    updateProgress(i * 100 / readersToUpdate.Count, reader.TravelLogUnit.Name);

                    using (DbTransaction tn = cn.BeginTransaction())
                    {
                        foreach (JObject jo in reader.ReadSystems(cancelRequested, currentcmdrid))
                        {
                            jo["EDDMapColor"] = defaultMapColour;

                            JournalLocOrJump je = new JournalFSDJump(jo);
                            je.SetTLUCommander(reader.TravelLogUnit.id, currentcmdrid);

                            while (ji < vsSystemsEnts.Count && vsSystemsEnts[ji].EventTimeUTC < je.EventTimeUTC)
                            {
                                ji++;   // move to next entry which is bigger in time or equal to ours.
                            }

                            JournalLocOrJump prev = (ji > 0 && (ji - 1) < vsSystemsEnts.Count) ? vsSystemsEnts[ji - 1] : null;
                            JournalLocOrJump next = ji < vsSystemsEnts.Count ? vsSystemsEnts[ji] : null;

                            bool previssame = (prev != null && prev.StarSystem.Equals(je.StarSystem, StringComparison.CurrentCultureIgnoreCase) && (!prev.HasCoordinate || !je.HasCoordinate || (prev.StarPos - je.StarPos).LengthSquared < 0.01));
                            bool nextissame = (next != null && next.StarSystem.Equals(je.StarSystem, StringComparison.CurrentCultureIgnoreCase) && (!next.HasCoordinate || !je.HasCoordinate || (next.StarPos - je.StarPos).LengthSquared < 0.01));

                            // System.Diagnostics.Debug.WriteLine("{0} {1} {2}", ji, vsSystemsEnts[ji].EventTimeUTC, je.EventTimeUTC);

                            if (!(previssame || nextissame))
                            {
                                je.Add(jo, cn, tn);
                                System.Diagnostics.Debug.WriteLine("Add {0} {1}", je.EventTimeUTC, jo.ToString());
                            }
                        }

                        tn.Commit();

                        reader.TravelLogUnit.Update();
                    }

                    if (updateProgress != null)
                    {
                        updateProgress((i + 1) * 100 / readersToUpdate.Count, reader.TravelLogUnit.Name);
                    }
                }
            }
        }
Exemplo n.º 14
0
 public void UpdateMaterials(JournalEntry je, HistoryEntry prev)
 {
     MaterialCommodity = MaterialCommoditiesList.Process(je, prev?.MaterialCommodity);
 }
Exemplo n.º 15
0
        public List <Tuple <JournalEntry, ISystem> > ToProcess = new List <Tuple <JournalEntry, ISystem> >();     // entries seen but yet to be processed due to no scan node (used by reports which do not create scan nodes)

        public void SaveForProcessing(JournalEntry je, ISystem sys)
        {
            ToProcess.Add(new Tuple <JournalEntry, ISystem>(je, sys));
        }
Exemplo n.º 16
0
        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
                }
            }
        }
Exemplo n.º 17
0
        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);
        }
Exemplo n.º 18
0
        public static HistoryEntry FromJournalEntry(JournalEntry je, HistoryEntry prev, out bool journalupdate, SQLiteConnectionSystem conn = null, EDCommander cmdr = null)
        {
            ISystem isys    = prev == null ? new SystemClass("Unknown") : prev.System;
            int     indexno = prev == null ? 1 : prev.Indexno + 1;

            int mapcolour = 0;

            journalupdate = false;
            bool starposfromedsm = false;
            bool firstdiscover   = false;

            if (je.EventTypeID == JournalTypeEnum.Location || je.EventTypeID == JournalTypeEnum.FSDJump)
            {
                JournalLocOrJump jl = je as JournalLocOrJump;

                ISystem newsys;

                if (jl != null && jl.HasCoordinate)       // LAZY LOAD IF it has a co-ord.. the front end will when it needs it
                {
                    newsys = new SystemClass(jl.StarSystem, jl.StarPos.X, jl.StarPos.Y, jl.StarPos.Z)
                    {
                        EDSMID         = jl.EdsmID < 0 ? 0 : jl.EdsmID, // pass across the EDSMID for the lazy load process.
                        Faction        = jl.Faction,
                        Government     = jl.EDGovernment,
                        PrimaryEconomy = jl.EDEconomy,
                        Security       = jl.EDSecurity,
                        Population     = jl.Population ?? 0,
                        State          = jl.EDState,
                        Allegiance     = jl.EDAllegiance,
                        UpdateDate     = jl.EventTimeUTC,
                        status         = SystemStatusEnum.EDDiscovery,
                        SystemAddress  = jl.SystemAddress,
                    };

                    // If it was a new system, pass the coords back to the StartJump
                    if (prev != null && prev.journalEntry is JournalStartJump)
                    {
                        prev.System = newsys;       // give the previous startjump our system..
                    }
                }
                else
                {
                    // NOTE Rob: 09-JAN-2018 I've removed the Jumpstart looking up a system by name since they were using up lots of lookup time during history reading.
                    // This is used for pre 2.2 systems without co-ords, which now should be limited.
                    // JumpStart still gets the system when the FSD loc is processed, see above.
                    // Jumpstart was also screwing about with the EDSM ID fill in which was broken.  This is now working again.

                    // Default one
                    newsys        = new SystemClass(jl.StarSystem);
                    newsys.EDSMID = je.EdsmID;

                    ISystem s = SystemCache.FindSystem(newsys, conn); // has no co-ord, did we find it?

                    if (s != null)                                    // found a system..
                    {
                        if (jl != null && jl.HasCoordinate)           // if journal Loc, and journal has a star position, use that instead of EDSM..
                        {
                            s.X = Math.Round(jl.StarPos.X * 32.0) / 32.0;
                            s.Y = Math.Round(jl.StarPos.Y * 32.0) / 32.0;
                            s.Z = Math.Round(jl.StarPos.Z * 32.0) / 32.0;
                        }

                        //Debug.WriteLine("HistoryList found system {0} {1}", s.id_edsm, s.name);
                        newsys = s;

                        if (jl != null && je.EdsmID <= 0 && newsys.EDSMID > 0) // only update on a JL..
                        {
                            journalupdate = true;
                            Debug.WriteLine("HE EDSM ID update requested {0} {1}", newsys.EDSMID, newsys.Name);
                        }
                    }
                    else
                    {
                        newsys.EDSMID = -1;        // mark as checked but not found
                    }
                }

                JournalFSDJump jfsd = je as JournalFSDJump;

                if (jfsd != null)
                {
                    if (jfsd.JumpDist <= 0 && isys.HasCoordinate && newsys.HasCoordinate) // if no JDist, its a really old entry, and if previous has a co-ord
                    {
                        jfsd.JumpDist = isys.Distance(newsys);                            // fill it out here

                        if (jfsd.JumpDist > 0)
                        {
                            journalupdate = true;
                            Debug.WriteLine("Je Jump distance update(3) requested {0} {1} {2}", newsys.EDSMID, newsys.Name, jfsd.JumpDist);
                        }
                    }

                    mapcolour = jfsd.MapColor;
                }

                isys            = newsys;
                starposfromedsm = (jl != null && jl.HasCoordinate) ? jl.StarPosFromEDSM : newsys.HasCoordinate;
                firstdiscover   = jl == null ? false : jl.EDSMFirstDiscover;
            }

            string summary, info, detailed;

            je.FillInformation(out summary, out info, out detailed);

            HistoryEntry he = new HistoryEntry
            {
                Indexno             = indexno,
                EntryType           = je.EventTypeID,
                Journalid           = je.Id,
                journalEntry        = je,
                System              = isys,
                EventTimeUTC        = je.EventTimeUTC,
                MapColour           = mapcolour,
                EdsmSync            = je.SyncedEDSM,
                EDDNSync            = je.SyncedEDDN,
                EGOSync             = je.SyncedEGO,
                StartMarker         = je.StartMarker,
                StopMarker          = je.StopMarker,
                EventSummary        = summary,
                EventDescription    = info,
                EventDetailedInfo   = detailed,
                IsStarPosFromEDSM   = starposfromedsm,
                IsEDSMFirstDiscover = firstdiscover,
                Commander           = cmdr ?? EDCommander.GetCommander(je.CommanderId)
            };


            // WORK out docked/landed state

            if (prev != null)
            {
                if (prev.docked.HasValue)                   // copy docked..
                {
                    he.docked = prev.docked;
                }
                if (prev.landed.HasValue)
                {
                    he.landed = prev.landed;
                }
                if (prev.hyperspace.HasValue)
                {
                    he.hyperspace = prev.hyperspace;
                }
                if (prev.marketId != null)
                {
                    he.marketId = prev.marketId;
                }
                if (prev.wanted.HasValue)
                {
                    he.wanted = prev.wanted;
                }

                he.stationName       = prev.stationName;
                he.shiptype          = prev.shiptype;
                he.shipid            = prev.shipid;
                he.whereami          = prev.whereami;
                he.onCrewWithCaptain = prev.onCrewWithCaptain;
                he.gamemode          = prev.gamemode;
                he.group             = prev.group;
            }

            if (je.EventTypeID == JournalTypeEnum.Location)
            {
                JournalLocation jl = je as JournalLocation;
                he.docked     = jl.Docked;
                he.landed     = jl.Latitude.HasValue;
                he.whereami   = jl.Docked ? jl.StationName : jl.Body;
                he.hyperspace = false;
                he.wanted     = jl.Wanted;
            }
            else if (je.EventTypeID == JournalTypeEnum.Docked)
            {
                JournalDocked jl = je as JournalDocked;
                he.docked      = true;
                he.whereami    = jl.StationName;
                he.stationName = jl.StationName;
                he.marketId    = jl.MarketID;
            }
            else if (je.EventTypeID == JournalTypeEnum.Undocked)
            {
                he.docked      = false;
                he.stationName = null;
                he.marketId    = null;
            }
            else if (je.EventTypeID == JournalTypeEnum.Touchdown)
            {
                he.landed = true;
            }
            else if (je.EventTypeID == JournalTypeEnum.Liftoff)
            {
                he.landed = !(je as JournalLiftoff).PlayerControlled;
            }
            else if (je.EventTypeID == JournalTypeEnum.SupercruiseEntry)
            {
                he.whereami   = (je as JournalSupercruiseEntry).StarSystem;
                he.hyperspace = true;
            }
            else if (je.EventTypeID == JournalTypeEnum.SupercruiseExit)
            {
                he.whereami   = (je as JournalSupercruiseExit).Body;
                he.hyperspace = false;
            }
            else if (je.EventTypeID == JournalTypeEnum.FSDJump)
            {
                JournalFSDJump ju = (je as JournalFSDJump);
                he.whereami   = ju.StarSystem;
                he.hyperspace = true;
                he.wanted     = ju.Wanted;
            }
            else if (je.EventTypeID == JournalTypeEnum.StartJump)
            {
                he.hyperspace = true;   // some of these are just to make sure, as FSDJump will also set it
            }
            else if (je.EventTypeID == JournalTypeEnum.LoadGame)
            {
                JournalLoadGame jl = je as JournalLoadGame;

                he.onCrewWithCaptain = null;        // can't be in a crew at this point
                he.gamemode          = jl.GameMode; // set game mode
                he.group             = jl.Group;    // and group, may be empty
                he.landed            = jl.StartLanded;
                he.hyperspace        = false;

                if (jl.Ship.IndexOf("buggy", StringComparison.InvariantCultureIgnoreCase) == -1)        // load game with buggy, can't tell what ship we get back into, so ignore
                {
                    he.shiptype = (je as JournalLoadGame).Ship;
                    he.shipid   = (je as JournalLoadGame).ShipId;
                }
            }
            else if (je.EventTypeID == JournalTypeEnum.ShipyardBuy)         // BUY does not have ship id, but the new entry will that is written later - journals 8.34
            {
                he.shiptype = (je as JournalShipyardBuy).ShipType;
            }
            else if (je.EventTypeID == JournalTypeEnum.ShipyardNew)
            {
                he.shiptype = (je as JournalShipyardNew).ShipType;
                he.shipid   = (je as JournalShipyardNew).ShipId;
            }
            else if (je.EventTypeID == JournalTypeEnum.ShipyardSwap)
            {
                he.shiptype = (je as JournalShipyardSwap).ShipType;
                he.shipid   = (je as JournalShipyardSwap).ShipId;
            }
            else if (je.EventTypeID == JournalTypeEnum.JoinACrew)
            {
                he.onCrewWithCaptain = (je as JournalJoinACrew).Captain;
            }
            else if (je.EventTypeID == JournalTypeEnum.QuitACrew)
            {
                he.onCrewWithCaptain = null;
            }

            if (prev != null && prev.travelling)      // if we are travelling..
            {
                he.travelled_distance    = prev.travelled_distance;
                he.travelled_missingjump = prev.travelled_missingjump;
                he.travelled_jumps       = prev.travelled_jumps;

                if (he.IsFSDJump && !he.MultiPlayer)   // if jump, and not multiplayer..
                {
                    double dist = ((JournalFSDJump)je).JumpDist;
                    if (dist <= 0)
                    {
                        he.travelled_missingjump++;
                    }
                    else
                    {
                        he.travelled_distance += dist;
                        he.travelled_jumps++;
                    }
                }

                he.travelled_seconds = prev.travelled_seconds;
                TimeSpan diff = he.EventTimeUTC.Subtract(prev.EventTimeUTC);

                if (he.EntryType != JournalTypeEnum.LoadGame && diff < new TimeSpan(2, 0, 0))   // time between last entry and load game is not real time
                {
                    he.travelled_seconds += diff;
                }

                if (he.StopMarker || he.StartMarker)
                {
                    //Debug.WriteLine("Travelling stop at " + he.Indexno);
                    he.travelling         = false;
                    he.EventDetailedInfo += ((he.EventDetailedInfo.Length > 0) ? Environment.NewLine : "") + "Travelled " + he.travelled_distance.ToStringInvariant("0.0") + " LY"
                                            + ", " + he.travelled_jumps + " jumps"
                                            + ((he.travelled_missingjump > 0) ? ", " + he.travelled_missingjump + " unknown distance jumps" : "") +
                                            ", time " + he.travelled_seconds;

                    he.travelled_distance = 0;
                    he.travelled_seconds  = new TimeSpan(0);
                }
                else
                {
                    he.travelling = true;

                    if (he.IsFSDJump)
                    {
                        he.EventDetailedInfo += ((he.EventDetailedInfo.Length > 0) ? Environment.NewLine : "") + "Travelling" +
                                                " distance " + he.travelled_distance.ToString("0.0") + " LY"
                                                + ", " + he.travelled_jumps + " jumps"
                                                + ((he.travelled_missingjump > 0) ? ", " + he.travelled_missingjump + " unknown distance jumps" : "") +
                                                ", time " + he.travelled_seconds;
                    }
                }
            }

            if (he.StartMarker)
            {
                //Debug.WriteLine("Travelling start at " + he.Indexno);
                he.travelling = true;
            }

            return(he);
        }
Exemplo n.º 19
0
        // ordered in time, id order, ascending, oldest first

        static public List <JournalEntry> GetAll(int commander         = -999, DateTime?afterutc = null, DateTime?beforeutc = null,
                                                 JournalTypeEnum[] ids = null, DateTime?allidsafterutc = null)
        {
            var tluslist = TravelLogUnit.GetAll();
            Dictionary <long, TravelLogUnit> tlus = tluslist.ToDictionary(t => t.ID);

            DbCommand           cmd     = null;
            DbDataReader        reader  = null;
            List <JournalEntry> entries = new List <JournalEntry>();

            try
            {
                cmd    = UserDatabase.Instance.ExecuteWithDatabase(cn => cn.Connection.CreateCommand("select * from JournalEntries"));
                reader = UserDatabase.Instance.ExecuteWithDatabase(cn =>
                {
                    string cnd = "";
                    if (commander != -999)
                    {
                        cnd = cnd.AppendPrePad("CommanderID = @commander", " and ");
                        cmd.AddParameterWithValue("@commander", commander);
                    }
                    if (afterutc != null)
                    {
                        cnd = cnd.AppendPrePad("EventTime >= @after", " and ");
                        cmd.AddParameterWithValue("@after", afterutc.Value);
                    }
                    if (beforeutc != null)
                    {
                        cnd = cnd.AppendPrePad("EventTime <= @before", " and ");
                        cmd.AddParameterWithValue("@before", beforeutc.Value);
                    }
                    if (ids != null)
                    {
                        int[] array = Array.ConvertAll(ids, x => (int)x);
                        if (allidsafterutc != null)
                        {
                            cmd.AddParameterWithValue("@idafter", allidsafterutc.Value);
                            cnd = cnd.AppendPrePad("(EventTypeId in (" + string.Join(",", array) + ") Or EventTime>=@idafter)", " and ");
                        }
                        else
                        {
                            cnd = cnd.AppendPrePad("EventTypeId in (" + string.Join(",", array) + ")", " and ");
                        }
                    }

                    if (cnd.HasChars())
                    {
                        cmd.CommandText += " where " + cnd;
                    }

                    cmd.CommandText += " Order By EventTime,Id ASC";

                    return(cmd.ExecuteReader());
                });

                List <JournalEntry> retlist = null;

                do
                {
                    // experiments state that reading the DL takes 270/4000ms, reading json -> 1250, then the rest is creating and decoding the fields
                    // not much scope to improve it outside of the core json speed.

                    retlist = UserDatabase.Instance.ExecuteWithDatabase(cn =>       // split into smaller chunks to allow other things access..
                    {
                        List <JournalEntry> list = new List <JournalEntry>();

                        while (list.Count < 1000 && reader.Read())
                        {
                            JournalEntry sys = JournalEntry.CreateJournalEntry(reader);
                            sys.beta         = tlus.ContainsKey(sys.TLUId) ? tlus[sys.TLUId].Beta : false;
                            list.Add(sys);
                        }

                        return(list);
                    });

                    entries.AddRange(retlist);
                }while (retlist != null && retlist.Count != 0);
            }
            catch (Exception ex)
            {
                System.Diagnostics.Debug.WriteLine("Getall Exception " + ex);
            }
            finally
            {
                if (reader != null || cmd != null)
                {
                    UserDatabase.Instance.ExecuteWithDatabase(cn =>
                    {
                        reader?.Close();
                        cmd?.Dispose();
                    });
                }
            }

            return(entries);
        }
Exemplo n.º 20
0
        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,
                                              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;
                foreach (JournalEntry inje in jlist)
                {
                    foreach (JournalEntry je in hist.ProcessJournalEntry(inje)) // pass thru the repeat remover..
                    {
                        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, 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);
        }
Exemplo n.º 21
0
        public void ParseJournalFiles(Func <bool> cancelRequested, Action <int, string> updateProgress, bool forceReload = false)
        {
//            System.Diagnostics.Trace.WriteLine(BaseUtils.AppTicks.TickCountLap("PJF", true), "Scanned " + WatcherFolder);

            Dictionary <string, TravelLogUnit> m_travelogUnits = TravelLogUnit.GetAll().Where(t => (t.type & TravelLogUnit.TypeMask) == TravelLogUnit.JournalType).GroupBy(t => t.Name).Select(g => g.First()).ToDictionary(t => t.Name);

            // order by file write time so we end up on the last one written
            FileInfo[] allFiles = Directory.EnumerateFiles(WatcherFolder, journalfilematch, SearchOption.AllDirectories).Select(f => new FileInfo(f)).OrderBy(p => p.LastWriteTime).ToArray();

            List <EDJournalReader> readersToUpdate = new List <EDJournalReader>();

            for (int i = 0; i < allFiles.Length; i++)
            {
                FileInfo fi = allFiles[i];

                var reader = OpenFileReader(fi, m_travelogUnits);       // open it

                if (!m_travelogUnits.ContainsKey(reader.TravelLogUnit.Name))
                {
                    m_travelogUnits[reader.TravelLogUnit.Name] = reader.TravelLogUnit;
                    reader.TravelLogUnit.type = TravelLogUnit.JournalType;
                    reader.TravelLogUnit.Add();
                }

                if (!netlogreaders.ContainsKey(reader.TravelLogUnit.Name))
                {
                    netlogreaders[reader.TravelLogUnit.Name] = reader;
                }

                if (forceReload)
                {
                    // Force a reload of the travel log
                    reader.TravelLogUnit.Size = 0;
                }

                if (reader.filePos != fi.Length || i == allFiles.Length - 1)  // File not already in DB, or is the last one
                {
                    readersToUpdate.Add(reader);
                }
            }

            //System.Diagnostics.Trace.WriteLine(BaseUtils.AppTicks.TickCountLap("PJF"), "Ready to update");

            for (int i = 0; i < readersToUpdate.Count; i++)
            {
                EDJournalReader reader = readersToUpdate[i];
                updateProgress(i * 100 / readersToUpdate.Count, reader.TravelLogUnit.Name);

                //System.Diagnostics.Trace.WriteLine(BaseUtils.AppTicks.TickCountLap("PJF"), i + " read ");

                reader.ReadJournal(out List <JournalReaderEntry> entries, out List <UIEvent> uievents, historyrefreshparsing: true, resetOnError: true);      // this may create new commanders, and may write to the TLU db

                UserDatabase.Instance.ExecuteWithDatabase(cn =>
                {
                    if (entries.Count > 0)
                    {
                        ILookup <DateTime, JournalEntry> existing = JournalEntry.GetAllByTLU(reader.TravelLogUnit.id, cn.Connection).ToLookup(e => e.EventTimeUTC);

                        //System.Diagnostics.Trace.WriteLine(BaseUtils.AppTicks.TickCountLap("PJF"), i + " into db");

                        using (DbTransaction tn = cn.Connection.BeginTransaction())
                        {
                            foreach (JournalReaderEntry jre in entries)
                            {
                                if (!existing[jre.JournalEntry.EventTimeUTC].Any(e => JournalEntry.AreSameEntry(jre.JournalEntry, e, cn.Connection, ent1jo: jre.Json)))
                                {
                                    jre.JournalEntry.Add(jre.Json, cn.Connection, tn);
                                    //System.Diagnostics.Trace.WriteLine(string.Format("Write Journal to db {0} {1}", jre.JournalEntry.EventTimeUTC, jre.JournalEntry.EventTypeStr));
                                }
                            }

                            tn.Commit();
                        }
                    }

                    reader.TravelLogUnit.Update(cn.Connection);

                    updateProgress((i + 1) * 100 / readersToUpdate.Count, reader.TravelLogUnit.Name);

                    lastnfi = reader;
                });
            }

            updateProgress(-1, "");
        }
Exemplo n.º 22
0
        public IEnumerable <JObject> ReadSystems(Func <bool> cancelRequested = null, int cmdrid = -1)
        {
            if (cancelRequested == null)
            {
                cancelRequested = () => false;
            }

            if (cmdrid < 0)
            {
                cmdrid = EDCommander.CurrentCmdrID;
            }

            JournalLocOrJump last     = null;
            long             startpos = filePos;

            if (TimeZone == null)
            {
                if (!ReadHeader())  // may be empty if we read it too fast.. don't worry, monitor will pick it up
                {
                    System.Diagnostics.Trace.WriteLine("File was empty (for now) " + FileName);
                    yield break;
                }
            }

            JObject          jo;
            JournalLocOrJump je;

            using (Stream stream = File.Open(this.FileName, FileMode.Open, FileAccess.Read, FileShare.ReadWrite))
            {
                System.Diagnostics.Debug.WriteLine("ReadData " + FileName + " from " + startpos + " to " + filePos);

                while (!cancelRequested() && ReadNetLogSystem(out jo, out je, cancelRequested, stream))
                {
                    if (last == null)
                    {
                        if (systems.Count == 0)
                        {
                            last = JournalEntry.GetLast <JournalLocOrJump>(cmdrid, je.EventTimeUTC);
                        }
                        else
                        {
                            last = systems[systems.Count - 1];
                        }
                    }

                    if (last != null && je.StarSystem.Equals(last.StarSystem, StringComparison.InvariantCultureIgnoreCase) &&
                        (!je.HasCoordinate || !last.HasCoordinate || (je.StarPos - last.StarPos).LengthSquared < 0.001))
                    {
                        continue;
                    }

                    if (je.EventTimeUTC.Subtract(gammastart).TotalMinutes > 0)  // Ta bara med efter gamma.
                    {
                        systems.Add(je);
                        yield return(jo);

                        last = je;
                    }
                }
            }

            if (startpos != filePos)
            {
                System.Diagnostics.Debug.WriteLine("Parse ReadData " + FileName + " from " + startpos + " to " + filePos);
            }
        }
Exemplo n.º 23
0
        public static HistoryEntry FromJournalEntry(JournalEntry je, HistoryEntry prev, bool checkedsm, out bool journalupdate, SQLiteConnectionSystem conn = null, EDCommander cmdr = null)
        {
            ISystem isys    = prev == null ? new SystemClassDB("Unknown") : prev.System;
            int     indexno = prev == null ? 1 : prev.Indexno + 1;

            int mapcolour = 0;

            journalupdate = false;
            bool starposfromedsm = false;
            bool firstdiscover   = false;


            if (je.EventTypeID == JournalTypeEnum.Location || je.EventTypeID == JournalTypeEnum.FSDJump)
            {
                JournalLocOrJump jl   = je as JournalLocOrJump;
                JournalFSDJump   jfsd = je as JournalFSDJump;

                ISystem newsys;

                if (jl.HasCoordinate)       // LAZY LOAD IF it has a co-ord.. the front end will when it needs it
                {
                    newsys         = new SystemClassDB(jl.StarSystem, jl.StarPos.X, jl.StarPos.Y, jl.StarPos.Z);
                    newsys.id_edsm = jl.EdsmID < 0 ? 0 : jl.EdsmID;               // pass across the EDSMID for the lazy load process.

                    if (jfsd != null && jfsd.JumpDist <= 0 && isys.HasCoordinate) // if we don't have a jump distance (pre 2.2) but the last sys does have pos, we can compute distance and update entry
                    {
                        jfsd.JumpDist = SystemClassDB.Distance(isys, newsys);     // fill it out here
                        journalupdate = true;
                    }
                }
                else
                {                           // Default one
                    newsys         = new SystemClassDB(jl.StarSystem);
                    newsys.id_edsm = jl.EdsmID;

                    if (checkedsm)                                              // see if we can find the right system
                    {
                        SystemClassDB s = SystemClassDB.FindEDSM(newsys, conn); // has no co-ord, did we find it?

                        if (s != null)                                          // yes, use, and update the journal with the esdmid, and also the position if we have a co-ord
                        {                                                       // so next time we don't have to do this again..
                            if (jl.HasCoordinate)
                            {
                                s.x = Math.Round(jl.StarPos.X * 32.0) / 32.0;
                                s.y = Math.Round(jl.StarPos.Y * 32.0) / 32.0;
                                s.z = Math.Round(jl.StarPos.Z * 32.0) / 32.0;
                            }

                            newsys = s;

                            if (jfsd != null && jfsd.JumpDist <= 0 && newsys.HasCoordinate && isys.HasCoordinate) // if we don't have a jump distance (pre 2.2) but the last sys does, we can compute
                            {
                                jfsd.JumpDist = SystemClassDB.Distance(isys, newsys);                             // fill it out here.  EDSM systems always have co-ords, but we should check anyway
                                journalupdate = true;
                            }

                            if (jl.EdsmID <= 0 && newsys.id_edsm > 0)
                            {
                                journalupdate = true;
                            }
                        }
                    }
                }

                if (jfsd != null)
                {
                    if (jfsd.JumpDist <= 0 && isys.HasCoordinate && newsys.HasCoordinate) // if no JDist, its a really old entry, and if previous has a co-ord
                    {
                        jfsd.JumpDist = SystemClassDB.Distance(isys, newsys);             // fill it out here
                        journalupdate = true;
                    }

                    mapcolour = jfsd.MapColor;
                }

                isys            = newsys;
                starposfromedsm = jl.HasCoordinate ? jl.StarPosFromEDSM : newsys.HasCoordinate;
                firstdiscover   = jl.EDSMFirstDiscover;
            }

            string summary, info, detailed;

            je.FillInformation(out summary, out info, out detailed);

            HistoryEntry he = new HistoryEntry
            {
                Indexno             = indexno,
                EntryType           = je.EventTypeID,
                Journalid           = je.Id,
                journalEntry        = je,
                System              = isys,
                EventTimeUTC        = je.EventTimeUTC,
                MapColour           = mapcolour,
                EdsmSync            = je.SyncedEDSM,
                EDDNSync            = je.SyncedEDDN,
                EGOSync             = je.SyncedEGO,
                StartMarker         = je.StartMarker,
                StopMarker          = je.StopMarker,
                EventSummary        = summary,
                EventDescription    = info,
                EventDetailedInfo   = detailed,
                IsStarPosFromEDSM   = starposfromedsm,
                IsEDSMFirstDiscover = firstdiscover,
                Commander           = cmdr ?? EDCommander.GetCommander(je.CommanderId)
            };


            // WORK out docked/landed state

            if (prev != null)
            {
                if (prev.docked.HasValue)                   // copy docked..
                {
                    he.docked = prev.docked;
                }
                if (prev.landed.HasValue)
                {
                    he.landed = prev.landed;
                }

                he.shiptype          = prev.shiptype;
                he.shipid            = prev.shipid;
                he.whereami          = prev.whereami;
                he.onCrewWithCaptain = prev.onCrewWithCaptain;
                he.gamemode          = prev.gamemode;
                he.group             = prev.group;
            }

            if (je.EventTypeID == JournalTypeEnum.Location)
            {
                JournalLocation jl = je as JournalLocation;
                he.docked   = jl.Docked;
                he.whereami = jl.Docked ? jl.StationName : jl.Body;
            }
            else if (je.EventTypeID == JournalTypeEnum.Docked)
            {
                JournalDocked jl = je as JournalDocked;
                he.docked   = true;
                he.whereami = jl.StationName;
            }
            else if (je.EventTypeID == JournalTypeEnum.Undocked)
            {
                he.docked = false;
            }
            else if (je.EventTypeID == JournalTypeEnum.Touchdown)
            {
                he.landed = true;
            }
            else if (je.EventTypeID == JournalTypeEnum.Liftoff)
            {
                he.landed = false;
            }
            else if (je.EventTypeID == JournalTypeEnum.SupercruiseEntry)
            {
                he.whereami = (je as JournalSupercruiseEntry).StarSystem;
            }
            else if (je.EventTypeID == JournalTypeEnum.SupercruiseExit)
            {
                he.whereami = (je as JournalSupercruiseExit).Body;
            }
            else if (je.EventTypeID == JournalTypeEnum.FSDJump)
            {
                he.whereami = (je as JournalFSDJump).StarSystem;
            }
            else if (je.EventTypeID == JournalTypeEnum.LoadGame)
            {
                JournalLoadGame jl = je as JournalLoadGame;

                he.onCrewWithCaptain = null;        // can't be in a crew at this point
                he.gamemode          = jl.GameMode; // set game mode
                he.group             = jl.Group;    // and group, may be empty
                he.landed            = jl.StartLanded;

                if (jl.Ship.IndexOf("buggy", StringComparison.InvariantCultureIgnoreCase) == -1)        // load game with buggy, can't tell what ship we get back into, so ignore
                {
                    he.shiptype = (je as JournalLoadGame).Ship;
                    he.shipid   = (je as JournalLoadGame).ShipId;
                }
            }
            else if (je.EventTypeID == JournalTypeEnum.ShipyardBuy)         // BUY does not have ship id, but the new entry will that is written later - journals 8.34
            {
                he.shiptype = (je as JournalShipyardBuy).ShipType;
            }
            else if (je.EventTypeID == JournalTypeEnum.ShipyardNew)
            {
                he.shiptype = (je as JournalShipyardNew).ShipType;
                he.shipid   = (je as JournalShipyardNew).ShipId;
            }
            else if (je.EventTypeID == JournalTypeEnum.ShipyardSwap)
            {
                he.shiptype = (je as JournalShipyardSwap).ShipType;
                he.shipid   = (je as JournalShipyardSwap).ShipId;
            }
            else if (je.EventTypeID == JournalTypeEnum.JoinACrew)
            {
                he.onCrewWithCaptain = (je as JournalJoinACrew).Captain;
            }
            else if (je.EventTypeID == JournalTypeEnum.QuitACrew)
            {
                he.onCrewWithCaptain = null;
            }

            if (prev != null && prev.travelling)      // if we are travelling..
            {
                he.travelled_distance    = prev.travelled_distance;
                he.travelled_missingjump = prev.travelled_missingjump;
                he.travelled_jumps       = prev.travelled_jumps;

                if (he.IsFSDJump && !he.MultiPlayer)   // if jump, and not multiplayer..
                {
                    double dist = ((JournalFSDJump)je).JumpDist;
                    if (dist <= 0)
                    {
                        he.travelled_missingjump++;
                    }
                    else
                    {
                        he.travelled_distance += dist;
                        he.travelled_jumps++;
                    }
                }

                he.travelled_seconds = prev.travelled_seconds;
                TimeSpan diff = he.EventTimeUTC.Subtract(prev.EventTimeUTC);

                if (he.EntryType != JournalTypeEnum.LoadGame && diff < new TimeSpan(2, 0, 0))   // time between last entry and load game is not real time
                {
                    he.travelled_seconds += diff;
                }

                if (he.StopMarker || he.StartMarker)
                {
                    //Debug.WriteLine("Travelling stop at " + he.Indexno);
                    he.travelling         = false;
                    he.EventDetailedInfo += ((he.EventDetailedInfo.Length > 0) ? Environment.NewLine : "") + "Travelled " + he.travelled_distance.ToStringInvariant("0.0") + " LY"
                                            + ", " + he.travelled_jumps + " jumps"
                                            + ((he.travelled_missingjump > 0) ? ", " + he.travelled_missingjump + " unknown distance jumps" : "") +
                                            ", time " + he.travelled_seconds;

                    he.travelled_distance = 0;
                    he.travelled_seconds  = new TimeSpan(0);
                }
                else
                {
                    he.travelling = true;

                    if (he.IsFSDJump)
                    {
                        he.EventDetailedInfo += ((he.EventDetailedInfo.Length > 0) ? Environment.NewLine : "") + "Travelling" +
                                                " distance " + he.travelled_distance.ToString("0.0") + " LY"
                                                + ", " + he.travelled_jumps + " jumps"
                                                + ((he.travelled_missingjump > 0) ? ", " + he.travelled_missingjump + " unknown distance jumps" : "") +
                                                ", time " + he.travelled_seconds;
                    }
                }
            }

            if (he.StartMarker)
            {
                //Debug.WriteLine("Travelling start at " + he.Indexno);
                he.travelling = true;
            }

            return(he);
        }
Exemplo n.º 24
0
        // History load system, read DB for entries and make a history up

        public static HistoryList LoadHistory(Action <string> reportProgress,
                                              int CurrentCommander,
                                              int fullhistoryloaddaylimit, string essentialitems
                                              )
        {
            HistoryList hist = new HistoryList();

            Trace.WriteLine(BaseUtils.AppTicks.TickCountLapDelta("HLL", true).Item1 + " History Load");

            reportProgress("Reading Database");

            List <JournalEntry> jlist;       // returned in date ascending, oldest first order.

            if (fullhistoryloaddaylimit > 0)
            {
                var list = (essentialitems == nameof(JournalEssentialEvents.JumpScanEssentialEvents)) ? JournalEssentialEvents.JumpScanEssentialEvents :
                           (essentialitems == nameof(JournalEssentialEvents.JumpEssentialEvents)) ? JournalEssentialEvents.JumpEssentialEvents :
                           (essentialitems == nameof(JournalEssentialEvents.NoEssentialEvents)) ? JournalEssentialEvents.NoEssentialEvents :
                           (essentialitems == nameof(JournalEssentialEvents.FullStatsEssentialEvents)) ? JournalEssentialEvents.FullStatsEssentialEvents :
                           JournalEssentialEvents.EssentialEvents;

                jlist = JournalEntry.GetAll(CurrentCommander,
                                            ids: list,
                                            allidsafterutc: DateTime.UtcNow.Subtract(new TimeSpan(fullhistoryloaddaylimit, 0, 0, 0))
                                            );
            }
            else
            {
                jlist = JournalEntry.GetAll(CurrentCommander);
            }

            Trace.WriteLine(BaseUtils.AppTicks.TickCountLapDelta("HLL").Item1 + " Journals read from DB");

            reportProgress("Creating History");

            hist.hlastprocessed = null;

            foreach (JournalEntry je in jlist)
            {
                if (MergeOrDiscardEntries(hist.hlastprocessed?.journalEntry, je))        // if we merge, don't store into HE
                {
                    continue;
                }

                // Clean up "UnKnown" systems from EDSM log
                if (je is JournalFSDJump && ((JournalFSDJump)je).StarSystem == "UnKnown")
                {
                    JournalEntry.Delete(je.Id);
                    continue;
                }

                HistoryEntry he = HistoryEntry.FromJournalEntry(je, hist.hlastprocessed);     // create entry

                he.UpdateMaterialsCommodities(hist.MaterialCommoditiesMicroResources.Process(je, hist.hlastprocessed?.journalEntry, he.Status.TravelState == HistoryEntryStatus.TravelStateType.SRV));

                // IN THIS order, so suits can be added, then weapons, then loadouts
                he.UpdateSuits(hist.SuitList.Process(je, he.WhereAmI, he.System));
                he.UpdateWeapons(hist.WeaponList.Process(je, he.WhereAmI, he.System));          // update the entries in suit entry list
                he.UpdateLoadouts(hist.SuitLoadoutList.Process(je, hist.WeaponList, he.WhereAmI, he.System));

                he.UpdateStats(je, hist.statisticsaccumulator, he.StationFaction);
                he.UpdateSystemNote();

                hist.CashLedger.Process(je);            // update the ledger
                he.Credits = hist.CashLedger.CashTotal;

                hist.Shipyards.Process(je);
                hist.Outfitting.Process(je);

                Tuple <ShipInformation, ModulesInStore> ret = hist.ShipInformationList.Process(je, he.WhereAmI, he.System);  // the ships
                he.UpdateShipInformation(ret.Item1);
                he.UpdateShipStoredModules(ret.Item2);

                he.UpdateMissionList(hist.MissionListAccumulator.Process(je, he.System, he.WhereAmI));

                hist.hlastprocessed = he;

                var reorderlist = hist.ReorderRemove(he);

                foreach (var heh in reorderlist.EmptyIfNull())
                {
                    // System.Diagnostics.Debug.WriteLine("   ++ {0} {1}", heh.EventTimeUTC.ToString(), heh.EntryType);
                    heh.Index = hist.historylist.Count; // store its index for quick ordering, after all removal etc
                    hist.historylist.Add(heh);          // then add to history
                    hist.AddToVisitsScan(null);         // add to scan database but don't complain
                }
            }

            Trace.WriteLine(BaseUtils.AppTicks.TickCountLapDelta("HLL").Item1 + " History List Created");

            foreach (var s in hist.StarScan.ToProcess)
            {
                System.Diagnostics.Debug.WriteLine("StarScan could not find " + s.Item2.SystemAddress + " at " + s.Item1.EventTimeUTC);
            }

            //for (int i = hist.Count - 10; i < hist.Count; i++)  System.Diagnostics.Debug.WriteLine("Hist {0} {1} {2}", hist[i].EventTimeUTC, hist[i].Indexno , hist[i].EventSummary);

            // now database has been updated due to initial fill, now fill in stuff which needs the user database

            Trace.WriteLine(BaseUtils.AppTicks.TickCountLapDelta("HLL").Item1 + " Anaylsis End");

            hist.CommanderId = CurrentCommander;

#if LISTSCANS
            {
                using (var fileout = new System.IO.StreamWriter(@"c:\code\scans.csv"))
                {
                    fileout.WriteLine($"System,0,fullname,ownname,customname,bodyname,bodydesignation, bodyid,parentlist");
                    foreach (var sn in hist.StarScan.ScansSortedByName())
                    {
                        foreach (var body in sn.Bodies)
                        {
                            string pl = body.ScanData?.ParentList();

                            fileout.WriteLine($"{sn.System.Name},0, {body.FullName},{body.OwnName},{body.CustomName},{body.ScanData?.BodyName},{body.ScanData?.BodyDesignation},{body.BodyID},{pl}");
                        }
                    }
                }
            }
#endif

            return(hist);
        }
Exemplo n.º 25
0
        public static HistoryEntry FromJournalEntry(JournalEntry je, HistoryEntry prev, bool checkdbforunknownsystem, out bool journalupdate)
        {
            ISystem isys    = prev == null ? new SystemClass("Unknown") : prev.System;
            int     indexno = prev == null ? 1 : prev.Indexno + 1;

            journalupdate = false;

            if (je.EventTypeID == JournalTypeEnum.Location || je.EventTypeID == JournalTypeEnum.FSDJump)
            {
                JournalLocOrJump jl = je as JournalLocOrJump;

                ISystem newsys;

                if (jl != null && jl.HasCoordinate)       // LAZY LOAD IF it has a co-ord.. the front end will when it needs it
                {
                    newsys = new SystemClass(jl.StarSystem, jl.StarPos.X, jl.StarPos.Y, jl.StarPos.Z)
                    {
                        EDSMID         = jl.EdsmID < 0 ? 0 : jl.EdsmID, // pass across the EDSMID for the lazy load process.
                        SystemAddress  = jl.SystemAddress,
                        Population     = jl.Population ?? 0,
                        Faction        = jl.Faction,
                        Government     = jl.EDGovernment,
                        Allegiance     = jl.EDAllegiance,
                        State          = jl.EDState,
                        Security       = jl.EDSecurity,
                        PrimaryEconomy = jl.EDEconomy,
                        Power          = jl.PowerList,
                        PowerState     = jl.PowerplayState,
                        source         = jl.StarPosFromEDSM ? SystemSource.FromEDSM : SystemSource.FromJournal,
                    };

                    SystemCache.FindCachedJournalSystem(newsys);

                    // If it was a new system, pass the coords back to the StartJump
                    if (prev != null && prev.journalEntry is JournalStartJump)
                    {
                        prev.System = newsys;       // give the previous startjump our system..
                    }
                }
                else
                {
                    // NOTE Rob: 09-JAN-2018 I've removed the Jumpstart looking up a system by name since they were using up lots of lookup time during history reading.
                    // This is used for pre 2.2 systems without co-ords, which now should be limited.
                    // JumpStart still gets the system when the FSD loc is processed, see above.
                    // Jumpstart was also screwing about with the EDSM ID fill in which was broken.  This is now working again.

                    // Default one
                    newsys        = new SystemClass(jl.StarSystem);  // this will be a synthesised one, unless we find an EDSM to replace it
                    newsys.EDSMID = je.EdsmID;

                    ISystem s = checkdbforunknownsystem ? SystemCache.FindSystem(newsys) : null; // did we find it?

                    if (s != null)                                                               // found a system..
                    {
                        if (jl != null && jl.HasCoordinate)                                      // if journal Loc, and journal has a star position, use that instead of EDSM..
                        {
                            s.X = Math.Round(jl.StarPos.X * 32.0) / 32.0;
                            s.Y = Math.Round(jl.StarPos.Y * 32.0) / 32.0;
                            s.Z = Math.Round(jl.StarPos.Z * 32.0) / 32.0;
                        }

                        //Debug.WriteLine("HistoryList found system {0} {1}", s.id_edsm, s.name);
                        newsys = s;

                        if (jl != null && je.EdsmID <= 0 && newsys.EDSMID > 0) // only update on a JL..
                        {
                            journalupdate = true;
                            Debug.WriteLine("HE EDSM ID update requested {0} {1}", newsys.EDSMID, newsys.Name);
                        }
                    }
                    else
                    {
                        newsys.EDSMID = -1;        // mark as checked but not found
                    }
                }

                JournalFSDJump jfsd = je as JournalFSDJump;

                if (jfsd != null)
                {
                    if (jfsd.JumpDist <= 0 && isys.HasCoordinate && newsys.HasCoordinate) // if no JDist, its a really old entry, and if previous has a co-ord
                    {
                        jfsd.JumpDist = isys.Distance(newsys);                            // fill it out here

                        if (jfsd.JumpDist > 0)
                        {
                            journalupdate = true;
                            Debug.WriteLine("Je Jump distance update(3) requested {0} {1} {2}", newsys.EDSMID, newsys.Name, jfsd.JumpDist);
                        }
                    }
                }

                isys = newsys;
            }

            HistoryEntry he = new HistoryEntry
            {
                Indexno      = indexno,
                journalEntry = je,
                System       = isys,
                EntryStatus  = HistoryEntryStatus.Update(prev?.EntryStatus, je, isys.Name)
            };

            he.TravelStatus = HistoryTravelStatus.Update(prev?.TravelStatus, prev, he);     // need a real he so can't do that as part of the constructor.

            return(he);
        }
Exemplo n.º 26
0
        // this allows entries to be merged or discarded before any processing
        // true if to discard
        public static bool MergeOrDiscardEntries(JournalEntry prev, JournalEntry je)
        {
            if (prev != null && !EliteConfigInstance.InstanceOptions.DisableMerge)
            {
                bool prevsame = je.EventTypeID == prev.EventTypeID;

                if (prevsame)
                {
                    if (je.EventTypeID == JournalTypeEnum.FuelScoop)  // merge scoops
                    {
                        EliteDangerousCore.JournalEvents.JournalFuelScoop jfs     = je as EliteDangerousCore.JournalEvents.JournalFuelScoop;
                        EliteDangerousCore.JournalEvents.JournalFuelScoop jfsprev = prev as EliteDangerousCore.JournalEvents.JournalFuelScoop;
                        jfsprev.Scooped += jfs.Scooped;
                        jfsprev.Total    = jfs.Total;
                        //System.Diagnostics.Debug.WriteLine("Merge FS " + jfsprev.EventTimeUTC);
                        return(true);
                    }
                    else if (je.EventTypeID == JournalTypeEnum.Friends) // merge friends
                    {
                        EliteDangerousCore.JournalEvents.JournalFriends jfprev = prev as EliteDangerousCore.JournalEvents.JournalFriends;
                        EliteDangerousCore.JournalEvents.JournalFriends jf     = je as EliteDangerousCore.JournalEvents.JournalFriends;
                        jfprev.AddFriend(jf);
                        //System.Diagnostics.Debug.WriteLine("Merge Friends " + jfprev.EventTimeUTC + " " + jfprev.NameList.Count);
                        return(true);
                    }
                    else if (je.EventTypeID == JournalTypeEnum.FSSSignalDiscovered)
                    {
                        var jdprev = prev as EliteDangerousCore.JournalEvents.JournalFSSSignalDiscovered;
                        var jd     = je as EliteDangerousCore.JournalEvents.JournalFSSSignalDiscovered;
                        jdprev.Add(jd);
                        return(true);
                    }
                    else if (je.EventTypeID == JournalTypeEnum.ShipTargeted)
                    {
                        var jdprev = prev as EliteDangerousCore.JournalEvents.JournalShipTargeted;
                        var jd     = je as EliteDangerousCore.JournalEvents.JournalShipTargeted;
                        jdprev.Add(jd);
                        return(true);
                    }
                    else if (je.EventTypeID == JournalTypeEnum.UnderAttack)
                    {
                        var jdprev = prev as EliteDangerousCore.JournalEvents.JournalUnderAttack;
                        var jd     = je as EliteDangerousCore.JournalEvents.JournalUnderAttack;
                        jdprev.Add(jd.Target);
                        return(true);
                    }
                    else if (je.EventTypeID == JournalTypeEnum.ReceiveText)
                    {
                        var jdprev = prev as EliteDangerousCore.JournalEvents.JournalReceiveText;
                        var jd     = je as EliteDangerousCore.JournalEvents.JournalReceiveText;

                        // merge if same channel
                        if (jd.Channel == jdprev.Channel)
                        {
                            jdprev.Add(jd);
                            return(true);
                        }
                    }
                    else if (je.EventTypeID == JournalTypeEnum.FSSAllBodiesFound)
                    {
                        var jdprev = prev as EliteDangerousCore.JournalEvents.JournalFSSAllBodiesFound;
                        var jd     = je as EliteDangerousCore.JournalEvents.JournalFSSAllBodiesFound;

                        // throw away if same..
                        if (jdprev.SystemName == jd.SystemName && jdprev.Count == jd.Count) // if same, we just waste the repeater, ED sometimes spews out multiples
                        {
                            return(true);
                        }
                    }
                }
            }

            return(false);
        }
Exemplo n.º 27
0
        static public List <JournalEntry> GetAll(int commander         = -999, DateTime?after = null, DateTime?before = null,
                                                 JournalTypeEnum[] ids = null, DateTime?allidsafter = null)
        {
            Dictionary <long, TravelLogUnit> tlus = TravelLogUnit.GetAll().ToDictionary(t => t.id);
            DbCommand           cmd     = null;
            DbDataReader        reader  = null;
            List <JournalEntry> entries = new List <JournalEntry>();

            try
            {
                cmd    = UserDatabase.Instance.ExecuteWithDatabase(cn => cn.Connection.CreateCommand("select * from JournalEntries"));
                reader = UserDatabase.Instance.ExecuteWithDatabase(cn =>
                {
                    string cnd = "";
                    if (commander != -999)
                    {
                        cnd = cnd.AppendPrePad("CommanderID = @commander", " and ");
                        cmd.AddParameterWithValue("@commander", commander);
                    }
                    if (after != null)
                    {
                        cnd = cnd.AppendPrePad("EventTime >= @after", " and ");
                        cmd.AddParameterWithValue("@after", after.Value);
                    }
                    if (before != null)
                    {
                        cnd = cnd.AppendPrePad("EventTime <= @before", " and ");
                        cmd.AddParameterWithValue("@before", before.Value);
                    }
                    if (ids != null)
                    {
                        int[] array = Array.ConvertAll(ids, x => (int)x);
                        if (allidsafter != null)
                        {
                            cmd.AddParameterWithValue("@idafter", allidsafter.Value);
                            cnd = cnd.AppendPrePad("(EventTypeId in (" + string.Join(",", array) + ") Or EventTime>=@idafter)", " and ");
                        }
                        else
                        {
                            cnd = cnd.AppendPrePad("EventTypeId in (" + string.Join(",", array) + ")", " and ");
                        }
                    }

                    if (cnd.HasChars())
                    {
                        cmd.CommandText += " where " + cnd;
                    }

                    cmd.CommandText += " Order By EventTime ASC";

                    return(cmd.ExecuteReader());
                });

                List <JournalEntry> retlist = null;

                do
                {
                    retlist = UserDatabase.Instance.ExecuteWithDatabase(cn =>
                    {
                        List <JournalEntry> list = new List <JournalEntry>();

                        while (list.Count < 1000 && reader.Read())
                        {
                            JournalEntry sys = JournalEntry.CreateJournalEntry(reader);
                            sys.beta         = tlus.ContainsKey(sys.TLUId) ? tlus[sys.TLUId].Beta : false;
                            list.Add(sys);
                        }

                        return(list);
                    });

                    entries.AddRange(retlist);
                }while (retlist != null && retlist.Count != 0);

                return(entries);
            }
            finally
            {
                if (reader != null || cmd != null)
                {
                    UserDatabase.Instance.ExecuteWithDatabase(cn =>
                    {
                        reader?.Close();
                        cmd?.Dispose();
                    });
                }
            }
        }
Exemplo n.º 28
0
        // inhistoryrefreshparse = means reading history in batch mode
        private JournalReaderEntry ProcessLine(string line, bool inhistoryrefreshparse, bool resetOnError)
        {
            int cmdrid = -2;        //-1 is hidden, -2 is never shown

            if (TravelLogUnit.CommanderId.HasValue)
            {
                cmdrid = TravelLogUnit.CommanderId.Value;
                // System.Diagnostics.Trace.WriteLine(string.Format("TLU says commander {0} at {1}", cmdrid, TravelLogUnit.Name));
            }

            if (line.Length == 0)
            {
                return(null);
            }

            JObject      jo = null;
            JournalEntry je = null;

            try
            {
                jo = JObject.Parse(line);
                je = JournalEntry.CreateJournalEntry(jo);
            }
            catch
            {
                System.Diagnostics.Trace.WriteLine($"Bad journal line:\n{line}");

                if (resetOnError)
                {
                    throw;
                }
                else
                {
                    return(null);
                }
            }

            if (je == null)
            {
                System.Diagnostics.Trace.WriteLine($"Bad journal line:\n{line}");
                return(null);
            }

            if (StoreJsonInJE)
            {
                je.JsonCached = jo;
            }

            bool toosoon = false;

            if (je.EventTypeID == JournalTypeEnum.Fileheader)
            {
                JournalEvents.JournalFileheader header = (JournalEvents.JournalFileheader)je;

                if ((header.Beta && !EliteConfigInstance.InstanceOptions.DisableBetaCommanderCheck) || EliteConfigInstance.InstanceOptions.ForceBetaOnCommander) // if beta, and not disabled, or force beta
                {
                    TravelLogUnit.type |= TravelLogUnit.BetaMarker;
                }

                if (header.Part > 1)
                {
                    JournalEvents.JournalContinued contd = JournalEntry.GetLast <JournalEvents.JournalContinued>(je.EventTimeUTC.AddSeconds(1), e => e.Part == header.Part);

                    // Carry commander over from previous log if it ends with a Continued event.
                    if (contd != null && Math.Abs(header.EventTimeUTC.Subtract(contd.EventTimeUTC).TotalSeconds) < 5 && contd.CommanderId >= 0)
                    {
                        TravelLogUnit.CommanderId = contd.CommanderId;
                    }
                }
            }
            else if (je.EventTypeID == JournalTypeEnum.LoadGame)
            {
                var    jlg     = je as JournalEvents.JournalLoadGame;
                string newname = jlg.LoadGameCommander;

                if ((TravelLogUnit.type & TravelLogUnit.BetaMarker) == TravelLogUnit.BetaMarker)
                {
                    newname = "[BETA] " + newname;
                }

                EDCommander commander = EDCommander.GetCommander(newname);

                if (commander == null)
                {
                    // in the default condition, we have a hidden commander, and first Cmdr. Jameson.
                    commander = EDCommander.GetListCommanders().FirstOrDefault();
                    if (EDCommander.NumberOfCommanders == 2 && commander != null && commander.Name == "Jameson (Default)")
                    {
                        commander.Name     = newname;
                        commander.EdsmName = newname;
                        EDCommander.Update(new List <EDCommander> {
                            commander
                        }, false);
                    }
                    else
                    {
                        commander = EDCommander.Create(newname, null, EDJournalClass.GetDefaultJournalDir().Equals(TravelLogUnit.Path) ? "" : TravelLogUnit.Path);
                    }
                }

                commander.FID = jlg.FID;

                cmdrid = commander.Nr;

                if (!TravelLogUnit.CommanderId.HasValue)
                {
                    TravelLogUnit.CommanderId = cmdrid;
                    TravelLogUnit.Update();
//                    System.Diagnostics.Trace.WriteLine(string.Format("TLU {0} updated with commander {1}", TravelLogUnit.Path, cmdrid));
                }
            }
            else if (je is ISystemStationEntry && ((ISystemStationEntry)je).IsTrainingEvent)
            {
                System.Diagnostics.Trace.WriteLine($"Training detected:\n{line}");
                return(null);
            }

            if (je is IAdditionalFiles)
            {
                if ((je as IAdditionalFiles).ReadAdditionalFiles(Path.GetDirectoryName(FileName), inhistoryrefreshparse, ref jo) == false)     // if failed
                {
                    return(null);
                }
            }

            if (je is JournalEvents.JournalShipyard)                // when going into shipyard
            {
                toosoon      = lastshipyard != null && lastshipyard.Yard.Equals((je as JournalEvents.JournalShipyard).Yard);
                lastshipyard = je as JournalEvents.JournalShipyard;
            }
            else if (je is JournalEvents.JournalStoredShips)        // when going into shipyard
            {
                toosoon = laststoredships != null && CollectionStaticHelpers.Equals(laststoredships.ShipsHere, (je as JournalEvents.JournalStoredShips).ShipsHere) &&
                          CollectionStaticHelpers.Equals(laststoredships.ShipsRemote, (je as JournalEvents.JournalStoredShips).ShipsRemote);
                laststoredships = je as JournalEvents.JournalStoredShips;
            }
            else if (je is JournalEvents.JournalStoredModules)      // when going into outfitting
            {
                toosoon           = laststoredmodules != null && CollectionStaticHelpers.Equals(laststoredmodules.ModuleItems, (je as JournalEvents.JournalStoredModules).ModuleItems);
                laststoredmodules = je as JournalEvents.JournalStoredModules;
            }
            else if (je is JournalEvents.JournalOutfitting)         // when doing into outfitting
            {
                toosoon        = lastoutfitting != null && lastoutfitting.ItemList.Equals((je as JournalEvents.JournalOutfitting).ItemList);
                lastoutfitting = je as JournalEvents.JournalOutfitting;
            }
            else if (je is JournalEvents.JournalMarket)
            {
                toosoon    = lastmarket != null && lastmarket.Equals(je as JournalEvents.JournalMarket);
                lastmarket = je as JournalEvents.JournalMarket;
            }
            else if (je is JournalEvents.JournalUndocked || je is JournalEvents.JournalLoadGame)             // undocked, Load Game, repeats are cleared
            {
                lastshipyard      = null;
                laststoredmodules = null;
                lastoutfitting    = null;
                laststoredmodules = null;
                laststoredships   = null;
            }

            if (toosoon)                                                // if seeing repeats, remove
            {
                // System.Diagnostics.Debug.WriteLine("**** Remove as dup " + je.EventTypeStr);
                return(null);
            }

            je.SetTLUCommander(TravelLogUnit.id, cmdrid);

            return(new JournalReaderEntry {
                JournalEntry = je, Json = jo
            });
        }
Exemplo n.º 29
0
        public void ParseJournalFiles(Func <bool> cancelRequested, Action <int, string> updateProgress, bool forceReload = false)
        {
            System.Diagnostics.Trace.WriteLine("Scanned " + m_watcherfolder);

            Dictionary <string, TravelLogUnit> m_travelogUnits = TravelLogUnit.GetAll().Where(t => (t.type & 0xFF) == 3).GroupBy(t => t.Name).Select(g => g.First()).ToDictionary(t => t.Name);

            // order by file write time so we end up on the last one written
            FileInfo[] allFiles = Directory.EnumerateFiles(m_watcherfolder, "Journal*.log", SearchOption.AllDirectories).Select(f => new FileInfo(f)).OrderBy(p => p.LastWriteTime).ToArray();

            List <EDJournalReader> readersToUpdate = new List <EDJournalReader>();

            for (int i = 0; i < allFiles.Length; i++)
            {
                FileInfo fi = allFiles[i];

                var reader = OpenFileReader(fi, m_travelogUnits);

                if (!m_travelogUnits.ContainsKey(reader.TravelLogUnit.Name))
                {
                    m_travelogUnits[reader.TravelLogUnit.Name] = reader.TravelLogUnit;
                    reader.TravelLogUnit.type = 3;
                    reader.TravelLogUnit.Add();
                }

                if (!netlogreaders.ContainsKey(reader.TravelLogUnit.Name))
                {
                    netlogreaders[reader.TravelLogUnit.Name] = reader;
                }

                if (forceReload)
                {
                    // Force a reload of the travel log
                    reader.TravelLogUnit.Size = 0;
                }

                if (reader.filePos != fi.Length || i == allFiles.Length - 1)  // File not already in DB, or is the last one
                {
                    readersToUpdate.Add(reader);
                }
            }

            for (int i = 0; i < readersToUpdate.Count; i++)
            {
                using (SQLiteConnectionUser cn = new SQLiteConnectionUser(utc: true))
                {
                    EDJournalReader reader = readersToUpdate[i];
                    updateProgress(i * 100 / readersToUpdate.Count, reader.TravelLogUnit.Name);

                    List <JournalReaderEntry>        entries  = reader.ReadJournalLog(true).ToList(); // this may create new commanders, and may write to the TLU db
                    ILookup <DateTime, JournalEntry> existing = JournalEntry.GetAllByTLU(reader.TravelLogUnit.id).ToLookup(e => e.EventTimeUTC);

                    using (DbTransaction tn = cn.BeginTransaction())
                    {
                        foreach (JournalReaderEntry jre in entries)
                        {
                            if (!existing[jre.JournalEntry.EventTimeUTC].Any(e => JournalEntry.AreSameEntry(jre.JournalEntry, e, ent1jo: jre.Json)))
                            {
                                System.Diagnostics.Trace.WriteLine(string.Format("Write Journal to db {0} {1}", jre.JournalEntry.EventTimeUTC, jre.JournalEntry.EventTypeStr));
                                jre.JournalEntry.Add(jre.Json, cn, tn);
                            }
                        }

                        tn.Commit();
                    }

                    reader.TravelLogUnit.Update(cn);

                    updateProgress((i + 1) * 100 / readersToUpdate.Count, reader.TravelLogUnit.Name);

                    lastnfi = reader;
                }
            }

            updateProgress(-1, "");
        }
Exemplo n.º 30
0
        static public List <JournalEntry> GetAll(int commander         = -999, DateTime?after = null, DateTime?before = null,
                                                 JournalTypeEnum[] ids = null, DateTime?allidsafter = null)
        {
            Dictionary <long, TravelLogUnit> tlus = TravelLogUnit.GetAll().ToDictionary(t => t.id);

            List <JournalEntry> list = new List <JournalEntry>();

            using (SQLiteConnectionUser cn = new SQLiteConnectionUser(utc: true))
            {
                using (DbCommand cmd = cn.CreateCommand("select * from JournalEntries"))
                {
                    string cnd = "";
                    if (commander != -999)
                    {
                        cnd = cnd.AppendPrePad("CommanderID = @commander", " and ");
                        cmd.AddParameterWithValue("@commander", commander);
                    }
                    if (after != null)
                    {
                        cnd = cnd.AppendPrePad("EventTime >= @after", " and ");
                        cmd.AddParameterWithValue("@after", after.Value);
                    }
                    if (before != null)
                    {
                        cnd = cnd.AppendPrePad("EventTime <= @before", " and ");
                        cmd.AddParameterWithValue("@before", before.Value);
                    }
                    if (ids != null)
                    {
                        int[] array = Array.ConvertAll(ids, x => (int)x);
                        if (allidsafter != null)
                        {
                            cmd.AddParameterWithValue("@idafter", allidsafter.Value);
                            cnd = cnd.AppendPrePad("(EventTypeId in (" + string.Join(",", array) + ") Or EventTime>=@idafter)", " and ");
                        }
                        else
                        {
                            cnd = cnd.AppendPrePad("EventTypeId in (" + string.Join(",", array) + ")", " and ");
                        }
                    }

                    if (cnd.HasChars())
                    {
                        cmd.CommandText += " where " + cnd;
                    }

                    cmd.CommandText += " Order By EventTime ASC";

                    using (DbDataReader reader = cmd.ExecuteReader())
                    {
                        while (reader.Read())
                        {
                            JournalEntry sys = JournalEntry.CreateJournalEntry(reader);
                            sys.beta = tlus.ContainsKey(sys.TLUId) ? tlus[sys.TLUId].Beta : false;
                            list.Add(sys);
                        }
                    }

                    return(list);
                }
            }
        }