static public bool?SendToEDDN(HistoryEntry he, bool debugonly = false)
        {
            EDDNClass eddn = new EDDNClass();

            if (he.Commander != null)
            {
                eddn.commanderName = he.Commander.EdsmName;
                if (string.IsNullOrEmpty(eddn.commanderName))
                {
                    eddn.commanderName = he.Commander.Name;
                }

                if (he.Commander.Name.StartsWith("[BETA]", StringComparison.InvariantCultureIgnoreCase))
                {
                    eddn.isBeta = true;
                }
            }

            if (he.IsBetaMessage)
            {
                eddn.isBeta = true;
            }

            JournalEntry je = he.journalEntry;

            if (je == null)
            {
                je = JournalEntry.Get(he.Journalid);
            }

            BaseUtils.JSON.JObject msg = null;

            if (je.EventTypeID == JournalTypeEnum.FSDJump)
            {
                msg = eddn.CreateEDDNMessage(je as JournalFSDJump);
            }
            else if (je.EventTypeID == JournalTypeEnum.Location)
            {
                msg = eddn.CreateEDDNMessage(je as JournalLocation);
            }
            else if (je.EventTypeID == JournalTypeEnum.CarrierJump)
            {
                msg = eddn.CreateEDDNMessage(je as JournalCarrierJump);
            }
            else if (je.EventTypeID == JournalTypeEnum.Docked)
            {
                msg = eddn.CreateEDDNMessage(je as JournalDocked, he.System);
            }
            else if (je.EventTypeID == JournalTypeEnum.Scan)
            {
                msg = eddn.CreateEDDNMessage(je as JournalScan, he.System);
            }
            else if (je.EventTypeID == JournalTypeEnum.SAASignalsFound)
            {
                msg = eddn.CreateEDDNMessage(je as JournalSAASignalsFound, he.System);
            }
            else if (je.EventTypeID == JournalTypeEnum.Outfitting)
            {
                msg = eddn.CreateEDDNOutfittingMessage(je as JournalOutfitting);
            }
            else if (je.EventTypeID == JournalTypeEnum.Shipyard)
            {
                msg = eddn.CreateEDDNShipyardMessage(je as JournalShipyard);
            }
            else if (je.EventTypeID == JournalTypeEnum.Market)
            {
                JournalMarket jm = je as JournalMarket;
                msg = eddn.CreateEDDNCommodityMessage(jm.Commodities, jm.StarSystem, jm.Station, jm.MarketID, jm.EventTimeUTC);      // if its devoid of data, null returned
            }

            if (msg != null)
            {
                System.Diagnostics.Debug.WriteLine("Send to EDDN " + msg.ToString(true));

                if (!debugonly && eddn.PostMessage(msg))
                {
                    he.journalEntry.SetEddnSync();
                    return(true);
                }
                else
                {
                    return(false);
                }
            }
            else
            {
                return(null);
            }
        }
        // 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, "");
        }