示例#1
0
        public virtual void BackupDb(Stream s)
        {
            var dbReader = new DbReader(DbCommand);

            using (var backupCreator = new BackupCreator(new StreamWriter(s), dbReader))
            {
                // Header
                backupCreator.WriteFileHeader();
                // Tables
                var tableNames = dbReader.GetTableNames();
                foreach (var name in tableNames)
                {
                    backupCreator.WriteSqlContent(new Table(name, dbReader.GetTableDdl(name)));
                }
                // Views
                var viewNames = dbReader.GetViewNames();
                foreach (var name in viewNames)
                {
                    backupCreator.WriteSqlContent(new View(name, dbReader.GetViewDdl(name)));
                }
                // Events
                var eventNames = dbReader.GetEventNames();
                foreach (var name in eventNames)
                {
                    backupCreator.WriteSqlContent(new Event(name, dbReader.GetEventDdl(name)));
                }
                // Functions
                var functionNames = dbReader.GetFunctionNames();
                foreach (var name in functionNames)
                {
                    backupCreator.WriteSqlContent(new Function(name, dbReader.GetFunctionDdl(name)));
                }
                // Stored Procedures
                var procedureNames = dbReader.GetProcedureNames();
                foreach (var name in procedureNames)
                {
                    backupCreator.WriteSqlContent(new Procedure(name, dbReader.GetProcedureDdl(name)));
                }
                // Triggers
                var triggerNames = dbReader.GetTriggerNames();
                foreach (var name in triggerNames)
                {
                    backupCreator.WriteSqlContent(new Trigger(name, dbReader.GetTriggerDdl(name)));
                }
                // Writing to Stream Is Complete
                backupCreator.WriteFileFooter();
            }
        }
示例#2
0
 /// <summary>
 ///     Creates a Stream Writer Backup Creator object
 ///     that accepts a "StreamWriter" and "DbReader" as parameters
 /// </summary>
 /// <param name="streamWriter"></param>
 /// <param name="dbReader"></param>
 public BackupCreator(StreamWriter streamWriter, DbReader dbReader)
 {
     _streamWriter = streamWriter;
     _dbReader     = dbReader;
 }