Example #1
0
        public void ContainsExistingViaGenericCollection()
        {
            ICollection <KeyValuePair <string, object> > obj = new JsonObject();

            obj.Add(new KeyValuePair <string, object>("first", 123));
            Assert.IsTrue(obj.Contains(new KeyValuePair <string, object>("first", 123)));
        }
Example #2
0
        public void ContainsNonExistingKeyMatchingValueViaGenericCollection()
        {
            ICollection <KeyValuePair <string, object> > obj = new JsonObject();

            obj.Add(new KeyValuePair <string, object>("first", 123));
            Assert.IsFalse(obj.Contains(new KeyValuePair <string, object>("second", 123)));
        }
Example #3
0
 public void ContainsNonExistingViaGenericCollection()
 {
     ICollection<KeyValuePair<string, object>> obj = new JsonObject();
     obj.Add(new KeyValuePair<string, object>("first", 123));
     Assert.IsFalse(obj.Contains(new KeyValuePair<string, object>("second", 456)));
 }
Example #4
0
 /**
 * @param json
 * @return module id from the request, or null if not present
 * @throws JSONException
 */
 private static string getModuleId(JsonObject json)
 {
     if (json.Contains("moduleId"))
     {
         return json["moduleId"].ToString();
     }
     return null;
 }
Example #5
0
  /**
 * Parse the steps in the path into JSON Objects.
 */
  static JsonObject BuildHolder(JsonObject root, String[] steps, int currentStep)
  {
      if (currentStep > steps.Length - 2)
      {
          return root;
      }
      Match matcher = ARRAY_MATCH.Match(steps[currentStep]);
      if (matcher.Success)
      {
          // Handle as array
          String fieldName = matcher.Groups[1].Value;
          int index = int.Parse(matcher.Groups[2].Value);
          JsonArray newArrayStep;
          if (root.Contains(fieldName))
          {
              newArrayStep = root[fieldName] as JsonArray;
          }
          else
          {
              newArrayStep = new JsonArray();
              root.Put(fieldName, newArrayStep);
          }
          JsonObject newStep = new JsonObject();
          newArrayStep[index] = newStep;
          return BuildHolder(newStep, steps, ++currentStep);
      }
      else
      {
          JsonObject newStep;
          if (root.Contains(steps[currentStep]))
          {
              newStep = root[steps[currentStep]] as JsonObject;
          }
          else
          {
              newStep = new JsonObject();
              root.Put(steps[currentStep], newStep);
          }
          return BuildHolder(newStep, steps, ++currentStep);
      }
  }
Example #6
0
		/// <summary>
		///     Create an item from json code
		/// </summary>
		/// <param name="jsonObject">the json object to parse</param>
		public ServerListItem(JsonObject jsonObject)
		{
			if (jsonObject.Contains("name")) Name = jsonObject["name"].ToString();
			if (jsonObject.Contains("ip")) Ip = jsonObject["ip"].ToString();
			if (jsonObject.Contains("uuid")) Uuid = jsonObject["uuid"].ToString();
			if (jsonObject.Contains("level")) OpLevel = int.Parse(jsonObject["level"].ToString());
			if (jsonObject.Contains("created")) Created = jsonObject["created"].ToString();
			if (jsonObject.Contains("source")) Source = jsonObject["source"].ToString();
			if (jsonObject.Contains("expires")) Expires = jsonObject["expires"].ToString();
			if (jsonObject.Contains("reason")) Reason = jsonObject["reason"].ToString();
		}
Example #7
0
 public static string getArrayItem(JsonObject ob, string arrayname, int arrayind)
 {
     if (ob == null || !ob.Contains(arrayname)) return "";
     if (!(ob[arrayname] is JsonArray)) return "";
     JsonArray arr = (JsonArray)ob[arrayname];
     if (arr.Length < arrayind) return "";
     return Converter.toString(arr[arrayind]);
 }
Example #8
0
        private void dispatch(JsonObject request, HttpResponse servletResponse, ISecurityToken token)
        {
            String key = null;
            if (request.Contains("id"))
            {
                key = request["id"] as String;
            }
            RpcRequestItem requestItem = new RpcRequestItem(request, token, jsonConverter);

            // Resolve each Future into a response.
            // TODO: should use shared deadline across each request
            ResponseItem response = getResponseItem(HandleRequestItem(requestItem));
            Object result = getJsonResponse(key, response, requestItem);

            servletResponse.Output.Write(jsonConverter.ConvertToString(result));
        }
Example #9
0
  /**
   * Inspects the passed object for one of several specific properties and, if
   * found, returns that property as a JsonObject object. All valid response
   * objects which encapsulate a single data item (e.g. a person) must have
   * this property.
   * 
   * @param  root JsonObject to query for the presence of the specific property
   * @throws OpenSocialRequestException if property is not found _in the passed
   *         object
   * @throws JSONException
   */
  private static JsonObject getEntryObject(JsonObject root)
    {

    JsonObject entry = new JsonObject();

    if (root.Contains("data")) {
      entry = root.getJSONObject("data");
    } else if (root.Contains("entry")) {
      entry = root.getJSONObject("entry");
    } else {
      throw new OpenSocialRequestException("Entry not found");
    }

    return entry;
  }
Example #10
0
  /**
   * Inspects the passed object for one of several specific properties and, if
   * found, returns that property as a JsonArray object. All valid response
   * objects which contain a data collection (e.g. a collection of people)
   * must have this property.
   * 
   * @param  root JsonObject to query for the presence of the specific property
   * @throws OpenSocialRequestException if property is not found _in the passed
   *         object
   * @throws JSONException
   */
  private static JsonArray getEntryArray(JsonObject root)
    {

    JsonArray entry = new JsonArray();

    if (root.Contains("entry")) {
      entry = (JsonArray)root["entry"];
    } else if (root.Contains("data")) {
      entry = (JsonArray)root.getJSONObject("data")["list"];
    } else {
      throw new OpenSocialRequestException("Entry not found");
    }

    return entry;
  }