public InputParameters(string[] args)
{
if (args.Length == 0)
{
_DisplayUsage = true;
return;
}
for (int _Index = 0; _Index < args.Length; _Index++)
{
switch (args[_Index])
{
case "-U":
case "/U":
this._UserID = args[++_Index];
break;
case "-P":
case "/P":
if ((args.Length >= (_Index + 2))
&& !args[_Index + 1].StartsWith("-", StringComparison.Ordinal)
&& !args[_Index + 1].StartsWith("/", StringComparison.Ordinal))
{
this._Password = args[++_Index];
}
break;
case "-S":
case "/S":
this._Server = args[++_Index];
break;
case "-d":
case "/d":
this._DatabaseName = args[++_Index];
break;
case "-H":
case "/H":
this._WorkstationName = args[++_Index];
break;
case "-Q":
case "/Q":
if ((args.Length >= (_Index + 2))
&& !args[_Index + 1].StartsWith("-", StringComparison.Ordinal)
&& !args[_Index + 1].StartsWith("/", StringComparison.Ordinal))
{
this._Query = args[++_Index].TrimEnd(null);
}
break;
case "-l":
case "/l":
Int32.TryParse(args[++_Index], out this._LoginTimeout);
if (this.LoginTimeout < 0)
{
throw new ArgumentException(String.Concat("Invalid Connect / Login Timeout value: ",
this.LoginTimeout, "; the value must be >= 0."), "-l");
}
break;
case "-t":
case "/t":
Int32.TryParse(args[++_Index], out this._QueryTimeout);
if (this.QueryTimeout < 0)
{
throw new ArgumentException(String.Concat("Invalid Query / Command Timeout value: ",
this.QueryTimeout, "; the value must be >= 0."), "-t");
}
break;
case "-K":
case "/K":
if ((args.Length >= (_Index + 2))
&& !args[_Index + 1].StartsWith("-", StringComparison.Ordinal)
&& !args[_Index + 1].StartsWith("/", StringComparison.Ordinal))
{
if (!Enum.TryParse<ApplicationIntent>(args[++_Index], out this._AppIntent))
{
throw new ArgumentException(String.Concat("Invalid ApplicationIntent value: ",
args[_Index], ".\nValid values are: ReadWrite and ReadOnly."), "-K");
}
}
break;
case "-N":
case "/N":
this._EncryptConnection = true;
break;
case "-C":
case "/C":
this._TrustServerCertificate = true;
break;
case "-M":
case "/M":
this._MultiSubnetFailover = true;
break;
case "-o":
case "/o":
this._OutputFile = args[++_Index].Trim();
break;
case "-s":
case "/s":
this._ColumnSeparator = args[++_Index];
break;
case "-a":
case "/a":
UInt16.TryParse(args[++_Index], out this._PacketSize);
if (this.PacketSize < 512)
{
throw new ArgumentException(String.Concat("Invalid PacketSize value: ",
this.PacketSize, "; the value must be between 512 and 32767."), "-a");
}
break;
case "-u":
case "/u":
this._OutputEncoding = new UnicodeEncoding();
break;
case "-i":
case "/i":
if ((args.Length >= (_Index + 2))
&& !args[_Index + 1].StartsWith("-", StringComparison.Ordinal)
&& !args[_Index + 1].StartsWith("/", StringComparison.Ordinal))
{
foreach(string _File in args[++_Index].Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries))
{
if (File.Exists(_File))
{
this._InputFiles.Add(_File);
}
else
{
throw new ArgumentException(String.Concat("The input file \"", _File, "\" could not be found."), "-i");
}
}
}
break;
case "-c":
case "/c":
if ((args.Length >= (_Index + 2))
&& !args[_Index + 1].StartsWith("-", StringComparison.Ordinal)
&& !args[_Index + 1].StartsWith("/", StringComparison.Ordinal))
{
this._BatchTerminator = args[++_Index].Trim();
}
break;
case "-an":
case "/an":
this._ApplicationName = args[++_Index];
break;
case "-ad":
case "/ad":
if ((args.Length >= (_Index + 2))
&& !args[_Index + 1].StartsWith("-", StringComparison.Ordinal)
&& !args[_Index + 1].StartsWith("/", StringComparison.Ordinal))
{
this._AttachDBFilename = args[++_Index].Trim();
}
break;
case "-cs":
case "/cs":
this._ConnectionString = args[++_Index];
break;
case "-ra":
case "/ra":
this._RowsAffectedDestination = args[++_Index];
break;
case "-mf":
case "/mf":
this._MessagesFile = args[++_Index].Trim();
break;
case "-ef":
case "/ef":
this._ErrorFile = args[++_Index];
break;
case "-oh":
case "/oh":
switch (args[++_Index].ToUpperInvariant())
{
case "OVERWRITE":
this._OutputFileAppend = false;
break;
case "APPEND":
this._OutputFileAppend = true;
break;
case "ERROR":
// The existence check cannot be done immediately due to no enforced
// order of input parameters: "-o" might not have been parsed yet.
this._CheckForExistingOutputFile = true;
break;
default:
throw new ArgumentException(String.Concat("Invalid OutputFileHandling value: ",
args[_Index], ".\nValid values are: Overwrite, Append, and Error."), "-oh");
}
break;
case "-help":
case "-?":
case "/help":
case "/?":
this._DisplayUsage = true;
break;
case "-debug":
case "/debug":
if ((args.Length >= (_Index + 2))
&& !args[_Index + 1].StartsWith("-", StringComparison.Ordinal)
&& !args[_Index + 1].StartsWith("/", StringComparison.Ordinal))
{
this._DebugInfoFile = args[++_Index].Trim();
}
break;
default:
throw new ArgumentException("Invalid parameter specified.", args[_Index]);
} // switch (args[_Index])
} // for (int _Index = 0; _Index < args.Length; _Index++)
if (!this.DisplayUsage)
{
ValidateParameters();
}
}