public IEnumerable <EddnEvent> Convert(JournalEvent @event, string commanderName)
        {
            if (@event.Timestamp.Add(MaxAge) < DateTime.UtcNow)
            {
                return(Enumerable.Empty <EddnEvent>());
            }
            try
            {
                switch (@event)
                {
                case CarrierJump _:
                case Docked _:
                case FsdJump _:
                case Scan _:
                case Location _:
                case SaaSignalsFound _:
                    return(MakeJournalEvent(@event, commanderName));

                case Market e:
                    return(ConvertMarketEvent(e, commanderName));

                case Outfitting e:
                    return(ConvertOutfittingEvent(e, commanderName));

                case Shipyard e:
                    return(ConvertShipyardEvent(e, commanderName));
                }
            }
            catch (Exception e)
            {
                Log.Error(e, "Error converting message");
            }
            return(Enumerable.Empty <EddnEvent>());
        }
        private IEnumerable <EddnEvent> MakeJournalEvent(LogEvent e)
        {
            var @event = new JournalEvent {
                Header = CreateHeader(), Message = Strip(e.Raw)
            };

            if (@event.Message["StarSystem"] == null)
            {
                var system = stateHistoryRecorder.GetPlayerSystem(e.Timestamp);
                if (system != null)
                {
                    @event.Message.Add("StarSystem", system);
                }
                else // if we can't determine player's location, abort
                {
                    logger.Error("Unable to determine player location");
                    yield break;
                }
            }

            if (@event.Message["StarPos"] == null)
            {
                var starSystem = @event.Message["StarSystem"].ToObject <string>();
                var starPos    = stateHistoryRecorder.GetStarPos(starSystem);
                if (starPos == null)
                {
                    yield break; // we don't know what the system coordinates are
                }
                @event.Message.Add("StarPos", new JArray(starPos));
            }
            yield return(@event);
        }
        private IEnumerable <EddnEvent> MakeJournalEvent(JournalEvent e, string commanderName)
        {
            var @event = new EddnJournalEvent {
                Header = CreateHeader(commanderName), Message = Strip(e.Raw)
            };

            if (@event.Message["StarSystem"] == null)
            {
                string system = stateHistoryRecorder.GetPlayerSystem(e.Timestamp);

                // if we can't determine player's location, abort
                if (system != null)
                {
                    @event.Message.Add("StarSystem", system);
                }
                else
                {
                    Log.Error("Unable to determine player location");
                    yield break;
                }
            }

            string starSystem = @event.Message["StarSystem"].ToObject <string>();

            if (@event.Message["StarPos"] == null)
            {
                double[] starPos = stateHistoryRecorder.GetStarPos(starSystem);
                if (starPos == null)
                {
                    yield break; // we don't know what the system coordinates are
                }
                @event.Message.Add("StarPos", new JArray(starPos));
            }

            if (@event.Message["SystemAddress"] == null)
            {
                ulong?systemAddress = stateHistoryRecorder.GetSystemAddress(starSystem);
                if (systemAddress != null)
                {
                    @event.Message.Add("SystemAddress", systemAddress);
                }
            }

            if (Log.IsTraceEnabled)
            {
                Log.Trace()
                .Message("Converted message")
                .Property("source", Serialize.ToJson(e))
                .Property("output", Serialize.ToJson(@event))
                .Write();
            }

            yield return(@event);
        }