/// <summary> /// Imports the prices from a list of csv-strings in EDDB format /// </summary> /// <param name="CSV_Strings">data to import</param> /// <param name="importBehaviour">filter, which prices to import</param> /// <param name="dataSource">if data has no information about the datasource, this setting will count</param> public void ImportPricesFromEDDBStrings(String[] CSV_Strings, enImportBehaviour importBehaviour, enDataSource dataSource, PriceImportParameters importParams) { List<EDStation> StationData; Boolean updateTables = false; ProgressEventArgs eva=new ProgressEventArgs(); Int32 initialSize=0; try { StationData = fromCSV_EDDB(CSV_Strings); if(importParams != null) { DataTable data = Program.Data.GetNeighbourSystems(importParams.SystemID, importParams.Radius); String info = "filter data to the bubble (radius " + importParams.Radius+ " ly) : " + data.Rows.Count +" systems..."; eva = new ProgressEventArgs() { Info=info, NewLine=true}; if(!sendProgressEvent(eva)) { if(data.Rows.Count > 0) { updateTables = true; initialSize = StationData.Count(); for (int i = StationData.Count()-1 ; i >= 0 ; i--) { if(data.Rows.Find(StationData[i].SystemId) == null) { // system is not in the bubble StationData.Remove(StationData[i]); } else { // system is in the bubble - set as visited Program.Data.checkPotentiallyNewSystemOrStation(StationData[i].SystemName, StationData[i].Name, null, true); } eva = new ProgressEventArgs() { Info=info, CurrentValue=initialSize-i, TotalValue=initialSize }; sendProgressEvent(eva); if(eva.Cancelled) break; } } else StationData.Clear(); } eva = new ProgressEventArgs() { Info=info, CurrentValue=initialSize, TotalValue=initialSize, ForceRefresh=true }; sendProgressEvent(eva); } if((!eva.Cancelled) && (updateTables)) { eva = new ProgressEventArgs() { Info = "refreshing basetables in memory...", NewLine=true }; sendProgressEvent(eva); if(!eva.Cancelled) { Program.Data.updateVisitedFlagsFromBase(); eva = new ProgressEventArgs() { Info = "refreshing basetables in memory...", CurrentValue=25, TotalValue=100, ForceRefresh=true }; sendProgressEvent(eva); } if(!eva.Cancelled) { Program.Data.PrepareBaseTables(Program.Data.BaseData.tbsystems.TableName); eva = new ProgressEventArgs() { Info = "refreshing basetables in memory...", CurrentValue=50, TotalValue=100, ForceRefresh=true }; sendProgressEvent(eva); } if(!eva.Cancelled) { Program.Data.PrepareBaseTables(Program.Data.BaseData.tbstations.TableName); eva = new ProgressEventArgs() { Info = "refreshing basetables in memory...", CurrentValue=75, TotalValue=100, ForceRefresh=true }; sendProgressEvent(eva); } if(!eva.Cancelled) { Program.Data.PrepareBaseTables(Program.Data.BaseData.visystemsandstations.TableName); eva = new ProgressEventArgs() { Info = "refreshing basetables in memory...", CurrentValue=100, TotalValue=100, ForceRefresh=true }; sendProgressEvent(eva); } } // now import the prices if(!eva.Cancelled) { ImportPrices(StationData, importBehaviour, dataSource); } } catch (Exception ex) { throw new Exception("Error while importing self collected price data", ex); } }
/// <summary> /// Imports the prices from a file with csv-strings (e.g. the old autosave-file) /// </summary> /// <param name="filename"></param> /// <param name="importBehaviour"></param> /// <param name="dataSource"></param> /// <param name="importParams">only for control import behaviour from EDDB files, can be null</param> /// <returns></returns> public Int32 ImportPricesFromCSVFile(String filename, enImportBehaviour importBehaviour, enDataSource dataSource, PriceImportParameters importParams = null) { try { List<String> CSV_Strings = new List<string>(); ProgressEventArgs eva; var reader = new StreamReader(File.OpenRead(filename)); Int32 counter = 0; string header = reader.ReadLine(); sendProgressEvent(new ProgressEventArgs() { Info="reading data from file ...", AddSeparator=true }); if(header.StartsWith("System;Station;Commodity;Sell;Buy;Demand;;Supply")) { // old RN format do { CSV_Strings.Add(reader.ReadLine()); counter ++; if(sendProgressEvent(new ProgressEventArgs() { Info="reading data from file ...", CurrentValue=counter})) break; } while (!reader.EndOfStream); reader.Close(); if(!sendProgressEvent(new ProgressEventArgs() { Info="reading data from file ...", CurrentValue=counter, TotalValue=counter, ForceRefresh = true})) ImportPricesFromCSVStrings(CSV_Strings.ToArray(), importBehaviour, dataSource); } else if(header.StartsWith("id,station_id,commodity_id,supply,buy_price,sell_price,demand")) { // EDDB format do { CSV_Strings.Add(reader.ReadLine()); counter ++; if(sendProgressEvent(new ProgressEventArgs() { Info="reading data from file ...", CurrentValue=counter})) break; } while (!reader.EndOfStream); reader.Close(); if(!sendProgressEvent(new ProgressEventArgs() { Info="reading data from file ...", CurrentValue=counter, TotalValue=counter, ForceRefresh = true})) ImportPricesFromEDDBStrings(CSV_Strings.ToArray(), importBehaviour, dataSource, importParams); } return CSV_Strings.Count(); } catch (Exception ex) { throw new Exception("Error while importing self collected price data", ex); } }