示例#1
0
        private void AddNewHistoryRow(bool insert, HistoryEntry item)            // second part of add history row, adds item to view.
        {
            SystemNoteClass snc = SystemNoteClass.GetNoteOnJournalEntry(item.Journalid);

            if (snc == null && item.IsFSDJump)
            {
                snc = SystemNoteClass.GetNoteOnSystem(item.System.name, item.System.id_edsm);
            }

            // Try to fill EDSM ID where a system note is set but journal item EDSM ID is not set
            if (snc != null && snc.Name != null && snc.EdsmId > 0 && item.System.id_edsm <= 0)
            {
                item.System.id_edsm = 0;
                discoveryform.history.FillEDSM(item);

                if (snc.Journalid != item.Journalid && item.System.id_edsm > 0 && snc.EdsmId != item.System.id_edsm)
                {
                    snc = null;
                }
            }

            if (snc != null && snc.Name != null && snc.Journalid == item.Journalid && item.System.id_edsm > 0 && snc.EdsmId != item.System.id_edsm)
            {
                snc.EdsmId = item.System.id_edsm;
                snc.Update();
            }

            //string debugt = item.Journalid + "  " + item.System.id_edsm + " " + item.System.GetHashCode() + " "; // add on for debug purposes to a field below

            object[] rowobj = { EDDiscoveryForm.EDDConfig.DisplayUTC?item.EventTimeUTC : item.EventTimeLocal, "", item.EventSummary, item.EventDescription, (snc != null) ? snc.Note : "" };

            int rownr;

            if (insert)
            {
                dataGridViewTravel.Rows.Insert(0, rowobj);
                rownr = 0;
            }
            else
            {
                dataGridViewTravel.Rows.Add(rowobj);
                rownr = dataGridViewTravel.Rows.Count - 1;
            }

            dataGridViewTravel.Rows[rownr].Cells[TravelHistoryColumns.HistoryTag].Tag = item;
            dataGridViewTravel.Rows[rownr].Cells[TravelHistoryColumns.NoteTag].Tag    = snc;

            dataGridViewTravel.Rows[rownr].DefaultCellStyle.ForeColor = (item.System.HasCoordinate || item.EntryType != JournalTypeEnum.FSDJump) ? discoveryform.theme.VisitedSystemColor : discoveryform.theme.NonVisitedSystemColor;

            string tip = item.EventSummary + Environment.NewLine + item.EventDescription + Environment.NewLine + item.EventDetailedInfo;

            dataGridViewTravel.Rows[rownr].Cells[0].ToolTipText = tip;
            dataGridViewTravel.Rows[rownr].Cells[1].ToolTipText = tip;
            dataGridViewTravel.Rows[rownr].Cells[2].ToolTipText = tip;
            dataGridViewTravel.Rows[rownr].Cells[3].ToolTipText = tip;
            dataGridViewTravel.Rows[rownr].Cells[4].ToolTipText = tip;
        }
