예제 #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 };
    }
			public void Initialize(JSONValue json)
			{
				if (json.ContainsKey("label"))
				{
					this.label = json["label"].AsString();
				}
				if (json.ContainsKey("id"))
				{
					this.id = json["id"].AsString();
				}
			}
			public void Initialize(JSONValue json)
			{
				if (json.ContainsKey("type"))
				{
					this.type = json["type"].AsString();
				}
				if (json.ContainsKey("id"))
				{
					this.id = json["id"].AsString();
				}
			}
 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;
 }
예제 #9
0
 internal JSONValue GetAssetText(string assetPath)
 {
     Object obj2 = AssetDatabase.LoadAssetAtPath(assetPath, typeof(Object));
     if (obj2 == null)
     {
         throw new RestRequestException(HttpStatusCode.BadRequest, "AssetNotFound");
     }
     JSONValue value2 = new JSONValue();
     value2["file"] = assetPath;
     value2["contents"] = Convert.ToBase64String(Encoding.UTF8.GetBytes(obj2.ToString()));
     return value2;
 }
예제 #10
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();
 }
예제 #11
0
			public void Initialize(JSONValue json)
			{
				if (json.ContainsKey("title"))
				{
					this.title = json["title"].AsString();
				}
				if (json.ContainsKey("id"))
				{
					this.id = json["id"].AsString();
				}
				if (json.ContainsKey("version"))
				{
					this.version = json["version"].AsString();
				}
				if (json.ContainsKey("version_id"))
				{
					this.version_id = json["version_id"].AsString();
				}
				if (json.ContainsKey("local_icon"))
				{
					this.local_icon = json["local_icon"].AsString();
				}
				if (json.ContainsKey("local_path"))
				{
					this.local_path = json["local_path"].AsString();
				}
				if (json.ContainsKey("pubdate"))
				{
					this.pubdate = json["pubdate"].AsString();
				}
				if (json.ContainsKey("description"))
				{
					this.description = json["description"].AsString();
				}
				if (json.ContainsKey("publisher"))
				{
					this.publisher = new AssetStoreContext.LabelAndId();
					this.publisher.Initialize(json["publisher"]);
				}
				if (json.ContainsKey("category"))
				{
					this.category = new AssetStoreContext.LabelAndId();
					this.category.Initialize(json["category"]);
				}
				if (json.ContainsKey("link"))
				{
					this.link = new AssetStoreContext.Link();
					this.link.Initialize(json["link"]);
				}
			}
예제 #12
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);
     }
 }
예제 #13
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 };
      }
