Пример #1
0
        public async Task <RefreshPacket> Refresh()
        {
            var tcs = new TaskCompletionSource <RefreshPacket>();

            _commandsQueue.Enqueue(stream =>
            {
                stream.WriteLine("REFRESH");

                if (!stream.ReadUntil("REFRESH\r\n").Result)
                {
                    System.Console.WriteLine("Something went wrong");
                    tcs.SetResult(null);
                    return;
                }

                var refreshPacketLength = 1188;
                var packet = new byte[refreshPacketLength];
                var read   = stream.Read(packet, 0, refreshPacketLength);
                if (read != refreshPacketLength)
                {
                    System.Console.WriteLine("Not everything read");
                }

                var refreshPacket = _packetParser.ParseRefreshPacket(packet, 0);
                tcs.SetResult(refreshPacket);
            });

            return(await tcs.Task);
        }