public HttpResponseMessage Get(string plugin, int timeout, string arg1 = null, string arg2 = null, string arg3 = null) { try { var behaviour = new PhantomJsBehaviour(); string result; if (arg1 == null) result = behaviour.Execute(plugin, TimeSpan.FromSeconds(timeout)); else if (arg2 == null) result = behaviour.Execute(plugin, TimeSpan.FromSeconds(timeout), arg1); else if (arg3 == null) result = behaviour.Execute(plugin, TimeSpan.FromSeconds(timeout), arg1, arg2); else result = behaviour.Execute(plugin, TimeSpan.FromSeconds(timeout), arg1, arg2, arg3); return new HttpResponseMessage { Content = new StringContent(result, new UTF8Encoding(), "application/json"), StatusCode = HttpStatusCode.OK }; } catch (Exception ex) { return new HttpResponseMessage { Content = new StringContent(ex.Message + ex.StackTrace + (ex.InnerException ?? new Exception())), StatusCode = HttpStatusCode.InternalServerError }; } }
public TimingResponse NetSniff(string url, int timeout) { var behaviour = new PhantomJsBehaviour(); var message = behaviour.Execute("netsniff.js", TimeSpan.FromSeconds(timeout), url); using (var streamReader = new StringReader(message)) using (var jsonReader = new JsonTextReader(streamReader)) { var serializer = new JsonSerializer(); return serializer.Deserialize<TimingResponse>(jsonReader); } }