Beispiel #1
0
        private IEnumerable <ApiEvent> ConvertEvent(ShipyardSwap e)
        {
            // Send event for old ship indicating it's location
            var @event = new ApiEvent("setCommanderShip")
            {
                Timestamp = e.Timestamp,
                EventData = new Dictionary <string, object>()
                {
                    { "shipType", e.StoreOldShip },
                    { "shipGameID", e.StoreShipId },
                    { "marketID", e.MarketId },
                    { "starsystemName", playerStateRecorder.GetPlayerSystem(e.Timestamp) },
                    { "stationName", playerStateRecorder.GetPlayerStation(e.Timestamp) },
                    { "isCurrentShip", false }
                }
            };

            yield return(@event);

            // and for new, indicating that it's now current
            @event = new ApiEvent("setCommanderShip")
            {
                Timestamp = e.Timestamp,
                EventData = new Dictionary <string, object>()
                {
                    { "shipType", e.ShipType },
                    { "shipGameID", e.ShipId },
                    { "marketID", e.MarketId },
                    { "starsystemName", playerStateRecorder.GetPlayerSystem(e.Timestamp) },
                    { "stationName", playerStateRecorder.GetPlayerStation(e.Timestamp) },
                    { "isCurrentShip", true }
                }
            };
            yield return(@event);
        }
        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);
        }
        public void ShouldNotFailOnEvents(LogEvent e)
        {
            eventConverter.OnNext(e);

            eventConverter.GetPlayerSystem(DateTime.UtcNow);
            eventConverter.GetPlayerShipType(DateTime.UtcNow);
            eventConverter.GetPlayerShipId(DateTime.UtcNow);
            eventConverter.GetPlayerIsInCrew(DateTime.UtcNow);
        }
        private JObject Enrich(JObject @event)
        {
            @event = (JObject)@event.DeepClone();
            var timestamp = DateTime.Parse(@event["timestamp"].ToString());

            @event["_systemName"] = playerStateRecorder.GetPlayerSystem(timestamp);
            @event["_shipId"]     = playerStateRecorder.GetPlayerShipId(timestamp);
            return(@event);
        }
        public IEnumerable <JObject> Convert(JournalEvent sourceEvent)
        {
            var    @event     = (JObject)sourceEvent.Raw.DeepClone();
            var    timestamp  = sourceEvent.Timestamp;
            string starSystem = @event["StarSystem"]?.ToObject <string>() ?? playerStateRecorder.GetPlayerSystem(timestamp);

            @event["_systemName"] = starSystem;
            @event["_shipId"]     = playerStateRecorder.GetPlayerShipId(timestamp);
            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);
        }