当前位置: 首页>>代码示例>>C#>>正文


C# ILog.IndentScope方法代码示例

本文整理汇总了C#中ILog.IndentScope方法的典型用法代码示例。如果您正苦于以下问题:C# ILog.IndentScope方法的具体用法?C# ILog.IndentScope怎么用?C# ILog.IndentScope使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在ILog的用法示例。


在下文中一共展示了ILog.IndentScope方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: RestoreDatabase

        private void RestoreDatabase(DatabaseBackupInfo db, bool dryRun, ILog log)
        {
            var sb = new StringBuilder();
            var dbName = SqlUtils.ToBracketedIdentifier(db.Name);
            var sqlParams = new SqlParamCollection();

            sb.AppendFormat(
                "USE [master]\n" +
                "IF db_id(@dbName) IS NOT NULL\n" +
                "  ALTER DATABASE {0} SET SINGLE_USER WITH ROLLBACK IMMEDIATE\n" +
                "RESTORE DATABASE {0} FROM DISK = @backupFile WITH FILE = 1, NOUNLOAD, STATS = 5",
                dbName);

            sqlParams.Add("@dbName", SqlDbType.NVarChar).Value = db.Name;
            sqlParams.Add("@backupFile", SqlDbType.NVarChar).Value = db.BackupFilePath;

            if (mDatabaseConnection.Relocate)
            {
                var names = SqlUtils.GetLogicalAndPhysicalNamesFromBackupFile(mDatabaseConnection, db.BackupFilePath);

                var i = 0;
                foreach (var tuple in names)
                {
                    var logical = string.Format("@l{0}", i);
                    var physical = string.Format("@p{0}", i);
                    sb.AppendFormat(",\n  MOVE {0} TO {1}", logical, physical);

                    var destPath = GetRelocation(db.Name, mDatabaseConnection.RelocatePath, tuple.Item2);
                    sqlParams.Add(logical, SqlDbType.NVarChar).Value = tuple.Item1;
                    sqlParams.Add(physical, SqlDbType.NVarChar).Value = destPath;

                    ++i;
                }
            }

            sb.AppendFormat(
                "\nALTER DATABASE {0} SET MULTI_USER\n", dbName);

            log.LogFormat("Restoring {0} from {1}", db.Name, db.BackupFilePath);

            if (!dryRun)
            {
                using (var process = SqlUtils.Exec(mDatabaseConnection, db.Name, sb.ToString(), sqlParams))
                using (log.IndentScope())
                {
                    foreach (var processOutputLine in process.GetOutput())
                    {
                        log.Log(processOutputLine.Line);
                    }
                }
            }

            log.Log("Database restore completed.");
        }
开发者ID:aiedail92,项目名称:DBBranchManager,代码行数:54,代码来源:RestoreDatabasesTransform.cs


注:本文中的ILog.IndentScope方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。