コード例 #1
0
        // Called by ScanForNewEntries (from EDJournalClass Scan Tick Worker) to scan a NFI for new entries

        private void ScanReader(EDJournalReader nfi, List <JournalEntry> entries, List <UIEvent> uientries)
        {
            int netlogpos = 0;

            try
            {
                if (nfi.TravelLogUnit.id == 0)
                {
                    nfi.TravelLogUnit.type = TravelLogUnit.JournalType;
                    nfi.TravelLogUnit.Add();
                }

                netlogpos = nfi.TravelLogUnit.Size;

                bool readanything = nfi.ReadJournal(out List <JournalEntry> ents, out List <UIEvent> uie, historyrefreshparsing: false, resetOnError: false);

                uientries.AddRange(uie);

                if (readanything)           // if we read, we must update the travel log pos
                {
                    //System.Diagnostics.Debug.WriteLine("ScanReader " + Path.GetFileName(nfi.FileName) + " read " + ents.Count + " ui " +uientries.Count + " size " + netlogpos);

                    UserDatabase.Instance.ExecuteWithDatabase(cn =>
                    {
                        using (DbTransaction txn = cn.Connection.BeginTransaction())
                        {
                            ents = ents.Where(jre => JournalEntry.FindEntry(jre, cn, jre.GetJson()).Count == 0).ToList();

                            foreach (JournalEntry jre in ents)
                            {
                                entries.Add(jre);
                                jre.Add(jre.GetJson(), cn.Connection, txn);
                            }

                            //System.Diagnostics.Debug.WriteLine("Wrote " + ents.Count() + " to db and updated TLU");

                            nfi.TravelLogUnit.Update(cn.Connection);

                            txn.Commit();
                        }
                    });
                }
            }
            catch (Exception ex)
            {
                System.Diagnostics.Debug.WriteLine("Exception " + ex.Message);
                // Revert and re-read the failed entries
                if (nfi != null && nfi.TravelLogUnit != null)
                {
                    nfi.TravelLogUnit.Size = netlogpos;
                }

                throw;
            }
        }
コード例 #2
0
        // Called by ScanForNewEntries (from EDJournalClass Scan Tick Worker) to scan a NFI for new entries

        private void ScanReader(List <JournalEntry> entries, List <UIEvent> uientries)
        {
            System.Diagnostics.Debug.Assert(lastnfi.ID != 0);                             // must have committed it at this point, prev code checked for it but it must have been done
            System.Diagnostics.Debug.Assert(netlogreaders.ContainsKey(lastnfi.FullName)); // must have added to netlogreaders.. double check

            bool readanything = lastnfi.ReadJournal(entries, uientries, historyrefreshparsing: false);

            if (StoreToDBDuringUpdateRead)
            {
                if (entries.Count > 0 || readanything)
                {
                    UserDatabase.Instance.ExecuteWithDatabase(cn =>
                    {
                        System.Diagnostics.Stopwatch sw = new System.Diagnostics.Stopwatch();
                        sw.Start();

                        using (DbTransaction txn = cn.Connection.BeginTransaction())
                        {
                            if (entries.Count > 0)
                            {
                                entries = entries.Where(jre => JournalEntry.FindEntry(jre, cn, jre.GetJson(cn.Connection, txn)).Count == 0).ToList();

                                foreach (JournalEntry jre in entries)
                                {
                                    var json = jre.GetJson(cn.Connection, txn);
                                    jre.Add(json, cn.Connection, txn);
                                }
                            }

                            lastnfi.TravelLogUnit.Update(cn.Connection, txn);       // update TLU pos

                            txn.Commit();
                        }

                        if (sw.ElapsedMilliseconds >= 50)        // this is written to the log to try and debug bad DB behaviour
                        {
                            System.Diagnostics.Trace.WriteLine("Warning access to DB to write new journal entries slow " + sw.ElapsedMilliseconds);
                            foreach (var e in entries)
                            {
                                System.Diagnostics.Trace.WriteLine(".." + e.EventTimeUTC + " " + e.EventTypeStr);
                            }
                        }
                    });
                }
            }
            else
            {
                if (readanything)
                {
                    lastnfi.TravelLogUnit.Update();
                }
            }

            //if ( entries.Count()>0 || uientries.Count()>0) System.Diagnostics.Debug.WriteLine("ScanRead " + entries.Count() + " " + uientries.Count());
        }
