public bool Load(string[] args)
{
StringBuilder sb = new StringBuilder();
for (int i = 0; i < args.Length; i++)
{
sb.Append(args[i]).Append(' ');
}
string line = sb.ToString();
this.ArgumentLine = line;
//char delim = '-';
char[] delims = new char[] { (char)45, (char)8211, (char)65533 }; //'-', '–', '?';
int idx = FindDelimAfterWhitespace(line, 0, delims); //int idx = line.IndexOf(delim);
if (idx == -1)
{
//if we have arguments, but they didn't include flags, it's probably a file,
//look for the file.
if (File.Exists(args[0]))
{
var lines = File.ReadAllLines(args[0]);
sb = new StringBuilder();
foreach (string chunk in lines)
{
if (chunk.StartsWith("#") || chunk.StartsWith("/"))
continue;
if (string.IsNullOrEmpty(chunk))
continue;
string tmpChunk = Utilities.TrimComments(chunk, '#');
sb.Append(tmpChunk.Trim()).Append(" ");
}
line = sb.ToString();
}
else
{
_log.ErrorFormat("The arguments file you provided could not be read: {0}", args[0]);
return false;
}
}
// iterate over our input, copying values to our properties
var thisType = typeof(ImportJob);
idx = FindDelimAfterWhitespace(line, 0, delims); //int idx = line.IndexOf(delim);
while (idx >= 0)
{
int nextSpace = line.IndexOf(' ', idx + 1);
string flag = line.Substring(idx + 1, nextSpace - (idx + 1));
string contents = string.Empty;
idx += 1 + flag.Length;
int end = FindDelimAfterWhitespace(line, idx, delims); //int end = line.IndexOf(delim, idx);
if (end == -1)
{
end = line.Length;
}
if (end > idx)
{
contents = line.Substring(idx, end - idx).Trim();
if (string.IsNullOrEmpty(contents))
{
contents = true.ToString();
}
idx = end;
}
idx = FindDelimAfterWhitespace(line, idx, delims); //idx = line.IndexOf(delim, idx);
// actually set the properties now
for (int p = 0; p < Arguments.Length; p++)
{
var arg = Arguments[p];
if (arg.Flag == flag)
{
var prop = thisType.GetProperty(arg.PropertyName);
object defval = (prop.PropertyType == typeof(AcsState)) ? (object)AcsState.None : null;
prop.SetValue(this, Utilities.GetAsType(prop.PropertyType, contents, defval), null);
break;
}
}
}
return true;
}