示例#2
0
        private void Sync(EDSMClass edsm)
        {
            try
            {
                mainForm.LogLine("EDSM sync begin");

                List <HistoryEntry> hlfsdunsyncedlist = mainForm.history.FilterByNotEDSMSyncedAndFSD; // first entry is oldest

                if (_syncTo && hlfsdunsyncedlist.Count > 0)                                           // send systems to edsm (verified with dates, 29/9/2016, utc throughout)
                {
                    DateTime logstarttime = DateTime.MinValue;
                    DateTime logendtime   = DateTime.MinValue;

                    mainForm.LogLine("EDSM: Sending " + hlfsdunsyncedlist.Count.ToString() + " flightlog entries");

                    List <HistoryEntry> edsmsystemlog = null;

                    int edsmsystemssent = 0;

                    foreach (var he in hlfsdunsyncedlist)
                    {
                        if (Exit)
                        {
                            running = false;
                            return;
                        }

                        if (edsmsystemlog == null || he.EventTimeUTC >= logendtime.AddDays(-1))
                        {
                            edsm.GetLogs(he.EventTimeUTC.AddDays(-1), null, out edsmsystemlog, out logstarttime, out logendtime);        // always returns a log, time is in UTC as per HistoryEntry and JournalEntry
                        }

                        if (logendtime < logstarttime)
                        {
                            running = false;
                            return;
                        }

                        if (edsmsystemlog == null)
                        {
                            running = false;
                            return;
                        }

                        HistoryEntry ps2 = (from c in edsmsystemlog where c.System.name == he.System.name && c.EventTimeUTC.Ticks == he.EventTimeUTC.Ticks select c).FirstOrDefault();

                        if (ps2 != null)                // it did, just make sure EDSM sync flag is set..
                        {
                            he.SetEdsmSync();
                        }
                        else
                        {
                            string errmsg;              // (verified with EDSM 29/9/2016)
                            bool   firstdiscover;
                            int    edsmid;

                            if (edsm.SendTravelLog(he.System.name, he.EventTimeUTC, he.System.HasCoordinate && !he.IsStarPosFromEDSM, he.System.x, he.System.y, he.System.z, out errmsg, out firstdiscover, out edsmid))
                            {
                                if (edsmid != 0 && he.System.id_edsm <= 0)
                                {
                                    he.System.id_edsm = edsmid;
                                    EDDiscovery.EliteDangerous.JournalEntry.UpdateEDSMIDPosJump(he.Journalid, he.System, false, -1);
                                }

                                if (firstdiscover)
                                {
                                    he.SetFirstDiscover();
                                }

                                he.SetEdsmSync();
                                edsmsystemssent++;
                            }

                            if (errmsg.Length > 0)
                            {
                                mainForm.LogLine(errmsg);
                                break;
                            }
                        }
                    }

                    mainForm.LogLine(string.Format("EDSM Systems sent {0}", edsmsystemssent));
                }

                // TBD Comments to edsm?

                if (_syncFrom)                                                              // Verified ok with time 29/9/2016
                {
                    var json = edsm.GetComments(new DateTime(2011, 1, 1));

                    if (json != null)
                    {
                        JObject msg   = JObject.Parse(json);
                        int     msgnr = msg["msgnum"].Value <int>();

                        JArray comments = (JArray)msg["comments"];
                        if (comments != null)
                        {
                            int commentsadded = 0;

                            foreach (JObject jo in comments)
                            {
                                string name    = jo["system"].Value <string>();
                                string note    = jo["comment"].Value <string>();
                                string utctime = jo["lastUpdate"].Value <string>();
                                int    edsmid  = 0;

                                if (!Int32.TryParse(JSONHelper.GetStringDef(jo["systemId"], "0"), out edsmid))
                                {
                                    edsmid = 0;
                                }

                                DateTime localtime = DateTime.ParseExact(utctime, "yyyy-MM-dd HH:mm:ss",
                                                                         CultureInfo.InvariantCulture, DateTimeStyles.AssumeUniversal).ToLocalTime();

                                SystemNoteClass curnote = SystemNoteClass.GetNoteOnSystem(name, edsmid);

                                if (curnote != null)
                                {
                                    // curnote uses local time to store
                                    if (localtime.Ticks > curnote.Time.Ticks)   // if newer, add on (verified with EDSM 29/9/2016)
                                    {
                                        curnote.Note  += ". EDSM: " + note;
                                        curnote.Time   = localtime;
                                        curnote.EdsmId = edsmid;
                                        curnote.Update();
                                        commentsadded++;
                                    }
                                }
                                else
                                {
                                    curnote           = new SystemNoteClass();
                                    curnote.Note      = note;
                                    curnote.Time      = localtime;
                                    curnote.Name      = name;
                                    curnote.Journalid = 0;
                                    curnote.EdsmId    = edsmid;
                                    curnote.Add();
                                    commentsadded++;
                                }
                            }

                            mainForm.LogLine(string.Format("EDSM Comments downloaded/updated {0}", commentsadded));
                        }
                    }
                }

                mainForm.LogLine("EDSM sync Done");
            }
            catch (Exception ex)
            {
                System.Diagnostics.Trace.WriteLine("Exception ex:" + ex.Message);
                mainForm.LogLineHighlight("EDSM sync Exception " + ex.Message);
            }
        }
