示例#1
0
        /// <summary>
        /// Manages the signatures of objects in the schema database
        /// </summary>
        /// <param name="connection">The connection to the database</param>
        /// <param name="schemaGroup">The name of the schema group to modify</param>
        public SchemaRegistry(RecordingDbConnection connection, string schemaGroup)
        {
            SchemaGroup = schemaGroup;
            Connection  = connection;

            // make sure we have a table to work with
            EnsureSchemaTable();

            // load in the entries from the database
            Connection.DoNotLog(() =>
            {
                Entries = Connection.QuerySql(
                    String.Format(CultureInfo.InvariantCulture, "SELECT * FROM [{0}] WHERE SchemaGroup = @SchemaGroup", SchemaRegistryTableName),
                    new Dictionary <string, object>()
                {
                    { "SchemaGroup", schemaGroup }
                }).Select(
                    (dynamic e) => new SchemaRegistryEntry()
                {
                    SchemaGroup   = e.SchemaGroup,
                    ObjectName    = e.ObjectName,
                    Signature     = e.Signature,
                    Type          = (SchemaObjectType)Enum.Parse(typeof(SchemaObjectType), e.Type),
                    OriginalOrder = e.OriginalOrder
                }).ToList();

                // automatically handle the old format for entries
                // WAS: 'ROLE [foo]'
                // NOW: '[foo]'
                foreach (var entry in Entries.Where(e =>
                                                    e.Type == SchemaObjectType.Schema ||
                                                    e.Type == SchemaObjectType.Login ||
                                                    e.Type == SchemaObjectType.User ||
                                                    e.Type == SchemaObjectType.Role ||
                                                    e.Type == SchemaObjectType.Queue ||
                                                    e.Type == SchemaObjectType.Service))
                {
                    entry.ObjectName = _registryUpgradeRegex.Replace(entry.ObjectName, "");
                }

                // automatically reformat names to fully qualified name
                // WAS: '[foo]'
                // NOW: '[dbo].[foo]'
                foreach (var entry in Entries)
                {
                    entry.ObjectName = new SchemaObject(entry.Type, entry.ObjectName, null).Name;
                }
            });
        }
 /// <summary>
 /// Determine if this is a type of object that we can modify.
 /// </summary>
 /// <param name="type">The type of the object.</param>
 /// <returns>True if we know how to drop the object.</returns>
 internal bool CanModify(SchemaInstaller.InstallContext context, RecordingDbConnection connection)
 {
     return(connection.DoNotLog(() => _implementation.CanModify(context, connection)));
 }