/// <summary>
/// Validate the whole FileStream line by line until no more come.
/// Convert the lines into a datatuple based on the datastructure.
/// Return value is a list of datatuples
/// </summary>
/// <remarks>A list of errorMessages is filled when the fil is not valid </remarks>
/// <seealso cref="AsciiFileReaderInfo"/>
/// <seealso cref="DataTuple"/>
/// <seealso cref="StructuredDataStructure"/>
/// <param name="FileStream">Stream of the FileStream</param>
/// <param name="fileName">name of the FileStream</param>
/// <param name="fri">AsciiFileReaderInfo needed</param>
/// <param name="sds">StructuredDataStructure</param>
/// <param name="datasetId">Id of the dataset</param>
public void ValidateFile(Stream file, string fileName, long datasetId)
{
this.FileStream = file;
this.FileName = fileName;
this.DatasetId = datasetId;
AsciiFileReaderInfo fri = (AsciiFileReaderInfo)Info;
// Check params
if (this.FileStream == null)
{
this.ErrorMessages.Add(new Error(ErrorType.Other, "File not exist"));
}
if (!this.FileStream.CanRead)
{
this.ErrorMessages.Add(new Error(ErrorType.Other, "File is not readable"));
}
if (this.Info.Variables <= 0)
{
this.ErrorMessages.Add(new Error(ErrorType.Other, "Startrow of Variable can´t be 0"));
}
if (this.Info.Data <= 0)
{
this.ErrorMessages.Add(new Error(ErrorType.Other, "Startrow of Data can´t be 0"));
}
if (this.ErrorMessages.Count == 0)
{
using (StreamReader streamReader = new StreamReader(file, encoding))
{
string line;
int index = 1;
char seperator = AsciiFileReaderInfo.GetSeperator(fri.Seperator);
bool dsdIsOk = false;
while ((line = streamReader.ReadLine()) != null)
{
if (index == this.Info.Variables)
{
dsdIsOk = ValidateDatastructure(line, seperator);
// if data is not in the correct order, create a dictionary with the new position
}
if (dsdIsOk && index >= this.Info.Data && !string.IsNullOrEmpty(line) && !isEmpty(line, seperator))
{
var r = rowToList(line, seperator);
var e = ValidateRow(r, index);
this.ErrorMessages = this.ErrorMessages.Union(e).ToList();
if (this.ErrorMessages.Count >= 1000)
{
break;
}
}
index++;
}
}
}
}