示例#3
0
        private void Sync(EDSMClass edsm)
        {
            try
            {
                mainForm.LogLine("EDSM sync begin");

                List <HistoryEntry> hlfsdunsyncedlist = mainForm.history.FilterByNotEDSMSyncedAndFSD; // first entry is oldest

                if (_syncTo && hlfsdunsyncedlist.Count > 0)                                           // send systems to edsm (verified with dates, 29/9/2016, utc throughout)
                {
                    DateTime utcmin = hlfsdunsyncedlist[0].EventTimeUTC.AddDays(-1);                  // 1 days for margin ;-)  only get them back to this date for speed..

                    mainForm.LogLine("EDSM: Sending " + hlfsdunsyncedlist.Count.ToString() + " flightlog entries");

                    List <HistoryEntry> edsmsystemlog = null;
                    edsm.GetLogs(utcmin, out edsmsystemlog);        // always returns a log, time is in UTC as per HistoryEntry and JournalEntry

                    int edsmsystemssent = 0;

                    foreach (var he in hlfsdunsyncedlist)
                    {
                        if (Exit)
                        {
                            running = false;
                            return;
                        }

                        HistoryEntry ps2 = (from c in edsmsystemlog where c.System.name == he.System.name && c.EventTimeUTC.Ticks == he.EventTimeUTC.Ticks select c).FirstOrDefault();

                        if (ps2 != null)                // it did, just make sure EDSM sync flag is set..
                        {
                            he.SetEdsmSync();
                        }
                        else
                        {
                            string errmsg;              // (verified with EDSM 29/9/2016)

                            // it converts to UTC inside the function, supply local for now
                            if (edsm.SendTravelLog(he.System.name, he.EventTimeUTC, he.System.HasCoordinate && !he.IsStarPosFromEDSM, he.System.x, he.System.y, he.System.z, out errmsg))
                            {
                                he.SetEdsmSync();
                            }

                            if (errmsg.Length > 0)
                            {
                                mainForm.LogLine(errmsg);
                            }

                            edsmsystemssent++;
                        }
                    }

                    mainForm.LogLine(string.Format("EDSM Systems sent {0}", edsmsystemssent));
                }

                // TBD Comments to edsm?

                if (_syncFrom)                                                              // Verified ok with time 29/9/2016
                {
                    var json = edsm.GetComments(new DateTime(2011, 1, 1));

                    if (json != null)
                    {
                        JObject msg   = JObject.Parse(json);
                        int     msgnr = msg["msgnum"].Value <int>();

                        JArray comments = (JArray)msg["comments"];
                        if (comments != null)
                        {
                            int commentsadded = 0;

                            foreach (JObject jo in comments)
                            {
                                string name    = jo["system"].Value <string>();
                                string note    = jo["comment"].Value <string>();
                                string utctime = jo["lastUpdate"].Value <string>();
                                int    edsmid  = 0;

                                if (!Int32.TryParse(JSONHelper.GetStringDef(jo["systemId"], "0"), out edsmid))
                                {
                                    edsmid = 0;
                                }

                                DateTime localtime = DateTime.ParseExact(utctime, "yyyy-MM-dd HH:mm:ss",
                                                                         CultureInfo.InvariantCulture, DateTimeStyles.AssumeUniversal).ToLocalTime();

                                SystemNoteClass curnote = SystemNoteClass.GetNoteOnSystem(name, edsmid);

                                if (curnote != null)
                                {
                                    // curnote uses local time to store
                                    if (localtime.Ticks > curnote.Time.Ticks)   // if newer, add on (verified with EDSM 29/9/2016)
                                    {
                                        curnote.Note  += ". EDSM: " + note;
                                        curnote.Time   = localtime;
                                        curnote.EdsmId = edsmid;
                                        curnote.Update();
                                        commentsadded++;
                                    }
                                }
                                else
                                {
                                    curnote           = new SystemNoteClass();
                                    curnote.Note      = note;
                                    curnote.Time      = localtime;
                                    curnote.Name      = name;
                                    curnote.Journalid = 0;
                                    curnote.EdsmId    = edsmid;
                                    curnote.Add();
                                    commentsadded++;
                                }
                            }

                            mainForm.LogLine(string.Format("EDSM Comments downloaded/updated {0}", commentsadded));
                        }
                    }
                }

                if (_syncFrom)      // verified after struggle 29/9/2016
                {
                    List <HistoryEntry> edsmsystemlog = null;
                    edsm.GetLogs(new DateTime(2011, 1, 1), out edsmsystemlog);        // get the full list of systems
                    edsmsystemlog = edsmsystemlog.OrderBy(s => s.EventTimeUTC).ToList();

                    List <HistoryEntry> hlfsdlist = mainForm.history.FilterByFSD.OrderBy(h => h.EventTimeUTC).ToList();  // FSD jumps only

                    List <HistoryEntry> toadd = new List <HistoryEntry>();

                    int previdx = -1;
                    foreach (HistoryEntry he in edsmsystemlog)      // find out list of ones not present
                    {
                        int index = hlfsdlist.FindIndex(x => x.System.name.Equals(he.System.name, StringComparison.InvariantCultureIgnoreCase) && x.EventTimeUTC.Ticks == he.EventTimeUTC.Ticks);

                        if (index < 0)
                        {
                            // Look for any entries where DST may have thrown off the time
                            foreach (var vi in hlfsdlist.Select((v, i) => new { v = v, i = i }).Where(vi => vi.v.System.name.Equals(he.System.name, StringComparison.InvariantCultureIgnoreCase)))
                            {
                                if (vi.i > previdx)
                                {
                                    double hdiff = vi.v.EventTimeUTC.Subtract(he.EventTimeUTC).TotalHours;
                                    if (hdiff >= -2 && hdiff <= 2 && hdiff == Math.Floor(hdiff))
                                    {
                                        if (vi.v.System.id_edsm <= 0)
                                        {
                                            vi.v.System.id_edsm = 0;
                                            mainForm.history.FillEDSM(vi.v);
                                        }

                                        if (vi.v.System.id_edsm <= 0 || vi.v.System.id_edsm == he.System.id_edsm)
                                        {
                                            index = vi.i;
                                            break;
                                        }
                                    }
                                }
                            }
                        }

                        if (index < 0)
                        {
                            toadd.Add(he);
                        }
                        else
                        {
                            previdx = index;
                        }
                    }

                    if (toadd.Count > 0)                         // if we have any, we can add
                    {
                        TravelLogUnit tlu = new TravelLogUnit(); // need a tlu for it
                        tlu.type        = 2;                     // EDSM
                        tlu.Name        = "EDSM-" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss", CultureInfo.InvariantCulture);
                        tlu.Size        = 0;
                        tlu.Path        = "EDSM";
                        tlu.CommanderId = EDDiscoveryForm.EDDConfig.CurrentCommander.Nr;
                        tlu.Add();  // Add to Database

                        using (SQLiteConnectionUser cn = new SQLiteConnectionUser(utc: true))
                        {
                            foreach (HistoryEntry he in toadd)
                            {
                                EDDiscovery.EliteDangerous.JournalEntry je =
                                    EDDiscovery.EliteDangerous.JournalEntry.CreateFSDJournalEntry(tlu.id, tlu.CommanderId.Value, he.EventTimeUTC,
                                                                                                  he.System.name, he.System.x, he.System.y, he.System.z,
                                                                                                  _defmapcolour, (int)EDDiscovery.EliteDangerous.SyncFlags.EDSM);

                                System.Diagnostics.Trace.WriteLine(string.Format("Add {0} {1}", je.EventTimeUTC, he.System.name));
                                je.Add(cn);
                            }
                        }

                        if (OnDownloadedSystems != null)
                        {
                            OnDownloadedSystems();
                        }

                        mainForm.LogLine(string.Format("EDSM downloaded {0} systems", toadd.Count));
                    }
                }

                mainForm.LogLine("EDSM sync Done");
            }
            catch (Exception ex)
            {
                System.Diagnostics.Trace.WriteLine("Exception ex:" + ex.Message);
                mainForm.LogLineHighlight("EDSM sync Exception " + ex.Message);
            }
        }
