Ejemplo n.º 1
0
        public void Execute(Action callback)
        {
            _connectionHandler.Connect();

            _policyChain.Pop(this);
            _policyChain.Next(callback);
        }
Ejemplo n.º 2
0
        public void DontReceiveMessageTest()
        {
            TaskCompletionSource <IMessage> msgReceived = new TaskCompletionSource <IMessage>();

            IRequest           emptyMessage   = null;
            Mock <IConnection> connectionMock = new Mock <IConnection>();

            connectionMock.Setup(connection => connection.GetData()).Returns(new byte[0]);
            connectionMock.Setup(connection => connection.IsConnected).Returns(true);

            Mock <IMessageHandler> messageHandlerMock = new Mock <IMessageHandler>();

            messageHandlerMock.Setup(messageHandler => messageHandler.GetRequest(It.IsAny <byte[]>()))
            .Returns(emptyMessage);

            IConnectionHandler connectionHandler = new ConnectionHandler(connectionMock.Object, messageHandlerMock.Object, "Test");

            connectionHandler.MessageReceived += (sender, message) =>
            {
                msgReceived.TrySetResult(message);
            };

            connectionHandler.Connect();

            bool success = msgReceived.Task.Wait(100);

            Assert.IsFalse(success);
        }
Ejemplo n.º 3
0
        public static async Task Main(string[] args)
        {
            string            ipaddr            = "127.0.0.1";
            ushort            port              = 1044;
            ConnectionHandler connectionHandler = new ConnectionHandler();
            MessageHandler    messageHandler    = new MessageHandler(connectionHandler);

            connectionHandler.Connect(ipaddr, port);
            await Task.Factory.StartNew(() => connectionHandler.Listen(), TaskCreationOptions.LongRunning);

            //Task.Run(() => connectionHandler.Listen());
            await Task.Delay(-1);
        }
Ejemplo n.º 4
0
        public void MissingEventHarvestConfig_ShouldNotGenerateSupportabilityMetrics()
        {
            ConnectRespondsWithEventHarvestConfig(null);

            _connectionHandler.Connect();

            ShouldNotGenerateAnyEventHarvestSupportabilityMetrics();
        }
Ejemplo n.º 5
0
        public void WhenConnectedThenConnectedEventCalled()
        {
            Mock.Get(_netClient).Setup(c => c.Connect()).Callback(() =>
            {
                Mock.Get(_netClient).Setup(c => c.IsConnected).Returns(true);
            });
            int fireCount = 0;

            _connectionHandler.Connected += (obj, args) => { fireCount++; };

            _connectionHandler.Connect();

            Assert.Equal(1, fireCount);
        }
Ejemplo n.º 6
0
        public void Execute(Action callback)
        {
            _connectionHandler.Disconnect();

            if (_reconnectDelay > TimeSpan.Zero)
            {
                Thread.Sleep(_reconnectDelay);
            }

            _connectionHandler.Connect();

            _policyChain.Pop(this);
            _policyChain.Next(callback);
        }
Ejemplo n.º 7
0
        void Reconnect()
        {
            if (_connectionlLock.TryEnterWriteLock((int)_reconnectDelay.TotalMilliseconds / 2))
            {
                try
                {
                    if (_log.IsDebugEnabled)
                    {
                        _log.Debug("Disconnecting connection handler.");
                    }
                    _connectionHandler.Disconnect();

                    if (_reconnectDelay > TimeSpan.Zero)
                    {
                        Thread.Sleep(_reconnectDelay);
                    }

                    if (_log.IsDebugEnabled)
                    {
                        _log.Debug("Re-connecting connection handler...");
                    }
                    _connectionHandler.Connect();
                }
                catch (Exception ex)
                {
                    _log.Warn("Failed to reconnect, deferring to connection policy for reconnection");
                    _connectionHandler.ForceReconnect(_reconnectDelay);
                }
                finally
                {
                    _connectionlLock.ExitWriteLock();
                }
            }
            else
            {
                try
                {
                    _connectionlLock.EnterReadLock();
                    if (_log.IsDebugEnabled)
                    {
                        _log.Debug("Waiting for reconnect in another thread.");
                    }
                }
                finally
                {
                    _connectionlLock.ExitReadLock();
                }
            }
        }
Ejemplo n.º 8
0
 //private ConnectionHandler connectionHandlerTest = new ConnectionHandler();
 public async Task Connect(Form form)
 {
     if (connectionHandler == null)
     {
         connectionHandler = new ConnectionHandler();
     }
     if (await connectionHandler.GetConnectedPlayersCount() >= 4)
     {
         connectionHandler.State = new RoomFullState();
     }
     else
     {
         await connectionHandler.Connect(form);
     }
 }
Ejemplo n.º 9
0
        static void Main(string[] args)
        {
            //client.Connect(APISecretKey);
            client.Connect();

            client.SubscribeHearbeat();                                       // Subscribe to anonymous channel
            client.SubscribePrices("BTC-USD", GranularityValues.FiveMinutes); // Subscribe to anonymous channel
            //client.UnsubscribePrices("BTC-USD"); // Unsubscribe to anonymous channel

            client.OnAuthorisationEvent += AuthorizationEvent;
            client.OnHeartbeatEvent     += HeartbeatEvent;
            client.OnBalanceEvent       += BalanceEvent;
            client.OnOrderBookL2Event   += OrderBookL2Event;
            client.OnOrderBookL3Event   += OrderBookL3Event;
            client.OnPriceEvent         += PriceEvent;
            client.OnSymbolEvent        += SymbolEvent;
            client.OnTickerEvent        += TickerEvent;
            client.OnTradesEvent        += TradesEvent;
            client.OnTradingEvent       += TradingEvent;

            client.RunAsync().Wait();
        }
Ejemplo n.º 10
0
 public override async void Handle(ConnectionHandler context)
 {
     await context.Connect();
 }
Ejemplo n.º 11
0
 public static void Connect()
 {
     ConnectionHandler.Connect();
 }
Ejemplo n.º 12
0
        public void ItExists()
        {
            Mock.Get(_netClient).Setup(c => c.IsConnected).Returns(true);

            _connectionHandler.Connect();
        }