protected DataTable ReadVariablesFile(string filename, DataTable dt)
{
int line = 0;
try
{
if (string.IsNullOrEmpty(_filename))
{
if (!this.LoadFile(filename))
{
_log.ErrorFormat("ImportDesiredVariables failed: the file couldn't be read");
}
}
foreach (List<string> row in this)
{
line++; //base 1
if ((row.Count < 1) || (string.IsNullOrEmpty(row[0])) || (row[0].StartsWith("#")))
{
//skip blank lines / comments
continue;
}
if (row.Count > 2)
{
_log.WarnFormat("Line {0}: too many fields ({1}) provided, using first two", line, row.Count);
}
string variableID = row[0];
string variableAlias = (row.Count > 1) ? row[1] : row[0];
//string marginErrorAlias = Utilities.EnsureMaxLength(Settings.MoEPrefix + variableAlias, 10);
if (variableAlias.Length > 10)
{
_log.WarnFormat("Line {0}: \"{1}\" name was too long, truncating to 10 characters", line, variableAlias);
variableAlias = Utilities.EnsureMaxLength(variableAlias, 10);
}
//////Track duplicates
//AddIntToDict(columnConflicts, line, variableAlias, marginErrorAlias);
//IfSetAddIntToDict(reservedColumns, reservedConflicts, line, variableAlias, marginErrorAlias);
//uniqueColumnNames.Add(variableAlias);
//uniqueColumnNames.Add(marginErrorAlias);
dt.Rows.Add(variableID, variableAlias);//, marginErrorAlias, line);
}
}
catch (Exception ex)
{
_log.Error("ReadVariablesFile: Exception thrown!", ex);
_log.ErrorFormat("Variable Import made it to line {0}:{1}", filename, line);
}
return dt;
}