예제 #1
0
 /// <summary>
 /// Reads the given Journal file from specified position and generates the events
 /// </summary>
 /// <param name="textReader">Stream reader for input data</param>
 /// <returns>Sequence of events read from input</returns>
 public IEnumerable <JournalEvent> ReadEventsFromStream(TextReader textReader)
 {
     if (textReader == null)
     {
         throw new ArgumentNullException(nameof(textReader));
     }
     using (var jsonReader = new JsonTextReader(textReader)
     {
         SupportMultipleContent = true, CloseInput = false
     })
     {
         while (jsonReader.Read())
         {
             var          @object = Converter.Serializer.Deserialize <JObject>(jsonReader);
             JournalEvent @event  = null;
             try
             {
                 @event = JournalEventConverter.Convert(@object);
             }
             catch (Exception e)
             {
                 Log.Error(e, "Error deserializing event from journal");
             }
             if (@event != null)
             {
                 yield return(@event);
             }
         }
     }
 }
예제 #2
0
        public void JsonExtractorShouldNotFailOnEvents(JournalEvent e)
        {
            var result = eventConverter.Convert(e);

            Assert.NotNull(result);
            CollectionAssert.AllItemsAreInstancesOfType(result, typeof(JObject));
        }
예제 #3
0
        public void Track(JournalEvent @event)
        {
            if (@event is Cargo cargo)
            {
                _items.Clear();

                foreach (var inventory in cargo.Inventory)
                {
                    _items.Add(new Inventory
                    {
                        Name          = inventory.Name,
                        NameLocalised = inventory.NameLocalised,
                        Count         = inventory.Count,
                        Stolen        = inventory.Stolen,
                    });
                }

                _isInitialized = true;
            }
            else if (!_isInitialized)
            {
                // do nothing
                return;
            }

            if (@event is MiningRefined miningRefined)
            {
                // TODO
            }
            else if (@event is SellDrones sellDrones)
            {
                // TODO
            }
        }
        public void InaraConverterShouldNotFailOnEvents(JournalEvent e)
        {
            var result = eventConverter.Convert(e);

            Assert.NotNull(result);
            CollectionAssert.AllItemsAreInstancesOfType(result, typeof(ApiInputEvent));
        }
예제 #5
0
        private JournalOperation ExtractOperation(JObject data, JournalEvent journalEvent)
        {
            switch (journalEvent)
            {
            case JournalEvent.ManualUserChange:
                return(ExctractManualOperation(data));

            case JournalEvent.MiningRefined:
                return(ExtractMiningRefined(data));

            case JournalEvent.EngineerCraft:
                return(ExtractEngineerOperation(data));

            case JournalEvent.MarketSell:
                return(ExtractMarketSell(data));

            case JournalEvent.MarketBuy:
                return(ExtractMarketBuy(data));

            case JournalEvent.MaterialDiscarded:
                return(ExtractMaterialDiscarded(data));

            case JournalEvent.MaterialCollected:
                return(ExtractMaterialCollected(data));

            case JournalEvent.MissionCompleted:
                return(ExtractMissionCompleted(data));

            case JournalEvent.CollectCargo:
                return(ExtractCollectCargo(data));

            case JournalEvent.EjectCargo:
                return(ExtractEjectCargo(data));

            case JournalEvent.Synthesis:
                return(ExtractSynthesis(data));

            case JournalEvent.EngineerContribution:
                return(ExtractEngineerContribution(data));

            case JournalEvent.ScientificResearch:
                return(ExtractMaterialDiscarded(data));

            case JournalEvent.Died:
                return(new DeathOperation()
                {
                    JournalEvent = JournalEvent.Died
                });

            /* COMMODITY REMOVED
             * case JournalEvent.Cargo:
             *  return ExtractCargoDump(data);*/
            case JournalEvent.Materials:
                return(ExtractMaterialsDump(data));

            default:
                return(null);
            }
        }
        public void OnNext(JournalEvent @event)
        {
            if (@event == null)
            {
                throw new ArgumentNullException(nameof(@event));
            }
            try
            {
                switch (@event)
                {
                // Ship change events
                case ShipyardSwap e:
                    Process(e);
                    break;

                case LoadGame e:
                    Process(e);
                    break;

                case Loadout e:
                    Process(e);
                    break;

                // Location change events
                case Location e:
                    Process(e);
                    break;

                case FsdJump e:
                    Process(e);
                    break;

                case Docked e:
                    Process(e);
                    break;

                case SupercruiseEntry e:
                    Process(e);
                    break;

                case Undocked e:
                    Process(e);
                    break;

                // Crew status change events
                case JoinACrew e:
                    Process(e);
                    break;

                case QuitACrew e:
                    Process(e);
                    break;
                }
            }
            catch (Exception e)
            {
                Log.Error(e, "Error in OnNext");
            }
        }
