private bool CheckInDb(IRegisterServiceJugador jugador) { bool result = false; RegisterServiceClient register; register = new RegisterServiceClient(new NetTcpBinding(SecurityMode.None), new EndpointAddress("net.tcp://" + CurrentPlayer.IPDirection + ":8091/RegisterServices")); IRegisterServiceJugador player = jugador; switch (register.SerachUserInDB(player)) { case DBOperationResultAddResult.Success: result = true; break; case DBOperationResultAddResult.ExistingRecord: Debug.Log("entra aquí"); throw new DuplicateRecordException(); case DBOperationResultAddResult.SQLError: Debug.Log("sql error"); throw new TimeoutException(); case DBOperationResultAddResult.NullObject: throw new SocketException(); } return(result); }
private void button2_Click(object sender, EventArgs e) { if (string.IsNullOrWhiteSpace(this.loginBox.Text) || string.IsNullOrWhiteSpace(this.passwordBox.Text)) { MessageBox.Show("Error : Login and password should not be empty."); return; } try { using (RegisterServiceClient svc = new RegisterServiceClient()) { svc.InnerChannel.OperationTimeout = TimeSpan.FromSeconds(_PrefferedTimeoutSec); if (svc.Register(_MD5Calc.GetHash(this.loginBox.Text, this.passwordBox.Text))) { MessageBox.Show("Учетная запись зарегистрирована"); } else { MessageBox.Show("Ошибка : Данная учетная запись уже зарегистрирована."); } } } catch (Exception ex) { MessageBox.Show("Ошибка регистрации : сбой на сервере"); MessageBox.Show(ex.StackTrace, string.Format("Exception {0} ", ex.Message)); } }
public Task RegisterPlayer() { System.Random generator = new System.Random(); UtilitiesHash utilitiesHash = new UtilitiesHash(); RegisterServiceClient register; register = new RegisterServiceClient(new NetTcpBinding(SecurityMode.None), new EndpointAddress("net.tcp://" + CurrentPlayer.IPDirection + ":8091/RegisterServices")); IRegisterServiceJugador player = new IRegisterServiceJugador(); player.Correo = Email_InputField.text; player.Nombre = Name_InputField.text; player.Username = User_InputField.text; player.Password = utilitiesHash.PassHash(Password_InputField.text); player.Código = generator.Next(0, 999999).ToString("D6"); try { if (CheckInDb(player)) { switch (register.AddUser(player)) { case DBOperationResultAddResult.Success: SendEmail(player); break; case DBOperationResultAddResult.SQLError: throw new TimeoutException(); case DBOperationResultAddResult.NullObject: throw new SocketException(); } } } catch (SocketException) { throw new SocketException(); } catch (TimeoutException) { throw new TimeoutException(); } catch (DuplicateRecordException) { throw new DuplicateRecordException(); } CurrentPlayer.Username = player.Username; CurrentPlayer.Email = player.Correo; CurrentPlayer.Código = player.Código; return(Task.CompletedTask); }
private void register() { try { NewUser user = new NewUser(); user.Email = Email; user.Password = Password; user.ConfirmPassword = PasswordCheck; RegisterServiceClient rsc = new RegisterServiceClient(); rsc.RegisterUserAsync(user); rsc.RegisterUserCompleted += new EventHandler <RegisterUserCompletedEventArgs>(rsc_RegisterUserCompleted); } catch (Exception e) { Debug.WriteLine(e.Message); } }
private void OnRegister(object obj) { IsBusy = true; IsShowInfo = false; var asd = Application.Current.Dispatcher; RegisterServiceClient client = new RegisterServiceClient(); User.Image = CutForSquare(new Bitmap(Image.StreamSource), 256, 100); User.Password = HashHelper.ComputeStringMd5(Password); Task <RegError> task = client.RegisterAsync(User); task.ContinueWith(T => { switch (T.Result) { case RegError.NoError: IsShowHint = true; IsShowInfo = false; IsBusy = false; Thread.Sleep(3000); Application.Current.Dispatcher.Invoke(new Action(() => OnClose(null))); break; case RegError.UserExist: ErrorInfo = "该用户已存在"; RegisterFailed(); break; case RegError.Ohter: ErrorInfo = "注册失败,发生未知错误"; RegisterFailed(); break; default: break; } IsBusy = false; client.Close(); }); }