/// <summary> /// Requests a new account registration from the account server. /// </summary> /// <param name="username">The username to register</param> /// <param name="password">The password to register</param> public void RegisterAccount(Account.AccountRegistrationRequestModel requestModel) { if (_connection.BeginRegisterAccount(requestModel) != BeginRequestStatusCode.Ok) { MessageBox.Show("There was an error processing your request; please try again later."); } }
/// <summary> /// Starts the registration procedure with the account with the account server. /// /// When the response (if any) is received, the listeners associated with OnRegisterAccountResponse will be notified. /// </summary> /// <param name="requestModel">Data model for the registration request</param> /// <returns>true if successfully started; false otherwise</returns> public BeginRequestStatusCode BeginRegisterAccount(Account.AccountRegistrationRequestModel requestModel) { if (requestModel == null) { throw new ArgumentNullException("requestModel"); } // Create the registration form requestModel.PasswordHash = CalculateHashFor(requestModel.PasswordHash); string jsonModel = JsonConvert.SerializeObject(requestModel); byte[] contentBody = Encoding.UTF8.GetBytes(jsonModel); // Create the request var request = (HttpWebRequest)WebRequest.Create(RegisterUrl); request.Method = "PUT"; request.ContentType = "application/json"; request.ContentLength = contentBody.Length; try { var stream = request.GetRequestStream(); stream.Write(contentBody, 0, contentBody.Length); } catch (WebException) { return(BeginRequestStatusCode.Error); } // Off it goes! try { request.BeginGetResponse(AsyncRegisterAccountResponse, request); } catch (Exception) { return(BeginRequestStatusCode.Error); } return(BeginRequestStatusCode.Ok); }