Beispiel #1
0
        private static void SyncThread()
        {
            try
            {
                _running = 1;
                //mainForm.LogLine("Starting EDDN sync thread");

                while (hlscanunsyncedlist.Count != 0)
                {
                    List <HistoryEntry> hl = new List <HistoryEntry>();
                    HistoryEntry        he = null;

                    int eventcount = 0;

                    while (hlscanunsyncedlist.TryDequeue(out he))
                    {
                        hlscanevent.Reset();

                        TimeSpan age = he.AgeOfEntry();

                        if (age.Days >= 1 && he.EntryType != EliteDangerousCore.JournalTypeEnum.Scan)
                        {
                            System.Diagnostics.Debug.WriteLine("EDDN: Ignoring entry due to age");
                        }
                        else if (EDDNSync.SendToEDDN(he))
                        {
                            logger?.Invoke($"Sent {he.EntryType.ToString()} event to EDDN ({he.EventSummary})");
                            eventcount++;
                        }

                        if (Exit)
                        {
                            return;
                        }

                        Thread.Sleep(1000);   // Throttling to 1 per second to not kill EDDN network
                    }

                    SentEvents?.Invoke(eventcount);     // tell the system..

                    if (hlscanunsyncedlist.IsEmpty)     // if nothing there..
                    {
                        hlscanevent.WaitOne(60000);     // Wait up to 60 seconds for another EDDN event to come in
                    }
                    if (Exit)
                    {
                        return;
                    }
                }
            }
            catch (Exception ex)
            {
                System.Diagnostics.Trace.WriteLine("Exception ex:" + ex.Message);
                logger?.Invoke("EDDN sync Exception " + ex.Message);
            }
            finally
            {
                _running = 0;
            }
        }
Beispiel #2
0
        private static void SyncThread()
        {
            try
            {
                _running = 1;
                //mainForm.LogLine("Starting EDDN sync thread");

                while (hlscanunsyncedlist.Count != 0)
                {
                    List <HistoryEntry> hl = new List <HistoryEntry>();
                    HistoryEntry        he = null;

                    while (hlscanunsyncedlist.TryDequeue(out he))
                    {
                        hlscanevent.Reset();

                        TimeSpan age = he.AgeOfEntry();

                        if (age.Days >= 1)
                        {
                            System.Diagnostics.Debug.WriteLine("EDDN: Ignoring entry due to age");
                        }
                        else if (EDDNSync.SendToEDDN(he))
                        {
                            mainForm.LogLine($"Sent {he.EntryType.ToString()} event to EDDN ({he.EventSummary})");
                        }

                        if (Exit)
                        {
                            return;
                        }

                        Thread.Sleep(1000);   // Throttling to 1 per second to not kill EDDN network
                    }

                    // Wait up to 60 seconds for another EDDN event to come in
                    hlscanevent.WaitOne(60000);
                    if (Exit)
                    {
                        return;
                    }
                }

                //mainForm.LogLine("EDDN sync thread exiting");
            }
            catch (Exception ex)
            {
                System.Diagnostics.Trace.WriteLine("Exception ex:" + ex.Message);
                mainForm.LogLineHighlight("EDDN sync Exception " + ex.Message);
            }
            finally
            {
                _running = 0;
            }
        }
        private static void SyncThread()
        {
            running = 1;
            //mainForm.LogLine("Starting EDDN sync thread");

            while (hlscanunsyncedlist.Count != 0)
            {
                HistoryEntry he = null;

                int eventcount = 0;

                while (hlscanunsyncedlist.TryDequeue(out he))
                {
                    try
                    {
                        hlscanevent.Reset();

                        TimeSpan age = he.AgeOfEntry();

                        if (age.Days >= 1 && he.EntryType != EliteDangerousCore.JournalTypeEnum.Scan)
                        {
                            System.Diagnostics.Debug.WriteLine("EDDN: Ignoring entry due to age");
                        }
                        else
                        {
                            bool?res = EDDNSync.SendToEDDN(he);

                            if (res != null)    // if attempted to send
                            {
                                if (res.Value == true)
                                {
                                    logger?.Invoke($"Sent {he.EntryType.ToString()} event to EDDN ({he.EventSummary})");
                                    eventcount++;
                                }
                                else
                                {
                                    logger?.Invoke($"Failed sending {he.EntryType.ToString()} event to EDDN ({he.EventSummary})");
                                }
                            }
                            else
                            {
                                continue; // skip the 1 second delay if nothing was sent
                            }
                        }
                    }
                    catch (Exception ex)
                    {
                        System.Diagnostics.Trace.WriteLine("Exception ex:" + ex.Message);
                        System.Diagnostics.Trace.WriteLine("Exception ex:" + ex.StackTrace);
                        logger?.Invoke("EDDN sync Exception " + ex.Message + Environment.NewLine + ex.StackTrace);
                    }

                    if (Exit)
                    {
                        running = 0;
                        return;
                    }

                    Thread.Sleep(1000);   // Throttling to 1 per second to not kill EDDN network
                }

                SentEvents?.Invoke(eventcount);     // tell the system..

                if (hlscanunsyncedlist.IsEmpty)     // if nothing there..
                {
                    hlscanevent.WaitOne(60000);     // Wait up to 60 seconds for another EDDN event to come in
                }
                if (Exit)
                {
                    break;
                }
            }

            running = 0;
        }
