コード例 #1
0
        public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer)
        {
            if (reader.TokenType == JsonToken.Null)
            {
                return(null);
            }
            // Read the message type and serialize accordingly
            JToken value;
            string typeCode = null;
            var    json     = JObject.ReadFrom(reader) as JObject;

            if (json.TryGetValue("mt", out value) == true && value.Type == JTokenType.String)
            {
                typeCode = value.ToString();
            }
            var type = RealTimeMessage.GetType(typeCode);

            if (type != null)
            {
                return(new JsonSerializer().Deserialize(json.CreateReader(), RealTimeMessage.GetType(typeCode)));
            }
            else
            {
                return(null);
            }
        }
コード例 #2
0
        private TrainLeg GetTrainLeg(RealTimeMessage message, InfrastructureMapping mapping)
        {
            var ebuefZeitVon      = TimeSpan.FromSeconds(mapping.EBuEfVonVerschiebungSekunden.ToInt());
            var ebuefZeitpunktVon = message.SimulationsZeit.Value.Add(ebuefZeitVon).TimeOfDay;

            var ebuefZeitNach      = TimeSpan.FromSeconds(mapping.EBuEfNachVerschiebungSekunden.ToInt());
            var ebuefZeitpunktNach = message.SimulationsZeit.Value.Add(ebuefZeitNach).TimeOfDay;

            var ivuZeit      = TimeSpan.FromSeconds(mapping.IVUVerschiebungSekunden.ToInt());
            var ivuZeitpunkt = message.SimulationsZeit.Value.Add(ivuZeit).TimeOfDay;

            var fahrzeuge = message?.Decoder.AsEnumerable();

            var result = new TrainLeg
            {
                EBuEfBetriebsstelleNach = mapping.EBuEfNachBetriebsstelle,
                EBuEfBetriebsstelleVon  = mapping.EBuEfVonBetriebsstelle,
                EBuEfGleisNach          = message.EndGleis,
                EBuEfGleisVon           = message.StartGleis,
                EBuEfZeitpunktNach      = ebuefZeitpunktNach,
                EBuEfZeitpunktVon       = ebuefZeitpunktVon,
                Fahrzeuge    = fahrzeuge,
                IstPrognose  = message.Modus == MessageType.Prognose,
                IVUGleis     = mapping.IVUGleis,
                IVULegTyp    = mapping.IVUTrainPositionType,
                IVUNetzpunkt = mapping.IVUNetzpunkt,
                IVUZeitpunkt = ivuSessionDate.Add(ivuZeitpunkt),
                Zugnummer    = message.Zugnummer,
            };

            return(result);
        }
コード例 #3
0
        public void Notify(RealTimeMessage msg)
        {
            var copy = this.Triggered;

            if (copy != null)
            {
                copy(msg);
            }
        }
コード例 #4
0
 internal static async Task SendMessageAsync(RealTimeMessage msg)
 {
     if (App.EnableRealtime == false)
     {
         throw new Exception("Real time support has not been enabled on the SDK. Initialize the application with AppacitiveSettings.EnableRealTimeSupport as true.");
     }
     if (App.Channel == null)
     {
         throw new Exception("Real time infrastucture not initialized. Make sure that App has been initialized.");
     }
     await App.Channel.SendAsync(msg);
 }
コード例 #5
0
        private void RealTime(RealTimeMessage msg)
        {
            // Avoid raising a timing clock event if the class is disposing (or disposed).
            // There may be cases where Dispose() has been called but we get a further clock tick to handle, and to avoid
            // complications we avoid propagating such an event any further.
            if (1 == Interlocked.CompareExchange(ref _isDisposing, 1, 1))
            {
                return;
            }

            if (_isRunning && msg.MessageType == RealTimeMessageType.TimingClock)
            {
                OnTimingClock();
            }
        }
