示例#1
0
        // We cannot use regular access thru EntitySession - db info/version loads at the very start of connecting to db;
        // the entity app is not ready yet (schema not updated, etc).
        public DbVersionInfo LoadDbInfo(DbSettings settings, string appName, Vita.Data.Driver.DbModelLoader loader)
        {
            var thisSchema       = settings.ModelConfig.GetSchema(this.Area);
            var prefix           = settings.ModelConfig.Options.IsSet(DbOptions.AddSchemaToTableNames) ? thisSchema + "_" : string.Empty;
            var dbInfoName       = prefix + "DbInfo";
            var dbModuleInfoName = prefix + "DbModuleInfo";

            if (!loader.TableExists(thisSchema, dbInfoName))
            {
                return(null);
            }
            try {
                var dbInfo = new DbVersionInfo();
                var sql    = settings.Driver.GetDirectSelectAllSql(thisSchema, dbInfoName);
                var dt     = loader.ExecuteSelect(sql);
                var appRow = dt.FindRow("AppName", appName);
                if (appRow != null)
                {
                    dbInfo.InstanceType = (DbInstanceType)appRow.GetAsInt("InstanceType");
                    var     strVersion = appRow.GetAsString("Version");
                    Version dbVersion;
                    if (Version.TryParse(strVersion, out dbVersion))
                    {
                        dbInfo.Version = dbVersion;
                    }
                    // 'Values' column appears in v 1.1
                    if (dt.HasColumn("Values"))
                    {
                        var strValues = appRow.GetAsString("Values");
                        DeserializeValues(dbInfo, strValues);
                    }
                } //if appRow
                //Read modules
                sql = settings.Driver.GetDirectSelectAllSql(thisSchema, dbModuleInfoName);
                dt  = loader.ExecuteSelect(sql);
                foreach (DbRow row in dt.Rows)
                {
                    var     moduleName       = row.GetAsString("ModuleName");
                    var     schema           = row.GetAsString("Schema");
                    var     strModuleVersion = row.GetAsString("Version");
                    Version v;
                    if (!Version.TryParse(strModuleVersion, out v))
                    {
                        v = null;
                    }
                    dbInfo.Modules.Add(new ModuleDbVersionInfo(schema, moduleName, v));
                }
                return(dbInfo);
            } catch (Exception ex) {
                Trace.WriteLine("Failed to load DbInfo record:  " + ex.ToLogString());
                //Debugger.Break();
                return(null);
            }
        } //method
示例#2
0
 public DbVersionInfo LoadDbVersionInfo(DbModelLoader loader)
 {
     var infoProvider = _database.Settings.DbInfoProvider;
       if (infoProvider == null)
     return null;
       var versionInfo = infoProvider.LoadDbInfo(_database.Settings, _app.AppName, loader);
       loader.VersionInfo = versionInfo;
       return versionInfo;
 }