コード例 #1
0
ファイル: MessageHandler.cs プロジェクト: dndoanh/navtrack
        public async Task HandleMessage(Client client, INetworkStreamWrapper networkStream, byte[] bytes)
        {
            ICustomMessageHandler customMessageHandler = GetMessageHandler(client.Protocol);

            MessageInput messageInput = new MessageInput
            {
                Client        = client,
                NetworkStream = networkStream,
                DataMessage   = new DataMessage(bytes, client.Protocol.SplitMessageBy)
            };

            logger.LogTrace(
                $"{client.Protocol}: received {HexUtil.ConvertHexStringArrayToHexString(messageInput.DataMessage.Hex)}");

            int connectionMessageId = await connectionService.AddMessage(client.DeviceConnection.Id, messageInput.DataMessage.HexString);

            try
            {
                List <Location> locations = customMessageHandler.ParseRange(messageInput)?.ToList();

                if (locations != null && locations.Any())
                {
                    // TODO refactor this
                    await connectionService.SetDeviceId(client);

                    await locationService.AddRange(locations, connectionMessageId);
                }
            }
            catch (Exception e)
            {
                logger.LogCritical(e,
                                   $"{customMessageHandler.GetType()}: Error parsing {messageInput.DataMessage.Hex} ");
            }
        }
コード例 #2
0
ファイル: MessageHandler.cs プロジェクト: dndoanh/navtrack
        private ICustomMessageHandler GetMessageHandler(IProtocol protocol)
        {
            Type type = typeof(ICustomMessageHandler <>).MakeGenericType(protocol.GetType());

            ICustomMessageHandler customMessageHandler = (ICustomMessageHandler)serviceProvider.GetService(type);

            if (customMessageHandler == null)
            {
                throw new Exception($"There is no message handler implemented for {protocol}");
            }

            return(customMessageHandler);
        }
コード例 #3
0
        public ProtocolTester(IProtocol protocol, ICustomMessageHandler customMessageHandler)
        {
            cancellationTokenSource = new CancellationTokenSource();
            TotalParsedLocations    = new List <Location>();

            Client = new Client
            {
                Protocol = protocol
            };

            SetupLocationService();
            SetupStreamHandler(customMessageHandler);
            SetupNetworkStreamMock();
        }
コード例 #4
0
ファイル: RaknetSession.cs プロジェクト: CiviledCode/Alex
        public RaknetSession(ConnectionInfo connectionInfo, RaknetConnection packetSender, IPEndPoint endPoint, short mtuSize, ICustomMessageHandler messageHandler = null)
        {
            Log.Debug($"Create session for {endPoint}");

            _packetSender        = packetSender;
            ConnectionInfo       = connectionInfo;
            CustomMessageHandler = messageHandler ?? new DefaultMessageHandler();
            EndPoint             = endPoint;
            MtuSize = mtuSize;

            InactivityTimeout = 30000;
            ResendThreshold   = 10;

            _cancellationToken = new CancellationTokenSource();
        }
コード例 #5
0
        public RakSession(ConnectionInfo connectionInfo, IPacketSender packetSender, IPEndPoint endPoint, short mtuSize, ICustomMessageHandler messageHandler = null)
        {
            Log.Debug($"Create session for {endPoint}");

            _packetSender        = packetSender;
            ConnectionInfo       = connectionInfo;
            CustomMessageHandler = messageHandler ?? new DefaultMessageHandler();
            EndPoint             = endPoint;
            MtuSize = mtuSize;

            InactivityTimeout = Config.GetProperty("InactivityTimeout", 8500);
            ResendThreshold   = Config.GetProperty("ResendThreshold", 10);

            _cancellationToken = new CancellationTokenSource();
            //_tickerHighPrecisionTimer = new HighPrecisionTimer(10, SendTick, true);
        }