public void Login() { new Task(() => Loading()).Start(); MessengerClient messengerClient = new MessengerClient(); string login = "", password = ""; Dispatcher.Invoke(() => password = tbPassword.Password); Dispatcher.Invoke(() => login = tbLogin.Text); AccountDTO account = messengerClient.Login(login, password); if (account != null) { MainWindow mainWindow = null; Dispatcher.Invoke(() => mainWindow = new MainWindow(account)); Dispatcher.Invoke(() => mainWindow.Show()); } else { Dispatcher.Invoke(() => { tbPassword.Password = ""; tbPassword.Foreground = Brushes.Red; MaterialDesignThemes.Wpf.HintAssist.SetHelperText(tbPassword, "Incorrect login or password"); }); } timer.Stop(); Dispatcher.Invoke(() => { pnlLoading.Visibility = Visibility.Hidden; tbLoading.Visibility = Visibility.Hidden; // this.Hide(); }); }
public void Login() { MessengerClient messengerClient = new MessengerClient(); string login = "", password = "", email = " ", name = ""; byte[] img = null; Dispatcher.Invoke(() => { password = Account.Password; login = Account.Login; email = Account.Email; name = Account.Name; img = Account.Image; }); messengerClient.Registrate(email, login, password, name, img); AccountDTO account = messengerClient.Login(login, password); MainWindow mainWindow = null; Dispatcher.Invoke(() => mainWindow = new MainWindow(account)); Dispatcher.Invoke(() => mainWindow.Show()); this.Hide(); }
/* private MessengerClient CreateClient() { string key0 = ConfigurationManager.AppSettings["Key0"]; System.ServiceModel.BasicHttpBinding binding = new BasicHttpBinding(BasicHttpSecurityMode.None); EndpointAddress ep = new EndpointAddress("http://localhost:55560/MessengerService.svc"); //EndpointAddress ep = new EndpointAddress("http://li4shi2.azurewebsites.net/MessengerService.svc"); return new MessengerClient(binding, ep); } */ private void Form1_Load(object sender, EventArgs e) { try { //mClient = CreateClient(); //mClient = new MessengerClient(); //mClient = new MessengerClient(new System.ServiceModel.WSHttpBinding(System.ServiceModel.SecurityMode.None), new EndpointAddress("http://192.168.98.129:8000/Messenger")); mClient = new MessengerClient(new System.ServiceModel.WSHttpBinding(System.ServiceModel.SecurityMode.None), new EndpointAddress("http://localhost:8000/Messenger")); // get ip address string ipaddr = string.Empty; IPHostEntry host; host = Dns.GetHostEntry(Dns.GetHostName()); foreach (IPAddress ip in host.AddressList) { if (ip.AddressFamily == System.Net.Sockets.AddressFamily.InterNetwork) { ipaddr = ip.ToString(); break; } } //mUserId = DateTime.Now.ToString("hhmmss"); mUserId = System.Environment.MachineName + "-" + System.Diagnostics.Process.GetCurrentProcess().Id; if (mClient.Login(mUserId) == false) { MessageBox.Show("Login failed."); Application.ExitThread(); return; } this.Text = mUserId; string list = mClient.GetMemberList(); updateMemberList(list); receiveMemberCompletedHandler = new EventHandler<ReceiveMemberListCompletedEventArgs>(OnReceiveMemberListCompleted); mClient.ReceiveMemberListCompleted += receiveMemberCompletedHandler; mClient.ReceiveMemberListAsync(mUserId); receiveConnectionCompletedHandler = new EventHandler<ReceiveConnectionCompletedEventArgs>(OnReceiveConnectionCompleted); mClient.ReceiveConnectionCompleted += receiveConnectionCompletedHandler; mClient.ReceiveConnectionAsync(mUserId); } catch (Exception ex) { MessageBox.Show(ex.Message); Application.ExitThread(); } }