private string ValidateProfileName() { _profileNameTextBox.Text = _profileNameTextBox.Text.Trim(); if (string.IsNullOrEmpty(_profileNameTextBox.Text)) { return("请输入配置文件名"); } if (LogonCredentials.IsCustomProfile(ProfileName)) { return("'{0}' 是保留的配置文件名称".InvariantFormat("Custom")); } CredentialsStore credentialsProfiles = Program.CredentialsProfiles; string text = "Global"; if (ProfileScope == ProfileScope.File) { credentialsProfiles = _file.CredentialsProfiles; text = _file.Text; } if (credentialsProfiles.Contains(ProfileName)) { DialogResult dialogResult = FormTools.YesNoDialog(ProfileName + " already exists in " + text + Environment.NewLine + "Update?", MessageBoxDefaultButton.Button2); if (dialogResult != DialogResult.Yes) { return("配置文件存在"); } } return(null); }
private void DeleteCredentials() { int selectedIndex = _credentialsListBox.SelectedIndex; if (selectedIndex == -1) { return; } CredentialsProfile credentialsProfile = _credentialsListBox.Items[selectedIndex] as CredentialsProfile; ICollection <string> credentialsInUseLocations = GetCredentialsInUseLocations(credentialsProfile); if (credentialsInUseLocations.Count > 0) { StringBuilder stringBuilder = new StringBuilder(); stringBuilder.AppendLine(credentialsProfile.ProfileName + " 在这些节点中正在使用:").AppendLine(); foreach (string item in credentialsInUseLocations) { stringBuilder.AppendLine(item); } stringBuilder.AppendLine().AppendLine("你确定你要删除它?"); if (FormTools.YesNoDialog(stringBuilder.ToString()) != DialogResult.Yes) { return; } } _credentialsStore.Remove(credentialsProfile.ProfileName); _credentialsListBox.Items.RemoveAt(selectedIndex); RevertDeletedCredentials(credentialsProfile); }
private string ValidateServerName() { _serverNameTextBox.Text = _serverNameTextBox.Text.Trim(); string text = _serverNameTextBox.Text; if (text.Length == 0) { return("Please enter a server name"); } if (text.IndexOf(' ') != -1) { return("Spaces are not permitted in a server name"); } if (text.IndexOf('/') != -1 || text.IndexOf('\\') != -1) { return("Slashes are not permitted in a server name"); } try { List <string> list = new List <string>(StringUtilities.ExpandPattern(text)); if (list.Count > 1 && list.Count > 20 && FormTools.YesNoDialog("Expansion results in " + list.Count + " servers. Are you sure?") == DialogResult.No) { return("Expansion too large"); } ExpandedServerNames = list; } catch (ArgumentException ex) { return(ex.Message); } return(null); }
private void DoRemoveChildren(RdcTreeNode node) { GroupBase groupBase = node as GroupBase; if (groupBase.Nodes.Count > 0) { DialogResult dialogResult = FormTools.YesNoDialog("删除 " + groupBase.Text + " 组中的所有子项?"); if (dialogResult != DialogResult.Yes) { return; } } groupBase.RemoveChildren(); }
public static void CloseFileGroup(FileGroup file) { file.AnyOrAllConnected(out bool anyConnected, out bool _); if (anyConnected) { DialogResult dialogResult = FormTools.YesNoDialog("There are active connections from " + file.Text + ". Are you sure you want to close it?"); if (dialogResult == DialogResult.No) { return; } } if (SaveFileGroup(file) != 0) { ServerTree.Instance.RemoveNode(file); Program.Preferences.NeedToSave = true; } }
public override bool ConfirmRemove(bool askUser) { if (!CanRemove(popUI: true)) { return(false); } if (askUser) { string text = "Remove '{0}' {1} from '{2}'?".InvariantFormat(base.Text, RemoveTypeDescription, base.Parent.Text); DialogResult dialogResult = FormTools.YesNoDialog(ParentForm, text, MessageBoxDefaultButton.Button1); if (dialogResult != DialogResult.Yes) { return(false); } } return(true); }
public static void AddServersDialog(TreeNode suggestedParentNode) { if (!ServerTree.Instance.AnyOpenedEditableFiles()) { NotifyUserFileNeeded(); } else if (ServerTree.Instance.Nodes.OfType <FileGroup>().Any() || FormTools.YesNoDialog("RDCMan不允许混合使用服务器和组。 如果将服务器添加到顶级组,则将无法将任何组添加到该文件。 继续吗?") == DialogResult.Yes) { GroupBase groupBase = GetParentGroupForServerAdd(suggestedParentNode); ServerPropertiesDialog dlg = ServerPropertiesDialog.NewAddDialog(groupBase); if (dlg == null) { FormTools.InformationDialog(info1); return; } using (dlg) { if (dlg.ShowDialog() != DialogResult.OK) { return; } groupBase = dlg.PropertiesPage.ParentGroup; Server server = dlg.AssociatedNode as Server; server.UpdateSettings(dlg); ServerTree.Instance.Operation(OperationBehavior.SuspendSort | OperationBehavior.SuspendUpdate | OperationBehavior.SuspendGroupChanged, delegate { List <string> expandedServerNames = (dlg.PropertiesPage as ServerPropertiesTabPage).ExpandedServerNames; if (expandedServerNames.Count == 1) { Server.Create(dlg); } else { foreach (string item in expandedServerNames) { Server.Create(item, dlg); } } }); } FinishAddServers(groupBase); } }
private static bool ReadXml(XmlNode topNode, FileGroup fileGroup, ICollection <string> errors) { string text = "unknown"; int num = 0; try { XmlNode namedItem = topNode.Attributes.GetNamedItem("programVersion"); text = namedItem.InnerText; } catch { } try { XmlNode namedItem2 = topNode.Attributes.GetNamedItem("schemaVersion"); num = int.Parse(namedItem2.InnerText); } catch { } fileGroup.SchemaVersion = num; if (num > 3) { DialogResult dialogResult = FormTools.YesNoDialog("{0} was written by a newer version of RDCMan ({1}). It may not load properly. If it does and is saved by this version, it will revert to the older file schema possibly losing information. Continue?".CultureFormat(fileGroup.GetFilename(), text)); if (dialogResult == DialogResult.No) { return(false); } } GroupBase.SchemaVersion = num; if (GroupBase.SchemaVersion <= 2) { fileGroup.EncryptionSettings.InheritSettingsType.Mode = InheritanceMode.None; } Dictionary <string, Helpers.ReadXmlDelegate> nodeActions = new Dictionary <string, Helpers.ReadXmlDelegate>(); nodeActions["file"] = delegate(XmlNode childNode, RdcTreeNode group, ICollection <string> errors2) { (group as GroupBase).ReadXml(childNode, errors2); }; foreach (IBuiltInVirtualGroup virtualGroup in Program.BuiltInVirtualGroups.Where((IBuiltInVirtualGroup v) => !string.IsNullOrEmpty(v.XmlNodeName))) { Helpers.ReadXmlDelegate readXmlDelegate2 = nodeActions[virtualGroup.XmlNodeName] = delegate(XmlNode childNode, RdcTreeNode group, ICollection <string> errors2) { virtualGroup.ReadXml(childNode, fileGroup, errors2); }; } nodeActions["version"] = delegate { }; LongRunningActionForm.PerformOperation("Opening " + fileGroup.Pathname, showImmediately: false, delegate { foreach (XmlNode childNode in topNode.ChildNodes) { if (nodeActions.TryGetValue(childNode.Name, out Helpers.ReadXmlDelegate value)) { value(childNode, fileGroup, errors); } else { errors.Add("Unexpected Xml node {0} in '{1}'".CultureFormat(childNode.GetFullPath(), fileGroup.GetFilename())); } } });
private void ContextMenuPopup(object menuSender, EventArgs args) { ContextMenuStrip contextMenuStrip = menuSender as ContextMenuStrip; List <ServerBase> selectedServers = base.SelectedServers.ToList(); if (selectedServers.Count == 0) { if (base.ListView.FocusedItem == null) { return; } selectedServers.Add(base.ListView.FocusedItem.Tag as ServerBase); } contextMenuStrip.Items.Clear(); NodeHelper.AnyOrAllConnected(selectedServers, out bool anyConnected, out bool allConnected); ToolStripMenuItem toolStripMenuItem = new DelegateMenuItem("&C连接", MenuNames.SessionConnect, delegate { NodeHelper.ThrottledConnect(selectedServers); OK(); }); toolStripMenuItem.Enabled = !allConnected; contextMenuStrip.Items.Add(toolStripMenuItem); toolStripMenuItem = new DelegateMenuItem("&R重新连接", MenuNames.SessionReconnect, delegate { selectedServers.ForEach(delegate(ServerBase server) { server.Reconnect(); }); OK(); }); toolStripMenuItem.Enabled = anyConnected; contextMenuStrip.Items.Add(toolStripMenuItem); toolStripMenuItem = new DelegateMenuItem("&D断开连接", MenuNames.SessionDisconnect, delegate { NodeHelper.ThrottledDisconnect(selectedServers); OK(); }); toolStripMenuItem.Enabled = anyConnected; contextMenuStrip.Items.Add(toolStripMenuItem); contextMenuStrip.Items.Add("-"); toolStripMenuItem = new DelegateMenuItem("注销", MenuNames.SessionLogOff, delegate { selectedServers.ForEach(delegate(ServerBase server) { server.LogOff(); }); OK(); }); toolStripMenuItem.Enabled = (!Policies.DisableLogOff && anyConnected); contextMenuStrip.Items.Add(toolStripMenuItem); contextMenuStrip.Items.Add("-"); toolStripMenuItem = new DelegateMenuItem("删除", MenuNames.EditRemove, delegate { if (!anyConnected || FormTools.YesNoDialog("有活动的会话。 你确定吗?") == DialogResult.Yes) { selectedServers.ForEach(delegate(ServerBase server) { ServerTree.Instance.ConfirmRemove(server, askUser: false); }); Cancel(); } }); contextMenuStrip.Items.Add(toolStripMenuItem); contextMenuStrip.Items.Add("-"); contextMenuStrip.Items.Add(new DelegateMenuItem("添加到收藏夹", MenuNames.EditAddToFavorites, delegate { selectedServers.ForEach(delegate(ServerBase server) { FavoritesGroup.Instance.AddReference(server); }); OK(); })); }