예제 #1
0
 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;
        }
예제 #3
0
 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 override JSONValue HandlePost(Request request, JSONValue payload)
    {
      string str1 = payload.Get("action").AsString();
      string str2 = this.CurrentState();
      string key = str1;
      if (key != null)
      {
        // ISSUE: reference to a compiler-generated field
        if (PlayModeRestHandler.\u003C\u003Ef__switch\u0024mapA == null)
        {
          // ISSUE: reference to a compiler-generated field
          PlayModeRestHandler.\u003C\u003Ef__switch\u0024mapA = new Dictionary<string, int>(3)
          {
            {
              "play",
              0
            },
            {
              "pause",
              1
            },
            {
              "stop",
              2
            }
          };
        }
        int num;
        // ISSUE: reference to a compiler-generated field
        if (PlayModeRestHandler.\u003C\u003Ef__switch\u0024mapA.TryGetValue(key, out num))
        {
          switch (num)
          {
            case 0:
              EditorApplication.isPlaying = true;
              EditorApplication.isPaused = false;
              break;
            case 1:
              EditorApplication.isPaused = true;
              break;
            case 2:
              EditorApplication.isPlaying = false;
              break;
            default:
              goto label_8;
          }
          JSONValue jsonValue = new JSONValue();
          jsonValue["oldstate"] = (JSONValue) str2;
          jsonValue["newstate"] = (JSONValue) this.CurrentState();
          return jsonValue;
        }
      }
label_8:
      throw new RestRequestException() { HttpStatusCode = HttpStatusCode.BadRequest, RestErrorString = "Invalid action: " + str1 };
    }
 protected override JSONValue HandlePost(Request request, JSONValue payload)
 {
     JSONValue value2;
     if (payload.ContainsKey("documents"))
     {
         value2 = payload["documents"];
     }
     ScriptEditorSettings.OpenDocuments = (<>f__am$cache0 != null) ? new List<string>() : Enumerable.ToList<string>(Enumerable.Select<JSONValue, string>(value2.AsList(), <>f__am$cache0));
     ScriptEditorSettings.Save();
     return new JSONValue();
 }
 protected override JSONValue HandlePost(Request request, JSONValue payload)
 {
   ScriptEditorSettings.ServerURL = payload["url"].AsString();
   ScriptEditorSettings.Name = !payload.ContainsKey("name") ? (string) null : payload["name"].AsString();
   ScriptEditorSettings.ProcessId = !payload.ContainsKey("processid") ? -1 : (int) payload["processid"].AsFloat();
   Logger.Log("[Pair] Name: " + (ScriptEditorSettings.Name ?? "<null>") + " ServerURL " + ScriptEditorSettings.ServerURL + " Process id: " + (object) ScriptEditorSettings.ProcessId);
   JSONValue jsonValue = new JSONValue();
   jsonValue["unityprocessid"] = (JSONValue) Process.GetCurrentProcess().Id;
   jsonValue["unityproject"] = (JSONValue) Application.dataPath;
   return jsonValue;
 }
예제 #7
0
 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();
 }
예제 #8
0
 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);
     }
 }