예제 #15
0
 public static void Download(string package_id, string url, string key, string package_name, string publisher_name, string category_name, AssetStoreUtils.DownloadDoneCallback doneCallback)
 {
     string[] destination = PackageStorePath(publisher_name, category_name, package_name, package_id, url);
     JSONValue value2 = JSONParser.SimpleParse(AssetStoreUtils.CheckDownload(package_id, url, destination, key));
     if (value2.Get("in_progress").AsBool(true))
     {
         Debug.Log("Will not download " + package_name + ". Download is already in progress.");
     }
     else
     {
         string str = value2.Get("download.url").AsString(true);
         string str2 = value2.Get("download.key").AsString(true);
         bool resumeOK = (str == url) && (str2 == key);
         JSONValue value3 = new JSONValue();
         value3["url"] = url;
         value3["key"] = key;
         JSONValue value4 = new JSONValue();
         value4["download"] = value3;
         AssetStoreUtils.Download(package_id, url, destination, key, value4.ToString(), resumeOK, doneCallback);
     }
 }
 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["assets"] = Handler.ToJSON((IEnumerable<string>) AssetDatabase.FindAssets(string.Empty, new string[1]{ "Assets" }));
   return jsonValue;
 }
 internal JSONValue GetAssetText(string assetPath)
 {
   UnityEngine.Object @object = AssetDatabase.LoadAssetAtPath(assetPath, typeof (UnityEngine.Object));
   if (@object == (UnityEngine.Object) null)
     throw new RestRequestException(HttpStatusCode.BadRequest, "AssetNotFound");
   JSONValue jsonValue = new JSONValue();
   jsonValue["file"] = (JSONValue) assetPath;
   jsonValue["contents"] = (JSONValue) Convert.ToBase64String(Encoding.UTF8.GetBytes(@object.ToString()));
   return jsonValue;
 }
 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 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();
 }
 private static JSONValue JsonForProject()
 {
   List<ProjectStateRestHandler.Island> list = ((IEnumerable<MonoIsland>) InternalEditorUtility.GetMonoIslands()).Select<MonoIsland, ProjectStateRestHandler.Island>((Func<MonoIsland, ProjectStateRestHandler.Island>) (i => new ProjectStateRestHandler.Island() { MonoIsland = i, Name = Path.GetFileNameWithoutExtension(i._output), References = ((IEnumerable<string>) i._references).ToList<string>() })).ToList<ProjectStateRestHandler.Island>();
   using (List<ProjectStateRestHandler.Island>.Enumerator enumerator1 = list.GetEnumerator())
   {
     while (enumerator1.MoveNext())
     {
       ProjectStateRestHandler.Island current1 = enumerator1.Current;
       List<string> stringList1 = new List<string>();
       List<string> stringList2 = new List<string>();
       using (List<string>.Enumerator enumerator2 = current1.References.GetEnumerator())
       {
         while (enumerator2.MoveNext())
         {
           string current2 = enumerator2.Current;
           // ISSUE: object of a compiler-generated type is created
           // ISSUE: variable of a compiler-generated type
           ProjectStateRestHandler.\u003CJsonForProject\u003Ec__AnonStorey25 projectCAnonStorey25 = new ProjectStateRestHandler.\u003CJsonForProject\u003Ec__AnonStorey25();
           // ISSUE: reference to a compiler-generated field
           projectCAnonStorey25.refName = Path.GetFileNameWithoutExtension(current2);
           // ISSUE: reference to a compiler-generated method
           if (current2.StartsWith("Library/") && list.Any<ProjectStateRestHandler.Island>(new Func<ProjectStateRestHandler.Island, bool>(projectCAnonStorey25.\u003C\u003Em__31)))
           {
             // ISSUE: reference to a compiler-generated field
             stringList1.Add(projectCAnonStorey25.refName);
             stringList2.Add(current2);
           }
           if (current2.EndsWith("/UnityEditor.dll") || current2.EndsWith("/UnityEngine.dll") || (current2.EndsWith("\\UnityEditor.dll") || current2.EndsWith("\\UnityEngine.dll")))
             stringList2.Add(current2);
         }
       }
       current1.References.Add(InternalEditorUtility.GetEditorAssemblyPath());
       current1.References.Add(InternalEditorUtility.GetEngineAssemblyPath());
       using (List<string>.Enumerator enumerator2 = stringList1.GetEnumerator())
       {
         while (enumerator2.MoveNext())
         {
           string current2 = enumerator2.Current;
           current1.References.Add(current2);
         }
       }
       using (List<string>.Enumerator enumerator2 = stringList2.GetEnumerator())
       {
         while (enumerator2.MoveNext())
         {
           string current2 = enumerator2.Current;
           current1.References.Remove(current2);
         }
       }
     }
   }
   string[] array = list.SelectMany<ProjectStateRestHandler.Island, string>((Func<ProjectStateRestHandler.Island, IEnumerable<string>>) (i => (IEnumerable<string>) i.MonoIsland._files)).Concat<string>(ProjectStateRestHandler.GetAllSupportedFiles()).Distinct<string>().ToArray<string>();
   string[] projectPath = ProjectStateRestHandler.RelativeToProjectPath(ProjectStateRestHandler.FindEmptyDirectories(ProjectStateRestHandler.AssetsPath, array));
   JSONValue jsonValue1 = new JSONValue();
   jsonValue1["islands"] = new JSONValue((object) list.Select<ProjectStateRestHandler.Island, JSONValue>((Func<ProjectStateRestHandler.Island, JSONValue>) (i => ProjectStateRestHandler.JsonForIsland(i))).Where<JSONValue>((Func<JSONValue, bool>) (i2 => !i2.IsNull())).ToList<JSONValue>());
   jsonValue1["basedirectory"] = (JSONValue) ProjectStateRestHandler.ProjectPath;
   JSONValue jsonValue2 = new JSONValue();
   jsonValue2["files"] = Handler.ToJSON((IEnumerable<string>) array);
   jsonValue2["emptydirectories"] = Handler.ToJSON((IEnumerable<string>) projectPath);
   jsonValue1["assetdatabase"] = jsonValue2;
   return jsonValue1;
 }