예제 #7
0
        public void ShouldNotFailOnEvents(JournalEvent e)
        {
            eventConverter.OnNext(e);

            eventConverter.GetPlayerSystem(DateTime.UtcNow);
            eventConverter.GetPlayerShipType(DateTime.UtcNow);
            eventConverter.GetPlayerShipId(DateTime.UtcNow);
            eventConverter.GetPlayerIsInCrew(DateTime.UtcNow);
        }
        public void OnNext(JournalEvent @event)
        {
            if (@event == null)
            {
                throw new ArgumentNullException(nameof(@event));
            }
            try
            {
                dynamic e = @event.Raw;

                if (e.SystemAddress != null && e.StarSystem != null)
                {
                    systemAddresses.TryAdd((string)e.StarSystem, (ulong)e.SystemAddress);
                }

                if (e.StarSystem != null)
                {
                    starSystemRecorder.RecordState((string)e.StarSystem, @event.Timestamp);
                }

                if (e.StationName != null)
                {
                    stationRecorder.RecordState((string)e.StationName, @event.Timestamp);
                }

                if (e.Ship != null && e.ShipID != null)
                {
                    ProcessShipIDEvent((long?)e.ShipID, (string)e.Ship, @event.Timestamp);
                }

                // Special cases
                switch (@event)
                {
                case Undocked ud:
                    stationRecorder.RecordState(null, @event.Timestamp);
                    break;

                // Crew status change events
                case JoinACrew jc:
                    crewRecorder.RecordState(true, @event.Timestamp);
                    break;

                case QuitACrew lc:
                    crewRecorder.RecordState(false, @event.Timestamp);
                    break;

                case ShipyardSwap ss:
                    ProcessShipIDEvent(ss.ShipId, ss.ShipType, @event.Timestamp);
                    break;
                }
            }
            catch (Exception e)
            {
                Log.Error(e);
            }
        }
예제 #9
0
 public void Track(JournalEvent @event)
 {
     if (@event is EngineerProgress engineerProgress)
     {
         foreach (var engineer in engineerProgress.Engineers)
         {
             _engineers[engineer.EngineerID] = new EngineerRank(engineer.Name, engineer.EngineerID, engineer.Progress, engineer.Rank, engineerProgress.Timestamp);
         }
     }
 }
        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);
        }
예제 #11
0
        public virtual void AddEntry(JournalEvent entry)
        {
            Guards.Guard.AgainstNullArgument("entry", entry);

            if (entries.Any(e => e.Id == entry.Id))
            {
                throw new ArgumentException("An entry with the same id is already contained in the journal.");
            }

            entries.Add(entry);
        }
