/// <summary> /// 重置远程连接默认设置 /// </summary> private void PART_Reset_Change_Click(object sender, RoutedEventArgs e) { int i = 0; DbItemSetting itemSetting; if (PART_Reset_Rdp.IsChecked.Value) { i++; itemSetting = DbItemSettingRdp.FromDefault(); itemSetting.SetDefaultSetting(); } if (PART_Reset_Ssh.IsChecked.Value) { i++; itemSetting = DbItemSettingSsh.FromDefault(); itemSetting.SetDefaultSetting(); } if (PART_Reset_Telnet.IsChecked.Value) { i++; itemSetting = DbItemSettingTelnet.FromDefault(); itemSetting.SetDefaultSetting(); } MainWindow.ShowNoticeDialog("提示", i == 0 ? "至少选择一个要重置的项目" : "所选的项目重置重置成功"); }
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(); }