Esempio n. 1
0
        protected static List<T> FillArrayWithResponseData<T>(Type clazz, MPAPIResponse response) where T : MPBase
        {
            List<T> resourceArray = new List<T>();
            if (response.JsonObjectResponse != null)
            {
                JArray jsonArray = MPCoreUtils.GetArrayFromJsonElement<T>(response.JsonObjectResponse); 

                if (jsonArray != null)
                {
                    for (int i = 0; i < jsonArray.Count(); i++)
                    {
                        T resource = (T)MPCoreUtils.GetResourceFromJson<T>(clazz, (JObject)jsonArray[i]);

                        resource.DumpLog();

                        resource._lastKnownJson = MPCoreUtils.GetJsonFromResource(resource);
                        resourceArray.Add(resource);
                    }
                }
            } else {
                JArray jsonArray = MPCoreUtils.GetJArrayFromStringResponse<T>(response.StringResponse);
                if (jsonArray != null)
                {
                    for (int i = 0; i < jsonArray.Count(); i++)
                    {
                        T resource = (T)MPCoreUtils.GetResourceFromJson<T>(clazz, (JObject)jsonArray[i]);
                        resource._lastKnownJson = MPCoreUtils.GetJsonFromResource(resource);
                        resourceArray.Add(resource);
                    }
                }
            }
            return resourceArray;
        }
Esempio n. 2
0
        protected static List <T> FillArrayWithResponseData <T>(Type clazz, MPAPIResponse response) where T : MPBase
        {
            List <T> objList = new List <T>();

            if (response.JsonObjectResponse != null)
            {
                JArray arrayFromJsonElement = MPCoreUtils.GetArrayFromJsonElement <T>(response.JsonObjectResponse);
                if (arrayFromJsonElement != null)
                {
                    for (int index = 0; index < arrayFromJsonElement.Count <JToken>(); ++index)
                    {
                        T resourceFromJson = (T)MPCoreUtils.GetResourceFromJson <T>(clazz, (JObject)arrayFromJsonElement[index]);
                        //resourceFromJson.DumpLog();
                        resourceFromJson._lastKnownJson = MPCoreUtils.GetJsonFromResource <T>(resourceFromJson);
                        objList.Add(resourceFromJson);
                    }
                }
            }
            else
            {
                JArray fromStringResponse = MPCoreUtils.GetJArrayFromStringResponse <T>(response.StringResponse);
                if (fromStringResponse != null)
                {
                    for (int index = 0; index < fromStringResponse.Count <JToken>(); ++index)
                    {
                        T resourceFromJson = (T)MPCoreUtils.GetResourceFromJson <T>(clazz, (JObject)fromStringResponse[index]);
                        resourceFromJson._lastKnownJson = MPCoreUtils.GetJsonFromResource <T>(resourceFromJson);
                        objList.Add(resourceFromJson);
                    }
                }
            }
            return(objList);
        }
Esempio n. 3
0
 protected static MPBase FillResourceWithResponseData <T>(
     T resource,
     MPAPIResponse response)
     where T : MPBase
 {
     if (response.JsonObjectResponse != null && response.JsonObjectResponse != null)
     {
         JObject jsonObjectResponse = response.JsonObjectResponse;
         resource = (T)MPBase.FillResource <T>((T)MPCoreUtils.GetResourceFromJson <T>(resource.GetType(), jsonObjectResponse), resource);
         resource._lastKnownJson = MPCoreUtils.GetJsonFromResource <T>(resource);
     }
     return((MPBase)resource);
 }
Esempio n. 4
0
        /// <summary>
        /// Fills all the attributes members of the Resource obj.
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="resource"></param>
        /// <param name="response"></param>
        /// <returns></returns>
        protected static MPBase FillResourceWithResponseData<T>(T resource, MPAPIResponse response) where T : MPBase
        {
            if (response.JsonObjectResponse != null &&
                    response.JsonObjectResponse is JObject)
            {
                JObject jsonObject = null;

                jsonObject = (JObject)response.JsonObjectResponse;
                T resourceObject = (T)MPCoreUtils.GetResourceFromJson<T>(resource.GetType(), jsonObject);
                resource = (T)FillResource(resourceObject, resource);
                resource._lastKnownJson = MPCoreUtils.GetJsonFromResource(resource);
            }

            return resource;
        }