public List<EDStation> fromCSV(String[] CSV_Strings, ref List<EDSystem> foundSystems, ref List<CsvRow> csvRowList)
{
List<EDStation> foundValues = new List<EDStation>();
Dictionary<String, Int32> foundIndex = new Dictionary<String, Int32>();
Dictionary<String, Int32> foundSystemIndex = new Dictionary<String, Int32>();
String LastID = "";
EDSystem LastSystem = null;
String currentID = "";
EDStation currentStation = null;
Int32 Index = 0;
Dictionary<String, Int32> commodityIDCache = new Dictionary<string,Int32>(); // quick cache for finding commodity names
Int32 currentItem = 0;
ProgressEventArgs eva;
try
{
eva = new ProgressEventArgs() { Info="converting data...", CurrentValue=currentItem, TotalValue=CSV_Strings.GetUpperBound(0)+1, AddSeparator = true };
sendProgressEvent(eva);
if(foundSystems != null)
foundSystems.Clear();
else
foundSystems = new List<EDSystem>();
foreach (String CSV_String in CSV_Strings)
{
if(!String.IsNullOrEmpty(CSV_String.Trim()))
{
CsvRow currentRow = new CsvRow(CSV_String);
if(csvRowList != null)
csvRowList.Add(currentRow);
currentID = currentRow.StationID;
if(!LastID.Equals(currentID, StringComparison.InvariantCultureIgnoreCase))
{
if(currentStation != null)
currentStation.ListingExtendMode = false;
if(foundIndex.TryGetValue(currentID, out Index))
currentStation = foundValues[Index];
else
{
currentStation = new EDStation(currentRow);
foundValues.Add(currentStation);
foundIndex.Add(currentID, foundValues.Count-1);
}
LastID = currentRow.StationID;
currentStation.ListingExtendMode = true;
if((LastSystem == null) || (!LastSystem.Name.Equals(currentRow.SystemName, StringComparison.InvariantCultureIgnoreCase)))
{
if(foundSystemIndex.TryGetValue(currentRow.SystemName, out Index))
LastSystem = foundSystems[Index];
else
{
LastSystem = new EDSystem();
LastSystem.Name = currentRow.SystemName;
if(LastSystem.Id == 0)
LastSystem.Id = currentStation.SystemId;
foundSystems.Add(LastSystem);
foundSystemIndex.Add(currentRow.SystemName, foundSystems.Count-1);
}
}
}
currentStation.addListing(currentRow, ref commodityIDCache);
}
eva = new ProgressEventArgs() { Info="converting data...", CurrentValue=currentItem, TotalValue=CSV_Strings.GetUpperBound(0)+1};
sendProgressEvent(eva);
if(eva.Cancelled)
break;
currentItem++;
}
if(currentStation != null)
currentStation.ListingExtendMode = false;
eva = new ProgressEventArgs() { Info="converting data...", CurrentValue=currentItem, TotalValue=CSV_Strings.GetUpperBound(0)+1, ForceRefresh=true};
sendProgressEvent(eva);
return foundValues;
}
catch (Exception ex)
{
throw new Exception("Error while getting station values from CSV-String", ex);
}
}