private IResponse HandleMessage(Command message)
{
IResponse response;
switch (message.CommandType)
{
case CommandType.ExecJavascript:
var jsCommand = message as ExecJavascriptCommand;
response = message.CreateResponse(Browser.ExecJavascript(jsCommand.Javascript));
break;
case CommandType.Url:
var urlCommand = message as UrlCommand;
switch (urlCommand.Mode)
{
case CommandMode.Get:
response = message.CreateResponse(Browser.Url);
break;
case CommandMode.Set:
Browser.Navigate(urlCommand.Url);
response = message.CreateResponse(true);
break;
case CommandMode.Invoke:
throw new InvalidEnumArgumentException("Cannot Invoke the URL CommandType");
default:
throw new ArgumentOutOfRangeException();
}
break;
case CommandType.Screenshot:
response = message.CreateResponse(TakeScreenshot());
break;
case CommandType.Orientation:
var orientationCommand = message as OrientationCommand;
switch (orientationCommand.Mode)
{
case CommandMode.Get:
response = message.CreateResponse(Orientation);
break;
case CommandMode.Set:
Orientation = orientationCommand.Orientation;
response = message.CreateResponse(true);
break;
case CommandMode.Invoke:
throw new InvalidEnumArgumentException("Cannot Invoke the Orientation CommandType");
default:
throw new ArgumentOutOfRangeException();
}
break;
case CommandType.Disconnect:
Browser.Navigate("about:blank", false);
_communicator.SendResponse(message.CreateResponse(true));
_communicator.Close();
return null;
case CommandType.WaitForReady:
Browser.WaitForReady();
response = message.CreateResponse(true);
break;
case CommandType.Refresh:
Browser.Refresh();
response = message.CreateResponse(true);
break;
default:
throw new ArgumentOutOfRangeException();
}
return response;
}