/// <summary> /// checks if the data is allowed to be imported. /// returns "false", if the data is to old (> 5 mins) or comes from future times (> 5 mins) or /// is already recieved (e.g. from another relay or another user or simply "double sended") /// </summary> /// <param name="dataRow"></param> /// <returns></returns> public bool DataAccepted(string dataRow) { try { var converted = new CsvRow(dataRow); return DataAccepted(converted.SystemName, converted.StationName, converted.CommodityName, converted.SampleDate); } catch (Exception ex) { throw new Exception("Error while checking EDDN data (dataRow)", ex); } }
public EditPriceData(CsvRow csvRow, List<string> commodities) { InitializeComponent(); RowToEdit = csvRow; tbEditSystem.Text = RowToEdit.SystemName; tbEditStation.Text = RowToEdit.StationID; cbEditCommodityName.Text = RowToEdit.CommodityName; nEditSell.Value = RowToEdit.SellPrice; nEditBuy.Value = RowToEdit.BuyPrice; nEditDemand.Value = RowToEdit.Demand; nEditSupply.Value = RowToEdit.Supply; tbEditDemandLevel.Text = RowToEdit.DemandLevel; tbEditSupplyLevel.Text = RowToEdit.SupplyLevel; dtpEditSampleDate.Value = RowToEdit.SampleDate; tbEditFilename.Text = RowToEdit.SourceFileName; foreach (var x in commodities.OrderBy(y => y)) cbEditCommodityName.Items.Add(x); }
private void button1_Click(object sender, EventArgs e) { DialogResult = DialogResult.OK; var returnValue = new CsvRow { SystemName = tbEditSystem.Text, StationID = tbEditStation.Text + " ["+tbEditSystem.Text+"]", CommodityName = cbEditCommodityName.Text, SellPrice = nEditSell.Value, BuyPrice = nEditBuy.Value, Demand = nEditDemand.Value, Supply = nEditSupply.Value, DemandLevel = tbEditDemandLevel.Text, SupplyLevel = tbEditSupplyLevel.Text, SampleDate = dtpEditSampleDate.Value, SourceFileName = tbEditFilename.Text }; RowToEdit = returnValue; Close(); }
public bool checkPricePlausibility(string[] DataRows, bool simpleEDDNCheck = false) { bool implausible = false; SQL.Datasets.dsEliteDB.tbcommodityRow[] CommodityData; foreach (string s in DataRows) { if (s.Contains(";")) { string[] values = s.Split(';'); CsvRow currentRow = new CsvRow(); currentRow.SellPrice = -1; currentRow.BuyPrice = -1; currentRow.Demand = -1; currentRow.Supply = -1; currentRow.SystemName = values[0]; currentRow.StationName = _textInfo.ToTitleCase(values[1].ToLower()); currentRow.StationID = _textInfo.ToTitleCase(values[1].ToLower()) + " [" + currentRow.SystemName + "]"; currentRow.CommodityName = _textInfo.ToTitleCase(values[2].ToLower()); if (!String.IsNullOrEmpty(values[3])) Decimal.TryParse(values[3], out currentRow.SellPrice); if (!String.IsNullOrEmpty(values[4])) Decimal.TryParse(values[4], out currentRow.BuyPrice); if (!String.IsNullOrEmpty(values[5])) Decimal.TryParse(values[5], out currentRow.Demand); if (!String.IsNullOrEmpty(values[7])) Decimal.TryParse(values[7], out currentRow.Supply); currentRow.DemandLevel = _textInfo.ToTitleCase(values[6].ToLower()); currentRow.SupplyLevel = _textInfo.ToTitleCase(values[8].ToLower()); DateTime.TryParse(values[9], out currentRow.SampleDate); CommodityData = (SQL.Datasets.dsEliteDB.tbcommodityRow[]) Program.Data.BaseData.tbcommodity.Select("commodity = " + DBConnector.SQLAString(currentRow.CommodityName) + " or " + "loccommodity = " + DBConnector.SQLAString(currentRow.CommodityName)); if (currentRow.CommodityName == "Panik") Debug.Print("STOP"); if ((CommodityData != null) && (CommodityData.GetUpperBound(0) >= 0)) { if ((!String.IsNullOrEmpty(currentRow.SupplyLevel)) && (!String.IsNullOrEmpty(currentRow.DemandLevel))) { // demand AND supply !? implausible = true; } else if ((!String.IsNullOrEmpty(currentRow.SupplyLevel)) || (simpleEDDNCheck && (currentRow.Supply > 0))) { // check supply data if ((currentRow.SellPrice <= 0) || (currentRow.BuyPrice <= 0)) { // both on 0 is not plausible implausible = true; } if (((CommodityData[0].pwl_supply_sell_low >= 0) && (currentRow.SellPrice < CommodityData[0].pwl_supply_sell_low)) || ((CommodityData[0].pwl_supply_sell_high >= 0) && (currentRow.SellPrice > CommodityData[0].pwl_supply_sell_high))) { // sell price is out of range implausible = true; } if (((CommodityData[0].pwl_supply_buy_low >= 0) && (currentRow.BuyPrice < CommodityData[0].pwl_supply_buy_low)) || ((CommodityData[0].pwl_supply_buy_high >= 0) && (currentRow.SellPrice > CommodityData[0].pwl_supply_buy_high))) { // buy price is out of range implausible = true; } if (currentRow.Supply.Equals(-1)) { // no supply quantity implausible = true; } } else if ((!String.IsNullOrEmpty(currentRow.DemandLevel)) || (simpleEDDNCheck && (currentRow.Demand > 0))) { // check demand data if (currentRow.SellPrice <= 0) { // at least the sell price must be present implausible = true; } if (((CommodityData[0].pwl_demand_sell_low >= 0) && (currentRow.SellPrice < CommodityData[0].pwl_demand_sell_low)) || ((CommodityData[0].pwl_demand_sell_high >= 0) && (currentRow.SellPrice > CommodityData[0].pwl_demand_sell_high))) { // buy price is out of range implausible = true; } if (currentRow.BuyPrice >= 0) if (((CommodityData[0].pwl_demand_buy_low >= 0) && (currentRow.BuyPrice < CommodityData[0].pwl_demand_buy_low)) || ((CommodityData[0].pwl_demand_buy_high >= 0) && (currentRow.BuyPrice > CommodityData[0].pwl_demand_buy_high))) { // buy price is out of range implausible = true; } if (currentRow.Demand.Equals(-1)) { // no supply quantity implausible = true; } } else { // nothing ?! implausible = true; } } } if (implausible) break; } return implausible; }
/// <summary> /// register everything for sending with this function. /// 2 seconds after the last registration all data will be sent automatically /// </summary> /// <param name="CommodityData"></param> public void sendToEdDDN(CsvRow CommodityData) { // register next data row _SendItems.Enqueue(CommodityData); // reset the timer _SendDelayTimer.Start(); }
/// <summary> /// creates a list of "EDStations" with price listings from csv-array /// </summary> /// <param name="CSV_Strings">String to be converted</param> /// <param name="foundSystems"></param> /// <param name="csvRowList">for optional processing outside: a list of the data converted to CsvRow-objects</param> /// <returns></returns> 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); } }
/// <summary> /// imports prices from a JSON companion data object /// </summary> /// <param name="companionData">JSON object with companion data</param> /// <returns></returns> public Int32 ImportPrices(Newtonsoft.Json.Linq.JObject companionData) { String system; String starPort; Int32 commodityCount = 0; List<String> csvStrings = new List<string>(); List<EDStation> stationData = null; try { system = companionData["lastSystem"]["name"].ToString(); starPort = companionData["lastStarport"]["name"].ToString(); foreach (Newtonsoft.Json.Linq.JToken commodity in companionData.SelectTokens("lastStarport.commodities[*]")) { if(!commodity.Value<String>("categoryname").Equals("NonMarketable", StringComparison.InvariantCultureIgnoreCase)) { CsvRow csvData = new CsvRow(); csvData.SystemName = system; csvData.StationName = starPort; csvData.StationID = String.Format("{0} [{1}]", starPort, system); csvData.CommodityName = commodity.Value<String>("name"); csvData.SellPrice = commodity.Value<Int32>("sellPrice"); csvData.BuyPrice = commodity.Value<Int32>("buyPrice"); csvData.Demand = commodity.Value<Int32>("demand"); csvData.Supply = commodity.Value<Int32>("stock"); csvData.SampleDate = DateTime.Now; if((!String.IsNullOrEmpty(commodity.Value<String>("demandBracket"))) && (commodity.Value<Int32>("demandBracket") > 0)) csvData.DemandLevel = (String)Program.Data.BaseTableIDToName("economylevel", commodity.Value<Int32>("demandBracket") - 1, "level"); else csvData.DemandLevel = null; if((!String.IsNullOrEmpty(commodity.Value<String>("stockBracket"))) && (commodity.Value<Int32>("stockBracket") > 0)) csvData.SupplyLevel = (String)Program.Data.BaseTableIDToName("economylevel", commodity.Value<Int32>("stockBracket") - 1, "level"); else csvData.SupplyLevel = null; csvData.SourceFileName = ""; csvData.DataSource = ""; csvStrings.Add(csvData.ToString()); commodityCount++; } } if(csvStrings.Count > 0) stationData = ImportPricesFromCSVStrings(csvStrings.ToArray(), SQL.EliteDBIO.enImportBehaviour.OnlyNewer, SQL.EliteDBIO.enDataSource.fromIBE); return commodityCount; } catch (Exception ex) { throw new Exception("Error while importing prices from companion interface", ex); } }
/// <summary> /// Imports the prices from a list of csv-strings /// </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> /// <returns>a list of converted station data (including correct station ids) </returns> public List<EDStation> ImportPricesFromCSVStrings(String[] CSV_Strings, enImportBehaviour importBehaviour, enDataSource dataSource) { Boolean MissingSystem = false; Boolean MissingStation = false; String currentLanguage; DataTable newData; List<EDStation> StationData; List<EDSystem> SystemData = null; List<CsvRow> csvRowList = new List<CsvRow>(); ProgressEventArgs eva; Int32 counter = 0; Dictionary<String, String> foundNames = new Dictionary<string,string>(); // quick cache for finding commodity names try { // ***************************************************************** // START :section for automatically add unknown commodities currentLanguage = Program.DBCon.getIniValue(IBESettingsView.DB_GROUPNAME, "Language", Program.BASE_LANGUAGE, false); newData = new DataTable(); newData.TableName = "Names"; newData.Columns.Add(Program.BASE_LANGUAGE, typeof(String)); if(currentLanguage != Program.BASE_LANGUAGE) newData.Columns.Add(currentLanguage, typeof(String)); eva = new ProgressEventArgs() { Info="analysing data...", AddSeparator = true}; sendProgressEvent(eva); for (int i = 0; i < CSV_Strings.Length; i++) { String currentName; List<dsEliteDB.tbcommoditylocalizationRow> currentCommodity; if (CSV_Strings[i].Trim().Length > 0) { currentName = new CsvRow(CSV_Strings[i]).CommodityName; if (!String.IsNullOrEmpty(currentName)) { // check if we need to remap this name Datasets.dsEliteDB.tbdnmap_commodityRow mappedName = (Datasets.dsEliteDB.tbdnmap_commodityRow)BaseData.tbdnmap_commodity.Rows.Find(new object[] {currentName, ""}); if (mappedName != null) { CSV_Strings[i] = CSV_Strings[i].Replace(mappedName.CompanionName, mappedName.GameName); currentName = mappedName.GameName; } if (!foundNames.ContainsKey(currentName)) { currentCommodity = Program.Data.BaseData.tbcommoditylocalization.Where(x => x.locname.Equals(currentName, StringComparison.InvariantCultureIgnoreCase)).ToList(); if (currentCommodity.Count == 0) { if (currentLanguage == Program.BASE_LANGUAGE) newData.Rows.Add(currentName); else newData.Rows.Add(currentName, currentName); } foundNames.Add(currentName, ""); } } } counter++; eva = new ProgressEventArgs() { Info="analysing data...", CurrentValue=counter, TotalValue=CSV_Strings.GetUpperBound(0) + 1 }; sendProgressEvent(eva); if(eva.Cancelled) break; } eva = new ProgressEventArgs() { Info="analysing data...", CurrentValue=counter, TotalValue=counter, ForceRefresh=true }; sendProgressEvent(eva); if (!eva.Cancelled) if(newData.Rows.Count > 0) { // add found unknown commodities var ds = new DataSet(); ds.Tables.Add(newData); ImportCommodityLocalizations(ds); // refresh translation columns Program.Data.updateTranslation(); // refresh working tables Program.Data.PrepareBaseTables(Program.Data.BaseData.tbcommoditylocalization.TableName); Program.Data.PrepareBaseTables(Program.Data.BaseData.tbcommodity.TableName); } // END : section for automatically add unknown commodities // ***************************************************************** // convert csv-strings to EDStation-objects StationData = fromCSV(CSV_Strings, ref SystemData, ref csvRowList); // check if we've unknown systems or stations if(!eva.Cancelled) foreach (EDStation Station in StationData) { if (Station.SystemId == 0) MissingSystem = true; else if(Station.Id == 0) MissingStation = true; } if ((!eva.Cancelled) && MissingSystem) { // add unknown systems ImportSystems_Own(ref SystemData, true); } if (!eva.Cancelled && (MissingSystem || MissingStation)) { // add unknown stations foreach (EDStation Station in StationData) { // first get all missing system ids if (Station.SystemId == 0) { EDSystem thisSystem = SystemData.FirstOrDefault(x => x.Name == Station.SystemName); if(thisSystem != null) { // got it - set the id Station.SystemId = thisSystem.Id; } } } ImportStations_Own(StationData, new Dictionary<Int32, Int32>(), true); } // now import the prices ImportPrices(StationData, importBehaviour, dataSource); if (MissingSystem) { // reloading of base tables Program.Data.PrepareBaseTables(Program.Data.BaseData.tbsystems.TableName); } if (MissingSystem || MissingStation) { // reloading of base tables Program.Data.PrepareBaseTables(Program.Data.BaseData.tbstations.TableName); Program.Data.PrepareBaseTables(Program.Data.BaseData.visystemsandstations.TableName); } return StationData; } 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="timeStampIsLocal">true: timestamps are handled as local time, otherwise utc is assumed</param> /// <returns></returns> public Int32 ImportPricesFromCSVFile(String filename, Boolean timeStampIsLocal = false) { String currentLanguage; DataTable newData; try { String[] CSV_Strings = new String[0]; var reader = new StreamReader(File.OpenRead(filename)); string header = reader.ReadLine(); if(header.StartsWith("System;Station")) { CSV_Strings = reader.ReadToEnd().Split(new string[] { Environment.NewLine }, StringSplitOptions.None); } reader.Close(); // ***************************************************************** // START :section for automatically add unknown commodities currentLanguage = Program.DBCon.getIniValue(MTSettings.tabSettings.DB_GROUPNAME, "Language"); newData = new DataTable(); newData.TableName = "Names"; newData.Columns.Add(Program.BASE_LANGUAGE, typeof(String)); if(currentLanguage != Program.BASE_LANGUAGE) newData.Columns.Add(currentLanguage, typeof(String)); foreach (String DataLine in CSV_Strings) { String currentName; List<dsEliteDB.tbcommoditylocalizationRow> currentCommodity; if(DataLine.Trim().Length > 0) { currentName = new CsvRow(DataLine).CommodityName; currentCommodity = Program.Data.BaseData.tbcommoditylocalization.Where(x => x.locname.Equals(currentName, StringComparison.InvariantCultureIgnoreCase)).ToList(); if((currentCommodity.Count == 0) && (!String.IsNullOrEmpty(currentName))) { if(currentLanguage == Program.BASE_LANGUAGE) newData.Rows.Add(currentName); else newData.Rows.Add(currentName, currentName); } } } if(newData.Rows.Count > 0) { // add found unknown commodities var ds = new DataSet(); ds.Tables.Add(newData); ImportCommodityLocalizations(ds); // refresh translation columns Program.Data.updateTranslation(); // refresh working tables Program.Data.PrepareBaseTables(Program.Data.BaseData.tbcommoditylocalization.TableName); Program.Data.PrepareBaseTables(Program.Data.BaseData.tbcommodity.TableName); } // END : section for automatically add unknown commodities // ***************************************************************** ImportPricesFromCSVStrings(CSV_Strings); return CSV_Strings.Count(); } catch (Exception ex) { throw new Exception("Error while importing self collected price data", ex); } }
/// <summary> /// creates a list of "EDStations" with price listings from csv-array /// </summary> /// <param name="CSV_Strings"></param> /// <returns></returns> public List<EDStation> fromCSV(String[] CSV_Strings, ref List<EDSystem> foundSystems) { 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; try { 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); 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); } } if(currentStation != null) currentStation.ListingExtendMode = false; return foundValues; } catch (Exception ex) { throw new Exception("Error while getting station values from CSV-String", ex); } }
/// <summary> /// adds a record to the pricelistings of this station /// </summary> /// <param name="CSV_String"></param> public void addListing(CsvRow Csv_Row, ref Dictionary<string,Int32> foundCommodityCache) { SQL.Datasets.dsEliteDB.tbcommoditylocalizationRow[] CommodityRow; Int32 CommodityID = 0; Boolean known = false; try { if(foundCommodityCache != null) { if (!foundCommodityCache.TryGetValue(Csv_Row.CommodityName, out CommodityID)) { CommodityRow = (SQL.Datasets.dsEliteDB.tbcommoditylocalizationRow[])Program.Data.BaseData.tbcommoditylocalization.Select( String.Format("locname = '{0}'", SQL.DBConnector.DTEscape(Csv_Row.CommodityName))); if(CommodityRow.GetUpperBound(0) >= 0) { CommodityID = (Int32)CommodityRow[0].commodity_id; foundCommodityCache.Add(Csv_Row.CommodityName, CommodityID); known = true; } } else known = true; } else { CommodityRow = (SQL.Datasets.dsEliteDB.tbcommoditylocalizationRow[])Program.Data.BaseData.tbcommoditylocalization.Select( String.Format("locname = '{0}'", SQL.DBConnector.DTEscape(Csv_Row.CommodityName))); if(CommodityRow.GetUpperBound(0) >= 0) { CommodityID = (Int32)CommodityRow[0].commodity_id; known = true; } } if(known) { ListingExtendMode = true; Listing newListing = new Listing(); newListing.StationId = this.Id; newListing.CommodityId = CommodityID; newListing.Supply = (Int32)Csv_Row.Supply; newListing.SupplyLevel = Csv_Row.SupplyLevel.Trim() == "" ? null : Csv_Row.SupplyLevel; newListing.BuyPrice = (Int32)Csv_Row.BuyPrice; newListing.SellPrice = (Int32)Csv_Row.SellPrice; newListing.Demand = (Int32)Csv_Row.Demand; newListing.DemandLevel = Csv_Row.DemandLevel.Trim() == "" ? null : Csv_Row.DemandLevel; newListing.CollectedAt = new System.DateTimeOffset(Csv_Row.SampleDate).ToUnixTimeSeconds(); newListing.DataSource = Csv_Row.DataSource; newListing.UpdateCount = -1; Listings[currentIndex+1] = newListing; currentIndex++; } } catch (Exception ex) { throw new Exception("Error while adding a record to the pricelistings", ex); } }
/// <summary> /// creates a new station with values from the CsvRow object /// </summary> /// <param name="currentRow"></param> public EDStation(CsvRow Csv_Row) { try { var SystemsAndStations = Program.Data.BaseData.visystemsandstations; Id = 0; SystemId = 0; var stationID = (SQL.Datasets.dsEliteDB.visystemsandstationsRow[])SystemsAndStations.Select( String.Format("systemname = '{0}' and stationname = '{1}'", SQL.DBConnector.DTEscape(Csv_Row.SystemName), SQL.DBConnector.DTEscape(Csv_Row.StationName))); if(stationID.GetUpperBound(0) >= 0) { Id = stationID[0].StationID; SystemId = stationID[0].SystemID; } else { // we'll get the system-id later SystemName = Csv_Row.SystemName; } Name = Csv_Row.StationName; MaxLandingPadSize = null; DistanceToStar = null; Faction = null; Government = null; Allegiance = null; State = null; Type = null; HasBlackmarket = false; HasMarket = false; HasRefuel = false; HasRepair = false; HasRearm = false; HasOutfitting = false; HasShipyard = false; ImportCommodities = new String[0]; ExportCommodities = new String[0]; ProhibitedCommodities = new String[0]; Economies = new String[0]; Listings = new Listing[0]; UpdatedAt = 0; Shipyard_UpdatedAt = 0; Outfitting_UpdatedAt = 0; Market_UpdatedAt = 0; TypeID = null; HasCommodities = false; IsPlanetary = false; SellingShips = new String[0]; SellingModules = new Int32[0]; } catch (Exception ex) { throw new Exception("Error while creating new EDStation object with values from CsvRow object", ex); } }
private String[] ConvertCommodityV3_To_CSVRows(JObject commodityV3Data) { String system; String starPort; Int32 commodityCount = 0; List<String> csvStrings = new List<string>(); try { system = commodityV3Data["message"]["systemName"].ToString(); starPort = commodityV3Data["message"]["stationName"].ToString(); foreach (Newtonsoft.Json.Linq.JToken commodity in commodityV3Data.SelectTokens("message.commodities[*]")) { CsvRow csvData = new CsvRow(); csvData.SystemName = system; csvData.StationName = starPort; csvData.StationID = String.Format("{0} [{1}]", starPort, system); csvData.CommodityName = commodity.Value<String>("name"); csvData.SellPrice = commodity.Value<Int32>("sellPrice"); csvData.BuyPrice = commodity.Value<Int32>("buyPrice"); csvData.Demand = commodity.Value<Int32>("demand"); csvData.Supply = commodity.Value<Int32>("stock"); csvData.SampleDate = DateTime.Now; if((!String.IsNullOrEmpty(commodity.Value<String>("demandBracket"))) && (commodity.Value<Int32>("demandBracket") > 0)) csvData.DemandLevel = (String)Program.Data.BaseTableIDToName("economylevel", commodity.Value<Int32>("demandBracket") - 1, "level"); else csvData.DemandLevel = null; if((!String.IsNullOrEmpty(commodity.Value<String>("stockBracket"))) && (commodity.Value<Int32>("stockBracket") > 0)) csvData.SupplyLevel = (String)Program.Data.BaseTableIDToName("economylevel", commodity.Value<Int32>("stockBracket") - 1, "level"); else csvData.SupplyLevel = null; csvData.SourceFileName = ""; csvData.DataSource = ""; csvStrings.Add(csvData.ToString()); commodityCount++; } return csvStrings.ToArray(); } catch (Exception ex) { throw new Exception("Error while converting commodity v3 data to csv rows", ex); } }
/// <summary> /// adds a record to the pricelistings of this station /// </summary> /// <param name="CSV_String"></param> public void addListing(CsvRow Csv_Row) { SQL.Datasets.dsEliteDB.tbcommoditylocalizationRow[] CommodityRow; try { CommodityRow = (SQL.Datasets.dsEliteDB.tbcommoditylocalizationRow[])Program.Data.BaseData.tbcommoditylocalization.Select( String.Format("locname = '{0}'", SQL.DBConnector.DTEscape(Csv_Row.CommodityName))); if(CommodityRow.GetUpperBound(0) >= 0) { ListingExtendMode = true; Listing newListing = new Listing(); newListing.StationId = this.Id; newListing.CommodityId = (Int32)CommodityRow[0].commodity_id; newListing.Supply = (Int32)Csv_Row.Supply; newListing.SupplyLevel = Csv_Row.SupplyLevel.Trim() == "" ? null : Csv_Row.SupplyLevel; newListing.BuyPrice = (Int32)Csv_Row.BuyPrice; newListing.SellPrice = (Int32)Csv_Row.SellPrice; newListing.Demand = (Int32)Csv_Row.Demand; newListing.DemandLevel = Csv_Row.DemandLevel.Trim() == "" ? null : Csv_Row.DemandLevel; newListing.CollectedAt = new System.DateTimeOffset(Csv_Row.SampleDate).ToUnixTimeSeconds(); newListing.UpdateCount = -1; Listings[currentIndex+1] = newListing; currentIndex++; } } catch (Exception ex) { throw new Exception("Error while adding a record to the pricelistings", ex); } }