예제 #12
0
        public void ProcessEventForFSD(JournalEvent journalEvent)
        {
            switch (journalEvent.@event)
            {
            case EventType.StartJump:
                StartJump startJump = (StartJump)journalEvent;
                if (startJump.JumpType == JumpType.Hyperspace)
                {
                    fsdState = FSDState.CountdownHyperspace;
                    try
                    {
                        jumpStarClass = (StarClass)Enum.Parse(typeof(StarClass), startJump.StarClass, true);
                    }
                    catch (Exception e)
                    {
                        jumpStarClass = StarClass.K;
                    }
                }
                else
                {
                    fsdState      = FSDState.CountdownSupercruise;
                    jumpStarClass = StarClass.None;
                    SetFsdWaitingSupercruise(true);
                }

                SetFsdWaitingCooldown(true);
                fsdChargeStartTime = Utils.Time.GetMillisecondsSinceEpoch();
                break;

            case EventType.SupercruiseEntry:
                ResetFsd();
                SetFsdWaitingCooldown(false);
                break;

            case EventType.SupercruiseExit:
                ResetFsd();
                SetFsdWaitingCooldown(true);
                break;

            case EventType.FSDJump:
                ResetFsd();
                SetFsdWaitingCooldown(true);
                ExitStarClass = jumpStarClass;
                break;

            case EventType.Music:
                if (fsdState == FSDState.CountdownHyperspace && ((Music)journalEvent).MusicTrack.Equals("NoTrack"))
                {
                    ResetFsd();
                    fsdState = FSDState.InHyperspace;
                }
                break;
            }
        }
예제 #13
0
        private JournalOperation ExtractOperation(JObject data, JournalEvent journalEvent)
        {
            switch (journalEvent)
            {
            case JournalEvent.ManualUserChange:
                return(ExctractManualOperation(data));

            case JournalEvent.MiningRefined:
                return(ExtractMiningRefined(data));

            case JournalEvent.EngineerCraft:
                return(ExtractEngineerOperation(data));

            case JournalEvent.MarketSell:
                return(ExtractMarketSell(data));

            case JournalEvent.MarketBuy:
                return(ExtractMarketBuy(data));

            case JournalEvent.MaterialDiscarded:
                return(ExtractMaterialDiscarded(data));

            case JournalEvent.MaterialCollected:
                return(ExtractMaterialCollected(data));

            case JournalEvent.MissionCompleted:
                return(ExtractMissionCompleted(data));

            case JournalEvent.CollectCargo:
                return(ExtractCollectCargo(data));

            case JournalEvent.EjectCargo:
                return(ExtractEjectCargo(data));

            case JournalEvent.Synthesis:
                return(ExtractSynthesis(data));

            case JournalEvent.MaterialDiscovered:
                return(ExtractMaterialDiscovered(data));

            case JournalEvent.EngineerProgress:
                return(ExtractEngineerProgress(data));

            case JournalEvent.ScientificResearch:
                return(ExtractMaterialDiscarded(data));

            default:
                return(null);
            }
        }
예제 #14
0
 public JournalOperation ExtractOperation(JObject data, JournalEvent journalEvent)
 {
     switch (journalEvent)
     {
         case JournalEvent.ManualUserChange:
             return ExctractManualOperation(data);
         case JournalEvent.MiningRefined:
             return ExtractMiningRefined(data);
         case JournalEvent.EngineerCraft:
             return ExtractEngineerOperation(data);
         case JournalEvent.MarketSell:
             return ExtractMarketSell(data);
         case JournalEvent.MarketBuy:
             return ExtractMarketBuy(data);
         case JournalEvent.MaterialDiscarded:
             return ExtractMaterialDiscarded(data);
         case JournalEvent.MaterialCollected:
             return ExtractMaterialCollected(data);
         case JournalEvent.MissionCompleted:
             return ExtractMissionCompleted(data);
         case JournalEvent.CollectCargo:
             return ExtractCollectCargo(data);
         case JournalEvent.EjectCargo:
             return ExtractEjectCargo(data);
         case JournalEvent.Synthesis:
             return ExtractSynthesis(data);
         case JournalEvent.EngineerContribution:
             return ExtractEngineerContribution(data);
         case JournalEvent.ScientificResearch:
             return ExtractMaterialDiscarded(data);
         case JournalEvent.Materials:
             return ExtractMaterialsDump(data);
         case JournalEvent.Cargo:
             return ExtractCargoDump(data);
         case JournalEvent.MaterialTrade:
             return ExtractMaterialTrade(data);
         case JournalEvent.TechnologyBroker:
             return ExtractTechnologyBroker(data);
         case JournalEvent.Location:
         case JournalEvent.FSDJump:
             return ExtractSystemUpdated(data);
         case JournalEvent.Loadout:
             return ExtractLoadout(data);
         case JournalEvent.Died:
             return ExtractDied(data);
         default:
             return null;
     }
 }
