Exemplo n.º 1
0
 public void ClientSendData()
 {
     _forever = false;
     if (_client.Connected)
     {
         _client.Send("Test");
         Thread.Sleep(1000);
     }
     Assert.IsTrue(_clientDataPass);
 }
Exemplo n.º 2
0
        public void ClientSendDataConcurrent()
        {
            _forever = true;
            if (_client.Connected)
            {
                var client2 = new WebSocketClient("ws://127.0.0.1:54321/path")
                {
                    OnReceive = OnClientReceive
                };
                client2.Connect();

                if (client2.Connected)
                {
                    _client.Send("Test");
                    client2.Send("Test");
                }
                else
                {
                    _clientDataPass = false;
                }
                Thread.Sleep(5000);
            }
            else
            {
                _clientDataPass = false;
            }
            Assert.IsTrue(_clientDataPass);
        }
        public void ClientSendDataConcurrent()
        {
            _forever = true;
            if (_client.Connected)
            {
                var client2 = new WebSocketClient("ws://127.0.0.1:54321/path") { OnReceive = OnClientReceive };
                client2.Connect();

                if (client2.Connected)
                {
                    _client.Send("Test");
                    client2.Send("Test");
                }
                else
                {
                    _clientDataPass = false;
                }
                Thread.Sleep(5000);
            }
            else
            {
                _clientDataPass = false;
            }
            Assert.IsTrue(_clientDataPass);
        }
Exemplo n.º 4
0
 public void ClientSendData()
 {
     _forever        = false;
     _clientDataPass = true;
     Alchemy.Handlers.Handler.FastDirectSendingMode = false;
     _requestId      = 1;
     _responseId     = 1;
     _expectedLength = 5;
     if (_client.Connected)
     {
         _client.Send("Test1");
         Thread.Sleep(200);
     }
     Assert.IsTrue(_clientDataPass);
     Assert.AreEqual(2, _requestId);
     Assert.AreEqual(2, _responseId);
 }
Exemplo n.º 5
0
        public void ClientSendDataConcurrent()
        {
            _forever        = true;
            _clientDataPass = true;
            Alchemy.Handlers.Handler.FastDirectSendingMode = false;
            _requestId      = 1000;
            _responseId     = 1000;
            _requestId2     = 2000;
            _responseId2    = 2000;
            _expectedLength = 8;
            var client2 = new WebSocketClient("ws://127.0.0.1:54321/path")
            {
                OnReceive = OnClientReceive2
            };

            if (_client.Connected)
            {
                client2.Connect();

                if (client2.Connected)
                {
                    _client.Send("Test1000");
                    client2.Send("Halo2000");
                }
                else
                {
                    _clientDataPass = false;
                }
                Thread.Sleep(5000);
            }
            else
            {
                _clientDataPass = false;
            }
            Assert.IsTrue(_clientDataPass);
            Assert.IsTrue(_requestId == _responseId || _requestId - 1 == _responseId);
            Assert.IsTrue(_requestId2 == _responseId2 || _requestId2 - 1 == _responseId2);
            Assert.IsTrue(_responseId > 1010);
            Assert.IsTrue(_responseId2 > 2010);

            _client.Disconnect();
            client2.Disconnect();
            Assert.IsFalse(_client.Connected);
            Assert.IsFalse(client2.Connected);

            _client.Connect();
            Assert.IsTrue(_client.Connected);
        }
Exemplo n.º 6
0
        protected override void OnStart(string[] args)
        {
            try
            {
                string wsServer = ConfigurationManager.AppSettings["ws-server"];
                string stanox = ConfigurationManager.AppSettings["stanox"];
                if (string.IsNullOrEmpty(wsServer) || string.IsNullOrEmpty(stanox))
                    throw new ArgumentNullException("", "both ws-server and stanox must be set in app.config");

                _statistics = Delays.Load();
                if (_statistics.Created.Date < DateTime.Now.Date)
                {
                    const string start = "Early Departures for {0:dd-MM-yy}:";
                    var statsByMinute = _statistics.EarlyDepartures.GroupBy(v => v);
                    ICollection<string> values = new List<string>(statsByMinute.Count());
                    const string format = "{0} mins early:{1}";
                    foreach (var minutes in statsByMinute)
                    {
                        values.Add(string.Format(format, minutes.Key, minutes.Count()));
                    }

                    SendTweet(string.Concat(string.Format(start, _statistics.Created), string.Join(",", values.ToArray())));
                    _statistics = Delays.NewInstance();
                    _statistics.Save();
                }

                double lat, lng;
                if (double.TryParse(ConfigurationManager.AppSettings["Lat"], out lat) && double.TryParse(ConfigurationManager.AppSettings["Lng"], out lng))
                {
                    Latitude = lat;
                    Longitude = lng;
                }

                Trace.TraceInformation("Connecting to server on {0}", wsServer);
                _wsClient = new WebSocketClient(wsServer)
                {
                    OnReceive = OnReceive,
                    OnDisconnect = OnDisconnect
                };
                _wsClient.Connect();
                Trace.TraceInformation("Subscribing to stanox {0}", stanox);
                _wsClient.Send(string.Format("substanox:{0}", stanox));
            }
            catch (Exception e)
            {
                Trace.TraceError("Error starting service: {0}", e);
                throw;
            }
        }