Esempio n. 1
0
        internal void CheckCredentials()
        {
            Dictionary <string, List <string> > missingProfiles = new Dictionary <string, List <string> >(StringComparer.OrdinalIgnoreCase);

            this.VisitNodes(delegate(RdcTreeNode node)
            {
                CheckCredentials(node, node.LogonCredentials, "Logon Credentials", missingProfiles);
                CheckCredentials(node, node.GatewaySettings, "Gateway Settings", missingProfiles);
            });
            if (missingProfiles.Count > 0)
            {
                StringBuilder stringBuilder = new StringBuilder();
                stringBuilder.AppendLine("找不到某些凭证配置文件。").AppendLine("在连接到服务器,编辑属性等之前,请添加缺少的配置文件。否则,引用将丢失。").AppendLine("点击确定将详细信息复制到剪贴板。")
                .AppendLine();
                foreach (KeyValuePair <string, List <string> > item in missingProfiles)
                {
                    stringBuilder.AppendLine("配置文件名: " + item.Key);
                    stringBuilder.AppendFormat("引用于: ");
                    foreach (string item2 in item.Value)
                    {
                        stringBuilder.Append(" " + item2);
                    }
                    stringBuilder.AppendLine().AppendLine();
                }
                DialogResult dialogResult = FormTools.ExclamationDialog(stringBuilder.ToString(), MessageBoxButtons.OKCancel);
                if (dialogResult == DialogResult.OK)
                {
                    Clipboard.SetText(stringBuilder.ToString());
                }
            }
        }
Esempio n. 2
0
        public static void DecryptPasswords()
        {
            StringBuilder builder = new StringBuilder("解密某些证书时出现问题。").AppendLine().AppendLine("单击确定将详细信息复制到剪贴板。");
            bool          credentialsProfileFail = false;

            PendingDecryption.Where((DeferDecryptionItem d) => d.Object is CredentialsProfile).ForEach(delegate(DeferDecryptionItem item)
            {
                DecryptPassword(item, builder, "证书文件:", ref credentialsProfileFail);
            });
            bool passwordFail = false;

            PendingDecryption.Where((DeferDecryptionItem d) => d.Object is PasswordSetting).ForEach(delegate(DeferDecryptionItem item)
            {
                DecryptPassword(item, builder, "自定义密码:", ref passwordFail);
            });
            PendingDecryption.Clear();
            if (credentialsProfileFail || passwordFail)
            {
                DialogResult dialogResult = FormTools.ExclamationDialog(builder.ToString(), MessageBoxButtons.OKCancel);
                if (dialogResult == DialogResult.OK)
                {
                    Clipboard.SetText(builder.ToString());
                }
            }
        }
Esempio n. 3
0
 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);
     }
 }
Esempio n. 4
0
        private static void InstantiatePlugins()
        {
            PluginContext = new PluginContext();
            Assembly             callingAssembly      = Assembly.GetCallingAssembly();
            DirectoryCatalog     catalog              = new DirectoryCatalog(Path.GetDirectoryName(callingAssembly.Location), PluginPattern);
            CompositionContainer compositionContainer = new CompositionContainer(catalog);

            Plugins = new Dictionary <string, PluginConfig>(StringComparer.OrdinalIgnoreCase);
            StringBuilder stringBuilder = new StringBuilder();
            XmlNode       value         = Preferences.Settings.PluginSettings.Value;

            if (value != null)
            {
                foreach (XmlNode item in value.SelectNodes("//plugin"))
                {
                    try {
                        string value2 = item.Attributes["path"].Value;
                        if (!string.IsNullOrEmpty(value2))
                        {
                            PluginConfig pluginConfig = new PluginConfig();
                            pluginConfig.Name         = value2;
                            pluginConfig.SettingsNode = item;
                            PluginConfig value3 = pluginConfig;
                            Plugins[value2] = value3;
                        }
                    }
                    catch {
                    }
                }
            }
            foreach (IPlugin item2 in from e in compositionContainer.GetExports <IPlugin>()
                     select e.Value)
            {
                string name = item2.GetType().Assembly.GetName().Name;
                if (!Plugins.TryGetValue(name, out PluginConfig value4))
                {
                    PluginConfig pluginConfig2 = new PluginConfig();
                    pluginConfig2.Name = name;
                    value4             = pluginConfig2;
                    Plugins[name]      = value4;
                }
                try {
                    item2.PreLoad(PluginContext, value4.SettingsNode);
                    value4.Plugin = item2;
                }
                catch (Exception ex) {
                    stringBuilder.AppendLine("加载时出错 '{0}': {1}".InvariantFormat(name, ex.Message));
                }
            }
            foreach (PluginConfig item3 in Plugins.Values.Where((PluginConfig c) => c.Plugin == null))
            {
                stringBuilder.AppendLine("'{0}' 以前使用过,但现在未加载".InvariantFormat(item3.Name));
            }
            if (stringBuilder.Length > 0)
            {
                stringBuilder.AppendLine().Append("单击取消退出");
                string text = "某些插件尚未加载。 RDCMan可能无法按预期运行.{0}{0}".InvariantFormat(Environment.NewLine) + stringBuilder.ToString();
                if (FormTools.ExclamationDialog(text, MessageBoxButtons.OKCancel) == DialogResult.Cancel)
                {
                    Environment.Exit(1);
                }
            }
        }
