public static JSONResponse Status(JSONRequest request) { JSONResponse response = new JSONResponse(); response.Body = new Dictionary<string, object>(); response.Body["running"] = true; Dictionary<string,object> server = new Dictionary<string,object>(); server["name"] = "Twin"; server["version"] = Assembly.GetExecutingAssembly().GetName().Version.ToString(); response.Body["server"] = server; SessionFactory factory = GetFactory(request); List<Dictionary<string, object>> configurations = new List<Dictionary<string, object>>(); foreach(Configuration config in factory.Configurations) { Dictionary<string, object> serial = new Dictionary<string, object>(); serial["id"] = config.identifier; serial["capabilities"] = config.Capabilities; serial["path"] = config.appPath; if (config.arguments != null) serial["arguments"] = config.arguments; configurations.Add(serial); } response.Body["configurations"] = configurations; List<Dictionary<string, object>> sessions = new List<Dictionary<string, object>>(); foreach (KeyValuePair<Guid, Session> session in factory.GetSessions()) { Dictionary<string, object> serial = new Dictionary<string, object>(); serial["id"] = session.Key.ToString(); serial["configuration"] = session.Value.Configuration.identifier; serial["processId"] = session.Value.Process.Id; sessions.Add(serial); } response.Body["sessions"] = sessions; return response; }
public SessionRequest(JSONRequest basic) : base(basic) { try { this.Session = Sessions.GetSession(basic); } catch (ArgumentException ex) { throw new TwinException(ResponseStatus.NoSuchSession, ex.Message, ex); } }
public static JSONResponse Create(JSONRequest request) { if(!request.Body.ContainsKey("desiredCapabilities")) throw new ArgumentException("desiredCapabilities not provided"); Dictionary<string, object> sessionSetupInfo = request.Body.ContainsKey("sessionSetup") ? (Dictionary<string, object>)request.Body["sessionSetup"] : null; Session session = GetFactory(request).Create(flatten((Dictionary<string,object>)request.Body["desiredCapabilities"]), sessionSetupInfo); JSONResponse response = new JSONResponse(); response.StatusCode = 303; response.Location = "/session/" + session.ToString(); return response; }
public override void Respond(ParsedRequest request) { JSONRequest jreq = new JSONRequest(request); JSONResponse jres = null; try { jres = Respond(jreq); } catch (Exception e) { if (e is HttpException) { throw e; } jres = GetExceptionResponse(e); } WriteJSONResponse(jres, request.Request.Response); }
public override JSONResponse Respond(JSONRequest request) { SessionRequest sessionRequest = new SessionRequest(request); object value = Respond(sessionRequest); if (value is JSONResponse) { return((JSONResponse)value); } JSONResponse response = new JSONResponse(); response.Body = new Dictionary <string, object>(); response.Body["sessionId"] = sessionRequest.Session.ToString(); response.Body["status"] = (int)ResponseStatus.Success; response.Body["value"] = value; return(response); }
public JSONRequest(JSONRequest parent) : base(parent.Request, parent.Parameters) { Body = parent.Body; }
public virtual JSONResponse Respond(JSONRequest request) { return(handler(request)); }
public static JSONResponse Delete(JSONRequest request) { GetFactory(request).Delete(GetSession(request)); return CreateResponse(null, ResponseStatus.Success, null); }
public static JSONResponse GetCapabilities(JSONRequest request) { Session session = GetSession(request); return CreateResponse(session, ResponseStatus.Success, session); }
public static SessionFactory GetFactory(JSONRequest request) { return ((TwinRC)request.Servlet).SessionFactory; }
public static Session GetSession(JSONRequest request) { return GetFactory(request)[request.Parameters["session"]]; }
public virtual JSONResponse Respond(JSONRequest request) { return handler(request); }
public override JSONResponse Respond(JSONRequest request) { SessionRequest sessionRequest = new SessionRequest(request); object value = Respond(sessionRequest); if (value is JSONResponse) return (JSONResponse)value; JSONResponse response = new JSONResponse(); response.Body = new Dictionary<string, object>(); response.Body["sessionId"] = sessionRequest.Session.ToString(); response.Body["status"] = (int)ResponseStatus.Success; response.Body["value"] = value; return response; }
public override void Respond(ParsedRequest request) { JSONRequest jreq = new JSONRequest(request); JSONResponse jres = null; try { jres = Respond(jreq); } catch (Exception e) { if (e is HttpException) throw e; jres = GetExceptionResponse(e); } WriteJSONResponse(jres, request.Request.Response); }