Example #1
0
 /// <summary>
 /// Raises the <see cref="StartPageLogic.NewResponse"/> event.
 /// </summary>
 /// <param name="response">The response to be included in the event data.</param>
 private void RaiseNewResponseEvent(AuthResponse response)
 {
     if (NewResponse != null)
     {
         NewResponse(this, new AuthResponseEventArgs(response));
     }
 }
Example #2
0
        /// <summary>
        /// Sends an authorization request to the server.
        /// </summary>
        /// <param name="request">The request to send.</param>
        /// <returns><see cref="Task"/></returns>
        private async Task SendAuthRequestAsync(IRequest request)
        {
            try
            {
                var content = new HttpStringContent(request.Serialize());

                content.Headers["Content-Type"] = "application/json";

                var httpResponse = await _httpClient.PostAsync(new Uri(ServerUrl, UriKind.Absolute), content);
                var response = new AuthResponse() { StatusCode = httpResponse.StatusCode };
                var buffer = await httpResponse.Content.ReadAsBufferAsync();
                var bytes = buffer.ToArray();

                response.Deserialize(Encoding.UTF8.GetString(bytes, 0, bytes.Length));
                RaiseNewResponseEvent(response);
            }
            catch
            {
                var response = new AuthResponse { StatusCode = HttpStatusCode.InternalServerError };

                RaiseNewResponseEvent(response);
            }
        }