public static void AddSmartGroupDialog(TreeNode suggestedParentNode) { if (!ServerTree.Instance.AnyOpenedEditableFiles()) { NotifyUserFileNeeded(); return; } GroupBase parentGroupForGroupAdd = GetParentGroupForGroupAdd(suggestedParentNode); SmartGroupPropertiesDialog smartGroupPropertiesDialog = SmartGroupPropertiesDialog.NewAddDialog(parentGroupForGroupAdd); if (smartGroupPropertiesDialog == null) { FormTools.InformationDialog(info1); } else { using (smartGroupPropertiesDialog) { if (smartGroupPropertiesDialog.ShowDialog() == DialogResult.OK) { ServerTree.Instance.SelectedNode = SmartGroup.Create(smartGroupPropertiesDialog); } } } }
private static void CheckForUpdate() { try { ProgramUpdateElement updateElement = Current.RdcManSection.ProgramUpdate; if (!string.IsNullOrEmpty(updateElement.VersionPath) && !string.IsNullOrEmpty(updateElement.UpdateUrl)) { if (!DateTime.TryParse(Preferences.LastUpdateCheckTimeUtc, out DateTime result) || DateTime.UtcNow.Subtract(result).TotalDays < 1.0) { Log.Write("上次检查更新于 {0}, 明天之前不再检查", result.ToString("s")); } else { Preferences.LastUpdateCheckTimeUtc = DateTime.UtcNow.ToString("u"); string input = File.ReadAllText(updateElement.VersionPath); if (Version.TryParse(input, out Version result2)) { Assembly executingAssembly = Assembly.GetExecutingAssembly(); AssemblyName name = executingAssembly.GetName(); Log.Write("最新版本 = {0}", result2); if (name.Version < result2) { TheForm.Invoke((MethodInvoker) delegate { FormTools.InformationDialog("有一个新版本的RDCMan可从此处下载: {0}".InvariantFormat(updateElement.UpdateUrl)); }); } } } } } catch (Exception) { } }
private static bool ConnectNamedServers(ICollection <string> serverNames, bool isFirstConnection) { HashSet <string> nameHash = new HashSet <string>(serverNames, StringComparer.OrdinalIgnoreCase); List <ServerBase> serversToConnect = new List <ServerBase>(); ServerTree.Instance.Nodes.VisitNodes(delegate(RdcTreeNode node) { Server server = node as Server; if (server != null && nameHash.Contains(server.ServerName)) { if (!server.IsConnected) { serversToConnect.Add(server); } nameHash.Remove(server.ServerName); } }); isFirstConnection = ConnectServers(serversToConnect, isFirstConnection); if (nameHash.Count > 0) { StringBuilder stringBuilder = new StringBuilder("找不到以下服务器,无法连接:").AppendLine().AppendLine(); foreach (string item in nameHash) { stringBuilder.AppendLine(item); } FormTools.InformationDialog(stringBuilder.ToString()); } return(isFirstConnection); }
public virtual bool AllowEdit(bool popUI) { GroupBase readOnlyParent = GetReadOnlyParent(); if (readOnlyParent != null) { if (popUI) { FormTools.InformationDialog("{0} '{1}' 是只读的,无法编辑".CultureFormat((readOnlyParent == this) ? "群组" : "父群组", readOnlyParent.Text)); } 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); } }
public static FileGroup OpenFile(string filename) { using (Helpers.Timer("reading {0}", filename)) { XmlDocument xmlDocument = new XmlDocument(); XmlTextReader xmlTextReader = null; XmlNode topNode; try { xmlTextReader = new XmlTextReader(filename); xmlTextReader.WhitespaceHandling = WhitespaceHandling.None; xmlTextReader.MoveToContent(); topNode = xmlDocument.ReadNode(xmlTextReader); } catch (Exception ex) { FormTools.ErrorDialog(ex.Message); return(null); } finally { xmlTextReader?.Close(); } if (topNode == null) { throw new FileLoadException(filename + ": File format error"); } FileGroup fileGroup = new FileGroup(filename); FileGroup fileGroup2 = (from f in ServerTree.Instance.Nodes.OfType <FileGroup>() where f.Pathname.Equals(fileGroup.Pathname, StringComparison.OrdinalIgnoreCase) select f).FirstOrDefault(); if (fileGroup2 == null) { try { List <string> errors = new List <string>(); ServerTree.Instance.Operation((OperationBehavior)31, delegate { ServerTree.Instance.AddNode(fileGroup, ServerTree.Instance.RootNode); if (!ReadXml(topNode, fileGroup, errors)) { throw new Exception(string.Empty); } }); if (errors.Count > 0) { StringBuilder stringBuilder = new StringBuilder("The following errors were encountered:").AppendLine().AppendLine(); foreach (string item in errors) { stringBuilder.AppendLine(item); } stringBuilder.AppendLine().Append("The file was not loaded completely. If it is saved it almost certainly means losing information. Continue?"); DialogResult dialogResult = FormTools.ExclamationDialog(stringBuilder.ToString(), MessageBoxButtons.YesNo); if (dialogResult == DialogResult.No) { throw new Exception(string.Empty); } } using (Helpers.Timer("sorting root, builtin groups and file")) { ServerTree.Instance.SortRoot(); foreach (GroupBase builtInVirtualGroup in Program.BuiltInVirtualGroups) { ServerTree.Instance.SortGroup(builtInVirtualGroup); ServerTree.Instance.OnGroupChanged(builtInVirtualGroup, ChangeType.TreeChanged); } ServerTree.Instance.SortGroup(fileGroup, recurse: true); ServerTree.Instance.OnGroupChanged(fileGroup, ChangeType.TreeChanged); } SmartGroup.RefreshAll(fileGroup); fileGroup.VisitNodes(delegate(RdcTreeNode node) { GroupBase groupBase = node as GroupBase; if (groupBase != null && groupBase.Properties.Expanded.Value) { groupBase.Expand(); } }); Encryption.DecryptPasswords(); fileGroup.CheckCredentials(); fileGroup.VisitNodes(delegate(RdcTreeNode n) { n.ResetInheritance(); }); fileGroup.HasChangedSinceWrite = false; Program.Preferences.NeedToSave = true; return(fileGroup); } catch (Exception ex2) { if (!string.IsNullOrEmpty(ex2.Message)) { FormTools.ErrorDialog(ex2.Message); } ServerTree.Instance.RemoveNode(fileGroup); return(null); } } FormTools.InformationDialog("{0} is already open as '{1}'".CultureFormat(fileGroup.Pathname, fileGroup2.Text)); return(fileGroup2); } }
public sealed override bool ConfirmRemove(bool askUser) { FormTools.InformationDialog("Use the View menu to hide the " + base.Text + " group"); return(false); }
public override bool ConfirmRemove(bool askUser) { FormTools.InformationDialog("断开此服务器,将其从“Connected”组中删除"); return(false); }
private static void NotifyUserFileNeeded() { FormTools.InformationDialog("在添加服务器/组之前,请打开一个现有的非只读文件(File.Open)或创建一个新文件(File.New)。"); }
public sealed override bool ConfirmRemove(bool askUser) { FormTools.InformationDialog("使用“文件”菜单关闭 " + base.Text + " 组"); return(false); }