예제 #9
0
 private static void CallSafely(Request request, string payload, WriteResponse writeResponse, Func<Request, JSONValue, JSONValue> method)
 {
   try
   {
     JSONValue jsonValue = (JSONValue) ((string) null);
     if (payload.Trim().Length == 0)
     {
       jsonValue = new JSONValue();
     }
     else
     {
       try
       {
         jsonValue = new JSONParser(request.Payload).Parse();
       }
       catch (JSONParseException ex)
       {
         Handler.ThrowInvalidJSONException();
       }
     }
     writeResponse(HttpStatusCode.Ok, method(request, jsonValue).ToString());
   }
   catch (JSONTypeException ex)
   {
     Handler.ThrowInvalidJSONException();
   }
   catch (KeyNotFoundException ex)
   {
     Handler.RespondWithException(writeResponse, new RestRequestException()
     {
       HttpStatusCode = HttpStatusCode.BadRequest
     });
   }
   catch (RestRequestException ex)
   {
     Handler.RespondWithException(writeResponse, ex);
   }
   catch (Exception ex)
   {
     Handler.RespondWithException(writeResponse, new RestRequestException()
     {
       HttpStatusCode = HttpStatusCode.InternalServerError,
       RestErrorString = "InternalServerError",
       RestErrorDescription = "Caught exception while fulfilling request: " + (object) ex
     });
   }
 }
      protected override JSONValue HandlePost(Request request, JSONValue payload)
      {
        string str = payload.Get("action").AsString();
        string key = str;
        if (key != null)
        {
          // ISSUE: reference to a compiler-generated field
          if (AssetRestHandler.AssetHandler.\u003C\u003Ef__switch\u0024map9 == null)
          {
            // ISSUE: reference to a compiler-generated field
            AssetRestHandler.AssetHandler.\u003C\u003Ef__switch\u0024map9 = new Dictionary<string, int>(2)
            {
              {
                "move",
                0
              },
              {
                "create",
                1
              }
            };
          }
          int num;
          // ISSUE: reference to a compiler-generated field
          if (AssetRestHandler.AssetHandler.\u003C\u003Ef__switch\u0024map9.TryGetValue(key, out num))
          {
            if (num != 0)
            {
              if (num == 1)
                this.CreateAsset(request.Url.Substring("/unity/".Length), Encoding.UTF8.GetString(Convert.FromBase64String(payload.Get("contents").AsString())));
              else
                goto label_8;
            }
            else
              this.MoveAsset(request.Url.Substring("/unity/".Length), payload.Get("newpath").AsString());
            return new JSONValue();
          }
        }
label_8:
        throw new RestRequestException() { HttpStatusCode = HttpStatusCode.BadRequest, RestErrorString = "Uknown action: " + str };
      }
 protected override JSONValue HandlePost(Request request, JSONValue payload)
 {
     ScriptEditorSettings.ServerURL = payload["url"].AsString();
     ScriptEditorSettings.Name = !payload.ContainsKey("name") ? null : payload["name"].AsString();
     ScriptEditorSettings.ProcessId = !payload.ContainsKey("processid") ? -1 : ((int) payload["processid"].AsFloat());
     object[] objArray1 = new object[6];
     objArray1[0] = "[Pair] Name: ";
     if (ScriptEditorSettings.Name == null)
     {
     }
     objArray1[1] = "<null>";
     objArray1[2] = " ServerURL ";
     objArray1[3] = ScriptEditorSettings.ServerURL;
     objArray1[4] = " Process id: ";
     objArray1[5] = ScriptEditorSettings.ProcessId;
     Logger.Log(string.Concat(objArray1));
     JSONValue value5 = new JSONValue();
     value5["unityprocessid"] = Process.GetCurrentProcess().Id;
     value5["unityproject"] = Application.dataPath;
     return value5;
 }
 protected override JSONValue HandleGet(Request request, JSONValue payload)
 {
   JSONValue jsonValue = new JSONValue();
   jsonValue["documents"] = Handler.ToJSON((IEnumerable<string>) ScriptEditorSettings.OpenDocuments);
   return jsonValue;
 }
 protected override JSONValue HandleGet(Request request, JSONValue payload)
 {
   JSONValue jsonValue = new JSONValue();
   jsonValue["assets"] = Handler.ToJSON((IEnumerable<string>) AssetDatabase.FindAssets(string.Empty, new string[1]{ "Assets" }));
   return jsonValue;
 }
 protected override JSONValue HandleGet(Request request, JSONValue payload)
 {
     JSONValue value2 = new JSONValue();
     value2["state"] = this.CurrentState();
     return value2;
 }
 protected override JSONValue HandlePost(Request request, JSONValue payload)
 {
   ScriptEditorSettings.OpenDocuments = !payload.ContainsKey("documents") ? new List<string>() : payload["documents"].AsList().Select<JSONValue, string>((Func<JSONValue, string>) (d => d.AsString())).ToList<string>();
   ScriptEditorSettings.Save();
   return new JSONValue();
 }
 protected override JSONValue HandleGet(Request request, JSONValue payload)
 {
   AssetDatabase.Refresh();
   return ProjectStateRestHandler.JsonForProject();
 }
 protected override JSONValue HandleGet(Request request, JSONValue payload)
 {
     JSONValue value2 = new JSONValue();
     value2["documents"] = Handler.ToJSON(ScriptEditorSettings.OpenDocuments);
     return value2;
 }
예제 #18
0
 protected override JSONValue HandleGet(Request request, JSONValue payload)
 {
     int index = request.Url.ToLowerInvariant().IndexOf("/assets/");
     string assetPath = request.Url.ToLowerInvariant().Substring(index + 1);
     return this.GetAssetText(assetPath);
 }
예제 #19
0
 protected virtual JSONValue HandleDelete(Request request, JSONValue payload)
 {
   throw new RestRequestException() { HttpStatusCode = HttpStatusCode.MethodNotAllowed, RestErrorString = "MethodNotAllowed", RestErrorDescription = "This endpoint does not support the DELETE verb." };
 }
예제 #20
0
 protected override JSONValue HandleGet(Request request, JSONValue payload)
 {
     JSONValue value2 = new JSONValue();
     string[] searchInFolders = new string[] { "Assets" };
     value2["assets"] = Handler.ToJSON(AssetDatabase.FindAssets("", searchInFolders));
     return value2;
 }
예제 #21
0
 private void InvokeDelete(Request request, string payload, WriteResponse writeResponse)
 {
   Handler.CallSafely(request, payload, writeResponse, new Func<Request, JSONValue, JSONValue>(this.HandleDelete));
 }
 protected override JSONValue HandleGet(Request request, JSONValue payload)
 {
   JSONValue jsonValue = new JSONValue();
   jsonValue["state"] = (JSONValue) this.CurrentState();
   return jsonValue;
 }
 protected override JSONValue HandleGet(Request request, JSONValue payload)
 {
   int num = request.Url.ToLowerInvariant().IndexOf("/assets/");
   return this.GetAssetText(request.Url.ToLowerInvariant().Substring(num + 1));
 }
예제 #24
0
 private void InvokePost(Request request, string payload, Response writeResponse)
 {
     CallSafely(request, payload, writeResponse, new Func<Request, JSONValue, JSONValue>(this, (IntPtr) this.HandlePost));
 }