private static void getLevels(ref int? DemandLevel, ref int? SupplyLevel, Dictionary<String, int?> Levels, Listing StationListing) { try { DemandLevel = null; if (!String.IsNullOrEmpty(StationListing.DemandLevel)) if (!Levels.TryGetValue(StationListing.DemandLevel, out DemandLevel)) { dsEliteDB.tblevellocalizationRow[] LocRow = (dsEliteDB.tblevellocalizationRow[])Program.Data.BaseData.tblevellocalization.Select(String.Format("locname = '{0}'", StationListing.DemandLevel)); if (LocRow.GetUpperBound(0) >= 0) { DemandLevel = LocRow[0].economylevel_id; Levels.Add(StationListing.DemandLevel, LocRow[0].economylevel_id); } } SupplyLevel = null; if (!String.IsNullOrEmpty(StationListing.SupplyLevel)) if (!Levels.TryGetValue(StationListing.SupplyLevel, out SupplyLevel)) { dsEliteDB.tblevellocalizationRow[] LocRow = (dsEliteDB.tblevellocalizationRow[])Program.Data.BaseData.tblevellocalization.Select(String.Format("locname = '{0}'", StationListing.SupplyLevel)); if (LocRow.GetUpperBound(0) >= 0) { SupplyLevel = LocRow[0].economylevel_id; Levels.Add(StationListing.SupplyLevel, LocRow[0].economylevel_id); } } } catch (Exception ex) { throw new Exception("Error while caching levels", ex); } }
/// <summary> /// creates a list of "EDStations" with price listings from csv-array in EDDB format /// </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_EDDB(String[] CSV_Strings) { List<EDStation> foundValues = new List<EDStation>(); Dictionary<Int32, Int32> foundIndex = new Dictionary<Int32, Int32>(); Dictionary<String, Int32> foundSystemIndex = new Dictionary<String, Int32>(); Int32 LastID = 0; EDSystem LastSystem = null; Int32 currentID = 0; 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), NewLine= true}; sendProgressEvent(eva); foreach (String CSV_String in CSV_Strings) { if(!String.IsNullOrEmpty(CSV_String.Trim())) { Listing currentRow = new Listing(CSV_String); currentID = currentRow.StationId; if(LastID != currentID) { 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; } currentStation.addListing(currentRow); } eva = new ProgressEventArgs() { Info="converting data...", CurrentValue=currentItem, TotalValue=CSV_Strings.GetUpperBound(0)}; 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), ForceRefresh=true}; sendProgressEvent(eva); 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(Listing listingRow) { try { ListingExtendMode = true; Listings[currentIndex+1] = listingRow; currentIndex++; } catch (Exception ex) { throw new Exception("Error while adding a record to the pricelistings", 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); } }
public void clear() { Id = 0; SystemId = 0; Name = string.Empty; 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; //new System.DateTimeOffset(##).ToUnixTimeSeconds(); Shipyard_UpdatedAt = 0; Outfitting_UpdatedAt = 0; Market_UpdatedAt = 0; TypeID = null; HasCommodities = false; IsPlanetary = false; SellingShips = new String[0]; SellingModules = new Int32[0]; ListingExtendMode = false; }
/// <summary> /// creates a new station with values from the CsvRow object /// </summary> /// <param name="currentRow"></param> public EDStation(Listing listingString) { try { var SystemsAndStations = Program.Data.BaseData.visystemsandstations; Id = 0; SystemId = 0; var stationID = (SQL.Datasets.dsEliteDB.visystemsandstationsRow[])SystemsAndStations.Select( String.Format("stationid = '{0}'", listingString.StationId)); if(stationID.GetUpperBound(0) >= 0) { Id = stationID[0].StationID; SystemId = stationID[0].SystemID; } else { throw new Exception("unknown station id"); } Name = stationID[0].StationName; SystemName = stationID[0].SystemName; 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); } }
/// <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); } }