示例#1
0
        public static void ImportFromPortScan(IEnumerable hosts, ProtocolType protocol)
        {
            try
            {
                var rootTreeNode     = ConnectionTree.TreeView.Nodes[0];
                var selectedTreeNode = ConnectionTree.TreeView.SelectedNode;

                var parentTreeNode = GetParentTreeNode(rootTreeNode, selectedTreeNode);
                if (parentTreeNode == null)
                {
                    return;
                }

                PortScan.Import(hosts, protocol, parentTreeNode);

                parentTreeNode.Expand();
                var parentContainer = (ContainerInfo)parentTreeNode.Tag;
                if (parentContainer != null)
                {
                    parentContainer.IsExpanded = true;
                }

                Runtime.SaveConnectionsBG();
            }
            catch (Exception ex)
            {
                Runtime.MessageCollector.AddExceptionMessage("App.Import.ImportFromPortScan() failed.", ex,
                                                             logOnly: true);
            }
        }
示例#2
0
        public static void ImportFromActiveDirectory(string ldapPath)
        {
            try
            {
                var rootTreeNode     = ConnectionTree.TreeView.Nodes[0];
                var selectedTreeNode = ConnectionTree.TreeView.SelectedNode;

                var parentTreeNode = GetParentTreeNode(rootTreeNode, selectedTreeNode);
                if (parentTreeNode == null)
                {
                    return;
                }

                ActiveDirectory.Import(ldapPath, parentTreeNode);

                parentTreeNode.Expand();
                var parentContainer = (ContainerInfo)parentTreeNode.Tag;
                if (parentContainer != null)
                {
                    parentContainer.IsExpanded = true;
                }

                Runtime.SaveConnectionsBG();
            }
            catch (Exception ex)
            {
                Runtime.MessageCollector.AddExceptionMessage("App.Import.ImportFromActiveDirectory() failed.", ex,
                                                             logOnly: true);
            }
        }
示例#3
0
        public static void ImportFromFile(TreeNode rootTreeNode, TreeNode selectedTreeNode,
                                          bool alwaysUseSelectedTreeNode = false)
        {
            try
            {
                using (var openFileDialog = new OpenFileDialog())
                {
                    openFileDialog.CheckFileExists  = true;
                    openFileDialog.InitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.Personal);
                    openFileDialog.Multiselect      = true;

                    var fileTypes = new List <string>();
                    fileTypes.AddRange(new[] { Language.strFilterAllImportable, "*.xml;*.rdp;*.rdg;*.dat" });
                    fileTypes.AddRange(new[] { Language.strFiltermRemoteXML, "*.xml" });
                    fileTypes.AddRange(new[] { Language.strFilterRDP, "*.rdp" });
                    fileTypes.AddRange(new[] { Language.strFilterRdgFiles, "*.rdg" });
                    fileTypes.AddRange(new[] { Language.strFilterPuttyConnectionManager, "*.dat" });
                    fileTypes.AddRange(new[] { Language.strFilterAll, "*.*" });

                    openFileDialog.Filter = string.Join("|", fileTypes.ToArray());

                    if (openFileDialog.ShowDialog() != DialogResult.OK)
                    {
                        return;
                    }

                    var parentTreeNode = GetParentTreeNode(rootTreeNode, selectedTreeNode, alwaysUseSelectedTreeNode);
                    if (parentTreeNode == null)
                    {
                        return;
                    }

                    foreach (var fileName in openFileDialog.FileNames)
                    {
                        try
                        {
                            switch (DetermineFileType(fileName))
                            {
                            case FileType.mRemoteXml:
                                Config.Import.mRemoteNGImporter.Import(fileName, parentTreeNode);
                                break;

                            case FileType.RemoteDesktopConnection:
                                RemoteDesktopConnection.Import(fileName, parentTreeNode);
                                break;

                            case FileType.RemoteDesktopConnectionManager:
                                RemoteDesktopConnectionManager.Import(fileName, parentTreeNode);
                                break;

                            case FileType.PuttyConnectionManager:
                                PuttyConnectionManager.Import(fileName, parentTreeNode);
                                break;

                            default:
                                throw new FileFormatException("Unrecognized file format.");
                            }
                        }
                        catch (Exception ex)
                        {
                            MessageBox.Show(string.Format(Language.strImportFileFailedContent, fileName), Language.strImportFileFailedMainInstruction,
                                            MessageBoxButtons.OK, MessageBoxIcon.Exclamation, MessageBoxDefaultButton.Button1);
                            Runtime.MessageCollector.AddExceptionMessage("App.Import.ImportFromFile() failed:1", ex, logOnly: true);
                        }
                    }

                    parentTreeNode.Expand();
                    var parentContainer = (ContainerInfo)parentTreeNode.Tag;
                    if (parentContainer != null)
                    {
                        parentContainer.IsExpanded = true;
                    }

                    Runtime.SaveConnectionsBG();
                }
            }
            catch (Exception ex)
            {
                Runtime.MessageCollector.AddExceptionMessage("App.Import.ImportFromFile() failed:2", ex, logOnly: true);
            }
        }