예제 #1
0
        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()));
                    }
                }
            });
예제 #2
0
        private void PopulateNodeContextMenu(ContextMenuStrip menu, RdcTreeNode node)
        {
            menu.Items.Clear();
            if (node == null)
            {
                if (AnyOpenedEditableFiles())
                {
                    menu.Items.Add(new DelegateMenuItem("添加服务器", MenuNames.EditAddServer, AddNodeDialogHelper.AddServersDialog));
                    menu.Items.Add(new DelegateMenuItem("导入服务器配置", MenuNames.EditImportServers, AddNodeDialogHelper.ImportServersDialog));
                    menu.Items.Add("-");
                    menu.Items.Add(new DelegateMenuItem("添加群组", MenuNames.EditAddGroup, AddNodeDialogHelper.AddGroupDialog));
                }
                else
                {
                    ToolStripMenuItem toolStripMenuItem = new ToolStripMenuItem("Please open or create a file");
                    toolStripMenuItem.Enabled = false;
                    menu.Items.Add(toolStripMenuItem);
                }
                return;
            }
            GroupBase groupBase = node as GroupBase;

            if (groupBase != null)
            {
                groupBase.AnyOrAllConnected(out bool anyConnected, out bool allConnected);
                ToolStripMenuItem toolStripMenuItem = new DelegateMenuItem("整组连接", MenuNames.SessionConnect, groupBase.Connect);
                toolStripMenuItem.Enabled = !allConnected;
                menu.Items.Add(toolStripMenuItem);
                toolStripMenuItem         = new DelegateMenuItem("连接组为...", MenuNames.SessionConnectAs, groupBase.DoConnectAs);
                toolStripMenuItem.Enabled = !allConnected;
                menu.Items.Add(toolStripMenuItem);
                toolStripMenuItem         = new DelegateMenuItem("重连整组", MenuNames.SessionReconnect, groupBase.Reconnect);
                toolStripMenuItem.Enabled = anyConnected;
                menu.Items.Add(toolStripMenuItem);
                menu.Items.Add("-");
                toolStripMenuItem         = new DelegateMenuItem("断开整组", MenuNames.SessionDisconnect, groupBase.Disconnect);
                toolStripMenuItem.Enabled = anyConnected;
                menu.Items.Add(toolStripMenuItem);
                menu.Items.Add("-");
                toolStripMenuItem         = new DelegateMenuItem("登出整组", MenuNames.SessionLogOff, groupBase.LogOff);
                toolStripMenuItem.Enabled = (!Policies.DisableLogOff && anyConnected);
                menu.Items.Add(toolStripMenuItem);
                menu.Items.Add("-");
                toolStripMenuItem = new DelegateMenuItem("添加服务器", MenuNames.EditAddServer, delegate
                {
                    AddNodeDialogHelper.AddServersDialog(node);
                });
                toolStripMenuItem.Enabled = groupBase.CanAddServers();
                menu.Items.Add(toolStripMenuItem);
                toolStripMenuItem = new DelegateMenuItem("添加群组", MenuNames.EditAddGroup, delegate
                {
                    AddNodeDialogHelper.AddGroupDialog(node);
                });
                toolStripMenuItem.Enabled = groupBase.CanAddGroups();
                menu.Items.Add(toolStripMenuItem);
                toolStripMenuItem = new DelegateMenuItem("添加智能群组", MenuNames.EditAddSmartGroup, delegate
                {
                    AddNodeDialogHelper.AddSmartGroupDialog(node);
                });
                toolStripMenuItem.Enabled = groupBase.CanAddGroups();
                menu.Items.Add(toolStripMenuItem);
                menu.Items.Add("-");
                FileGroup file = node as FileGroup;
                if (file != null)
                {
                    toolStripMenuItem = new DelegateMenuItem("保存 " + file.GetFilename(), MenuNames.FileSave, delegate
                    {
                        Program.TheForm.DoFileSave(file);
                    });
                    toolStripMenuItem.Enabled = file.AllowEdit(popUI: false);
                    menu.Items.Add(toolStripMenuItem);
                    menu.Items.Add(new DelegateMenuItem("关闭 " + file.GetFilename(), MenuNames.FileClose, delegate
                    {
                        Program.TheForm.DoFileClose(file);
                    }));
                }
                else
                {
                    toolStripMenuItem = new DelegateMenuItem("删除服务器", MenuNames.EditRemoveServers, delegate
                    {
                        DoRemoveChildren(node);
                    });
                    toolStripMenuItem.Enabled = groupBase.CanRemoveChildren();
                    menu.Items.Add(toolStripMenuItem);
                    toolStripMenuItem = new DelegateMenuItem("删除群组", MenuNames.EditRemove, delegate
                    {
                        ConfirmRemove(node, askUser: true);
                    });
                    toolStripMenuItem.Enabled = node.CanRemove(popUI: false);
                    menu.Items.Add(toolStripMenuItem);
                }
                menu.Items.Add("-");
                toolStripMenuItem         = new DelegateMenuItem("属性", MenuNames.EditProperties, node.DoPropertiesDialog);
                toolStripMenuItem.Enabled = node.HasProperties;
                menu.Items.Add(toolStripMenuItem);
            }
            else
            {
                ServerBase server = node as ServerBase;
                MenuHelper.AddSessionMenuItems(menu, server);
                menu.Items.Add("-");
                MenuHelper.AddDockingMenuItems(menu, server);
                menu.Items.Add("-");
                MenuHelper.AddMaintenanceMenuItems(menu, server);
            }
        }