Esempio n. 5
0
        public static Preferences Load()
        {
            Preferences preferences = new Preferences();

            if (Program.ResetPreferences)
            {
                return(preferences);
            }
            List <string> list = new List <string>();
            //将旧版配置文件移动到新版位置
            string text  = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), "Microsoft Corporation", Application.ProductName);
            string text2 = Path.Combine(text, "RDCMan.settings");

            if (File.Exists(text2))
            {
                if (!File.Exists(preferences.SettingsPath))
                {
                    Directory.CreateDirectory(preferences.SettingsDirectory);
                    File.Move(text2, preferences.SettingsPath);
                }
                try
                {
                    Directory.Delete(text);
                }
                catch
                {
                }
            }
            bool flag = true;

            try
            {
                using (XmlTextReader reader = new XmlTextReader(preferences.SettingsPath))
                {
                    XmlDocument xmlDocument = new XmlDocument();
                    xmlDocument.Load(reader);
                    XmlNode lastChild = xmlDocument.LastChild;
                    try
                    {
                        _ = lastChild.Attributes["programVersion"].Value;
                        preferences.Settings.ReadXml(lastChild, null, list);
                        flag = false;
                    }
                    catch
                    {
                    }
                }
            }
            catch
            {
            }
            if (flag)
            {
                preferences.Settings.TransferPreferences(preferences);
                if (preferences.DefaultGroupSettings != null)
                {
                    MemoryStream  input         = new MemoryStream(preferences.DefaultGroupSettings);
                    XmlTextReader xmlTextReader = new XmlTextReader(input);
                    xmlTextReader.WhitespaceHandling = WhitespaceHandling.None;
                    XmlTextReader xmlTextReader2 = xmlTextReader;
                    xmlTextReader2.MoveToContent();
                    XmlDocument xmlDocument2 = new XmlDocument();
                    XmlNode     xmlNode      = xmlDocument2.ReadNode(xmlTextReader2);
                    xmlTextReader2.Close();
                    GroupBase.SchemaVersion = 2;
                    DefaultSettingsGroup.Instance.ReadXml(xmlNode, list);
                }
                if (preferences.CredentialsProfiles != null)
                {
                    MemoryStream  input2         = new MemoryStream(preferences.CredentialsProfiles);
                    XmlTextReader xmlTextReader3 = new XmlTextReader(input2);
                    xmlTextReader3.WhitespaceHandling = WhitespaceHandling.None;
                    XmlTextReader xmlTextReader4 = xmlTextReader3;
                    xmlTextReader4.MoveToContent();
                    XmlDocument xmlDocument3 = new XmlDocument();
                    XmlNode     xmlNode2     = xmlDocument3.ReadNode(xmlTextReader4);
                    xmlTextReader4.Close();
                    Program.CredentialsProfiles.ReadXml(xmlNode2, ProfileScope.Global, DefaultSettingsGroup.Instance, list);
                }
            }
            else
            {
                if (preferences.Settings.DefaultGroupSettings != null)
                {
                    XmlNode firstChild = preferences.Settings.DefaultGroupSettings.Value.FirstChild;
                    DefaultSettingsGroup.Instance.ReadXml(firstChild, list);
                }
                if (preferences.Settings.CredentialsProfiles != null)
                {
                    XmlNode firstChild2 = preferences.Settings.CredentialsProfiles.Value.FirstChild;
                    Program.CredentialsProfiles.ReadXml(firstChild2, ProfileScope.Global, DefaultSettingsGroup.Instance, list);
                }
            }
            Encryption.DecryptPasswords();
            if (list.Count > 0)
            {
                StringBuilder stringBuilder = new StringBuilder("The following errors were encountered:").AppendLine().AppendLine();
                foreach (string item in list)
                {
                    stringBuilder.AppendLine(item);
                }
                stringBuilder.AppendLine().Append("Your global configuration has 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)
                {
                    return(null);
                }
            }
            return(preferences);
        }