예제 #1
0
파일: Sessions.cs 프로젝트: kevtham/twin
        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;
        }
예제 #2
0
 public SessionRequest(JSONRequest basic) : base(basic)
 {
     try {
         this.Session = Sessions.GetSession(basic);
     } catch (ArgumentException ex) {
         throw new TwinException(ResponseStatus.NoSuchSession, ex.Message, ex);
     }
 }
예제 #3
0
파일: Sessions.cs 프로젝트: kevtham/twin
 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;
 }
예제 #4
0
        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);
        }
예제 #5
0
        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);
        }
예제 #6
0
 public JSONRequest(JSONRequest parent) : base(parent.Request, parent.Parameters)
 {
     Body = parent.Body;
 }
예제 #7
0
 public virtual JSONResponse Respond(JSONRequest request)
 {
     return(handler(request));
 }
예제 #8
0
파일: Sessions.cs 프로젝트: kevtham/twin
 public static JSONResponse Delete(JSONRequest request) {
     GetFactory(request).Delete(GetSession(request));
     return CreateResponse(null, ResponseStatus.Success, null);
 }
예제 #9
0
파일: Sessions.cs 프로젝트: kevtham/twin
 public static JSONResponse GetCapabilities(JSONRequest request) {
     Session session = GetSession(request);
     return CreateResponse(session, ResponseStatus.Success, session);
 }
예제 #10
0
파일: Sessions.cs 프로젝트: kevtham/twin
 public static SessionFactory GetFactory(JSONRequest request) {
     return ((TwinRC)request.Servlet).SessionFactory;
 }
예제 #11
0
파일: Sessions.cs 프로젝트: kevtham/twin
 public static Session GetSession(JSONRequest request) {
     return GetFactory(request)[request.Parameters["session"]];
 }
예제 #12
0
파일: Responders.cs 프로젝트: kevtham/twin
		public virtual JSONResponse Respond(JSONRequest request) {
			return handler(request);
		}
예제 #13
0
파일: Responders.cs 프로젝트: kevtham/twin
		public JSONRequest(JSONRequest parent) : base(parent.Request, parent.Parameters) {
			Body = parent.Body;
		}
예제 #14
0
파일: Responders.cs 프로젝트: kevtham/twin
		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;
		}
예제 #15
0
파일: Responders.cs 프로젝트: kevtham/twin
        public SessionRequest(JSONRequest basic) : base(basic) {
			try {
	            this.Session = Sessions.GetSession(basic);
			} catch (ArgumentException ex) {
				throw new TwinException(ResponseStatus.NoSuchSession, ex.Message, ex);
			}
        }		
예제 #16
0
파일: Responders.cs 프로젝트: kevtham/twin
		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);
		}