public override void Run() { // This is a sample worker implementation. Replace with your logic. while (true) { CityStorage cityStorage = new CityStorage(); cityStorage.SaveCityAllRecord(); Thread.Sleep(1000); } }
public void CityStorageDataTests() { CityStorage cs = new CityStorage(); Assert.IsNull(cs.Find(null), "Result should be null."); var result = cs.Find(new int[] { 1, 2, 3 }); Assert.IsNotNull(result, "Cities should be exist."); Assert.AreEqual(result.Count, 3, "Should return 3 cities."); var resultRaw = cs.GetData(); Assert.IsNotNull(resultRaw, "Cities dictionary should be exist."); Assert.AreNotEqual(resultRaw.Count, 0, "Cities dictionary is not filled."); }
public IEnumerable <int> Filter( GroupRequest.CityRequest city, CityStorage cities) { short cityId = cities.Get(city.City); if (_id2AccId[cityId] != null) { return(_id2AccId[cityId]); } else { return(Enumerable.Empty <int>()); } }
public IIterator Filter( FilterRequest.CityRequest city, IdStorage ids, CityStorage cities) { if (city.IsNull.HasValue) { if (city.IsNull.Value) { return((city.Eq == null && city.Any.Count == 0) ? _null.GetIterator() : ListHelper.EmptyInt); } } if (city.Eq != null && city.Any.Count > 0) { if (city.Any.Contains(city.Eq)) { short cityId = cities.Get(city.Eq); return(_id2AccId[cityId]?.GetIterator() ?? ListHelper.EmptyInt); } else { return(ListHelper.EmptyInt); } } if (city.Eq != null) { short cityId = cities.Get(city.Eq); return(_id2AccId[cityId]?.GetIterator() ?? ListHelper.EmptyInt); } else if (city.Any.Count > 0) { return(ListHelper .MergeSort( city.Any .Select(x => cities.Get(x)) .Where(x => _id2AccId[x] != null) .Select(x => _id2AccId[x].GetIterator()) .ToList())); } else { return(_ids.GetIterator()); } }
public CityService() { TsvParser parser = new TsvParser() { Filepath = "cities_canada-usa.tsv" }; CityStorage cityStorage = new CityStorage { Parser = parser, WordStorage = new WordTree() }; cityStorage.LoadData(); _cityStorage = cityStorage; _scorer = new Scorer(); _serializer = new JsonSerializer(); }
public void BasicTest() { MockStorage mockStorage = new MockStorage { Words = new List<string>(), AddCalled = false, AutoCompleteCalled = false }; CityStorage storage = new CityStorage { WordStorage = mockStorage }; // need to add the short name to the word storage City city1 = new City { FullName = "London, ON, Canada", ShortName = "London", Latitude = 42.98339, Longitude = -81.23304 }; storage.AddCity(city1); CollectionAssert.AreEquivalent(new string[] { "London" }, mockStorage.Words); Assert.IsTrue(mockStorage.AddCalled); mockStorage.AddCalled = false; // the short name has been added already, so no need to add again City city2 = new City { FullName = "London, OH, USA", ShortName = "London", Latitude = 39.88645, Longitude = -83.44825 }; storage.AddCity(city2); City city3 = new City { FullName = "London, KY, USA", ShortName = "London", Latitude = 37.12898, Longitude = -84.08326 }; storage.AddCity(city3); Assert.IsFalse(mockStorage.AddCalled); // a new short name, so need to add it too City city4 = new City { FullName = "Londontowne, MD, USA", ShortName = "Londontowne", Latitude = 38.93345, Longitude = -76.54941 }; storage.AddCity(city4); CollectionAssert.AreEquivalent(new string[] { "London", "Londontowne" }, mockStorage.Words); Assert.IsTrue(mockStorage.AddCalled); mockStorage.AddCalled = false; // when requesting city, should get the name from the word storage Assert.IsFalse(mockStorage.AutoCompleteCalled); IEnumerable<City> cities = storage.GetCitiesStartsWith("Lon"); Assert.IsTrue(mockStorage.AutoCompleteCalled); CollectionAssert.AreEquivalent(new City[] { city1, city2, city3, city4 }, cities.ToList()); }