예제 #22
0
		private JSONValue ParseNumber()
		{
			string text = string.Empty;
			if (this.cur == '-')
			{
				text = "-";
				this.Next();
			}
			while (this.cur >= '0' && this.cur <= '9')
			{
				text += this.cur;
				this.Next();
			}
			if (this.cur == '.')
			{
				this.Next();
				text += '.';
				while (this.cur >= '0' && this.cur <= '9')
				{
					text += this.cur;
					this.Next();
				}
			}
			if (this.cur == 'e' || this.cur == 'E')
			{
				text += "e";
				this.Next();
				if (this.cur != '-' && this.cur != '+')
				{
					text += this.cur;
					this.Next();
				}
				while (this.cur >= '0')
				{
					if (this.cur > '9')
					{
						break;
					}
					text += this.cur;
					this.Next();
				}
			}
			JSONValue result;
			try
			{
				float num = Convert.ToSingle(text);
				result = new JSONValue(num);
			}
			catch (Exception)
			{
				throw new JSONParseException("Cannot convert string to float : '" + text + "' at " + this.PosMsg());
			}
			return result;
		}
예제 #23
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." };
 }
예제 #24
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);
 }
예제 #25
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;
 }
 public static void Download(string package_id, string url, string key, string package_name, string publisher_name, string category_name, AssetStoreUtils.DownloadDoneCallback doneCallback)
 {
   string[] destination = AssetStoreContext.PackageStorePath(publisher_name, category_name, package_name, package_id, url);
   JSONValue jsonValue1 = JSONParser.SimpleParse(AssetStoreUtils.CheckDownload(package_id, url, destination, key));
   if (jsonValue1.Get("in_progress").AsBool(true))
   {
     Debug.Log((object) ("Will not download " + package_name + ". Download is already in progress."));
   }
   else
   {
     string str1 = jsonValue1.Get("download.url").AsString(true);
     string str2 = jsonValue1.Get("download.key").AsString(true);
     bool resumeOK = str1 == url && str2 == key;
     JSONValue jsonValue2 = new JSONValue();
     jsonValue2["url"] = (JSONValue) url;
     jsonValue2["key"] = (JSONValue) key;
     JSONValue jsonValue3 = new JSONValue();
     jsonValue3["download"] = jsonValue2;
     AssetStoreUtils.Download(package_id, url, destination, key, jsonValue3.ToString(), resumeOK, doneCallback);
   }
 }
 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));
 }
예제 #29
0
 private JSONValue ParseNumber()
 {
     JSONValue value2;
     string str = "";
     if (this.cur == '-')
     {
         str = "-";
         this.Next();
     }
     while ((this.cur >= '0') && (this.cur <= '9'))
     {
         str = str + this.cur;
         this.Next();
     }
     if (this.cur == '.')
     {
         this.Next();
         str = str + '.';
         while ((this.cur >= '0') && (this.cur <= '9'))
         {
             str = str + this.cur;
             this.Next();
         }
     }
     if ((this.cur == 'e') || (this.cur == 'E'))
     {
         str = str + "e";
         this.Next();
         if ((this.cur != '-') && (this.cur != '+'))
         {
             str = str + this.cur;
             this.Next();
         }
         while ((this.cur >= '0') && (this.cur <= '9'))
         {
             str = str + this.cur;
             this.Next();
         }
     }
     try
     {
         value2 = new JSONValue(Convert.ToSingle(str));
     }
     catch (Exception)
     {
         throw new JSONParseException("Cannot convert string to float : '" + str + "' at " + this.PosMsg());
     }
     return value2;
 }
 protected override JSONValue HandleGet(Request request, JSONValue payload)
 {
     JSONValue value2 = new JSONValue();
     value2["documents"] = Handler.ToJSON(ScriptEditorSettings.OpenDocuments);
     return value2;
 }