protected override JSONValue HandlePost(Request request, JSONValue payload) { string str = payload.Get("action").AsString(); string str2 = this.CurrentState(); switch (str) { case "play": EditorApplication.isPlaying = true; EditorApplication.isPaused = false; break; case "pause": EditorApplication.isPaused = true; break; case "stop": EditorApplication.isPlaying = false; break; default: { RestRequestException exception = new RestRequestException { HttpStatusCode = HttpStatusCode.BadRequest, RestErrorString = "Invalid action: " + str }; throw exception; } } return(new JSONValue { ["oldstate"] = str2, ["newstate"] = this.CurrentState() }); }
protected override JSONValue HandlePost(Request request, JSONValue payload) { string str = payload.Get("action").AsString(); switch (str) { case "move": { string from = request.Url.Substring("/unity/".Length); string to = payload.Get("newpath").AsString(); this.MoveAsset(from, to); break; } case "create": { string assetPath = request.Url.Substring("/unity/".Length); byte[] bytes = Convert.FromBase64String(payload.Get("contents").AsString()); string contents = Encoding.UTF8.GetString(bytes); this.CreateAsset(assetPath, contents); break; } default: { RestRequestException exception = new RestRequestException { HttpStatusCode = HttpStatusCode.BadRequest, RestErrorString = "Uknown action: " + str }; throw exception; } } return(new JSONValue()); }
protected override JSONValue HandlePost(Request request, JSONValue payload) { string str = payload.Get("action").AsString(); string str2 = this.CurrentState(); switch (str) { case "play": EditorApplication.isPlaying = true; EditorApplication.isPaused = false; break; case "pause": EditorApplication.isPaused = true; break; case "stop": EditorApplication.isPlaying = false; break; default: { RestRequestException exception = new RestRequestException { HttpStatusCode = HttpStatusCode.BadRequest, RestErrorString = "Invalid action: " + str }; throw exception; } } JSONValue value3 = new JSONValue(); value3["oldstate"] = str2; value3["newstate"] = this.CurrentState(); return value3; }
private static void ThrowInvalidJSONException() { RestRequestException exception = new RestRequestException { HttpStatusCode = HttpStatusCode.BadRequest, RestErrorString = "Invalid JSON" }; throw exception; }
protected virtual JSONValue HandleGet(Request request, JSONValue payload) { RestRequestException exception = new RestRequestException { HttpStatusCode = HttpStatusCode.MethodNotAllowed, RestErrorString = "MethodNotAllowed", RestErrorDescription = "This endpoint does not support the GET verb." }; throw exception; }
protected virtual JSONValue HandlePost(Request request, JSONValue payload) { RestRequestException exception = new RestRequestException { HttpStatusCode = HttpStatusCode.MethodNotAllowed, RestErrorString = "MethodNotAllowed", RestErrorDescription = "This endpoint does not support the POST verb." }; throw exception; }
private static void RespondWithException(WriteResponse writeResponse, RestRequestException rre) { StringBuilder stringBuilder = new StringBuilder("{"); if (rre.RestErrorString != null) stringBuilder.AppendFormat("\"error\":\"{0}\",", (object) rre.RestErrorString); if (rre.RestErrorDescription != null) stringBuilder.AppendFormat("\"errordescription\":\"{0}\"", (object) rre.RestErrorDescription); stringBuilder.Append("}"); writeResponse(rre.HttpStatusCode, stringBuilder.ToString()); }
protected override JSONValue HandleDelete(Request request, JSONValue payload) { if (!AssetDatabase.DeleteAsset(request.Url.Substring("/unity/".Length))) { RestRequestException exception = new RestRequestException { HttpStatusCode = HttpStatusCode.InternalServerError, RestErrorString = "FailedDeletingAsset", RestErrorDescription = "DeleteAsset() returned false" }; throw exception; } return(new JSONValue()); }
protected override JSONValue HandleDelete(Request request, JSONValue payload) { if (!AssetDatabase.DeleteAsset(request.Url.Substring("/unity/".Length))) { RestRequestException exception = new RestRequestException { HttpStatusCode = HttpStatusCode.InternalServerError, RestErrorString = "FailedDeletingAsset", RestErrorDescription = "DeleteAsset() returned false" }; throw exception; } return new JSONValue(); }
private static void CallSafely(Request request, string payload, WriteResponse writeResponse, Func <Request, JSONValue, JSONValue> method) { RestRequestException exception3; try { JSONValue value2 = 0; if (payload.Trim().Length == 0) { value2 = new JSONValue(); } else { try { value2 = new JSONParser(request.Payload).Parse(); } catch (JSONParseException) { ThrowInvalidJSONException(); } } writeResponse(HttpStatusCode.Ok, method(request, value2).ToString()); } catch (JSONTypeException) { ThrowInvalidJSONException(); } catch (KeyNotFoundException) { exception3 = new RestRequestException { HttpStatusCode = HttpStatusCode.BadRequest }; RespondWithException(writeResponse, exception3); } catch (RestRequestException exception) { RespondWithException(writeResponse, exception); } catch (Exception exception2) { exception3 = new RestRequestException { HttpStatusCode = HttpStatusCode.InternalServerError, RestErrorString = "InternalServerError", RestErrorDescription = "Caught exception while fulfilling request: " + exception2 }; RespondWithException(writeResponse, exception3); } }
private static void RespondWithException(Response writeResponse, RestRequestException rre) { var body = new StringBuilder("{"); if (rre.RestErrorString != null) { body.AppendFormat("\"error\":\"{0}\",", rre.RestErrorString); } if (rre.RestErrorDescription != null) { body.AppendFormat("\"errordescription\":\"{0}\"", rre.RestErrorDescription); } body.Append("}"); writeResponse.SimpleResponse(rre.HttpStatusCode, "application/json", body.ToString()); }
private static void RespondWithException(WriteResponse writeResponse, RestRequestException rre) { StringBuilder stringBuilder = new StringBuilder("{"); if (rre.RestErrorString != null) { stringBuilder.AppendFormat("\"error\":\"{0}\",", (object)rre.RestErrorString); } if (rre.RestErrorDescription != null) { stringBuilder.AppendFormat("\"errordescription\":\"{0}\"", (object)rre.RestErrorDescription); } stringBuilder.Append("}"); writeResponse(rre.HttpStatusCode, stringBuilder.ToString()); }
private static void CallSafely(Request request, string payload, Response writeResponse, Func<Request, JSONValue, JSONValue> method) { RestRequestException exception; try { JSONValue value2 = 0; if (payload.Trim().Length == 0) { value2 = new JSONValue(); } else { try { value2 = new JSONParser(request.Payload).Parse(); } catch (JSONParseException) { ThrowInvalidJSONException(); } } writeResponse.SimpleResponse(HttpStatusCode.Ok, method.Invoke(request, value2).ToString()); } catch (JSONTypeException) { ThrowInvalidJSONException(); } catch (KeyNotFoundException) { exception = new RestRequestException { HttpStatusCode = HttpStatusCode.BadRequest }; RespondWithException(writeResponse, exception); } catch (RestRequestException exception2) { RespondWithException(writeResponse, exception2); } catch (Exception exception3) { exception = new RestRequestException { HttpStatusCode = HttpStatusCode.InternalServerError, RestErrorString = "InternalServerError", RestErrorDescription = "Caught exception while fulfilling request: " + exception3 }; RespondWithException(writeResponse, exception); } }
protected override JSONValue HandlePost(Request request, JSONValue payload) { string str = payload.Get("action").AsString(); switch (str) { case "move": { string from = request.Url.Substring("/unity/".Length); string to = payload.Get("newpath").AsString(); this.MoveAsset(from, to); break; } case "create": { string assetPath = request.Url.Substring("/unity/".Length); byte[] bytes = Convert.FromBase64String(payload.Get("contents").AsString()); string contents = Encoding.UTF8.GetString(bytes); this.CreateAsset(assetPath, contents); break; } default: { RestRequestException exception = new RestRequestException { HttpStatusCode = HttpStatusCode.BadRequest, RestErrorString = "Uknown action: " + str }; throw exception; } } return new JSONValue(); }