Esempio n. 1
0
 public TLCFIClientSessionJsonRpcHandler(
     TLCFIClientStateManager stateManager,
     TLCProxy tlcProxy,
     TLCFIClientSessionState sessionState,
     TwoWayTcpClient tcpClient,
     CancellationToken token)
 {
     _stateManager             = stateManager;
     _tlcProxy                 = tlcProxy;
     _sessionCancellationToken = token;
     tcpClient.DataReceived   += async(o, e) =>
     {
         if (!_jsonRpcMethodRegex.IsMatch(e))
         {
             return;
         }
         var result = _service?.HandleRpc(e);
         if (result != null)
         {
             await tcpClient.SendDataAsync(result, token);
         }
     };
     _service = JsonRpcProcedureBinder.Default.GetInstanceService(this);
 }
Esempio n. 2
0
        public TLCFIClientSession(TLCFIClientStateManager stateManager, IPEndPoint ep, CancellationToken token)
        {
            _endPoint = ep;
            _sessionCancellationToken = token;
            _stateManager             = stateManager;

            Client               = new TwoWayTcpClient();
            Client.DataSent     += (o, e) => { DataSent?.Invoke(this, e); };
            Client.Disconnected += Client_Disconnected;

            RemoteEndPoint = ep;

            State = new TLCFIClientSessionState();

            TLCProxy        = new TLCProxy(Client);
            _jsonRpcHandler = new TLCFIClientSessionJsonRpcHandler(stateManager, TLCProxy, State, Client, token);
            _jsonRpcHandler.ReceivedAlive += (o, a) =>
            {
                _aliveReceivedTimer.Stop();
                _aliveReceivedTimer.Start();
            };
            _jsonRpcHandler.UpdateStateCalled += OnUpdateStateCalled;
            _jsonRpcHandler.NotifyEventCalled += OnNotifyEventCalled;
        }