Beispiel #4
0
        HistoryEntry lastuihe = null;                                       // last he that the ui was updated on.. used during store to try and prevent too much thrash

        public void HistoryEvent(HistoryEntry he, bool stored, bool recent) // recent is true on stored for last few entries..
        {
            bool dontupdateui = (lasthe != null && stored && !recent);

            if (!dontupdateui)      // so, if we have displayed one, and we are in stored reply, and not a recent entry.. don't update UI
            {
                bool reposbut = false;

                if (lastuihe == null || !he.Commander.Name.Equals(lastuihe.Commander.Name))
                {
                    labelCmdr.Text = he.Commander.Name;
                    if (EDCommander.Current.Name != he.Commander.Name)
                    {
                        labelCmdr.Text += " Report clash " + EDCommander.Current.Name;
                    }
                }

                if (lastuihe == null || he.Credits != lastuihe.Credits)
                {
                    labelCredits.Text = he.Credits.ToString("N0");
                }

                if (!labelSystem.Text.Equals(he.System.Name))       // because of StartJump rewriting the previous entry, we can't detect system names changes using UI
                {                                                   // which ends up we never seeing lastui.system.name being different to he.system.name
                    extButtonEDSMSystem.Enabled = extButtonInaraSystem.Enabled = extButtonEDDBSystem.Enabled = true;
                    labelSystem.Text            = he.System.Name;
                    reposbut = true;
                }

                if (lastuihe == null || !he.WhereAmI.Equals(lastuihe.WhereAmI))
                {
                    labelLocation.Text = he.WhereAmI;
                    reposbut           = true;
                }

                bool hasmarketid       = he?.MarketID.HasValue ?? false;
                bool hasbodyormarketid = hasmarketid || he.FullBodyID.HasValue;

                if (lastuihe == null || extButtonInaraStation.Enabled != hasmarketid)
                {
                    extButtonInaraStation.Enabled = extButtonEDDBStation.Enabled = hasmarketid;
                }

                if (lastuihe == null || extButtonSpanshStation.Enabled != hasbodyormarketid)
                {
                    extButtonSpanshStation.Enabled = hasbodyormarketid;
                }

                if ((he.ShipInformation != null) != extButtonEDSY.Enabled)      // enabled/visible causes effort, only do it if different
                {
                    extButtonEDSY.Enabled = extButtonCoriolis.Enabled = he.ShipInformation != null;
                }

                if (he.ShipInformation != null && (lastuihe == null || lastuihe.ShipInformation == null || he.ShipInformation.ShipNameIdentType != lastuihe.ShipInformation.ShipNameIdentType))
                {
                    labelShip.Text = he.ShipInformation.ShipNameIdentType ?? "Unknown";
                    reposbut       = true;
                }

                if (reposbut)
                {
                    int maxx = Math.Max(labelSystem.Right, labelLocation.Right) + 2;

                    extButtonEDSMSystem.Left   = maxx;
                    extButtonInaraSystem.Left  = extButtonEDSMSystem.Right + 2;
                    extButtonEDDBSystem.Left   = extButtonInaraSystem.Right + 2;
                    extButtonSpanshSystem.Left = extButtonEDDBSystem.Right + 2;

                    extButtonInaraStation.Left  = maxx;
                    extButtonEDDBStation.Left   = extButtonInaraStation.Right + 2;
                    extButtonSpanshStation.Left = extButtonEDDBStation.Right + 2;

                    extButtonCoriolis.Left = labelShip.Right + 2;
                    extButtonEDSY.Left     = extButtonCoriolis.Right + 2;
                }

                if (lastuihe == null || he.MaterialCommodity.DataCount != lastuihe.MaterialCommodity.DataCount || he.MaterialCommodity.CargoCount != lastuihe.MaterialCommodity.CargoCount ||
                    he.MaterialCommodity.MaterialsCount != lastuihe.MaterialCommodity.MaterialsCount)
                {
                    labelData.Text      = he.MaterialCommodity.DataCount.ToString();
                    labelCargo.Text     = he.MaterialCommodity.CargoCount.ToString();
                    labelMaterials.Text = he.MaterialCommodity.MaterialsCount.ToString();
                }

                he.journalEntry.FillInformation(out string info, out string detailed);
                LogLine(EDDConfig.Instance.ConvertTimeToSelectedFromUTC(he.EventTimeUTC) + " " + he.journalEntry.SummaryName(he.System) + ": " + info);

                if (he.MissionList != null)
                {
                    labelMissionCount.Text = he.MissionList.Missions.Count.ToString();
                    string mtext = "";
                    if (he.MissionList.Missions.Count > 0)
                    {
                        var list = he.MissionList.GetAllCurrentMissions(DateTime.Now);
                        if (list.Count > 0)
                        {
                            var last = list[0];
                            mtext = BaseUtils.FieldBuilder.Build("", last.Mission.LocalisedName, "", last.Mission.Expiry, "", last.Mission.DestinationSystem, "", last.Mission.DestinationStation);
                        }
                    }

                    labelLatestMission.Text = mtext;
                }

                lastuihe = he;
                System.Diagnostics.Debug.WriteLine("Set lastuihe to " + lastuihe.System.Name);
            }

            if (!stored)
            {
                if (he.Commander.SyncToEdsm)
                {
                    EDSMJournalSync.SendEDSMEvents(LogLine, he);
                }

                if (he.Commander.SyncToIGAU)
                {
                    EliteDangerousCore.IGAU.IGAUSync.NewEvent(LogLine, he);
                }

                if (EliteDangerousCore.EDDN.EDDNClass.IsEDDNMessage(he.EntryType, he.EventTimeUTC) && he.AgeOfEntry() < TimeSpan.FromDays(1.0) &&
                    he.Commander.SyncToEddn == true)
                {
                    EliteDangerousCore.EDDN.EDDNSync.SendEDDNEvents(LogLine, he);
                }

                if (he.Commander.SyncToInara)
                {
                    EliteDangerousCore.Inara.InaraSync.NewEvent(LogLine, he);
                }

                screenshot.NewJournalEntry(he.journalEntry);
            }

            if (DLLManager.Count > 0)       // if worth calling..
            {
                DLLManager.NewJournalEntry(EDDDLLCallerHE.CreateFromHistoryEntry(he, stored), stored);
            }

            lasthe = he;
        }
