Ejemplo n.º 1
0
        public void Save(ConnectionTreeModel connectionTreeModel)
        {
            if (SqlUserIsReadOnly())
            {
                Runtime.MessageCollector.AddMessage(MessageClass.InformationMsg, "Trying to save connection tree but the SQL read only checkbox is checked, aborting!");
                return;
            }


            using (var sqlConnector = DatabaseConnectorFactory.SqlDatabaseConnectorFromSettings())
            {
                sqlConnector.Connect();
                var databaseVersionVerifier = new SqlDatabaseVersionVerifier(sqlConnector);

                if (!databaseVersionVerifier.VerifyDatabaseVersion())
                {
                    Runtime.MessageCollector.AddMessage(MessageClass.ErrorMsg, Language.strErrorConnectionListSaveFailed);
                    return;
                }

                var rootTreeNode = connectionTreeModel.RootNodes.OfType <RootNodeInfo>().First();

                UpdateRootNodeTable(rootTreeNode, sqlConnector);
                UpdateConnectionsTable(rootTreeNode, sqlConnector);
                UpdateUpdatesTable(sqlConnector);
            }
        }
        public ConnectionTreeModel Load()
        {
            var connector               = DatabaseConnectorFactory.SqlDatabaseConnectorFromSettings();
            var dataProvider            = new SqlDataProvider(connector);
            var metaDataRetriever       = new SqlDatabaseMetaDataRetriever();
            var databaseVersionVerifier = new SqlDatabaseVersionVerifier(connector);
            var cryptoProvider          = new LegacyRijndaelCryptographyProvider();

            var metaData = metaDataRetriever.GetDatabaseMetaData(connector) ??
                           HandleFirstRun(metaDataRetriever, connector);
            var decryptionKey = GetDecryptionKey(metaData);

            if (!decryptionKey.Any())
            {
                throw new Exception("Could not load SQL connections");
            }

            databaseVersionVerifier.VerifyDatabaseVersion(metaData.ConfVersion);
            var dataTable      = dataProvider.Load();
            var deserializer   = new DataTableDeserializer(cryptoProvider, decryptionKey.First());
            var connectionTree = deserializer.Deserialize(dataTable);

            ApplyLocalConnectionProperties(connectionTree.RootNodes.First(i => i is RootNodeInfo));
            return(connectionTree);
        }
        public ConnectionTreeModel Load()
        {
            var connector               = DatabaseConnectorFactory.SqlDatabaseConnectorFromSettings();
            var dataProvider            = new SqlDataProvider(connector);
            var databaseVersionVerifier = new SqlDatabaseVersionVerifier(connector);

            databaseVersionVerifier.VerifyDatabaseVersion();
            var dataTable    = dataProvider.Load();
            var deserializer = new DataTableDeserializer();

            return(deserializer.Deserialize(dataTable));
        }
Ejemplo n.º 4
0
        public void Save(ConnectionTreeModel connectionTreeModel, string propertyNameTrigger = "")
        {
            var rootTreeNode = connectionTreeModel.RootNodes.OfType <RootNodeInfo>().First();

            UpdateLocalConnectionProperties(rootTreeNode);

            if (PropertyIsLocalOnly(propertyNameTrigger))
            {
                Runtime.MessageCollector.AddMessage(MessageClass.DebugMsg,
                                                    $"Property {propertyNameTrigger} is local only. Not saving to database.");
                return;
            }

            if (SqlUserIsReadOnly())
            {
                Runtime.MessageCollector.AddMessage(MessageClass.InformationMsg,
                                                    "Trying to save connection tree but the SQL read only checkbox is checked, aborting!");
                return;
            }

            using (var dbConnector = DatabaseConnectorFactory.DatabaseConnectorFromSettings())
            {
                dbConnector.Connect();
                var databaseVersionVerifier = new SqlDatabaseVersionVerifier(dbConnector);
                var metaDataRetriever       = new SqlDatabaseMetaDataRetriever();
                var metaData = metaDataRetriever.GetDatabaseMetaData(dbConnector);

                if (!databaseVersionVerifier.VerifyDatabaseVersion(metaData.ConfVersion))
                {
                    Runtime.MessageCollector.AddMessage(MessageClass.ErrorMsg,
                                                        Language.strErrorConnectionListSaveFailed);
                    return;
                }

                metaDataRetriever.WriteDatabaseMetaData(rootTreeNode, dbConnector);
                UpdateConnectionsTable(rootTreeNode, dbConnector);
                UpdateUpdatesTable(dbConnector);
            }

            Runtime.MessageCollector.AddMessage(MessageClass.DebugMsg, "Saved connections to database");
        }
Ejemplo n.º 5
0
        public ConnectionTreeModel LoadConnections(bool import)
        {
            IDeserializer deserializer;

            if (UseDatabase)
            {
                var connector               = new SqlDatabaseConnector();
                var dataProvider            = new SqlDataProvider(connector);
                var databaseVersionVerifier = new SqlDatabaseVersionVerifier(connector);
                databaseVersionVerifier.VerifyDatabaseVersion();
                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);
        }
Ejemplo n.º 6
0
        private void SaveToSql()
        {
            var sqlConnector = new SqlDatabaseConnector();

            sqlConnector.Connect();
            var databaseVersionVerifier = new SqlDatabaseVersionVerifier(sqlConnector);

            if (!databaseVersionVerifier.VerifyDatabaseVersion())
            {
                Runtime.MessageCollector.AddMessage(MessageClass.ErrorMsg, Language.strErrorConnectionListSaveFailed);
                return;
            }

            var rootTreeNode = Runtime.ConnectionTreeModel.RootNodes.OfType <RootNodeInfo>().First();

            UpdateRootNodeTable(rootTreeNode, sqlConnector);
            UpdateConnectionsTable(rootTreeNode, sqlConnector);
            UpdateUpdatesTable(sqlConnector);

            sqlConnector.Disconnect();
            sqlConnector.Dispose();
        }