示例#4
0
        public void Sync()
        {
            try
            {
                EDSMClass edsm = new EDSMClass();

                edsm.apiKey        = EDDiscoveryForm.EDDConfig.CurrentCommander.APIKey;
                edsm.commanderName = EDDiscoveryForm.EDDConfig.CurrentCommander.Name;

                //string comments =  edsm.GetComments(new DateTime(2015, 1, 1));
                List <VisitedSystemsClass> log;
                List <SystemNoteClass>     notes;
                int ret  = edsm.GetLogs(new DateTime(2011, 1, 1), out log);
                int nret = edsm.GetComments(new DateTime(2011, 1, 1), out notes);

                if (log == null)
                {
                    log = new List <VisitedSystemsClass>();
                }


                if (_syncTo)
                {
                    // Send Unsynced system to EDSM.

                    List <VisitedSystemsClass> systems = (from s in mainForm.VisitedSystems where s.EDSM_sync == false && s.Commander == EDDiscoveryForm.EDDConfig.CurrentCommander.Nr select s).ToList <VisitedSystemsClass>();
                    mainForm.LogLine("EDSM: Sending " + systems.Count.ToString() + " flightlog entries");
                    foreach (var system in systems)
                    {
                        if (Exit)
                        {
                            running = false;
                            return;
                        }

                        if (system.EDSM_sync == false)
                        {
                            // check if it exist in EDSM
                            VisitedSystemsClass ps2 = (from c in log where c.Name == system.Name && c.Time.Ticks == system.Time.Ticks select c).FirstOrDefault <VisitedSystemsClass>();
                            if (ps2 != null)
                            {
                                system.EDSM_sync = true;
                                system.Update();
                            }
                            else
                            {
                                SendTravelLog(edsm, system, mainForm);
                            }
                        }
                    }
                }

                TravelLogUnit tlu = null;

                bool newsystem = false;
                if (_syncFrom)
                {
                    // Check for new systems from EDSM
                    foreach (var system in log)
                    {
                        VisitedSystemsClass ps2 = mainForm?.VisitedSystems == null ? null :
                                                  (from c in mainForm.VisitedSystems where c.Name == system.Name && c.Time.Ticks == system.Time.Ticks select c).FirstOrDefault <VisitedSystemsClass>();
                        if (ps2 == null)     // Add to local DB...
                        {
                            if (tlu == null) // If we dontt have a travellogunit yet then create it.
                            {
                                tlu = new TravelLogUnit();

                                tlu.type = 2;  // EDSM
                                tlu.Path = "https://www.edsm.net/api-logs-v1/get-logs";
                                tlu.Name = "EDSM-" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss", CultureInfo.InvariantCulture);
                                tlu.Size = 0;

                                tlu.Add();  // Add to Database
                            }

                            VisitedSystemsClass vs = new VisitedSystemsClass();

                            vs.Source = tlu.id;
                            vs.Unit   = tlu.Name;

                            vs.Name      = system.Name;
                            vs.Time      = system.Time;
                            vs.MapColour = _defmapcolour;
                            vs.EDSM_sync = true;
                            vs.Commander = EDDiscoveryForm.EDDConfig.CurrentCommander.Nr;


                            vs.Add();  // Add to DB;
                            System.Diagnostics.Trace.WriteLine("New from EDSM");
                            newsystem = true;
                        }
                    }

                    // Sync comments from EDSM
                    foreach (var note in notes)
                    {
                        SystemNoteClass dbnote = SystemNoteClass.GetSystemNoteClass(note.Name.ToLower());

                        if (dbnote != null)         // if there..
                        {
                            if (note.Time > dbnote.Time)
                            {
                                dbnote.Time = note.Time;
                                dbnote.Note = note.Note;
                                dbnote.Update();
                            }
                        }
                        else
                        {
                            note.Add();
                        }
                    }
                }
                mainForm.LogLine("EDSM sync Done");

                if (newsystem)
                {
                    OnNewEDSMTravelLog(this);
                }
            }
            catch (Exception ex)
            {
                System.Diagnostics.Trace.WriteLine("Exception ex:" + ex.Message);
                mainForm.LogLineHighlight("EDSM sync Exception " + ex.Message);
            }
        }