Initial commit: BizTalk application catalog
This commit is contained in:
@@ -0,0 +1,115 @@
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Text.RegularExpressions;
|
||||
|
||||
namespace BizTalkApplicationCatalog.Configuration
|
||||
{
|
||||
/// <summary>
|
||||
/// Validiert die Kommandozeile und stellt ausschließlich normalisierte Werte bereit.
|
||||
/// </summary>
|
||||
internal sealed class CommandLineOptions
|
||||
{
|
||||
private static readonly Regex UnsafeEnvironment =
|
||||
new Regex("[^A-Z0-9_-]+", RegexOptions.Compiled | RegexOptions.CultureInvariant);
|
||||
|
||||
public string EnvironmentName { get; private set; }
|
||||
public string OutputDirectory { get; private set; }
|
||||
public string ManagementServer { get; private set; }
|
||||
public string ManagementDatabase { get; private set; }
|
||||
public bool SelfTest { get; private set; }
|
||||
public bool ShowHelp { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// Parst die Argumente. Unbekannte oder unvollständige Optionen werden abgelehnt.
|
||||
/// </summary>
|
||||
public static CommandLineOptions Parse(string[] args)
|
||||
{
|
||||
var result = new CommandLineOptions();
|
||||
for (var index = 0; index < args.Length; index++)
|
||||
{
|
||||
var argument = args[index];
|
||||
switch (argument.ToLowerInvariant())
|
||||
{
|
||||
case "--environment":
|
||||
result.EnvironmentName = Value(args, ref index, argument);
|
||||
break;
|
||||
case "--output":
|
||||
result.OutputDirectory = Value(args, ref index, argument);
|
||||
break;
|
||||
case "--management-server":
|
||||
result.ManagementServer = Value(args, ref index, argument);
|
||||
break;
|
||||
case "--management-database":
|
||||
result.ManagementDatabase = Value(args, ref index, argument);
|
||||
break;
|
||||
case "--self-test":
|
||||
result.SelfTest = true;
|
||||
break;
|
||||
case "--help":
|
||||
case "-h":
|
||||
case "/?":
|
||||
result.ShowHelp = true;
|
||||
break;
|
||||
default:
|
||||
throw new ArgumentException("Unbekannte Option: " + argument);
|
||||
}
|
||||
}
|
||||
|
||||
if (result.SelfTest || result.ShowHelp)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
if (string.IsNullOrWhiteSpace(result.EnvironmentName))
|
||||
{
|
||||
throw new ArgumentException("--environment fehlt.");
|
||||
}
|
||||
|
||||
result.EnvironmentName = UnsafeEnvironment.Replace(
|
||||
result.EnvironmentName.Trim().ToUpperInvariant(), "-").Trim('-');
|
||||
if (result.EnvironmentName.Length == 0)
|
||||
{
|
||||
throw new ArgumentException("--environment enthält keinen gültigen Namen.");
|
||||
}
|
||||
|
||||
if (string.IsNullOrWhiteSpace(result.OutputDirectory))
|
||||
{
|
||||
result.OutputDirectory = Path.Combine(
|
||||
Environment.CurrentDirectory, "BizTalk-Anwendungsinventar", result.EnvironmentName);
|
||||
}
|
||||
|
||||
result.OutputDirectory = Path.GetFullPath(
|
||||
Environment.ExpandEnvironmentVariables(result.OutputDirectory));
|
||||
return result;
|
||||
}
|
||||
|
||||
public static string Usage()
|
||||
{
|
||||
return string.Join(Environment.NewLine, new[]
|
||||
{
|
||||
"BEW BizTalk Application Catalog",
|
||||
string.Empty,
|
||||
"Aufruf:",
|
||||
" BizTalkApplicationCatalog.exe --environment ACC [--output PFAD]",
|
||||
" BizTalkApplicationCatalog.exe --environment PROD [--output PFAD]",
|
||||
string.Empty,
|
||||
"Optionen:",
|
||||
" --management-server NAME Optionaler SQL-Server-Hinweis.",
|
||||
" --management-database NAME Optionale Management-Datenbank.",
|
||||
" --self-test Prüft XLSX-Struktur und Kernlogik ohne BizTalk.",
|
||||
" --help Diese Hilfe."
|
||||
});
|
||||
}
|
||||
|
||||
private static string Value(string[] args, ref int index, string option)
|
||||
{
|
||||
index++;
|
||||
if (index >= args.Length || args[index].StartsWith("--", StringComparison.Ordinal))
|
||||
{
|
||||
throw new ArgumentException("Wert für " + option + " fehlt.");
|
||||
}
|
||||
|
||||
return args[index];
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user