public async Task <bool> UpdateAsync(T Value, params object[] Parameters) { bool result = false; string logParameters = ObjectHelper.ConvertArrayToString(Parameters); this.logger?.Log($"TypedBaseClient<{typeof(T)}>.UpdateAsync({logParameters}): entered"); string uriParameters = this.convertParameters(Parameters); HttpResponseMessage response = await this.httpClient.PutAsync(uriParameters, new StringContent(JsonConvert.SerializeObject(Value))); this.requestInfo.LastResponse = response; if (response.IsSuccessStatusCode) { result = true; } else { if (response.StatusCode != System.Net.HttpStatusCode.NotFound) { this.logger?.Log($"TypedBaseClient<{typeof(T)}>.UpdateAsync({logParameters}): error in request response '{response.StatusCode}: {response.ReasonPhrase}'", Contracts.Logger.Enums.LogLevel.Error); } else { result = false; //not found - this is ok with head } } this.logger?.Log($"TypedBaseClient<{typeof(T)}>.UpdateAsync({logParameters}): exited with result '{result}'"); return(result); }
public async Task <T> GetAsync(params object[] Parameters) { T result = default; string logParameters = ObjectHelper.ConvertArrayToString(Parameters); this.logger?.Log($"TypedBaseClient<{typeof(T)}>.GetAsync({logParameters}): entered"); string uriParameters = this.convertParameters(Parameters); HttpResponseMessage response = await this.httpClient.GetAsync(uriParameters); this.requestInfo.LastResponse = response; if (response.IsSuccessStatusCode) { string json = response.Content.ReadAsStringAsync().Result; this.requestInfo.LastContent = json; SimpleResult <T> requestResult = JsonConvert.DeserializeObject <SimpleResult <T> >(json); this.requestInfo.LastResult = requestResult; if (!requestResult.IsError) { result = requestResult.Payload; } else { this.logger?.Log($"TypedBaseClient<{typeof(T)}>.GetAsync({logParameters}): error in request result '{requestResult.Error.Id}: {requestResult.Error.Message}, {requestResult.Error.Ex}'"); } } else { this.logger?.Log($"TypedBaseClient<{typeof(T)}>.GetAsync({logParameters}): error in request response '{response.StatusCode}: {response.ReasonPhrase}'"); } this.logger?.Log($"TypedBaseClient<{typeof(T)}>.GetAsync({logParameters}): exited with result '{result}'"); return(result); }
public async Task <bool> DeleteAsync(params object[] Parameters) { bool result = false; string logParameters = ObjectHelper.ConvertArrayToString(Parameters); this.logger?.Log($"TypedBaseClient<{typeof(T)}>.DeleteAsync({logParameters}): entered"); string uriParameters = this.convertParameters(Parameters); HttpRequestMessage request = new HttpRequestMessage(HttpMethod.Delete, uriParameters); HttpResponseMessage response = await this.httpClient.SendAsync(request); this.requestInfo.LastResponse = response; if (response.IsSuccessStatusCode) { result = true; } else { if (response.StatusCode != System.Net.HttpStatusCode.NotFound) { this.logger?.Log($"TypedBaseClient<{typeof(T)}>.DeleteAsync({logParameters}): error in request response '{response.StatusCode}: {response.ReasonPhrase}'", Contracts.Logger.Enums.LogLevel.Error); } else { result = false; //not found - this is ok with delete } } this.logger?.Log($"TypedBaseClient<{typeof(T)}>.DeleteAsync({logParameters}): exited with result '{result}'"); return(result); }