/// <summary> /// Core implementation of processMethod. Retrieves a generic type. /// </summary> /// <typeparam name="T">Generic type that will return.</typeparam> /// <param name="clazz">Type of Class we are using.</param> /// <param name="resource">Resource we will use and return in the implementation.</param> /// <param name="methodName">The name of the method we are trying to call.</param> /// <param name="parameters">Parameters to use in the process.</param> /// <param name="useCache">Cache configuration.</param> /// <returns>Generic type object, containing information about retrieval process.</returns> protected static T ProcessMethod <T>(Type clazz, T resource, string methodName, Dictionary <string, string> parameters, bool useCache) where T : MPBase { if (resource == null) { try { resource = (T)Activator.CreateInstance(clazz); } catch (Exception ex) { throw new MPException(ex.Message); } } var clazzMethod = GetAnnotatedMethod(clazz, methodName); var restData = GetRestInformation(clazzMethod); HttpMethod httpMethod = (HttpMethod)restData["method"]; string path = ParsePath(restData["path"].ToString(), parameters, resource); PayloadType payloadType = (PayloadType)restData["payloadType"]; JObject payload = GeneratePayload(httpMethod, resource); int requestTimeout = (int)restData["requestTimeout"]; int retries = (int)restData["retries"]; WebHeaderCollection colHeaders = new WebHeaderCollection(); MPAPIResponse response = CallAPI(httpMethod, path, payloadType, payload, colHeaders, useCache, requestTimeout, retries); if (response.StatusCode >= 200 && response.StatusCode < 300) { if (httpMethod != HttpMethod.DELETE) { resource = (T)FillResourceWithResponseData(resource, response); resource._lastApiResponse = response; } else { resource = null; } } else if (response.StatusCode >= 400 && response.StatusCode < 500) { BadParamsError badParamsError = MPCoreUtils.GetBadParamsError(response.StringResponse); resource.Errors = badParamsError; } else { MPException webserverError = new MPException() { StatusCode = response.StatusCode, ErrorMessage = response.StringResponse }; webserverError.Cause.Add(response.JsonObjectResponse.ToString()); } return(resource); }
public static Ferda.Modules.BadParamsError BadParamsUnexpectedReasonError(Exception e, string boxIdentity) { Debug.WriteLine(e.Message); Ferda.Modules.BadParamsError ex = new BadParamsError(e); ex.boxIdentity = boxIdentity; ex.restrictionType = restrictionTypeEnum.UnexpectedReason; return ex; }
/// <summary> /// Gets BadParamsError exception. /// </summary> /// <param name="e">The inner exception.</param> /// <param name="boxIdentity">The box identity.</param> /// <param name="userMessage">The user message.</param> /// <param name="restrictionType">Type of the restriction.</param> /// <returns> /// The <see cref="T:Ferda.Modules.BadParamsError"/> exception. /// </returns> public static Ferda.Modules.BadParamsError BadParamsError(Exception e, string boxIdentity, string userMessage, restrictionTypeEnum restrictionType) { Debug.WriteLine(userMessage); Ferda.Modules.BadParamsError ex = new BadParamsError(e); ex.boxIdentity = boxIdentity; ex.userMessage = userMessage; ex.restrictionType = restrictionType; return ex; }
/// <summary> /// Static method that transforms JObject in to a resource. /// </summary> /// <returns>an object obteined from obj</returns> public static BadParamsError GetBadParamsError(string raw) { JObject jObj = JObject.Parse(raw); JsonSerializer serializer = new JsonSerializer { NullValueHandling = NullValueHandling.Ignore, ContractResolver = new CustomDeserializationContractResolver() }; BadParamsError badParams = (BadParamsError)jObj.ToObject <BadParamsError>(serializer); return(badParams); }
public void DelegateErrors(BadParamsError DelegatedErrors) { this._errors = DelegatedErrors; }
public void DelegateErrors(BadParamsError DelegatedErrors) { this._errors = new BadParamsError?(DelegatedErrors); }