Пример #1
0
        /// <summary>
        /// Get the default server schema compiled from the database.
        /// For a config variable, we fetch a static defined server, database and schema from the application's metadata to show "intellisence".
        /// </summary>
        /// <param name="defaultMetadatas">Metadatas of the plain old database</param>
        /// <param name="serverId">Could be an Id like 0 or a variable like {$KEY{SERVER_VALUE}} OR {$SERVER_SOURCE{1}}.</param>
        private static ServerMetadata GetServerMetadata(AppMetadata defaultMetadatas, string serverId)
        {
            if (serverId == null)
            {
                throw new ArgumentNullException("defaultMetadata");
            }

            //If is a serverId
            Int16 id;

            if (Int16.TryParse(serverId, out id))
            {
                if (defaultMetadatas.ContainsKey(id))
                {
                    return(defaultMetadatas[id]);
                }
            }

            //If is a variable
            var configVar = serverId.ParseConfigVariable();

            if (configVar != null && configVar.Server != 0 && defaultMetadatas.ContainsKey(configVar.Server))
            {
                return(defaultMetadatas[configVar.Server]);
            }

            throw new ConfigurationException(String.Format("Server not found in the configuration. Id : {0}", serverId));
        }
Пример #2
0
        /// <summary>
        /// Get the default schema compiled from the database.
        /// For a config variable, we fetch a static defined server, database and schema from the application's metadata to show "intellisence".
        /// </summary>
        /// <param name="schemaName">Could be a name like DBO or a variable like {$KEY{SERVER_VALUE}{DATABASE_VALUE}{SCHEMA_VALUE}}
        ///  OR {$DATABASE_SOURCE{1}{myDb}{dbo}}.</param>
        /// <param name="databaseMetadata">Metadatas</param>
        /// <param name="appMetadata">App metadata</param>
        private static SchemaMetadata GetSchemaMetadata(DatabaseMetadata databaseMetadata, AppMetadata appMetadata, string schemaName)
        {
            if (String.IsNullOrEmpty(schemaName))
            {
                throw new ArgumentNullException("databaseMetadata");
            }

            schemaName = schemaName.ToLower();

            //If is a schema name
            if (databaseMetadata.ContainsKey(schemaName))
            {
                return(databaseMetadata[schemaName]);
            }

            //If is a variable
            var v = schemaName.ParseConfigVariable();

            if (v != null &&
                appMetadata.ContainsKey(v.Server) &&
                appMetadata[v.Server].ContainsKey(v.Database) &&
                appMetadata[v.Server][v.Database].ContainsKey(v.Schema))
            {
                return(appMetadata[v.Server][v.Database][v.Schema]);
            }

            throw new ConfigurationException(String.Format("Schema not found in the configuration. Name : {0}", schemaName));
        }
Пример #3
0
        /// <summary>
        /// Get the default database schema compiled from the database.
        /// For a config variable, we fetch a static defined server, database and schema from the application's metadata to show "intellisence".
        /// </summary>
        /// <param name="databaseName">Could be a name like MyDb or a variable like {$KEY{SERVER_VALUE}{DATABASE_VALUE}} OR {$DATABASE_SOURCE{1}{myDb}}.</param>
        /// <param name="parentMetadata">Metadatas</param>
        /// <param name="appMetadata">App metadata</param>
        private static DatabaseMetadata GetDatabaseMetadata(ServerMetadata parentMetadata, AppMetadata appMetadata, string databaseName)
        {
            if (String.IsNullOrEmpty(databaseName))
            {
                throw new ArgumentNullException("databaseName");
            }

            databaseName = databaseName.ToLower();

            //If is a database name
            if (parentMetadata.ContainsKey(databaseName))
            {
                return(parentMetadata[databaseName]);
            }

            //If is a variable
            var v = databaseName.ParseConfigVariable();

            if (v != null &&
                appMetadata.ContainsKey(v.Server) &&
                appMetadata[v.Server].ContainsKey(v.Database))
            {
                return(appMetadata[v.Server][v.Database]);
            }

            throw new ConfigurationException(String.Format("Database not found in the configuration. Name : {0}", databaseName));
        }