public bool Matches(CityRow row) { for (int i = 0; i < _row.Length; i++) { if (!IsEqual(row._row[i], _row[i])) { return(false); } } return(true); }
public CityRow AddCityRow(string Primary, string Common) { CityRow rowCityRow = ((CityRow)(this.NewRow())); rowCityRow.ItemArray = new object[] { Primary, Common }; this.Rows.Add(rowCityRow); return(rowCityRow); }
public static void ToRow(City bean, CityRow row) { if (bean == null) { return; } row.CountryId = bean.CountryId; row.ZipCode = bean.ZipCode; row.Id = bean.Id; row.Name = bean.Name; }
internal static City ToBean(CityRow row) { if (row == null) { return(null); } var bean = new City(); bean.CountryId = row.CountryId; bean.ZipCode = row.ZipCode; bean.Id = row.Id; bean.Name = row.Name; return(bean); }
public City(CityTile[,] cityGrid) { _cityGrid = cityGrid.CopyArray(); var upRow = cityGrid.CopyRow(0); up = upRow.Contains(CityTile.Street) ? new CityRow(upRow) : null; var downRow = cityGrid.CopyRow(cityGrid.GetLength(0) - 1); down = downRow.Contains(CityTile.Street) ? new CityRow(downRow) : null; var rightRow = cityGrid.CopyColumn(cityGrid.GetLength(1) - 1); right = rightRow.Contains(CityTile.Street) ? new CityRow(rightRow) : null; var leftRow = cityGrid.CopyColumn(0); left = leftRow.Contains(CityTile.Street) ? new CityRow(leftRow) : null; }
private void CheckOpening(City c, int startX, int startY, CityRow row, Dir dir) { if (row != null) { for (int i = 0; i < row.Length; i++) { if (!c.IsVacant(startX + dir.X(), startY + dir.Y())) { return; } } openings.Add(new Opening { dir = dir, row = row, x = startX, y = startY }); } }
public CityRowChangeEvent(CityRow row, global::System.Data.DataRowAction action) { this.eventRow = row; this.eventAction = action; }
public void RemoveCityRow(CityRow row) { this.Rows.Remove(row); }
public void AddCityRow(CityRow row) { this.Rows.Add(row); }
public CityRowChangeEvent(CityRow row, DataRowAction action) { this.eventRow = row; this.eventAction = action; }
private void CheckOpening(City c, int startX, int startY, CityRow row, Dir dir) { if (row != null) { for (int i = 0; i < row.Length; i++) { if (!c.IsVacant(startX + dir.X(), startY + dir.Y())) return; } openings.Add(new Opening { dir = dir, row = row, x = startX, y = startY }); } }
/// <summary> /// Poutpulate data with http://www.geonames.org/export/ open datas /// </summary> private void CreateCities() { int rowCount; CountryRow country; Dictionary <string, int> duplicateCityZipCodes = new Dictionary <string, int>(); string line, cityShortName; string[] splitLine; try { string rootPath = Path.Combine(_env.WebRootPath, "databasedata", "zipcode"); if (!Directory.Exists(rootPath)) { return; } string[] cityFiles = Directory.GetFiles(rootPath, "*.txt"); foreach (string dataFilePath in cityFiles) { rowCount = 0; duplicateCityZipCodes.Clear(); cityShortName = Path.GetFileNameWithoutExtension(dataFilePath); country = _context.Country.Where(c => c.ShortName == cityShortName).FirstOrDefault(); if (country == null) { _logger.LogInformation(string.Format("country not found : {0}", cityShortName)); continue; } if (_context.City.Where(c => c.CountryId == country.Id).Count() == 0) { _logger.LogInformation(string.Format("Begin of Populate {0} cities in database", cityShortName)); using (var fileStream = File.OpenRead(dataFilePath)) { using (var streamReader = new StreamReader(fileStream, Encoding.UTF8)) { var cities = new List <CityRow>(); while ((line = streamReader.ReadLine()) != null) { if (line.StartsWith("#")) { continue; } splitLine = line.Split('\t'); if (splitLine != null && splitLine.Length > 2) { var city = new CityRow(); city.CountryId = country.Id; city.Name = splitLine[2]; city.ZipCode = splitLine[1]; if (!string.IsNullOrWhiteSpace(city.Name) && !string.IsNullOrWhiteSpace(city.ZipCode) && !city.ZipCode.Contains("CEDEX")) { //Manage duplicate name with different zip code if (duplicateCityZipCodes.ContainsKey(city.ZipCode)) { city.Id = duplicateCityZipCodes[city.ZipCode] + 1; duplicateCityZipCodes[city.ZipCode] = city.Id; } else { city.Id = 0; duplicateCityZipCodes.Add(city.ZipCode, city.Id); } cities.Add(city); rowCount++; if (rowCount % 5000 == 0) //Commit all 500 row { _context.City.AddRange(cities); _context.SaveChanges(); cities.Clear(); } } } } //Security save change if (cities.Count > 0) { _context.City.AddRange(cities); _context.SaveChanges(); cities.Clear(); } } } _logger.LogInformation(string.Format("End of Populate {0} cities in database: number row={1}", cityShortName, rowCount)); } } } catch (Exception exception) { _logger.LogCritical("Unable populate cities in database", exception); } }
public bool Matches(CityRow row) { for (int i = 0; i < _row.Length; i++) { if (!IsEqual(row._row[i], _row[i])) return false; } return true; }