本文整理汇总了C#中Args.Contains方法的典型用法代码示例。如果您正苦于以下问题:C# Args.Contains方法的具体用法?C# Args.Contains怎么用?C# Args.Contains使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Args
的用法示例。
在下文中一共展示了Args.Contains方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Execute
protected override void Execute(Args args)
{
var root = args.GetValue("directory");
var server = args.GetValue("server");
var database = args.GetValue("database");
if (args.Contains("quiet"))
{
Console.WriteLine("Exctracting artefacts from {0} {1}", server, database);
}
else
{
Console.Write("Exctract artefacts from {0} {1} (y/n)? ", server, database);
if (!Console.ReadLine().Equals("y", StringComparison.CurrentCultureIgnoreCase)) return;
}
var filters = new[]
{
"^_.+$",
"^(sp|fn)_.*diagram.*$",
"^.+_dts_.+$",
"^.+_gen_.+$",
"^conv_.+$",
"^IsScriptExecuted$",
"^syncobj_.+$",
"^sysextendedarticlesview$"
};
var types = new[]
{
new TypeDef{Key = "FN", Name = "function", Dir = "Functions"},
new TypeDef{Key = "P", Name = "procedure", Dir = "StoredProcedures"},
new TypeDef{Key = "V", Name = "view", Dir = "Views"}
};
var schemas = Database.Query<Item>("select * from sys.schemas").ToDictionary(x => x.schema_id, x => x.name);
foreach (var type in types)
{
var dir = Path.Combine(root, type.Dir);
MakeSureDirectoryExists(dir);
var files = Directory.GetFiles(dir, "*.sql", SearchOption.AllDirectories).ToList();
foreach (var file in files.ToList())
{
var fileNameWithoutExtension = Path.GetFileNameWithoutExtension(file);
if (!filters.Any(x => Regex.IsMatch(fileNameWithoutExtension, x, RegexOptions.IgnoreCase))) continue;
RemoveReadOnlyAttribute(file);
File.Delete(file);
files.Remove(file);
}
using (TemporaryConsoleColorError())
foreach (var @group in files.GroupBy(x => Path.GetFileName(x).ToLower()).Where(x => x.Count() > 1))
{
Console.WriteLine("duplicate filenames");
foreach (var file in @group)
Console.WriteLine(" " + file);
}
var filesByLowerCaseFileName = files.ToDictionary(x => Path.GetFileName(x).ToLower());
var selectItemsSql = string.Format("select name, schema_id from sys.objects where type = '{0}'", type.Key);
foreach (var item in Database.Query<Item>(selectItemsSql))
{
if (filters.Any(x => Regex.IsMatch(item.name, x, RegexOptions.IgnoreCase))) continue;
var schema = schemas[item.schema_id];
var filename = (schema == "dbo" ? item.name : schema + "." + item.name) + ".sql";
string targetPath;
if (!filesByLowerCaseFileName.TryGetValue(filename.ToLower(), out targetPath))
targetPath = Path.Combine(dir, filename);
RemoveReadOnlyAttribute(targetPath);
File.WriteAllText(targetPath, CreateScript(schema, item.name, type));
filesByLowerCaseFileName.Remove(filename.ToLower());
}
foreach (var file in filesByLowerCaseFileName.Values)
{
RemoveReadOnlyAttribute(file);
File.Delete(file);
}
}
}
示例2: Execute
protected override void Execute(Args args)
{
Console.WriteLine();
Console.WriteLine("Server " + args.GetValue("server"));
Console.WriteLine("Database " + args.GetValue("database"));
const string isInitialized =
"select * from INFORMATION_SCHEMA.TABLES where TABLE_SCHEMA = 'dbo' and TABLE_NAME = 'ScriptLog'";
if (!Database.Query(isInitialized).Any()) throw new ApplicationException("Database has not been intialized");
var scriptLogEntries = ScriptLogEntry.Load(Database).ToList();
var lastScriptLogEntry = GetLastScriptLogEntry(scriptLogEntries);
var executedScriptFileNames = GetExecutedScriptFileNames(scriptLogEntries);
var directory = args.GetValue("directory");
var recursive = args.Contains("recursive");
var scriptsNotExecuted = ScriptFile.Load(directory, recursive)
.Where(x => !executedScriptFileNames.Contains(x.VersionAndNumber))
.ToList();
var obsoleteScripts =
scriptsNotExecuted.Where(
x =>
x.GetComparableVersion() <
lastScriptLogEntry.GetComparableVersion(IncludeScriptNumber.Yes)).ToList();
var newScripts =
scriptsNotExecuted.Where(
x =>
x.GetComparableVersion() >
lastScriptLogEntry.GetComparableVersion(IncludeScriptNumber.No)).ToList();
Console.WriteLine();
Console.Write("Current version " + lastScriptLogEntry.Version);
if (lastScriptLogEntry.ScriptNumber.HasValue)
Console.Write("_" + lastScriptLogEntry.ScriptNumber);
Console.WriteLine();
if (obsoleteScripts.Any())
{
using (TemporaryConsoleColorWarning())
{
Console.WriteLine();
Console.WriteLine("Scripts that won't be executed");
foreach (var scriptFile in obsoleteScripts)
Console.WriteLine(" {0}", scriptFile.FileName);
}
}
if (!newScripts.Any())
{
Console.WriteLine();
Console.WriteLine("Did not find any scripts to execute");
return;
}
Console.WriteLine();
Console.WriteLine("Scripts that will be executed");
foreach (var scriptFile in newScripts)
{
Console.Write(" {0}", scriptFile.FileName);
if (scriptFile.Version == lastScriptLogEntry.Version &&
scriptFile.Number < lastScriptLogEntry.ScriptNumber.GetValueOrDefault())
using (TemporaryConsoleColorWarning())
Console.Write(" - older than current version");
Console.WriteLine();
}
if (!args.Contains("quiet"))
{
Console.WriteLine();
Console.Write("Continue (y/n): ");
if (!"y".Equals(Console.ReadLine(), StringComparison.CurrentCultureIgnoreCase))
return;
}
var includesNotFound = new List<string>();
var includesWithErrors = new Dictionary<string, IncludedScriptState>(StringComparer.CurrentCultureIgnoreCase);
var stopwatch = Stopwatch.StartNew();
foreach (var scriptFile in newScripts)
{
var scriptFileStopwatch = Stopwatch.StartNew();
Console.WriteLine();
Console.WriteLine("{0}", scriptFile.FileName);
Database.Execute(x =>
{
foreach (var batch in scriptFile.GetBatches())
{
var batchStopwatch = Stopwatch.StartNew();
var result = x.Execute(batch.Sql);
Console.WriteLine(" lines {0}-{1} affected {2} rows, executed in {3}",
batch.FromLine,
batch.ToLine,
result,
Format(batchStopwatch.Elapsed));
}
foreach (var includedScript in scriptFile.GetIncludes())
{
try
{
//.........这里部分代码省略.........