示例#1
0
 public void RegisterDataSource(DataSource dataSource) {
   Util.CheckNotEmpty(dataSource.Name, "DataSource name may not be empty.");
   //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)
       newDict = new Dictionary<string, DataSource>(StringComparer.InvariantCultureIgnoreCase);
     else
       newDict = new Dictionary<string, DataSource>(_dataSources, StringComparer.InvariantCultureIgnoreCase);
     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();
     ApplyMigrations(upgradeInfo); 
   }
   _events.OnDataSourceStatusChanging(new DataSourceEventArgs(dataSource, DataSourceEventType.Connected));
 }