public static void Load()
 {
   try
   {
     JSONValue jsonValue = new JSONParser(File.ReadAllText(ScriptEditorSettings.FilePath)).Parse();
     ScriptEditorSettings.Name = !jsonValue.ContainsKey("name") ? (string) null : jsonValue["name"].AsString();
     ScriptEditorSettings.ServerURL = !jsonValue.ContainsKey("serverurl") ? (string) null : jsonValue["serverurl"].AsString();
     ScriptEditorSettings.ProcessId = !jsonValue.ContainsKey("processid") ? -1 : (int) jsonValue["processid"].AsFloat();
     ScriptEditorSettings.OpenDocuments = !jsonValue.ContainsKey("opendocuments") ? new List<string>() : jsonValue["opendocuments"].AsList().Select<JSONValue, string>((Func<JSONValue, string>) (d => d.AsString())).ToList<string>();
     if (ScriptEditorSettings.ProcessId < 0)
       return;
     Process.GetProcessById(ScriptEditorSettings.ProcessId);
   }
   catch (FileNotFoundException ex)
   {
     ScriptEditorSettings.Clear();
     ScriptEditorSettings.Save();
   }
   catch (Exception ex)
   {
     Logger.Log(ex);
     ScriptEditorSettings.Clear();
     ScriptEditorSettings.Save();
   }
 }
예제 #2
0
 public static JSONValue SimpleParse(string jsondata)
 {
   JSONParser jsonParser = new JSONParser(jsondata);
   try
   {
     return jsonParser.Parse();
   }
   catch (JSONParseException ex)
   {
     Debug.LogError((object) ex.Message);
   }
   return new JSONValue((object) null);
 }
예제 #3
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);
     }
 }
예제 #4
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
     });
   }
 }
예제 #5
0
 public static JSONValue SimpleParse(string jsondata)
 {
     JSONParser parser = new JSONParser(jsondata);
     try
     {
         return parser.Parse();
     }
     catch (JSONParseException exception)
     {
         Debug.LogError(exception.Message);
     }
     return new JSONValue(null);
 }
예제 #6
0
		private static Dictionary<string, JSONValue> ParseJSON(string content, out string status, out string message)
		{
			message = null;
			status = null;
			JSONValue jSONValue;
			try
			{
				JSONParser jSONParser = new JSONParser(content);
				jSONValue = jSONParser.Parse();
			}
			catch (JSONParseException ex)
			{
				Debug.Log("Error parsing server reply: " + content);
				Debug.Log(ex.Message);
				Dictionary<string, JSONValue> result = null;
				return result;
			}
			Dictionary<string, JSONValue> dictionary;
			try
			{
				dictionary = jSONValue.AsDict(true);
				if (dictionary == null)
				{
					Debug.Log("Error parsing server message: " + content);
					Dictionary<string, JSONValue> result = null;
					return result;
				}
				if (dictionary.ContainsKey("result") && dictionary["result"].IsDict())
				{
					dictionary = dictionary["result"].AsDict(true);
				}
				if (dictionary.ContainsKey("message"))
				{
					message = dictionary["message"].AsString(true);
				}
				if (dictionary.ContainsKey("status"))
				{
					status = dictionary["status"].AsString(true);
				}
				else
				{
					if (dictionary.ContainsKey("error"))
					{
						status = dictionary["error"].AsString(true);
						if (status == string.Empty)
						{
							status = "ok";
						}
					}
					else
					{
						status = "ok";
					}
				}
			}
			catch (JSONTypeException ex2)
			{
				Debug.Log("Error parsing server reply. " + content);
				Debug.Log(ex2.Message);
				Dictionary<string, JSONValue> result = null;
				return result;
			}
			return dictionary;
		}
 private static Dictionary<string, JSONValue> ParseJSON(string content, out string status, out string message)
 {
   message = (string) null;
   status = (string) null;
   JSONValue jsonValue;
   try
   {
     jsonValue = new JSONParser(content).Parse();
   }
   catch (JSONParseException ex)
   {
     Debug.Log((object) ("Error parsing server reply: " + content));
     Debug.Log((object) ex.Message);
     return (Dictionary<string, JSONValue>) null;
   }
   Dictionary<string, JSONValue> dictionary;
   try
   {
     dictionary = jsonValue.AsDict(true);
     if (dictionary == null)
     {
       Debug.Log((object) ("Error parsing server message: " + content));
       return (Dictionary<string, JSONValue>) null;
     }
     if (dictionary.ContainsKey("result") && dictionary["result"].IsDict())
       dictionary = dictionary["result"].AsDict(true);
     if (dictionary.ContainsKey("message"))
       message = dictionary["message"].AsString(true);
     if (dictionary.ContainsKey("status"))
       status = dictionary["status"].AsString(true);
     else if (dictionary.ContainsKey("error"))
     {
       status = dictionary["error"].AsString(true);
       if (status == string.Empty)
         status = "ok";
     }
     else
       status = "ok";
   }
   catch (JSONTypeException ex)
   {
     Debug.Log((object) ("Error parsing server reply. " + content));
     Debug.Log((object) ex.Message);
     return (Dictionary<string, JSONValue>) null;
   }
   return dictionary;
 }