Inheritance: INotifyCollectionChanged, INotifyPropertyChanged
        public ConnectionTreeModel LoadConnections(bool import)
        {
            IDeserializer deserializer;
            if (UseDatabase)
            {
                var connector = new SqlDatabaseConnector();
                var dataProvider = new SqlDataProvider(connector);
                var dataTable = dataProvider.Load();
                deserializer = new DataTableDeserializer(dataTable);
            }
            else
            {
                var dataProvider = new FileDataProvider(ConnectionFileName);
                var xmlString = dataProvider.Load();
                deserializer = new XmlConnectionsDeserializer(xmlString, PromptForPassword);
            }

            var connectionTreeModel = deserializer.Deserialize();

            if (connectionTreeModel != null)
                frmMain.Default.ConnectionsFileName = ConnectionFileName;
            else
                connectionTreeModel = new ConnectionTreeModel();

            if (import) return connectionTreeModel;
            PuttySessionsManager.Instance.AddSessions();
            connectionTreeModel.RootNodes.AddRange(PuttySessionsManager.Instance.RootPuttySessionsNodes);

            return connectionTreeModel;
        }
 private ConnectionTreeModel SetupConnectionTreeModel()
 {
     /*
      * Root
      * |--- con0
      * |--- folder1
      * |    L--- con1
      * L--- folder2
      *      |--- con2
      *      L--- folder3
      *           |--- con3
      *           L--- con4
      */
     var connectionTreeModel = new ConnectionTreeModel();
     var rootNode = new RootNodeInfo(RootNodeType.Connection);
     var folder1 = new ContainerInfo { Name = "folder1" };
     var folder2 = new ContainerInfo { Name = "folder2" };
     var folder3 = new ContainerInfo { Name = "folder3" };
     var con0 = new ConnectionInfo { Name = "con0" };
     var con1 = new ConnectionInfo { Name = "con1" };
     var con2 = new ConnectionInfo { Name = "con2" };
     var con3 = new ConnectionInfo { Name = "con3" };
     var con4 = new ConnectionInfo { Name = "con4" };
     rootNode.AddChild(folder1);
     rootNode.AddChild(folder2);
     rootNode.AddChild(con0);
     folder1.AddChild(con1);
     folder2.AddChild(con2);
     folder2.AddChild(folder3);
     folder3.AddChild(con3);
     folder3.AddChild(con4);
     connectionTreeModel.AddRootNode(rootNode);
     return connectionTreeModel;
 }
        private ConnectionTreeModel SetupConnectionTreeModel()
        {
            /*
             * Tree:
             * Root
             * |--- folder1
             * |    |--- con1
             * |    L--- con2
             * |--- folder2
             * |    |--- con3
             * |    L--- con4
             * L--- con5
             *
             */
            var connectionTreeModel = new ConnectionTreeModel();
            var root = new RootNodeInfo(RootNodeType.Connection);
            _folder1 = new ContainerInfo { Name = "folder1"};
            _con1 = new ConnectionInfo { Name = "con1"};
            _con2 = new ConnectionInfo { Name = "con2"};
            _folder2 = new ContainerInfo { Name = "folder2" };
            _con3 = new ConnectionInfo { Name = "con3" };
            _con4 = new ConnectionInfo { Name = "con4" };
            _con5 = new ConnectionInfo { Name = "con5" };

            connectionTreeModel.AddRootNode(root);
            root.AddChildRange(new [] { _folder1, _folder2, _con5 });
            _folder1.AddChildRange(new [] { _con1, _con2 });
            _folder2.AddChildRange(new[] { _con3, _con4 });

            return connectionTreeModel;
        }
        public ConnectionTreeModel Deserialize()
        {
            var connectionTreeModel = new ConnectionTreeModel();
            var root = new RootNodeInfo(RootNodeType.Connection);
            connectionTreeModel.AddRootNode(root);

            ImportContainers(_ldapPath, root);

            return connectionTreeModel;
        }
        public ConnectionTreeModel Deserialize()
        {
            var connectionTreeModel = new ConnectionTreeModel();
            var root = new RootNodeInfo(RootNodeType.Connection);
            connectionTreeModel.AddRootNode(root);

            foreach (var host in _scannedHosts)
                ImportScannedHost(host, root);

            return connectionTreeModel;
        }
        public ConnectionTreeModel Deserialize(bool import)
        {
            try
            {
                if (!import)
                    Runtime.IsConnectionsFileLoaded = false;

                var rootXmlElement = _xmlDocument.DocumentElement;
                InitializeRootNode(rootXmlElement);
                CreateDecryptor(_rootNodeInfo, rootXmlElement);
                var connectionTreeModel = new ConnectionTreeModel();
                connectionTreeModel.AddRootNode(_rootNodeInfo);

                if (_confVersion > 1.3)
                {
                    var protectedString = _xmlDocument.DocumentElement?.Attributes["Protected"].Value;
                    if (!_decryptor.ConnectionsFileIsAuthentic(protectedString, _rootNodeInfo.PasswordString.ConvertToSecureString()))
                    {
                        mRemoteNG.Settings.Default.LoadConsFromCustomLocation = false;
                        mRemoteNG.Settings.Default.CustomConsPath = "";
                        return null;
                    }
                }

                if (_confVersion >= 2.6)
                {
                    if (rootXmlElement?.Attributes["FullFileEncryption"].Value == "True")
                    {
                        var decryptedContent = _decryptor.Decrypt(rootXmlElement.InnerText);
                        rootXmlElement.InnerXml = decryptedContent;
                    }
                }

                if (import && !IsExportFile(rootXmlElement))
                {
                    Runtime.MessageCollector.AddMessage(MessageClass.InformationMsg, Language.strCannotImportNormalSessionFile);
                    return null;
                }

                AddNodesFromXmlRecursive(_xmlDocument.DocumentElement, _rootNodeInfo);

                if (!import)
                    Runtime.IsConnectionsFileLoaded = true;

                return connectionTreeModel;
            }
            catch (Exception ex)
            {
                Runtime.IsConnectionsFileLoaded = false;
                Runtime.MessageCollector.AddExceptionStackTrace(Language.strLoadFromXmlFailed, ex);
                throw;
            }
        }
