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);
        }
Ejemplo n.º 2
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 SqlConnectionsUpdateChecker()
 {
     _sqlConnector           = DatabaseConnectorFactory.SqlDatabaseConnectorFromSettings();
     _sqlQuery               = new SqlCommand("SELECT * FROM tblUpdate", _sqlConnector.SqlConnection);
     _lastUpdateTime         = default(DateTime);
     _lastDatabaseUpdateTime = default(DateTime);
 }
        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.º 5
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 sqlConnector = DatabaseConnectorFactory.SqlDatabaseConnectorFromSettings())
            {
                sqlConnector.Connect();
                var databaseVersionVerifier = new SqlDatabaseVersionVerifier(sqlConnector);
                var metaDataRetriever       = new SqlDatabaseMetaDataRetriever();
                var metaData = metaDataRetriever.GetDatabaseMetaData(sqlConnector);

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

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

            Runtime.MessageCollector.AddMessage(MessageClass.DebugMsg, "Saved connections to database");
        }