Esempio n. 1
0
        public void RegisterDataSource(DataSource dataSource)
        {
            Util.CheckNotEmpty(dataSource.Name, "DataSource name may not be empty.");
            _app.SystemLog.Info("  Connecting to data source {0}.", dataSource.Name);
            //dataSource.Database.CheckConnectivity();
            lock (_lock) {
                var oldDs = LookupDataSource(dataSource.Name);
                if (oldDs != null)
                {
                    return;
                }
                //create copy, add to it, and then replace with interlock
                IDictionary <string, DataSource> newDict;
                if (_dataSources == null || _dataSources.Count == 0)
                {
                    newDict = new Dictionary <string, DataSource>(StringComparer.OrdinalIgnoreCase);
                }
                else
                {
                    newDict = new Dictionary <string, DataSource>(_dataSources, StringComparer.OrdinalIgnoreCase);
                }
                newDict.Add(dataSource.Name, dataSource);
                System.Threading.Interlocked.Exchange(ref _dataSources, newDict);
            }
            //Invoke upgrade
            _events.OnDataSourceStatusChanging(new DataSourceEventArgs(dataSource, DataSourceEventType.Connecting));
            // Update db model
            var db = dataSource.Database;

            if (db.Settings.UpgradeMode != DbUpgradeMode.Never)
            {
                var updateMgr   = new DbUpgradeManager(dataSource);
                var upgradeInfo = updateMgr.UpgradeDatabase();
                _app.CheckActivationErrors();
                ApplyPostUpgradeMigrations(upgradeInfo);
            }
            _events.OnDataSourceStatusChanging(new DataSourceEventArgs(dataSource, DataSourceEventType.Connected));
        }