// the discard list removes the ones to send
        // since the discard list may be the default one above, on first check, it may include some which are on the current discard list.
        // this is not a problem as it will be removed in the sync process

        public static void UpdateDiscardList()
        {
            if (lastDiscardFetch < DateTime.UtcNow.AddMinutes(-120))     // check if we need a new discard list
            {
                try
                {
                    EDSMClass edsm        = new EDSMClass();
                    var       discardlist = edsm.GetJournalEventsToDiscard();

                    if (discardlist != null)        // if got one
                    {
                        var newdiscardEvents = new HashSet <string>(discardlist);
                        System.Diagnostics.Debug.WriteLine("EDSM Discard list updated " + string.Join(",", newdiscardEvents));

                        lock (alwaysDiscard)        // use this as a perm proxy to lock discardEvents
                        {
                            discardEvents = newdiscardEvents;
                        }
                    }

                    lastDiscardFetch = DateTime.UtcNow; // try again later
                }
                catch (Exception ex)
                {
                    System.Diagnostics.Trace.WriteLine($"Unable to retrieve events to be discarded: {ex.ToString()}");
                }
            }
        }
Ejemplo n.º 2
0
        private static bool ShouldSendEvent(HistoryEntry he)
        {
            if (lastDiscardFetch < DateTime.UtcNow.AddMinutes(-30))
            {
                EDSMClass edsm = new EDSMClass();
                discardEvents    = new HashSet <string>(edsm.GetJournalEventsToDiscard());
                lastDiscardFetch = DateTime.UtcNow;
            }

            string eventtype = he.EntryType.ToString();

            if (he.EdsmSync ||
                he.MultiPlayer ||
                discardEvents.Contains(eventtype) ||
                alwaysDiscard.Contains(eventtype))
            {
                return(false);
            }

            return(true);
        }
Ejemplo n.º 3
0
        public static void UpdateDiscardList()
        {
            if (lastDiscardFetch < DateTime.UtcNow.AddMinutes(-120))     // check if we need a new discard list
            {
                try
                {
                    EDSMClass edsm             = new EDSMClass();
                    var       newdiscardEvents = new HashSet <string>(edsm.GetJournalEventsToDiscard());

                    lock (alwaysDiscard)        // use this as a perm proxy to lock discardEvents
                    {
                        discardEvents = newdiscardEvents;
                    }

                    lastDiscardFetch = DateTime.UtcNow;
                }
                catch (Exception ex)
                {
                    System.Diagnostics.Trace.WriteLine($"Unable to retrieve events to be discarded: {ex.ToString()}");
                }
            }
        }
Ejemplo n.º 4
0
        // Called by Perform, by Sync, by above.

        public static bool SendEDSMEvents(Action <string> log, IEnumerable <HistoryEntry> helist, bool manual = false)
        {
            if (lastDiscardFetch < DateTime.UtcNow.AddMinutes(-120))     // check if we need a new discard list
            {
                try
                {
                    EDSMClass edsm = new EDSMClass();
                    discardEvents    = new HashSet <string>(edsm.GetJournalEventsToDiscard());
                    lastDiscardFetch = DateTime.UtcNow;
                }
                catch (Exception ex)
                {
                    System.Diagnostics.Trace.WriteLine($"Unable to retrieve events to be discarded: {ex.ToString()}");
                }
            }

            System.Diagnostics.Debug.WriteLine("Send " + helist.Count());

            int      eventCount = 0;
            bool     hasbeta    = false;
            DateTime betatime   = DateTime.MinValue;

            foreach (HistoryEntry he in helist) // push list of events to historylist queue..
            {
                if (!he.EdsmSync)               // if we have not sent it..
                {
                    string eventtype = he.EntryType.ToString();

                    if (he.Commander.Name.StartsWith("[BETA]", StringComparison.InvariantCultureIgnoreCase) || he.IsBetaMessage)
                    {
                        hasbeta  = true;
                        betatime = he.EventTimeUTC;
                        he.journalEntry.SetEdsmSync();       // crappy slow but unusual, but lets mark them as sent..
                    }
                    else if (!(he.MultiPlayer || discardEvents.Contains(eventtype) || alwaysDiscard.Contains(eventtype)))
                    {
                        historylist.Enqueue(new HistoryQueueEntry {
                            HistoryEntry = he, Logger = log, ManualSync = manual
                        });
                        eventCount++;
                    }
                }
            }

            if (hasbeta && eventCount == 0)
            {
                log?.Invoke($"Cannot send Beta logs to EDSM - most recent timestamp: {betatime.ToString("yyyy-MM-dd'T'HH:mm:ss'Z'")}");
            }

            if (manual)     // if in manual mode, we want to tell the user the end, so push an end marker
            {
                string logline = (eventCount > 0) ? $"Sending {eventCount} journal event(s) to EDSM" : "No new events to send to EDSM";
                log?.Invoke(logline);

                if (eventCount > 0)      // push end of sync event.
                {
                    historylist.Enqueue(new HistoryQueueEntry {
                        HistoryEntry = null, Logger = log, ManualSync = manual
                    });
                }
            }

            if (eventCount > 0)
            {
                historyevent.Set();

                // Start the sync thread if it's not already running
                if (Interlocked.CompareExchange(ref running, 1, 0) == 0)
                {
                    Exit = false;
                    exitevent.Reset();
                    ThreadEDSMSync              = new System.Threading.Thread(new System.Threading.ThreadStart(SyncThread));
                    ThreadEDSMSync.Name         = "EDSM Journal Sync";
                    ThreadEDSMSync.IsBackground = true;
                    ThreadEDSMSync.Start();
                }
            }

            return(true);
        }