private VendorTestResult(TestItem testItem, Vendor vendor) : base() { this.Vendor = vendor; this.TestItem = testItem; this.Latitude = GeoMapUtil.LatLngNullValue; this.Longitude = GeoMapUtil.LatLngNullValue; }
public VendorTestResult(GeoCoding.PlaceBase place, TestItem testItem, Vendor vendor) { Longitude = place.Coordinates.Longitude; Latitude = place.Coordinates.Latitude; TestItem = testItem; //TestItemId = testItem.Id; // avoiding a dup here.. // Vendor = Models.Vendor.GetByName(vendor.Name); VendorId = vendor.Id; }
public static IList<TestItem> GetTestItems(IList<Models.vwMapTest> rawAddresses) { IList<TestItem> testItems = new List<TestItem>(); foreach (vwMapTest rawAddress in rawAddresses) { using (var dbTest = new ResultModelContainer()) { // create a test item from the raw address var testItem = new TestItem { Address = GeoMapUtil.GetLocationString(rawAddress.City, rawAddress.Region, rawAddress.PostalCode), ResellerId = rawAddress.ResellerID }; testItems.Add(testItem); } } return testItems; }
public VendorTestResult Query(TestItem testItem) { //PlaceBase place = null; VendorTestResult vr = null; if (testItem == null || string.IsNullOrEmpty(testItem.Address)) { throw new Exception("Address must not be a null or empty string."); } Vendor vendor = Vendor.GetByName(Provider.ToString()); // Check cache VendorTestResult cachedRecord = GetResultFromCache(testItem.Address, vendor); if (cachedRecord != null) { log.InfoFormat("Using cached coords for address '{0}' from {1}", testItem.Address, vendor.Name); vr = cachedRecord; } else { log.InfoFormat("Querying address '{0}' from {1}", testItem.Address, vendor.Name); Uri queryUri = GetQueryUri(testItem.Address); string response = null; try { response = new WebClient().DownloadString(queryUri); } catch (Exception) { log.Error("Bad response from " + vendor.Name); response = null; throw; } PlaceBase place = null; if (response != null) { place = ParseResponse(response, testItem.Address); } // CACHE IT if (place != null) { try { using (var dbContext = new ResultModelContainer()) { vr = new VendorTestResult(place, testItem, Vendor.GetByName(Provider.ToString())); dbContext.VendorTestResults.Add(vr); dbContext.SaveChanges(); } } catch (Exception e) { log.WarnFormat("Failed to cache address {0}\n{1}\n{2}", testItem.Address, e.ToString()); } } } return vr; }