Ejemplo n.º 1
0
        public void ProccessCommands()
        {
            string ip   = _configuration.GetValue <string>("Host");
            int    port = _configuration.GetValue <int>("Connections:Tcp:Port");

            ConnectTcpConnection(ip, port);
            foreach (AsyncCommand asyncCommand in _queue.GetConsumingEnumerable())
            {
                IResult res;
                string  recv;
                if (!ConnectTcpConnection(ip, port))
                {
                    res = new ServerErrorResult("couldn't connect to simulator");
                    asyncCommand.Completion.SetResult(res);
                    continue;
                }
                //try to write and read
                try
                {
                    _client.Write(GetSendCommand(asyncCommand));
                    recv = _client.Read();
                }
                //timeout
                catch (TimeoutException ex)
                {
                    res = new ServerErrorResult(ex.Message);
                    asyncCommand.Completion.SetResult(res);
                    continue;
                }
                //another error
                catch
                {
                    res = new ServerErrorResult(
                        "couldn't communicate with Flight Gear Simulator");
                    asyncCommand.Completion.SetResult(res);
                    continue;
                }
                //valid that send success
                if (!ValidOperation(recv, asyncCommand.Command))
                {
                    res = new ServerErrorResult("server didn't update");
                }
                else
                {
                    res = new OkResult("Successfully sent command");
                }
                asyncCommand.Completion.SetResult(res);
            }
        }
 public ServerError(ServerErrorResult result) : this(null, result) => Error = result;
 public ServerError(object id, ServerErrorResult result) : base(id)
 {
     Error = result;
 }