/// <summary>登录</summary> /// <returns></returns> public async Task <Object> Login() { XTrace.WriteLine("登录:{0}", Code); var info = GetLoginInfo(); // 登录前清空令牌,避免服务端使用上一次信息 Token = null; Logined = false; Info = null; var rs = Info = await LoginAsync(info); if (rs != null && !rs.Code.IsNullOrEmpty()) { XTrace.WriteLine("下发证书:{0}/{1}", rs.Code, rs.Secret); Code = rs.Code; Secret = rs.Secret; } // 登录后设置用于用户认证的token Token = rs.Token; Logined = true; OnLogined?.Invoke(this, EventArgs.Empty); StartTimer(); return(rs); }
private void onlogin(object sender) { OnLogined logined = delegate() { try { client.Show(); //this.Close(); this.Hide(); } catch (Exception we) { string msg = we.Message; } }; try { if (this.InvokeRequired) { this.Invoke(logined); } else { logined(); } } catch (Exception ignore) { string msg = ignore.Message; } }
private void Logined() { if (OnLogined != null) { var delegates = OnLogined.GetInvocationList(); foreach (Delegate d in delegates) { Action <IUser> act = d as Action <IUser>; act?.Invoke(this.User); } } }
/// <summary>登录</summary> /// <returns></returns> public async Task <Object> Login() { XTrace.WriteLine("登录:{0}", Code); var info = GetLoginInfo(); // 登录前清空令牌,避免服务端使用上一次信息 Token = null; Logined = false; Info = null; var rs = Info = await LoginAsync(info); if (rs != null && !rs.Code.IsNullOrEmpty()) { XTrace.WriteLine("下发证书:{0}/{1}", rs.Code, rs.Secret); Code = rs.Code; Secret = rs.Secret; } // 登录后设置用于用户认证的token Token = rs.Token; Logined = true; OnLogined?.Invoke(this, EventArgs.Empty); if (Logined && _timer == null) { lock (this) { if (_timer == null) { _timer = new TimerX(s => Ping().Wait(), null, 5_000, 60_000, "Device") { Async = true }; #if DEBUG _timer.Period = 5_000; _timer.Scheduler.Log = XTrace.Log; #endif } } } return(rs); }
private async Task <Object> OnLoginAsync() { var args = OnPreLogin(); // 登录前清空密钥 if (Logined) { Key = null; } var rs = await OnLogin(args); // 注册成功则保存 var dic = rs.ToDictionary(); if (Password.IsNullOrEmpty() && dic.ContainsKey("pass")) { UserName = dic["user"] + ""; Password = dic["pass"] + ""; WriteLog("注册成功!{0}/{1}", UserName, Password); } else { WriteLog("登录成功!"); } // 从响应中解析通信密钥 if (Encrypted) { //var dic = rs.ToDictionary(); //!!! 使用密码解密通信密钥 Key = (dic["Key"] + "").ToHex().RC4(Password.GetBytes()); WriteLog("密匙:{0}", Key.ToHex()); } Logined = true; OnLogined?.Invoke(this, new EventArgs <Object>(rs)); // 尽快开始一次心跳 Timer?.SetNext(1000); return(rs); }