protected byte[] Serialize <T>([NotNull] T obj) { return(httpSerializer.Serialize(obj)); }
protected byte[] Serialize <T>([NotNull] T obj) where T : class { return(httpSerializer.Serialize(obj)); }
public void Function1_POST(User body, Guid ID, String AuthKey, Action <string> OKCallback = null, Action <string> BadRequestCallback = null, Action <HttpResponseMessage> ResponseCallback = null, Action <FlurlHttpException> ExceptionCallback = null, Action <HttpResponseMessage> UnauthorizedCallback = null, IDictionary <String, Object> headers = null, IEnumerable <Cookie> cookies = null, TimeSpan?timeout = null, CancellationToken cancellationToken = default) { string url = $@"/api/helloMe"; HttpResponseMessage response = null; response = HttpOverride.GetResponseAsync(HttpMethod.Post, url, null, cancellationToken).ConfigureAwait(false).GetAwaiter().GetResult(); bool responseHandled = response != null; if (response == null) { try { response = Client.ClientWrapper.Request(url).WithCookies(cookies).WithHeaders(headers).WithTimeout(timeout ?? Client.Timeout).WithFunctionAuthorizationKey(AuthKey).WithHeader("ID", ID).AllowAnyHttpStatus().PostAsync(Serializer.Serialize(body), cancellationToken).ConfigureAwait(false).GetAwaiter().GetResult(); } catch (FlurlHttpException fhex) { if (ExceptionCallback != null && ExceptionCallback.Method.IsDefined(typeof(AsyncStateMachineAttribute), true)) { throw new NotSupportedException("Async void action delegates for ExceptionCallback are not supported.As they will run out of the scope of this call."); } if (ExceptionCallback != null) { responseHandled = true; ExceptionCallback?.Invoke(fhex); } else { throw fhex; } return; } HttpOverride.OnNonOverridedResponseAsync(HttpMethod.Post, url, body, response, cancellationToken).ConfigureAwait(false).GetAwaiter().GetResult(); } if (OKCallback != null && OKCallback.Method.IsDefined(typeof(AsyncStateMachineAttribute), true)) { throw new NotSupportedException("Async void action delegates for OKCallback are not supported.As they will run out of the scope of this call."); } if (response.StatusCode == System.Net.HttpStatusCode.OK) { if (OKCallback != null) { responseHandled = true; OKCallback.Invoke(Serializer.Deserialize <string>(response.Content).ConfigureAwait(false).GetAwaiter().GetResult()); } } if (BadRequestCallback != null && BadRequestCallback.Method.IsDefined(typeof(AsyncStateMachineAttribute), true)) { throw new NotSupportedException("Async void action delegates for BadRequestCallback are not supported.As they will run out of the scope of this call."); } if (response.StatusCode == System.Net.HttpStatusCode.BadRequest) { if (BadRequestCallback != null) { responseHandled = true; BadRequestCallback.Invoke(Serializer.Deserialize <string>(response.Content).ConfigureAwait(false).GetAwaiter().GetResult()); } } if (ResponseCallback != null && ResponseCallback.Method.IsDefined(typeof(AsyncStateMachineAttribute), true)) { throw new NotSupportedException("Async void action delegates for ResponseCallback are not supported.As they will run out of the scope of this call."); } if (ResponseCallback != null) { responseHandled = true; ResponseCallback.Invoke(response); } if (UnauthorizedCallback != null && UnauthorizedCallback.Method.IsDefined(typeof(AsyncStateMachineAttribute), true)) { throw new NotSupportedException("Async void action delegates for UnauthorizedCallback are not supported.As they will run out of the scope of this call."); } if (response.StatusCode == System.Net.HttpStatusCode.Unauthorized) { if (UnauthorizedCallback != null) { responseHandled = true; UnauthorizedCallback.Invoke(Serializer.Deserialize <HttpResponseMessage>(response.Content).ConfigureAwait(false).GetAwaiter().GetResult()); } } if (!responseHandled) { throw new System.InvalidOperationException($"Response Status of {response.StatusCode} was not handled properly."); } return; }