コード例 #3
0
        // Called by ScanForNewEntries (from EDJournalClass Scan Tick Worker) to scan a NFI for new entries

        private void ScanReader(EDJournalReader nfi, List <JournalEntry> entries)
        {
            int netlogpos = 0;

            try
            {
                if (nfi.TravelLogUnit.id == 0)
                {
                    nfi.TravelLogUnit.type = 3;
                    nfi.TravelLogUnit.Add();
                }

                netlogpos = nfi.TravelLogUnit.Size;

                bool readanything = nfi.ReadJournal(out List <JournalReaderEntry> ents, historyrefreshparsing: false, resetOnError: false);

                //System.Diagnostics.Debug.WriteLine("ScanReader " + Path.GetFileName(nfi.FileName) + " read " + ents.Count + " size " + netlogpos);

                if (readanything)           // if we read, we must update the travel log pos
                {
                    using (SQLiteConnectionUser cn = new SQLiteConnectionUser(utc: true))
                    {
                        using (DbTransaction txn = cn.BeginTransaction())
                        {
                            ents = ents.Where(jre => JournalEntry.FindEntry(jre.JournalEntry, jre.Json).Count == 0).ToList();

                            foreach (JournalReaderEntry jre in ents)
                            {
                                entries.Add(jre.JournalEntry);
                                jre.JournalEntry.Add(jre.Json, cn, txn);
                                ticksNoActivity = 0;
                            }

                            System.Diagnostics.Debug.WriteLine("Wrote " + ents.Count() + " to db and updated TLU");
                            nfi.TravelLogUnit.Update(cn);

                            txn.Commit();
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                System.Diagnostics.Debug.WriteLine("Exception " + ex.Message);
                // Revert and re-read the failed entries
                if (nfi != null && nfi.TravelLogUnit != null)
                {
                    nfi.TravelLogUnit.Size = netlogpos;
                }

                throw;
            }
        }
コード例 #4
0
        // Called by ScanForNewEntries (from EDJournalClass Scan Tick Worker) to scan a NFI for new entries

        private void ScanReader(EDJournalReader nfi, List <JournalEntry> entries)
        {
            int netlogpos = 0;

            try
            {
                if (nfi.TravelLogUnit.id == 0)
                {
                    nfi.TravelLogUnit.type = 3;
                    nfi.TravelLogUnit.Add();
                }

                netlogpos = nfi.TravelLogUnit.Size;

                List <JournalReaderEntry> ents = nfi.ReadJournalLog().ToList();

                //System.Diagnostics.Debug.WriteLine("ScanReader " + Path.GetFileName(nfi.FileName) + " read " + ents.Count + " size " + netlogpos);

                if (ents.Count > 0)
                {
                    using (SQLiteConnectionUser cn = new SQLiteConnectionUser(utc: true))
                    {
                        using (DbTransaction txn = cn.BeginTransaction())
                        {
                            ents = ents.Where(jre => JournalEntry.FindEntry(jre.JournalEntry, jre.Json).Count == 0).ToList();

                            foreach (JournalReaderEntry jre in ents)
                            {
                                entries.Add(jre.JournalEntry);
                                jre.JournalEntry.Add(jre.Json, cn, txn);
                                ticksNoActivity = 0;
                            }

                            nfi.TravelLogUnit.Update(cn);

                            txn.Commit();
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                System.Diagnostics.Debug.WriteLine("Exception " + ex.Message);
                // Revert and re-read the failed entries
                if (nfi != null && nfi.TravelLogUnit != null)
                {
                    nfi.TravelLogUnit.Size = netlogpos;
                }

                throw;
            }
        }
コード例 #5
0
        private void ScanReader(EDJournalReader nfi, List <JournalEntry> entries)
        {
            int netlogpos = 0;

            try
            {
                if (nfi.TravelLogUnit.id == 0)
                {
                    nfi.TravelLogUnit.type = 3;
                    nfi.TravelLogUnit.Add();
                }

                netlogpos = nfi.TravelLogUnit.Size;

                List <JournalReaderEntry> ents = nfi.ReadJournalLog().ToList();

                if (ents.Count > 0)
                {
                    using (SQLiteConnectionUser cn = new SQLiteConnectionUser(utc: true))
                    {
                        using (DbTransaction txn = cn.BeginTransaction())
                        {
                            ents = ents.Where(jre => JournalEntry.FindEntry(jre.JournalEntry, jre.Json).Count == 0).ToList();

                            foreach (JournalReaderEntry jre in ents)
                            {
                                entries.Add(jre.JournalEntry);
                                jre.JournalEntry.Add(jre.Json, cn, txn);
                                ticksNoActivity = 0;
                            }

                            nfi.TravelLogUnit.Update(cn);

                            txn.Commit();
                        }
                    }
                }
            }
            catch
            {
                // Revert and re-read the failed entries
                if (nfi != null && nfi.TravelLogUnit != null)
                {
                    nfi.TravelLogUnit.Size = netlogpos;
                }

                throw;
            }
        }