Пример #1
0
        public Proxy()
        {
            _cts   = new CancellationTokenSource();
            _token = _cts.Token;

            var settings    = new Settings();
            var dbCache     = new DbCache();
            var inputCache  = new MessageCache();
            var outputCache = new MessageCache();

            var settingsInitTask = settings.InitAsync();
            var dbCacheInitTask  = dbCache.InitAsync();

            Task.WaitAll(new[] { settingsInitTask, dbCacheInitTask }, _token);

            _dbReceiver          = new DbReceiver(settings, dbCache);
            _sisposReceiver      = new SISPOSReceiver(settings, inputCache);
            _sisposDataProcessor = new SISPOSDataProcessor(settings, dbCache, inputCache, outputCache);
            _sisposTransmitter   = new SISPOSTransmitter(settings, outputCache);
        }
Пример #2
0
        public void SendingTest()
        {
            var messageCache = new MessageCache();
            var testReceiver = new UdpPacketReceiver();
            var payloads     = new[]
            {
                Encoding.ASCII.GetBytes("$PANSPT,33,22,1*88\r\n$PANSPT,44,55,1*99\r\n"),
                Encoding.ASCII.GetBytes("$PANSPT,44,55,1*77\r\n$PANSPT,11,22,1*55\r\n")
            };
            var result = new byte[_ports.Length][];

            foreach (var payload in payloads)
            {
                messageCache.Push(payload);
            }

            using (var transmitter = new SISPOSTransmitter(_settings, messageCache))
            {
                var tasks = new Task <byte[]> [_ports.Length];

                for (int i = 0; i < tasks.Length; i++)
                {
                    tasks[i] = testReceiver.ReceiveAsync(_ports[i]);
                }

                Thread.Sleep(100);

                transmitter.Start();

                Task.WaitAll(tasks, 1000);

                for (int i = 0; i < result.Length; i++)
                {
                    result[i] = tasks[i].Result;
                }
            }

            Assert.IsTrue(result.All(x => x != null && x.Length > 0));
            Assert.IsTrue(result.All(x => payloads[0].ContainsSubArray(x)));
        }