예제 #15
0
 public void Track(JournalEvent @event)
 {
     if (@event is Location location)
     {
         foreach (var faction in location.Factions ?? new Faction[0])
         {
             _reputation[faction.Name] = new MinorFactionReputation(faction.Name, faction.MyReputation, location.Timestamp);
         }
     }
     else if (@event is FSDJump fsdJump)
     {
         foreach (var faction in fsdJump.Factions ?? new Faction[0])
         {
             _reputation[faction.Name] = new MinorFactionReputation(faction.Name, faction.MyReputation, fsdJump.Timestamp);
         }
     }
 }
        public void EddnConverterShouldConvertAndValidate(JournalEvent e)
        {
            var recorderMock = GetRecorderMock();

            var eventConverter = new EddnEventConverter(recorderMock)
            {
                MaxAge = TimeSpan.FromDays(5000)
            };
            var result = eventConverter.Convert(e, TestCredentials.UserName).ToList();

            Assert.NotNull(result);
            CollectionAssert.AllItemsAreInstancesOfType(result, typeof(EddnEvent));
            foreach (var @event in result)
            {
                Assert.IsTrue(validator.ValidateSchema(@event), "Event {0} should have validated", e.Event);
            }
        }
예제 #17
0
        private JournalOperation ExtractUpgrade(JObject data, JournalEvent journalEvent)
        {
            var name      = (string)data["Name"];
            var equipment = converter.GetEquipment(journalEvent, name);

            if (equipment == null)
            {
                return(null);
            }

            var upgrade = new UpgradeOperation()
            {
                EquipmentName = equipment.Name,
                Class         = (int)data["Class"]
            };

            return(upgrade);
        }
