public void Login() { try { var wc = new WebClient() { Credentials = Credentials }; string response = wc.DownloadString(API_URL + API_AUTH_URL); AccessToken = JObject.Parse(response)["token"].ToString(); OnUserLoginSuccess?.Invoke(this, new CnCNetEventUserLoginSuccess(response)); } catch (WebException ex) { try { OnUserLoginError?.Invoke(this, new CnCNetEventUserLoginError("Invalid username or password", ((HttpWebResponse)ex.Response).StatusCode)); } catch (Exception exx) { OnFatalError?.Invoke(this, new CnCNetEventFatalError(HttpStatusCode.BadGateway)); } } }
/// <summary> /// 在发生登录错误或其他登录事件时调用 /// </summary> private void MyRdp_OnLogonError(object sender, IMsTscAxEvents_OnLogonErrorEvent e) { string discReason = $"未知错误,错误代码{e.lError}。";; if (e.lError == (int)LogonError.ACCESSDENIED) { discReason = "用户拒绝访问。"; } if (e.lError == (int)LogonError.ERRORUSERPASSWRD) { discReason = "用户名和密码不匹配。"; } if (e.lError == (int)LogonError.LOCKUSER) { discReason = "用户被锁定。"; } if (e.lError == (int)LogonError.PASSWORDEXPIRED) { discReason = "密码已过期。"; } if (e.lError == (int)LogonError.OTHER) { discReason = $"其他错误:错误代码{e.lError}。"; } OnFatalError?.Invoke("登入错误", discReason); }
public static void NotifyOnError(string errorMessage) { var args = new FatalErrorEventArgs() { ErrorMessage = errorMessage }; OnFatalError?.Invoke(null, args); }
public override void Connect(DbItemRemoteLink linkSettings, FinalItemSetting finalItemSetting) { string[] values = linkSettings.Server.Split(':'); if (values.Length > 2) { throw new Exception($"服务器地址不正确。"); //地址不正确 } string server = values[0]; string port = values.Length == 2 ? $"-P {values[1]}" : "-P 23"; FinalItemSetting_telnet finalSetting = (FinalItemSetting_telnet)finalItemSetting; IntPtr parentHwnd = FormsControl.Handle; Window windows = Window.GetWindow(this); int width = (int)windows.Width - 4; int height = (int)windows.Height - 34; Task.Run(() => { Putty.Settings settings = new Putty.Settings { fontname = finalSetting.FontName, fontsize = finalSetting.FontSize, curtype = finalSetting.Cursor - 1, linecodepage = Encoding.GetEncoding(finalSetting.Character).BodyName, backspaceisdelete = finalSetting.Fallbackkeys - 1, mouseisxterm = finalSetting.MouseAction - 1, puttycolor = new Putty.PuttyColor(finalSetting.GetPuttyColor()), rxvthomeend = finalSetting.HomeAndEnd - 1, functionkeys = finalSetting.FnAndKeypad - 1, cjkambigwide = finalSetting.CJKAmbigWide.Value, capslockcyr = finalSetting.CapsLockCyr.Value, crimplieslf = finalSetting.CRImpliesLF.Value, lfimpliescr = finalSetting.LFImpliesCR.Value, }; string user = string.IsNullOrEmpty(linkSettings.UserName) ? "" : $"-l {linkSettings.UserName}"; string pw = string.IsNullOrEmpty(linkSettings.Password) ? "" : $"-pw {linkSettings.Password}"; if (!_putty.Create(parentHwnd, $"-telnet {port} {user} {pw} {server}", 0, 0, width, height, settings)) { string errorText = Marshal.PtrToStringAnsi(_putty.GetError()); Dispatcher.Invoke(() => { OnFatalError?.Invoke("错误", errorText); }); } _putty.Dispose(); _putty = null; GC.Collect(); GC.SuppressFinalize(this); }); }
private void Error_Event(int level, IntPtr title, IntPtr text, int lParam) { Dispatcher.Invoke(() => { if (level == ERROR_FATAL) { OnFatalError?.Invoke(Marshal.PtrToStringAnsi(title), Marshal.PtrToStringAnsi(text)); } if (level == ERROR_NOTIC) { OnNonfatal?.Invoke(Marshal.PtrToStringAnsi(title), Marshal.PtrToStringAnsi(text)); } }); }
/// <summary> /// rdp控件遇到致命错误 /// </summary> private void MyRdp_OnFatalError(object sender, IMsTscAxEvents_OnFatalErrorEvent e) { string errorText = $"未知错误,错误代码{e.errorCode}。"; if (e.errorCode == 0) { errorText = "出现未知错误。"; } if (e.errorCode == 1) { errorText = "内部错误代码1。"; } if (e.errorCode == 2) { errorText = "发生了内存不足错误。"; } if (e.errorCode == 3) { errorText = "发生了窗口创建错误。"; } if (e.errorCode == 4) { errorText = "内部错误代码2。"; } if (e.errorCode == 5) { errorText = "内部错误代码3.这不是有效状态。"; } if (e.errorCode == 6) { errorText = "内部错误代码4。"; } if (e.errorCode == 7) { errorText = "客户端连接期间发生了不可恢复的错误。"; } if (e.errorCode == 100) { errorText = "Winsock初始化错误。"; } OnFatalError?.Invoke("错误", errorText); }
private void OnFatalError(string description, string more) { //Uh oh. Shut down everything. try { session.EndSession(); } catch { } status = EmulatorStatus.Crashed; //Tell the clients something went wrong. OnFatalError e = new OnFatalError { error_text = description, error_text_more = more }; SendData(e, WebReplyType.OnFatalError); }
public void GetUsernames() { try { var wc = new WebClient(); wc.Headers.Add("Authorization", "Bearer:" + AccessToken); string response = wc.DownloadString(API_URL + API_ACCOUNT_URL); OnUsernamesSuccess?.Invoke(this, new CnCNetEventUsernamesSuccess(response)); } catch (WebException ex) { try { OnUserLoginError?.Invoke(this, new CnCNetEventUserLoginError(ex.Message, ((HttpWebResponse)ex.Response).StatusCode)); } catch (Exception exx) { OnFatalError?.Invoke(this, new CnCNetEventFatalError(HttpStatusCode.BadGateway)); } } }
public void AddUser(string username) { try { var wc = new WebClient(); wc.Headers.Add("Authorization", "Bearer:" + AccessToken); string response = wc.UploadString(API_URL + "/player/" + username, "POST"); OnCreateUsernameSuccess?.Invoke(this, new CnCNetEventCreateUserSuccess(response)); } catch (WebException ex) { try { OnCreateUsernameError?.Invoke(this, new CnCNetEventCreateUserError("This username already exists", ((HttpWebResponse)ex.Response).StatusCode)); } catch (Exception exx) { OnFatalError?.Invoke(this, new CnCNetEventFatalError(HttpStatusCode.BadGateway)); } } }
/// <summary> /// 远程桌面断开连接 /// </summary> private void MyRdp_OnDisconnected(object sender, IMsTscAxEvents_OnDisconnectedEvent e) { if (e.discReason == 0x001) { MyRdp_OnRequestLeaveFullScreen(null, null); Closed?.Invoke(); return; } string discReason = $"未知错误,错误代码{e.discReason}。"; if (e.discReason == 0x904) { discReason = $"网络连接被关闭,错误代码{e.discReason}。"; } else if (e.discReason == 0x3) { discReason = $"远程桌面服务会话已结束。\n\n另一用户已连接到此远程计算机,因此你的连接已丢失,请尝试再次连接。"; } else if (e.discReason == 0x108) { discReason = $"连接超时,错误代码{e.discReason}。"; } else if (e.discReason == 0x104) { discReason = $"DNS名称查找失败,错误代码{e.discReason}。"; } else if (e.discReason == 0x508) { discReason = $"DNS查找失败,错误代码{e.discReason}。"; } else if (e.discReason == 0x208) { discReason = $"主机未找到错误,错误代码{e.discReason}。"; } else if (e.discReason == 0x408) { discReason = $"内部错误,错误代码{e.discReason}。"; } else if (e.discReason == 0x906 || e.discReason == 0xA06) { discReason = $"内部安全错误,错误代码{e.discReason}。"; } else if (e.discReason == 0x804) { discReason = $"指定了错误的IP地址,错误代码{e.discReason}。"; } else if (e.discReason == 0x308) { discReason = $"指定的IP地址无效,错误代码{e.discReason}。"; } else if (e.discReason == 0x106 || e.discReason == 0x206 || e.discReason == 0x306) { discReason = $"内存不足,错误代码{e.discReason}。"; } else if (e.discReason == 0x2) { discReason = $"用户远程断开连接,错误代码{e.discReason}。"; } else if (e.discReason == 0x204) { discReason = $"网络连接失败,错误代码{e.discReason}。"; } OnFatalError?.Invoke("断开连接", discReason); }
protected void fireOnFatalError(FatalErrorCodeEnum code) { OnFatalError?.Invoke(this, code); }
public override void Connect(DbItemRemoteLink linkSettings, DbItemSetting lastSetting) { DbItemSettingSsh lastSettingSsh = lastSetting as DbItemSettingSsh; if (lastSettingSsh == null) { return; } string[] values = linkSettings.Server.Split(':'); if (values.Length > 2) { throw new Exception($"服务器地址不正确。"); //地址不正确 } string server = values[0]; string port = values.Length == 2 ? $"-P {values[1]}" : "-P 22"; IntPtr parentHwnd = FormsControl.Handle; Window windows = Window.GetWindow(this); int width = (int)windows.Width - 4; int height = (int)windows.Height - 34; Thread thread = new Thread(() => { Putty.Settings settings = new Putty.Settings { fontname = lastSettingSsh.FontName, fontsize = lastSettingSsh.FontSize, curtype = lastSettingSsh.Cursor - 1, linecodepage = Encoding.GetEncoding(lastSettingSsh.Character).BodyName, backspaceisdelete = lastSettingSsh.Fallbackkeys - 1, mouseisxterm = lastSettingSsh.MouseAction - 1, puttycolor = new Putty.PuttyColor(lastSettingSsh.GetPuttyColor()), rxvthomeend = lastSettingSsh.HomeAndEnd - 1, functionkeys = lastSettingSsh.FnAndKeypad - 1, cjkambigwide = lastSettingSsh.CJKAmbigWide.Value, capslockcyr = lastSettingSsh.CapsLockCyr.Value, crimplieslf = lastSettingSsh.CRImpliesLF.Value, lfimpliescr = lastSettingSsh.LFImpliesCR.Value, }; string user = string.IsNullOrEmpty(linkSettings.UserName) ? "" : $"-l {linkSettings.UserName}"; string pw = null; if (string.IsNullOrWhiteSpace(linkSettings.PrivateKey)) { pw = string.IsNullOrEmpty(linkSettings.Password) ? "" : $"-pw {linkSettings.Password}"; } else { _privateKey = Path.GetTempPath() + linkSettings.Id; using (StreamWriter streamWriter = new StreamWriter(_privateKey, false, Encoding.ASCII)) { streamWriter.Write(linkSettings.PrivateKey); streamWriter.Flush(); } pw = $"-i \"{_privateKey}\""; } if (!_putty.Create(parentHwnd, $"-ssh {port} {user} {pw} {server}", 0, 0, width, height, settings)) { string errorText = Marshal.PtrToStringAnsi(_putty.GetError()); Dispatcher.Invoke(() => { OnFatalError?.Invoke("错误", errorText); }); } _putty.Dispose(); _putty = null; if (_privateKey != null) { File.Delete(_privateKey); } GC.Collect(); GC.SuppressFinalize(this); }); thread.Start(); }