private string dataStructureToRow(long id)
{
StructuredDataStructure ds = GetDataStructure(id);
StringBuilder builder = new StringBuilder();
bool first = true;
if (ds.Variables != null && ds.Variables.Any())
{
List<Variable> variables = ds.Variables.ToList();
if (VisibleColumns != null)
{
variables = GetSubsetOfVariables(ds.Variables.ToList(), VisibleColumns);
}
variables = SortVariablesOnDatastructure(variables, ds);
foreach (Variable v in variables)
{
string value = v.Label.ToString();
// Add separator if this isn't the first value
if (!first)
builder.Append(AsciiHelper.GetSeperator(Delimeter));
// Implement special handling for values that contain comma or quote
// Enclose in quotes and double up any double quotes
if (value.IndexOfAny(new char[] { '"', ',' }) != -1)
builder.AppendFormat("\"{0}\"", value.Replace("\"", "\"\""));
else
builder.Append(value);
first = false;
// add to variable identifiers
this.VariableIdentifiers.Add
(
new VariableIdentifier
{
id = v.Id,
name = v.Label,
systemType = v.DataAttribute.DataType.SystemType
}
);
}
}
return builder.ToString();
}