예제 #18
0
        public Equipment GetEquipment(JournalEvent @event, string name)
        {
            string key;

            if (@event == JournalEvent.UpgradeWeapon)
            {
                key = name;
            }
            else
            {
                key = name.Split("_".ToCharArray())[0];
            }

            if (!equipments.TryGetValue(key, out var equipment))
            {
                _ = MessageBox.Show($"Unknown equipment {name}. Ctrl+C while this messagebox is on focus then kindly report this on github", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }

            return(equipment);
        }
예제 #19
0
 public void JournalReadCallback(int lineNumber, string lineValue)
 {
     try
     {
         JournalEvent newEvent =
             JsonConvert.DeserializeObject <JournalEvent>(lineValue, journalSerializerSettings);
         if (newEvent != null)
         {
             //If the event is known, do something with it
             (_game_state as GameState_EliteDangerous).Journal.ProcessEvent(newEvent);
         }
     }
     catch (JsonSerializationException e)
     {
         Global.logger.Error("Error deserializing Journal event in " + currentJournalFile + " at line " + lineNumber);
         Global.logger.Error(lineValue);
         Global.logger.Error(e.Message);
         Global.logger.Error(e.StackTrace);
     }
 }
예제 #20
0
        public void ProcessEvent(JournalEvent journalEvent)
        {
            switch (journalEvent.@event)
            {
            case EventType.LaunchFighter:
                fighterStatus        = FighterStatus.Launched;
                nextLoadoutIsFighter = true;
                break;

            case EventType.FighterDestroyed:
            case EventType.DockFighter:
                fighterStatus = FighterStatus.None;
                break;

            case EventType.Loadout:
                SetModulesFromLoadout((Loadout)journalEvent);
                break;
            }

            ProcessEventForFSD(journalEvent);
        }
        internal JournalEvent ExecuteEvent(string eventName, string json)
        {
            var rawEvent = new OriginalEvent {
                EventName = eventName, Source = json
            };

            BeforeEvent?.Invoke(this, rawEvent);
            if (rawEvent.Ignore)
            {
                return(null);
            }

            if (_cache.Value.TryGetValue(eventName, out var eventCacheItem))
            {
                JournalEvent @event = null;
                try
                {
                    @event = (JournalEvent)eventCacheItem.Execute.Invoke(null, new object[] { json, this });
                }
                catch (Exception exception)
                {
                    LogJournalException(new JournalRecordException(json, exception));
                }

                if (@event != null)
                {
                    AllEvents?.Invoke(this, new ProcessedEvent
                    {
                        EventName = eventCacheItem.Name,
                        EventType = eventCacheItem.Type,
                        Event     = @event
                    });
                }
                return(@event);
            }
            LogJournalWarning(new JournalEventNotFoundException(eventName, json));

            return(null);
        }
예제 #22
0
        public void ShouldNotValidateEmptyObject()
        {
            var @event = new JournalEvent();

            Assert.IsFalse(new EventSchemaValidator().ValidateSchema(@event));
        }
예제 #23
0
        public JournalOperation ExtractOperation(JObject data, JournalEvent journalEvent)
        {
            switch (journalEvent)
            {
            case JournalEvent.ManualUserChange:
                return(ExctractManualOperation(data));

            case JournalEvent.MiningRefined:
                return(ExtractMiningRefined(data));

            case JournalEvent.EngineerCraft:
                return(ExtractEngineerOperation(data));

            case JournalEvent.MarketSell:
                return(ExtractMarketSell(data));

            case JournalEvent.MarketBuy:
                return(ExtractMarketBuy(data));

            case JournalEvent.MaterialDiscarded:
                return(ExtractMaterialDiscarded(data));

            case JournalEvent.MaterialCollected:
                return(ExtractMaterialCollected(data));

            case JournalEvent.MissionCompleted:
                return(ExtractMissionCompleted(data));

            case JournalEvent.CollectCargo:
                return(ExtractCollectCargo(data));

            case JournalEvent.EjectCargo:
                return(ExtractEjectCargo(data));

            case JournalEvent.Synthesis:
                return(ExtractSynthesis(data));

            case JournalEvent.EngineerContribution:
                return(ExtractEngineerContribution(data));

            case JournalEvent.ScientificResearch:
                return(ExtractMaterialDiscarded(data));

            case JournalEvent.Materials:
                return(ExtractMaterialsDump(data));

            case JournalEvent.Cargo:
                return(ExtractCargoDump(data));

            case JournalEvent.MaterialTrade:
                return(ExtractMaterialTrade(data));

            case JournalEvent.TechnologyBroker:
                return(ExtractTechnologyBroker(data));

            case JournalEvent.Location:
            case JournalEvent.FSDJump:
                return(ExtractSystemUpdated(data));

            case JournalEvent.Loadout:
                return(ExtractLoadout(data));

            case JournalEvent.Died:
                return(ExtractDied(data));

            case JournalEvent.ShipLocker:
            case JournalEvent.ShipLockerMaterials:
                return(ExtractShipLockerMaterials(data));

            case JournalEvent.TradeMicroResources:
                return(ExtractMicroResourcesTrade(data));

            case JournalEvent.SellMicroResources:
                return(ExtractMicroResourcesSold(data));

            case JournalEvent.TransferMicroResources:
                return(ExtractTransferMicroResources(data));

            case JournalEvent.UpgradeSuit:
            case JournalEvent.UpgradeWeapon:
                return(ExtractUpgrade(data, journalEvent));

            case JournalEvent.ApproachSettlement:
                return(ExtractApproachSettlement(data));

            case JournalEvent.CollectItems:
                return(ExtractCollectItems(data));

            case JournalEvent.Docked:
                return(ExtractDocked(data));

            case JournalEvent.Undocked:
            case JournalEvent.SupercruiseEntry:
                return(new LeaveSettlementOperation());

            case JournalEvent.BackpackChange:
                return(ExtractBackpackChange(data));

            case JournalEvent.ApproachBody:
                return(ExtractApproachBody(data));

            case JournalEvent.Touchdown:
                return(ExtractTouchdown(data));

            default:
                return(null);
            }
        }
예제 #24
0
        public IEnumerable <ApiInputEvent> Convert(JournalEvent @event)
        {
            try
            {
                string eventName = @event.Event;
                switch (@event)
                {
                // Generic
                case LoadGame e:
                    return(ConvertEvent(e));

                case Statistics e:
                    return(ConvertEvent(e));

                case Location e:
                    return(ConvertMinorFactionReputation(e.Timestamp, e.Factions));

                case Friends e:
                    return(ConvertEvent(e));

                // Inventory
                case Materials e:
                    return(ConvertEvent(e));

                case MaterialCollected e:
                    return(ConvertEvent(e));

                case MaterialTrade e:
                    return(ConvertEvent(e));

                case StoredModules e:
                    return(ConvertEvent(e));

                case Cargo e:
                    return(ConvertEvent(e));

                // Shipyard
                case ShipyardSell e:
                    return(ConvertEvent(e));

                case ShipyardTransfer e:
                    return(ConvertEvent(e));

                case StoredShips e:
                    return(ConvertEvent(e));

                // Travel
                case FsdJump e:
                    return(ConvertEvent(e));

                case Docked e:
                    return(ConvertEvent(e));

                // Ranks/reputation
                case EngineerProgress e:
                    return(ConvertEvent(e));

                case Rank e:
                    return(ConvertEvent(e));

                case Progress e:
                    return(ConvertEvent(e));

                case Reputation e:
                    return(ConvertEvent(e));

                // Powerplay pledge
                case Powerplay e:
                    return(ConvertEvent(e));

                case PowerplayLeave e:
                    return(ConvertEvent(e));

                case PowerplayJoin e:
                    return(ConvertEvent(e));

                case PowerplayDefect e:
                    return(ConvertEvent(e));

                // Combat
                case Interdicted e:
                    return(ConvertEvent(e));

                case Interdiction e:
                    return(ConvertEvent(e));

                case EscapeInterdiction e:
                    return(ConvertEvent(e));

                case PvpKill e:
                    return(ConvertEvent(e));

                // Ship events
                case Loadout e:
                    return(ConvertEvent(e));

                case ShipyardSwap e:
                    return(ConvertEvent(e));

                // Missions
                case MissionAccepted e:
                    return(ConvertEvent(e));

                case MissionCompleted e:
                    return(ConvertEvent(e));

                case MissionAbandoned e:
                    return(ConvertEvent(e));

                case MissionFailed e:
                    return(ConvertEvent(e));

                // Community goals
                case CommunityGoal e:
                    return(ConvertEvent(e));
                }
            }
            catch (Exception e)
            {
                Log.Error(e, "Error in OnNext");
            }
            return(Enumerable.Empty <ApiInputEvent>());
        }
예제 #25
0
        public static string GetLogLine(string userName, JournalEvent journalEvent)
        {
            var logLine = GetLogLine(userName, journalEvent.LogIndex, $"{journalEvent.Filename}.log");

            return(logLine);
        }
예제 #26
0
        public void Track(JournalEvent @event)
        {
            if (@event is Materials materials)
            {
                Materials.Clear();

                foreach (var material in materials.Raw)
                {
                    this[material.Name] = material.Count;
                }

                foreach (var material in materials.Encoded)
                {
                    this[material.Name] = material.Count;
                }

                foreach (var material in materials.Manufactured)
                {
                    this[material.Name] = material.Count;
                }

                _isInitialized = true;
            }
            else if (!_isInitialized)
            {
                // do nothing
                return;
            }

            if (@event is MaterialCollected materialCollected)
            {
                this[materialCollected.Name] += materialCollected.Count;
            }
            else if (@event is MaterialDiscarded materialDiscarded)
            {
                this[materialDiscarded.Name] -= materialDiscarded.Count;
            }
            else if (@event is MissionCompleted missionCompleted)
            {
                if (missionCompleted.MaterialsReward?.Length > 0)
                {
                    foreach (var reward in missionCompleted.MaterialsReward)
                    {
                        this[reward.Name] += reward.Count;
                    }
                }
            }
            else if (@event is Synthesis synthesis)
            {
                foreach (var material in synthesis.Materials)
                {
                    this[material.Name] -= material.Count;
                }
            }
            else if (@event is EngineerCraft engineerCraft)
            {
                foreach (var material in engineerCraft.Ingredients)
                {
                    this[material.Name] -= material.Count;
                }
            }
            else if (@event is EngineerContribution engineerContribution)
            {
                // TODO
            }
        }