コード例 #6
0
        public TrainLeg Convert(RealTimeMessage message)
        {
            var result = default(TrainLeg);

            var mapping = default(InfrastructureMapping);

            if (message.SimulationsZeit.HasValue)
            {
                mapping = infrastructureMappings
                          .Where(m => m.MessageBetriebsstelle.IsMatch(message.Betriebsstelle))
                          .Where(m => m.MessageStartGleis.IsMatchOrEmptyPatternOrEmptyValue(message.StartGleis) &&
                                 m.MessageEndGleis.IsMatchOrEmptyPatternOrEmptyValue(message.EndGleis))
                          .OrderByDescending(m => m.MessageStartGleis.IsMatch(message.StartGleis))
                          .ThenByDescending(m => m.MessageEndGleis.IsMatch(message.EndGleis)).FirstOrDefault();
            }

            if (mapping != default)
            {
                if ((message.SignalTyp == SignalType.ESig && mapping.IVUTrainPositionType != LegType.Ankunft) ||
                    (message.SignalTyp == SignalType.ASig && mapping.IVUTrainPositionType != LegType.Abfahrt) ||
                    (message.SignalTyp == SignalType.BkSig && mapping.IVUTrainPositionType != LegType.Durchfahrt))
                {
                    logger.LogWarning(
                        "Der IVUTrainPositionType des Mappings {mappingType} entspricht nicht dem SignalTyp der eingegangenen Nachricht: {message}",
                        mapping.IVUTrainPositionType,
                        message);
                }

                result = GetTrainLeg(
                    message: message,
                    mapping: mapping);
            }
            else
            {
                logger.LogWarning(
                    "Es wurde kein Mapping für die eingegangene Nachricht gefunden: {message}",
                    message);
            }

            return(result);
        }
コード例 #7
0
        // Called when we receive a real-time message from the network.
        // Messages in our game are made up of 2 bytes: the first one is 'F' or 'U'
        // indicating
        // whether it's a final or interim score. The second byte is the score.
        // There is also the
        // 'S' message, which indicates that the game should start.

        public void OnRealTimeMessageReceived(RealTimeMessage rtm)
        {
            byte[] buf    = rtm.GetMessageData();
            string sender = rtm.SenderParticipantId;

            Log.Debug(TAG, "Message received: " + (char)buf[0] + "/" + (int)buf[1]);

            if (buf[0] == 'F' || buf[0] == 'U')
            {
                int participantScore = 0;
                mParticipantScore.TryGetValue(sender, out participantScore);
                // score update.
                int existingScore = mParticipantScore.ContainsKey(sender) ?
                                    participantScore : 0;
                int thisScore = (int)buf[1];
                if (thisScore > existingScore)
                {
                    // this check is necessary because packets may arrive out of
                    // order, so we
                    // should only ever consider the highest score we received, as
                    // we know in our
                    // game there is no way to lose points. If there was a way to
                    // lose points,
                    // we'd have to add a "serial number" to the packet.
                    mParticipantScore[sender] = thisScore;
                }

                // update the scores on the screen
                UpdatePeerScoresDisplay();

                // if it's a final score, mark this participant as having finished
                // the game
                if ((char)buf[0] == 'F')
                {
                    mFinishedParticipants.Add(rtm.SenderParticipantId);
                }
            }
        }
コード例 #8
0
 public void OnRealTimeMessageReceived(RealTimeMessage p0)
 {
     Toast.MakeText(this, "Message Received", ToastLength.Short).Show();
     _gameFragment.ReceiveMessage(p0.GetMessageData());
 }
コード例 #9
0
 public async Task SendAsync(RealTimeMessage msg)
 {
     await this.Transport.SendAsync(msg.ToString());
 }
コード例 #10
0
 public void OnRealTimeMessageReceived(RealTimeMessage p0)
 {
     Toast.MakeText(this, "Message Received", ToastLength.Short).Show();
     _gameFragment.ReceiveMessage(p0.GetMessageData());
 }