private static bool SendPing(Session session)
 {
     Logger.Debug("Sending ping request to Test Server");
     var pingCmd = new Command("ping");
     var response = session.CommandForwarder.ForwardCommand(pingCmd, false, 2500);
     return response.Trim().Equals("pong");
 }
        public CommandResponse Do()
        {
            if (this.ExecutedCommand == null)
            {
                throw new NullReferenceException("ExecutedCommand property must be set before calling Do");
            }

            try
            {
                var session = this.ExecutedCommand.SessionId;
                this.Session = SessionsManager.GetSessionbyId(session);
                return CommandResponse.Create(HttpStatusCode.OK, this.DoImpl());
            }
            catch (AutomationException ex)
            {
                return CommandResponse.Create(HttpStatusCode.OK, this.JsonResponse(ex.Status, ex.Message));
            }
            catch (InnerDriverRequestException ex)
            {
                // Bad status returned by Inner Driver when trying to forward command
                return CommandResponse.Create(ex.StatusCode, ex.Message);
            }
            catch (NotImplementedException exception)
            {
                return CommandResponse.Create(
                    HttpStatusCode.NotImplemented,
                    this.JsonResponse(ResponseStatus.UnknownCommand, exception.Message));
            }
            catch (Exception exception)
            {
                return CommandResponse.Create(
                    HttpStatusCode.OK,
                    this.JsonResponse(ResponseStatus.UnknownError, "Unknown error: " + exception.Message));
            }
        }
        private static bool WaitForConnection(Session session)
        {
            var retires = session.ActualCapabilities.PingRetries;

            while (retires > 0)
            {
                --retires;
                var rv = SendPing(session);
                if (rv)
                {
                    return true;
                }
            }

            return false;
        }