public async Task <bool> Login(string username, string password) { try { var token = await _client.LoginAsync(username, password); if (token == null) { return(false); } UniqueToken = token; return(true); } catch { IsConnected = false; _timer.Start(); } return(false); }
private async void buttonConnect_Click(object sender, RoutedEventArgs e) { if (isConnected) { return; } channel = new Channel(textHost.Text + ":" + PORT.ToString(), ChannelCredentials.Insecure); client = new MessengerClient(channel); var currentClientTimeStamp = GetClientTimeStamp(); var loginRequest = new Messenger.LoginRequest { UserName = texUsername.Text }; var reply = await client.LoginAsync(loginRequest); if (reply.Result.Result == Messenger.ResultReply.Types.Result.Failed) { return; } userId = reply.UserId; lastTimeStamp = reply.TimeStamp; timeStampOffset = lastTimeStamp - currentClientTimeStamp; refreshTimer = new System.Windows.Threading.DispatcherTimer(); refreshTimer.Tick += new EventHandler(refreshTimer_Tick); refreshTimer.Interval = new TimeSpan(0, 0, 1); refreshTimer.Start(); sendTimer = new System.Windows.Threading.DispatcherTimer(); sendTimer.Tick += new EventHandler(sendTimer_Tick); sendTimer.Interval = new TimeSpan(0, 0, 0, 0, 100); sendTimer.Start(); isConnected = true; }