Example #1
0
        private Object getErrorJson(ResponseItem responseItem)
        {
            Dictionary<String, Object> error = new Dictionary<String, Object>();
            error.Add("code", responseItem.getErrorCode());

            String message = errorTitles[responseItem.getErrorCode()];
            if (message == null)
            {
                message = responseItem.getErrorMessage();
            }
            else
            {
                if (!string.IsNullOrEmpty(responseItem.getErrorMessage()))
                {
                    message += ": " + responseItem.getErrorMessage();
                }
            }

            if (!string.IsNullOrEmpty(message))
            {
                error.Add("message", message);
            }

            if (responseItem.getResponse() != null)
            {
                error.Add("data", responseItem.getResponse());
            }

            return error;
        }
Example #2
0
 Object getJsonResponse(String key, ResponseItem responseItem, RpcRequestItem requestItem)
 {
     var result = new Dictionary<string, object>();
     if (key != null)
     {
         result.Add("id", key);
     }
     if (responseItem.getErrorCode() < 200 ||
             responseItem.getErrorCode() >= 400)
     {
         result.Add("error", getErrorJson(responseItem));
     }
     else
     {
         Object response = responseItem.getResponse();
         if (response != null &&
             response is DataCollection)
         {
             result.Add("data", ((DataCollection)response).entry);
         }
         else if (response != null && (response is IRestfulCollection))
         {
             var map = new Dictionary<string, object>();
             var collection = (IRestfulCollection)response;
             map.Add("startIndex", collection.startIndex);
             map.Add("totalResults", collection.totalResults);
             if (requestItem != null && requestItem.getCount() != null)
             {
                 map.Add("itemsPerPage", requestItem.getCount());
             }
             map.Add("list", collection.getEntry());
             result.Add("data", map);
         }
         else
         {
             result.Add("data", response);
         }
         
     }
     return result;
 }