/// <summary>
        /// Initializes a new instance of the ReliableCommand class, and bind it to the specified ReliableConnection and innerCommand.
        /// </summary>
        /// <param name="retryStrategy">The retry strategy to use for the command.</param>
        /// <param name="innerCommand">The innerCommand to bind to.</param>
        public RecordingDbCommand(DbCommand innerCommand, RecordingDbConnection recordingConnection)
        {
            if (innerCommand is RecordingDbCommand)
            {
                throw new InvalidOperationException("Cannot record from within a RecordingDbCommand");
            }

            InnerCommand        = innerCommand;
            RecordingConnection = recordingConnection;
        }
Example #2
0
        public static DbConnection Unwrap(this DbConnection connection)
        {
            RecordingDbConnection recording = connection as RecordingDbConnection;

            if (recording != null)
            {
                return(recording.InnerConnection.Unwrap());
            }

            return(connection);
        }
Example #3
0
 /// <summary>
 /// Verify that all of the objects are in the database.
 /// </summary>
 /// <param name="connection">The connection to use for testing.</param>
 public void Verify(DbConnection connection)
 {
     using (RecordingDbConnection recordingConnection = new RecordingDbConnection(connection))
     {
         foreach (SchemaObject schemaObject in this)
         {
             if (!schemaObject.Exists(recordingConnection))
             {
                 throw new SchemaException(String.Format(CultureInfo.InvariantCulture, "SchemaObject {0} was not in the database", schemaObject.Name));
             }
         }
     }
 }
Example #4
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)));
 }
 internal bool Exists(RecordingDbConnection connection)
 {
     return(_implementation.Exists(connection));
 }
 /// <summary>
 /// Install the object into the database
 /// </summary>
 /// <param name="connection">The database connection to use</param>
 internal void Install(RecordingDbConnection connection, IEnumerable <SchemaObject> objects)
 {
     _implementation.Install(connection, objects);
 }