Exemplo n.º 1
0
 private static void FinishAddServers(GroupBase parentGroup)
 {
     ServerTree.Instance.SortGroup(parentGroup);
     ServerTree.Instance.OnGroupChanged(parentGroup, ChangeType.TreeChanged);
     ServerTree.Instance.SelectedNode = parentGroup;
     parentGroup.Expand();
 }
Exemplo n.º 2
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);
     }
 }