Exemple #7
0
        public static void ExportToFile(ConnectionInfo selectedNode, ConnectionTreeModel connectionTreeModel)
        {
            try
            {
                var saveSecurity = new SaveFilter();

                using (var exportForm = new ExportForm())
                {
                    if (selectedNode?.GetTreeNodeType() == TreeNodeType.Container)
                        exportForm.SelectedFolder = selectedNode as ContainerInfo;
                    else if (selectedNode?.GetTreeNodeType() == TreeNodeType.Connection)
                    {
                        if (selectedNode.Parent.GetTreeNodeType() == TreeNodeType.Container)
                            exportForm.SelectedFolder = selectedNode.Parent;
                        exportForm.SelectedConnection = selectedNode;
                    }

                    if (exportForm.ShowDialog(frmMain.Default) != DialogResult.OK)
                        return ;

                    ConnectionInfo exportTarget;
                    switch (exportForm.Scope)
                    {
                        case ExportForm.ExportScope.SelectedFolder:
                            exportTarget = exportForm.SelectedFolder;
                            break;
                        case ExportForm.ExportScope.SelectedConnection:
                            exportTarget = exportForm.SelectedConnection;
                            break;
                        default:
                            exportTarget = connectionTreeModel.RootNodes.First(node => node is RootNodeInfo);
                            break;
                    }

                    saveSecurity.SaveUsername = exportForm.IncludeUsername;
                    saveSecurity.SavePassword = exportForm.IncludePassword;
                    saveSecurity.SaveDomain = exportForm.IncludeDomain;
                    saveSecurity.SaveInheritance = exportForm.IncludeInheritance;

                    SaveExportFile(exportForm.FileName, exportForm.SaveFormat, saveSecurity, exportTarget);
                }

            }
            catch (Exception ex)
            {
                Runtime.MessageCollector.AddExceptionMessage("App.Export.ExportToFile() failed.", ex, logOnly: true);
            }
        }
        private ConnectionTreeModel CreateNodeHierarchy(List<ConnectionInfo> connectionList)
        {
            var connectionTreeModel = new ConnectionTreeModel();
            var rootNode = new RootNodeInfo(RootNodeType.Connection) {ConstantID = "0"};
            connectionTreeModel.AddRootNode(rootNode);

            foreach (DataRow row in _dataTable.Rows)
            {
                var id = (string) row["ConstantID"];
                var connectionInfo = connectionList.First(node => node.ConstantID == id);
                var parentId = (string) row["ParentID"];
                if (parentId == "0")
                    rootNode.AddChild(connectionInfo);
                else
                    (connectionList.First(node => node.ConstantID == parentId) as ContainerInfo)?.AddChild(connectionInfo);
            }
            return connectionTreeModel;
        }
        public ConnectionTreeModel Deserialize()
        {
            var connectionTreeModel = new ConnectionTreeModel();
            var root = new RootNodeInfo(RootNodeType.Connection);

            var xmlDocument = new XmlDocument();
            xmlDocument.LoadXml(_rdcmConnectionsXml);

            var rdcManNode = xmlDocument.SelectSingleNode("/RDCMan");
            VerifySchemaVersion(rdcManNode);
            VerifyFileVersion(rdcManNode);

            var fileNode = rdcManNode?.SelectSingleNode("./file");
            ImportFileOrGroup(fileNode, root);

            connectionTreeModel.AddRootNode(root);
            return connectionTreeModel;
        }
        public ConnectionTreeModel Deserialize()
        {
            var connectionTreeModel = new ConnectionTreeModel();
            var root = new RootNodeInfo(RootNodeType.Connection);
            connectionTreeModel.AddRootNode(root);

            var xmlDocument = new XmlDocument();
            xmlDocument.LoadXml(_puttycmConnectionsXml);

            var configurationNode = xmlDocument.SelectSingleNode("/configuration");

            var rootNodes = configurationNode?.SelectNodes("./root");
            if (rootNodes == null) return connectionTreeModel;
            foreach (XmlNode rootNode in rootNodes)
            {
                ImportRootOrContainer(rootNode, root);
            }

            return connectionTreeModel;
        }
        public ConnectionTreeModel Deserialize()
        {
            var connectionTreeModel = new ConnectionTreeModel();
            var root = new RootNodeInfo(RootNodeType.Connection);
            connectionTreeModel.AddRootNode(root);
            var connectionInfo = new ConnectionInfo();
            foreach (var line in _fileContent)
            {
                var parts = line.Split(new[] { ':' }, 3);
                if (parts.Length < 3)
                {
                    continue;
                }

                var key = parts[0];
                var value = parts[2];

                SetConnectionInfoParameter(connectionInfo, key, value);
            }
            root.AddChild(connectionInfo);

            return connectionTreeModel;
        }
 public void Teardown()
 {
     _connectionTreeModel = null;
 }
        private ConnectionTreeModel CreateConnectionTreeModel()
        {
            var model = new ConnectionTreeModel();
            var root = new RootNodeInfo(RootNodeType.Connection);
            var folder1 = new ContainerInfo {Name = "folder1", Username = "******", Domain = "domain1", Password = "******"};
            var con1 = new ConnectionInfo {Name = "Con1", Username = "******", Domain = "domain1", Password = "******" };
            var con2 = new ConnectionInfo {Name = "Con2", Username = "******", Domain = "domain2", Password = "******" };

            root.AddChild(folder1);
            root.AddChild(con2);
            folder1.AddChild(con1);
            model.AddRootNode(root);
            return model;
        }
 public void OnetimeSetup()
 {
     _connectionFileContents = Resources.test_remotedesktopconnection_rdp.Split(Environment.NewLine.ToCharArray());
     _deserializer = new RemoteDesktopConnectionDeserializer(_connectionFileContents);
     _connectionTreeModel = _deserializer.Deserialize();
 }
 public void Setup()
 {
     _connectionTreeModel = new ConnectionTreeModel();
 }
 public void Teardown()
 {
     _xmlConnectionsDeserializer = null;
     _connectionTreeModel = null;
 }
 private ConnectionTreeModel SetupConnectionTreeModel()
 {
     /*
      * Root
      * |--- con0
      * |--- folder1
      * |    L--- con1
      * L--- folder2
      *      |--- con2
      *      L--- folder3
      *           |--- con3
      *           L--- con4
      */
     BuildTreeNodes();
     var connectionTreeModel = new ConnectionTreeModel();
     var rootNode = new RootNodeInfo(RootNodeType.Connection);
     rootNode.AddChild(_folder1);
     rootNode.AddChild(_folder2);
     rootNode.AddChild(_con0);
     _folder1.AddChild(_con1);
     _folder2.AddChild(_con2);
     _folder2.AddChild(_folder3);
     _folder3.AddChild(_con3);
     _folder3.AddChild(_con4);
     connectionTreeModel.AddRootNode(rootNode);
     return connectionTreeModel;
 }