Beispiel #5
0
        public void HistoryEvent(HistoryEntry he, bool stored)
        {
            if (lasthe == null || he.Commander.Name != lasthe.Commander.Name)
            {
                labelCmdr.Text = he.Commander.Name;
                if (EDCommander.Current.Name != he.Commander.Name)
                {
                    labelCmdr.Text += " Report clash " + EDCommander.Current.Name;
                }
            }

            if (lasthe == null || he.System.Name != lasthe.System.Name)
            {
                extButtonEDSM.Enabled        = true;
                extButtonInaraSystem.Enabled = true;
                labelSystem.Text             = he.System.Name;
            }

            if (lasthe == null || he.WhereAmI != lasthe.WhereAmI)
            {
                labelLocation.Text = he.WhereAmI;
            }

            extButtonEDSY.Enabled = extButtonCoriolis.Enabled = he.ShipInformation != null;

            if (he.ShipInformation != null && (lasthe == null || lasthe.ShipInformation == null || he.ShipInformation.ShipNameIdentType != lasthe.ShipInformation.ShipNameIdentType))
            {
                labelShip.Text = he.ShipInformation.ShipNameIdentType ?? "Unknown";
            }

            if (lasthe == null || he.MaterialCommodity.DataCount != lasthe.MaterialCommodity.DataCount || he.MaterialCommodity.CargoCount != lasthe.MaterialCommodity.CargoCount ||
                he.MaterialCommodity.MaterialsCount != lasthe.MaterialCommodity.MaterialsCount)
            {
                labelData.Text      = he.MaterialCommodity.DataCount.ToString();
                labelCargo.Text     = he.MaterialCommodity.CargoCount.ToString();
                labelMaterials.Text = he.MaterialCommodity.MaterialsCount.ToString();
            }

            if (lasthe == null || he.Credits != lasthe.Credits)
            {
                labelCredits.Text = he.Credits.ToString("N0");
            }

            he.journalEntry.FillInformation(out string info, out string detailed);
            LogLine(he.EventTimeUTC + " " + he.journalEntry.EventTypeStr + " " + info);

            extButtonInaraStation.Enabled = he.IsDocked;

            if (he.MissionList != null)
            {
                labelMissionCount.Text = he.MissionList.Missions.Count.ToString();
                string mtext = "";
                if (he.MissionList.Missions.Count > 0)
                {
                    var list = he.MissionList.GetAllCurrentMissions(DateTime.Now);
                    if (list.Count > 0)
                    {
                        var last = list[0];
                        mtext = BaseUtils.FieldBuilder.Build("", last.Mission.LocalisedName, "", last.Mission.Expiry, "", last.Mission.DestinationSystem, "", last.Mission.DestinationStation);
                    }
                }

                labelLatestMission.Text = mtext;
            }

            lasthe = he;

            if (!stored)
            {
                if (he.Commander.SyncToEdsm)
                {
                    EDSMJournalSync.SendEDSMEvents(LogLine, he);
                }

                if (he.Commander.SyncToIGAU)
                {
                    EliteDangerousCore.IGAU.IGAUSync.NewEvent(LogLine, he);
                }

                if (EliteDangerousCore.EDDN.EDDNClass.IsEDDNMessage(he.EntryType, he.EventTimeUTC) && he.AgeOfEntry() < TimeSpan.FromDays(1.0) &&
                    he.Commander.SyncToEddn == true)
                {
                    EliteDangerousCore.EDDN.EDDNSync.SendEDDNEvents(LogLine, he);
                }

                if (he.Commander.SyncToInara)
                {
                    EliteDangerousCore.Inara.InaraSync.NewEvent(LogLine, he);
                }

                if (DLLManager.Count > 0)       // if worth calling..
                {
                    DLLManager.NewJournalEntry(EDDDLLCallerHE.CreateFromHistoryEntry(he));
                }

                screenshot.NewJournalEntry(he.journalEntry);
            }
        }