Exemple #18
0
        public static void LoadConnections(bool withDialog = false, bool update = false)
        {
            var connectionsLoader = new ConnectionsLoader();
            try
            {
                // disable sql update checking while we are loading updates
                RemoteConnectionsSyncronizer?.Disable();

                if (!Settings.Default.UseSQLServer)
                {
                    if (withDialog)
                    {
                        var loadDialog = Controls.ConnectionsLoadDialog();
                        if (loadDialog.ShowDialog() != DialogResult.OK) return;
                        connectionsLoader.ConnectionFileName = loadDialog.FileName;
                    }
                    else
                    {
                        connectionsLoader.ConnectionFileName = GetStartupConnectionFileName();
                    }

                    CreateBackupFile(Convert.ToString(connectionsLoader.ConnectionFileName));
                }

                connectionsLoader.UseDatabase = Settings.Default.UseSQLServer;
                ConnectionTreeModel = connectionsLoader.LoadConnections(false);
                Windows.TreeForm.ConnectionTreeModel = ConnectionTreeModel;

                if (Settings.Default.UseSQLServer)
                {
                    LastSqlUpdate = DateTime.Now;
                }
                else
                {
                    if (connectionsLoader.ConnectionFileName == GetDefaultStartupConnectionFileName())
                    {
                        Settings.Default.LoadConsFromCustomLocation = false;
                    }
                    else
                    {
                        Settings.Default.LoadConsFromCustomLocation = true;
                        Settings.Default.CustomConsPath = connectionsLoader.ConnectionFileName;
                    }
                }

                // re-enable sql update checking after updates are loaded
                RemoteConnectionsSyncronizer?.Enable();
            }
            catch (Exception ex)
            {
                if (Settings.Default.UseSQLServer)
                {
                    MessageCollector.AddExceptionMessage(Language.strLoadFromSqlFailed, ex);
                    var commandButtons = string.Join("|", Language.strCommandTryAgain, Language.strCommandOpenConnectionFile, string.Format(Language.strCommandExitProgram, Application.ProductName));
                    CTaskDialog.ShowCommandBox(Application.ProductName, Language.strLoadFromSqlFailed, Language.strLoadFromSqlFailedContent, MiscTools.GetExceptionMessageRecursive(ex), "", "", commandButtons, false, ESysIcons.Error, ESysIcons.Error);
                    switch (CTaskDialog.CommandButtonResult)
                    {
                        case 0:
                            LoadConnections(withDialog, update);
                            return;
                        case 1:
                            Settings.Default.UseSQLServer = false;
                            LoadConnections(true, update);
                            return;
                        default:
                            Application.Exit();
                            return;
                    }
                }
                if (ex is FileNotFoundException && !withDialog)
                {
                    MessageCollector.AddExceptionMessage(string.Format(Language.strConnectionsFileCouldNotBeLoadedNew, connectionsLoader.ConnectionFileName), ex, MessageClass.InformationMsg);
                    NewConnections(Convert.ToString(connectionsLoader.ConnectionFileName));
                    return;
                }

                MessageCollector.AddExceptionMessage(string.Format(Language.strConnectionsFileCouldNotBeLoaded, connectionsLoader.ConnectionFileName), ex);
                if (connectionsLoader.ConnectionFileName != GetStartupConnectionFileName())
                {
                    LoadConnections(withDialog, update);
                }
                else
                {
                    MessageBox.Show(frmMain.Default,
                        string.Format(Language.strErrorStartupConnectionFileLoad, Environment.NewLine, Application.ProductName, GetStartupConnectionFileName(), MiscTools.GetExceptionMessageRecursive(ex)),
                        @"Could not load startup file.", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    Application.Exit();
                }
            }
        }
Exemple #19
0
        public static void NewConnections(string filename)
        {
            try
            {
                var connectionsLoader = new ConnectionsLoader();

                if (filename == GetDefaultStartupConnectionFileName())
                {
                    Settings.Default.LoadConsFromCustomLocation = false;
                }
                else
                {
                    Settings.Default.LoadConsFromCustomLocation = true;
                    Settings.Default.CustomConsPath = filename;
                }

                var dirname = GetDirectoryName(filename);
                if(dirname != null)
                    Directory.CreateDirectory(dirname);

                // Use File.Open with FileMode.CreateNew so that we don't overwrite an existing file
                var fileStream = File.Open(filename, FileMode.CreateNew, FileAccess.Write, FileShare.None);
                using (var xmlTextWriter = new XmlTextWriter(fileStream, System.Text.Encoding.UTF8))
                {
                    xmlTextWriter.Formatting = Formatting.Indented;
                    xmlTextWriter.Indentation = 4;
                    xmlTextWriter.WriteStartDocument();
                    xmlTextWriter.WriteStartElement("Connections"); // Do not localize
                    xmlTextWriter.WriteAttributeString("Name", Language.strConnections);
                    xmlTextWriter.WriteAttributeString("Export", "", "False");
                    xmlTextWriter.WriteAttributeString("Protected", "", "GiUis20DIbnYzWPcdaQKfjE2H5jh//L5v4RGrJMGNXuIq2CttB/d/BxaBP2LwRhY");
                    xmlTextWriter.WriteAttributeString("ConfVersion", "", "2.5");
                    xmlTextWriter.WriteEndElement();
                    xmlTextWriter.WriteEndDocument();
                }

                // Load config
                connectionsLoader.ConnectionFileName = filename;
                ConnectionTreeModel = connectionsLoader.LoadConnections(false);
                Windows.TreeForm.ConnectionTreeModel = ConnectionTreeModel;
            }
            catch (Exception ex)
            {
                MessageCollector.AddExceptionMessage(Language.strCouldNotCreateNewConnectionsFile, ex);
            }
        }
 private RootNodeInfo GetRootNodeFromConnectionTreeModel(ConnectionTreeModel connectionTreeModel)
 {
     return (RootNodeInfo)connectionTreeModel.RootNodes.First(node => node is RootNodeInfo);
 }
 public XDocument CompileDocument(ConnectionTreeModel connectionTreeModel, bool fullFileEncryption, bool export)
 {
     var rootNodeInfo = GetRootNodeFromConnectionTreeModel(connectionTreeModel);
     return CompileDocument(rootNodeInfo, fullFileEncryption, export);
 }
Exemple #22
0
 public NodeSearcher(ConnectionTreeModel connectionTreeModel)
 {
     _connectionTreeModel = connectionTreeModel;
 }
 public void Setup(string confCons, string password)
 {
     _xmlConnectionsDeserializer = new XmlConnectionsDeserializer(confCons, password.ConvertToSecureString);
     _connectionTreeModel = _xmlConnectionsDeserializer.Deserialize();
 }
 public void OnetimeSetup()
 {
     _connectionFileContents = Resources.test_rdcman_v2_2_schema1;
     _deserializer = new RemoteDesktopConnectionManagerDeserializer(_connectionFileContents);
     _connectionTreeModel = _deserializer.Deserialize();
 }
Exemple #25
0
 public NodeSearcher(ConnectionTreeModel connectionTreeModel)
 {
     _connectionTreeModel = connectionTreeModel;
 }
 public IEnumerable<ToolStripDropDownItem> CreateToolStripDropDownItems(ConnectionTreeModel connectionTreeModel)
 {
     var rootNodes = connectionTreeModel.RootNodes;
     return CreateToolStripDropDownItems(rootNodes);
 }
 public void Setup()
 {
     _cryptographyProvider = new CryptographyProviderFactory().CreateAeadCryptographyProvider(BlockCipherEngines.AES, BlockCipherModes.GCM);
     _documentCompiler = new XmlConnectionsDocumentCompiler(_cryptographyProvider);
     _connectionTreeModel = SetupConnectionTreeModel();
 }
 public void Setup()
 {
     var encryptor = new AeadCryptographyProvider();
     _serializer = new XmlConnectionsSerializer(encryptor);
     _connectionTreeModel = SetupConnectionTreeModel();
 }