public async Task <List <ApiInstallation> > GetInstallations(LocationMapping location, double maxDistanceInKm = 3, int maxResults = -1) { var json = AirlyMockedInstallationsJson.Get(); var installations = JsonConvert.DeserializeObject <IEnumerable <ApiInstallation> >(json); return(installations.ToList()); }
public static Installation Create(long id, double elevation, bool isAirlyInstallation, LocationMapping location, Address address, Sponsor sponsor) => new Installation(id, elevation, isAirlyInstallation, location, address, sponsor);
public void VersionConflict() { // Arrange var validatorFactory = new Mock <IValidatorEngine>(); var mappingEngine = new Mock <IMappingEngine>(); var repository = new Mock <IRepository>(); var searchCache = new Mock <ISearchCache>(); var service = new LocationService(validatorFactory.Object, mappingEngine.Object, repository.Object, searchCache.Object); var message = new AmendMappingRequest { MappingId = 12, Mapping = new MdmId { SystemName = "Test", Identifier = "A" }, Version = 34 }; var mapping = new LocationMapping { Location = new MDM.Location() { Timestamp = BitConverter.GetBytes(25L) } }; validatorFactory.Setup(x => x.IsValid(It.IsAny <AmendMappingRequest>(), It.IsAny <IList <IRule> >())).Returns(true); repository.Setup(x => x.FindOne <LocationMapping>(12)).Returns(mapping); // Act service.UpdateMapping(message); }
public async Task <String> LocationForCurrentConnectionAsync( ServiceDefinition serviceDefinition, CancellationToken cancellationToken = default(CancellationToken)) { AccessMapping clientAccessMapping = await GetClientAccessMappingAsync(cancellationToken).ConfigureAwait(false); String location = await LocationForAccessMappingAsync(serviceDefinition, clientAccessMapping, cancellationToken).ConfigureAwait(false); if (location == null) { AccessMapping defaultAccessMapping = await GetDefaultAccessMappingAsync(cancellationToken).ConfigureAwait(false); location = await LocationForAccessMappingAsync(serviceDefinition, defaultAccessMapping, cancellationToken).ConfigureAwait(false); if (location == null) { LocationMapping firstLocationMapping = serviceDefinition.LocationMappings.FirstOrDefault(); if (firstLocationMapping == null) { throw new InvalidServiceDefinitionException(WebApiResources.ServiceDefinitionWithNoLocations(serviceDefinition.ServiceType)); } location = firstLocationMapping.Location; } } return(location); }
public LocationMapping Save(LocationMapping location) { if (_connection.Get.Insert(LocationEntity.FromDomain(location)) > 0) { return(location.WithId(_connection.LastIndex)); } return(null); }
/// <summary> /// /// </summary> /// <param name="serviceDefinition"></param> /// <param name="accessMapping"></param> /// <param name="cancellationToken"></param> /// <returns></returns> public Task <String> LocationForAccessMappingAsync( ServiceDefinition serviceDefinition, AccessMapping accessMapping, CancellationToken cancellationToken = default(CancellationToken)) { ArgumentUtility.CheckForNull(serviceDefinition, "serviceDefinition"); ArgumentUtility.CheckForNull(accessMapping, "accessMapping"); // If this is FullyQualified then look through our location mappings if (serviceDefinition.RelativeToSetting == RelativeToSetting.FullyQualified) { LocationMapping locationMapping = serviceDefinition.GetLocationMapping(accessMapping); if (locationMapping != null) { return(Task.FromResult <String>(locationMapping.Location)); } // We weren't able to find the location for the access mapping. Return null. return(Task.FromResult <String>(null)); } else { // Make sure the AccessMapping has a valid AccessPoint. if (String.IsNullOrEmpty(accessMapping.AccessPoint)) { throw new InvalidAccessPointException(WebApiResources.InvalidAccessMappingLocationServiceUrl()); } String webApplicationRelativeDirectory = m_locationDataCacheManager.WebApplicationRelativeDirectory; if (accessMapping.VirtualDirectory != null) { webApplicationRelativeDirectory = accessMapping.VirtualDirectory; } Uri uri = new Uri(accessMapping.AccessPoint); String properRoot = String.Empty; switch (serviceDefinition.RelativeToSetting) { case RelativeToSetting.Context: properRoot = PathUtility.Combine(uri.AbsoluteUri, webApplicationRelativeDirectory); break; case RelativeToSetting.WebApplication: properRoot = accessMapping.AccessPoint; break; default: Debug.Assert(true, "Found an unknown RelativeToSetting"); break; } return(Task.FromResult <String>(PathUtility.Combine(properRoot, serviceDefinition.RelativePath))); } }
protected static void Because_of() { entity = Script.LocationData.CreateBasicEntityWithOneMapping(); mapping = entity.Mappings[0]; client = new HttpClient(ServiceUrl["Location"] + string.Format("{0}/mapping/{1}", entity.Id, mapping.Id)); response = client.Get(); mappingResponse = response.Content.ReadAsDataContract<EnergyTrading.Mdm.Contracts.MappingResponse>(); }
public InstallationDomain toDomain(LocationMapping location, Core.Domain.Installation.Address address, Core.Domain.Installation.Sponsor sponsor) => new InstallationDomain(Id, Elevation, IsAirlyInstallation, location, address, sponsor);
protected static void Because_of() { entity = Script.LocationData.CreateBasicEntityWithOneMapping(); mapping = entity.Mappings[0]; client = new HttpClient(ServiceUrl["Location"] + string.Format("{0}/mapping/{1}", entity.Id, mapping.Id)); response = client.Get(); mappingResponse = response.Content.ReadAsDataContract <EnergyTrading.Mdm.Contracts.MappingResponse>(); }
public void ValidDetailsSaved() { const int mappingId = 12; // Arrange var validatorFactory = new Mock <IValidatorEngine>(); var mappingEngine = new Mock <IMappingEngine>(); var repository = new Mock <IRepository>(); var searchCache = new Mock <ISearchCache>(); var service = new LocationService(validatorFactory.Object, mappingEngine.Object, repository.Object, searchCache.Object); // NB Don't put mappingId here - service assigns it var identifier = new MdmId { SystemName = "Test", Identifier = "A" }; var message = new AmendMappingRequest { MappingId = mappingId, Mapping = identifier, Version = 34 }; var start = new DateTime(2000, 12, 31); var finish = DateUtility.Round(SystemTime.UtcNow().AddDays(5)); var s1 = new SourceSystem { Name = "Test" }; var m1 = new LocationMapping { Id = mappingId, System = s1, MappingValue = "1", Version = 34UL.GetVersionByteArray(), Validity = new DateRange(start, DateUtility.MaxDate) }; var m2 = new LocationMapping { Id = mappingId, System = s1, MappingValue = "1", Validity = new DateRange(start, finish) }; // NB We deliberately bypasses the business logic var entity = new MDM.Location(); m1.Location = entity; entity.Mappings.Add(m1); validatorFactory.Setup(x => x.IsValid(It.IsAny <AmendMappingRequest>(), It.IsAny <IList <IRule> >())).Returns(true); repository.Setup(x => x.FindOne <LocationMapping>(mappingId)).Returns(m1); mappingEngine.Setup(x => x.Map <EnergyTrading.Mdm.Contracts.MdmId, LocationMapping>(identifier)).Returns(m2); // Act service.UpdateMapping(message); // Assert Assert.AreEqual(mappingId, identifier.MappingId, "Mapping identifier differs"); // Proves we have an update not an add Assert.AreEqual(1, entity.Mappings.Count, "Mapping count differs"); // NB Don't verify result of Update - already covered by LocationMappingFixture repository.Verify(x => x.Save(entity)); repository.Verify(x => x.Flush()); }
public void OverlapsRangeFails() { // Assert var start = new DateTime(1999, 1, 1); var finish = new DateTime(2020, 12, 31); var validity = new DateRange(start, finish); var system = new MDM.SourceSystem { Name = "Test" }; var locationMapping = new LocationMapping { System = system, MappingValue = "1", Validity = validity }; var list = new List <LocationMapping> { locationMapping }; var repository = new Mock <IRepository>(); repository.Setup(x => x.Queryable <LocationMapping>()).Returns(list.AsQueryable()); var systemList = new List <MDM.SourceSystem>(); var systemRepository = new Mock <IRepository>(); systemRepository.Setup(x => x.Queryable <MDM.SourceSystem>()).Returns(systemList.AsQueryable()); var overlapsRangeIdentifier = new EnergyTrading.Mdm.Contracts.MdmId { SystemName = "Test", Identifier = "1", StartDate = start.AddHours(10), EndDate = start.AddHours(15) }; var identifierValidator = new NexusIdValidator <LocationMapping>(repository.Object); var validatorEngine = new Mock <IValidatorEngine>(); validatorEngine.Setup(x => x.IsValid(It.IsAny <EnergyTrading.Mdm.Contracts.MdmId>(), It.IsAny <IList <IRule> >())) .Returns((EnergyTrading.Mdm.Contracts.MdmId x, IList <IRule> y) => identifierValidator.IsValid(x, y)); var validator = new LocationValidator(validatorEngine.Object, repository.Object); var location = new Location { Identifiers = new EnergyTrading.Mdm.Contracts.MdmIdList { overlapsRangeIdentifier } }; // Act var violations = new List <IRule>(); var result = validator.IsValid(location, violations); // Assert Assert.IsFalse(result, "Validator succeeded"); }
public Installation(long id, double elevation, bool isAirlyInstallation, LocationMapping location, Address address, Sponsor sponsor) { Id = id; Location = location; Address = address; Elevation = elevation; Sponsor = sponsor; IsAirlyInstallation = isAirlyInstallation; }
internal static LocationMappingWrapper GetInstance() { LocationMapping real = default(LocationMapping); RealInstanceFactory(ref real); var instance = (LocationMappingWrapper)LocationMappingWrapper.GetWrapper(real); InstanceFactory(ref instance); if (instance == null) { Assert.Inconclusive("Could not Create Test Instance"); } return(instance); }
public async Task <List <MeasurementDomain> > GetMeasurements(LocationMapping location, int maxResults = 3) { var measurements = ReadMeasurements(); if (measurements.Count >= 1) { return(new List <MeasurementDomain>(measurements)); } ClearMeasurements(); measurements = await FetchMeasurements(location, maxResults); measurements = await SaveMeasurements(measurements); return(new List <MeasurementDomain>(measurements)); }
private static void Establish_Context() { var repository = new DbSetRepository(new DbContextProvider(() => new SampleMappingContext())); endur = new SourceSystem { Name = "Endur" + Guid.NewGuid() }; trayport = new SourceSystem { Name = "Trayport" + Guid.NewGuid() }; var entity = new Location { Name = Guid.NewGuid().ToString() }; trayportMapping = new LocationMapping { MappingValue = Guid.NewGuid().ToString(), System = trayport, Validity = new DateRange(DateTime.MinValue, DateTime.MaxValue) }; endurMapping = new LocationMapping { MappingValue = Guid.NewGuid().ToString(), System = endur, IsDefault = false, Validity = new DateRange(DateTime.MinValue, DateTime.MaxValue) }; endurMapping2 = new LocationMapping { MappingValue = Guid.NewGuid().ToString(), System = endur, IsDefault = false, Validity = new DateRange(DateTime.MinValue, DateTime.MaxValue) }; repository.Add(endur); repository.Add(trayport); entity.ProcessMapping(trayportMapping); entity.ProcessMapping(endurMapping); entity.ProcessMapping(endurMapping2); repository.Add(entity); repository.Flush(); }
protected static void Establish_context() { entity = Script.LocationData.CreateBasicEntityWithOneMapping(); currentTrayportMapping = entity.Mappings[0]; mapping = new EnergyTrading.Mdm.Contracts.Mapping { SystemName = currentTrayportMapping.System.Name, Identifier = currentTrayportMapping.MappingValue, SourceSystemOriginated = currentTrayportMapping.IsMaster, DefaultReverseInd = currentTrayportMapping.IsDefault, StartDate = currentTrayportMapping.Validity.Start, EndDate = currentTrayportMapping.Validity.Finish.AddDays(2) }; content = HttpContentExtensions.CreateDataContract(mapping); client = new HttpClient(); }
private async Task <List <MeasurementDomain> > FetchMeasurements(LocationMapping location, int maxResults = 3) { var apiInstallations = await _client.GetInstallations(location, maxResults); var installations = AirlyApiAdapter.FromApi(apiInstallations); var measurements = new List <MeasurementDomain>(); foreach (var installation in installations) { var measurement = await _client.GetMeasurementForInstallation(installation.Id); if (measurement != null) { measurements.Add(AirlyApiAdapter.FromApi(measurement, installation)); } } return(measurements); }
protected static void Establish_context() { entity = Script.LocationData.CreateBasicEntityWithOneMapping(); currentTrayportMapping = entity.Mappings[0]; mapping = new EnergyTrading.Mdm.Contracts.Mapping{ SystemName = currentTrayportMapping.System.Name, Identifier = currentTrayportMapping.MappingValue, SourceSystemOriginated = currentTrayportMapping.IsMaster, DefaultReverseInd = currentTrayportMapping.IsDefault, StartDate = currentTrayportMapping.Validity.Start, EndDate = currentTrayportMapping.Validity.Finish.AddDays(2) }; content = HttpContentExtensions.CreateDataContract(mapping); client = new HttpClient(); }
public MDM.Location CreateBasicEntityWithOneMapping() { var endur = repository.Queryable<SourceSystem>().Where(system => system.Name == "Endur").First(); var entity = ObjectMother.Create<Location>(); var endurMapping = new LocationMapping() { MappingValue = Guid.NewGuid().ToString(), System = endur, IsDefault = true, Validity = new DateRange(DateTime.MinValue, DateTime.MaxValue.Subtract(new TimeSpan(72, 0, 0))) }; entity.ProcessMapping(endurMapping); this.repository.Add(entity); this.repository.Flush(); return entity; }
public async Task <List <ApiInstallation> > GetInstallations(LocationMapping location, double maxDistanceInKm = 1, int maxResults = -1) { if (location == null) { System.Diagnostics.Debug.WriteLine("No location data."); return(null); } var query = HttpUrlBuilder.GetQuery(new Dictionary <string, object> { { "lat", location.Latitude }, { "lng", location.Longitude }, { "maxDistanceKM", maxDistanceInKm }, { "maxResults", maxResults } }); var url = _options.GetUrl(AirlyApiClientFunction.GetInstallations, query); var response = await GetHttpResponseAsync <IEnumerable <ApiInstallation> >(url); return(response.ToList()); }
public MDM.Location CreateBasicEntityWithOneMapping() { var endur = repository.Queryable <SourceSystem>().Where(system => system.Name == "Endur").First(); var entity = ObjectMother.Create <Location>(); var endurMapping = new LocationMapping() { MappingValue = Guid.NewGuid().ToString(), System = endur, IsDefault = true, Validity = new DateRange(DateTime.MinValue, DateTime.MaxValue.Subtract(new TimeSpan(72, 0, 0))) }; entity.ProcessMapping(endurMapping); this.repository.Add(entity); this.repository.Flush(); return(entity); }
public void Draw(SpriteBatch spriteBatch) { if (inventoryItems.Count != 0) { foreach (KeyValuePair <PlayerItems, Rectangle> hudElement in inventoryItems) { if (LocationMapping.ContainsKey(hudElement.Key)) { spriteBatch.Draw(Texture, hudElement.Value, ItemMap[hudElement.Key], Color.White); } } if (Item != PlayerItems.None && !HasBowArrowCombo()) { spriteBatch.Draw(Texture, CurrentItem, ItemMap[Item], Color.White); } else { DrawBowArrow(spriteBatch); } } }
public void ValidContractAdded() { // Arrange var validatorFactory = new Mock <IValidatorEngine>(); var mappingEngine = new Mock <IMappingEngine>(); var repository = new Mock <IRepository>(); var searchCache = new Mock <ISearchCache>(); var service = new LocationService(validatorFactory.Object, mappingEngine.Object, repository.Object, searchCache.Object); var identifier = new MdmId { SystemName = "Test", Identifier = "A" }; var message = new CreateMappingRequest { EntityId = 12, Mapping = identifier }; var system = new MDM.SourceSystem { Name = "Test" }; var mapping = new LocationMapping { System = system, MappingValue = "A" }; validatorFactory.Setup(x => x.IsValid(It.IsAny <CreateMappingRequest>(), It.IsAny <IList <IRule> >())).Returns(true); mappingEngine.Setup(x => x.Map <EnergyTrading.Mdm.Contracts.MdmId, LocationMapping>(identifier)).Returns(mapping); var location = new MDM.Location(); repository.Setup(x => x.FindOne <MDM.Location>(12)).Returns(location); // Act var candidate = (LocationMapping)service.CreateMapping(message); // Assert Assert.AreSame(mapping, candidate); repository.Verify(x => x.Save(location)); repository.Verify(x => x.Flush()); }
public void AddItem(PlayerItems newItem) { if (!HasItem(newItem) && LocationMapping.ContainsKey(newItem) && inventoryItems.Count <= maxItems) { if (!itemToSecondaryItem.ContainsKey(newItem)) { inventoryItems.Add(newItem, LocationMapping[newItem]); } else if (!secondaryItems.Contains(itemToSecondaryItem[newItem])) { secondaryItems.Add(itemToSecondaryItem[newItem]); inventoryItems.Add(newItem, LocationMapping[newItem]); } else { HandleSecondaryItem(newItem); } } else { HandleFairy(newItem); } }
public MDM.Location CreateEntityWithTwoDetailsAndTwoMappings() { var endur = repository.Queryable <SourceSystem>().Where(system => system.Name == "Endur").First(); var trayport = repository.Queryable <SourceSystem>().Where(system => system.Name == "Trayport").First(); var entity = new MDM.Location(); baseDate = DateTime.Today.Subtract(new TimeSpan(72, 0, 0)); SystemTime.UtcNow = () => new DateTime(DateTime.Today.Subtract(new TimeSpan(73, 0, 0)).Ticks); this.AddDetailsToEntity(entity, DateTime.MinValue, baseDate); this.AddDetailsToEntity(entity, baseDate, DateTime.MaxValue); SystemTime.UtcNow = () => DateTime.Now; var trayportMapping = new LocationMapping() { MappingValue = Guid.NewGuid().ToString(), System = trayport, Validity = new DateRange(DateTime.MinValue, DateTime.MaxValue) }; var endurMapping = new LocationMapping() { MappingValue = Guid.NewGuid().ToString(), System = endur, IsDefault = true, Validity = new DateRange(DateTime.MinValue, DateTime.MaxValue) }; entity.ProcessMapping(trayportMapping); entity.ProcessMapping(endurMapping); repository.Add(entity); repository.Flush(); return(entity); }
public MDM.Location CreateEntityWithTwoDetailsAndTwoMappings() { var endur = repository.Queryable<SourceSystem>().Where(system => system.Name == "Endur").First(); var trayport = repository.Queryable<SourceSystem>().Where(system => system.Name == "Trayport").First(); var entity = new MDM.Location(); baseDate = DateTime.Today.Subtract(new TimeSpan(72, 0, 0)); SystemTime.UtcNow = () => new DateTime(DateTime.Today.Subtract(new TimeSpan(73, 0, 0)).Ticks); this.AddDetailsToEntity(entity, DateTime.MinValue, baseDate); this.AddDetailsToEntity(entity, baseDate, DateTime.MaxValue); SystemTime.UtcNow = () => DateTime.Now; var trayportMapping = new LocationMapping() { MappingValue = Guid.NewGuid().ToString(), System = trayport, Validity = new DateRange(DateTime.MinValue, DateTime.MaxValue) }; var endurMapping = new LocationMapping() { MappingValue = Guid.NewGuid().ToString(), System = endur, IsDefault = true, Validity = new DateRange(DateTime.MinValue, DateTime.MaxValue) }; entity.ProcessMapping(trayportMapping); entity.ProcessMapping(endurMapping); repository.Add(entity); repository.Flush(); return entity; }
public void ValidDetailsSaved() { var validatorFactory = new Mock <IValidatorEngine>(); var mappingEngine = new Mock <IMappingEngine>(); var repository = new Mock <IRepository>(); var searchCache = new Mock <ISearchCache>(); // Contract var cd = new EnergyTrading.MDM.Contracts.Sample.LocationDetails(); var nexus = new EnergyTrading.Mdm.Contracts.SystemData { StartDate = new DateTime(2012, 1, 1) }; var identifier = new EnergyTrading.Mdm.Contracts.MdmId { SystemName = "Test", Identifier = "A" }; var contract = new EnergyTrading.MDM.Contracts.Sample.Location { Details = cd, MdmSystemData = nexus }; contract.Identifiers.Add(identifier); // Domain var system = new SourceSystem { Name = "Test" }; var mapping = new LocationMapping { System = system, MappingValue = "A" }; var d1 = ObjectMother.Create <Location>(); d1.Id = 1; d1.Timestamp = 74UL.GetVersionByteArray(); var entity = ObjectMother.Create <Location>(); entity.Timestamp = 74UL.GetVersionByteArray(); entity.AddDetails(d1); var d2 = ObjectMother.Create <Location>(); var range = new DateRange(new DateTime(2012, 1, 1), DateTime.MaxValue); validatorFactory.Setup(x => x.IsValid(It.IsAny <CreateMappingRequest>(), It.IsAny <IList <IRule> >())).Returns(true); validatorFactory.Setup(x => x.IsValid(It.IsAny <EnergyTrading.MDM.Contracts.Sample.Location>(), It.IsAny <IList <IRule> >())).Returns(true); repository.Setup(x => x.FindOne <Location>(1)).Returns(entity); mappingEngine.Setup(x => x.Map <EnergyTrading.MDM.Contracts.Sample.LocationDetails, Location>(cd)).Returns(d2); mappingEngine.Setup(x => x.Map <EnergyTrading.Mdm.Contracts.SystemData, DateRange>(nexus)).Returns(range); mappingEngine.Setup(x => x.Map <EnergyTrading.Mdm.Contracts.MdmId, LocationMapping>(identifier)).Returns(mapping); var service = new LocationService(validatorFactory.Object, mappingEngine.Object, repository.Object, searchCache.Object); // Act service.Update(1, 74, contract); // Assert Assert.AreEqual(0, d2.Mappings.Count, "Created entity mappings count differs"); Assert.AreEqual(0, d2.Id, "Created entity id differs"); Assert.AreEqual(1, entity.Mappings.Count, "Mapping count differs"); repository.Verify(x => x.Save(entity)); repository.Verify(x => x.Flush()); // Ok, hack the created one to align it d2.Id = entity.Id; foreach (var m in entity.Mappings) { d2.Mappings.Add(m); } // Should now be the same - avoid exposing what properties we have here Check(d2, entity); }
/// <summary> /// Reads the service definitions from the provided document. /// For a specification of what the xml should look like, see the /// corresponding Write method. /// </summary> /// <param name="document">The document to read from.</param> /// <returns>A list of service definitions.</returns> public List <ServiceDefinition> ReadServices(XmlDocument document, Dictionary <String, AccessMapping> accessMappings) { List <ServiceDefinition> definitions = new List <ServiceDefinition>(); XmlNodeList servicesNodeList = document.SelectNodes("//" + s_services); if (servicesNodeList == null) { return(definitions); } foreach (XmlNode servicesNode in servicesNodeList) { // Get all of the service definition nodes foreach (XmlNode definitionNode in servicesNode.SelectNodes("./" + s_serviceDefinition)) { ServiceDefinition definition = new ServiceDefinition(); // Get the service type - it must exist XmlNode serviceTypeNode = definitionNode.SelectSingleNode("./" + s_serviceType); LocationXmlOperator.CheckXmlNodeNullOrEmpty(serviceTypeNode, s_serviceType, definitionNode); definition.ServiceType = serviceTypeNode.InnerText; // Get the identifier if it exists - it must exist if this is the client cache XmlNode identifierNode = definitionNode.SelectSingleNode("./" + s_identifier); if (m_isClientCache) { LocationXmlOperator.CheckXmlNodeNullOrEmpty(identifierNode, s_identifier, definitionNode); } definition.Identifier = (identifierNode != null) ? XmlConvert.ToGuid(identifierNode.InnerText) : Guid.Empty; // Get the display name - it must exist XmlNode displayNameNode = definitionNode.SelectSingleNode("./" + s_displayName); LocationXmlOperator.CheckXmlNodeNullOrEmpty(displayNameNode, s_displayName, definitionNode); definition.DisplayName = displayNameNode.InnerText; // Get the description if it exists XmlNode descriptionNode = definitionNode.SelectSingleNode("./" + s_description); definition.Description = (descriptionNode != null) ? descriptionNode.InnerText : String.Empty; // Get the relativePath and the relativeTo setting XmlNode relativePathNode = definitionNode.SelectSingleNode("./" + s_relativePath); LocationXmlOperator.CheckXmlNodeNull(relativePathNode, s_relativePath, definitionNode); definition.RelativePath = relativePathNode.InnerText; // Get the relativeTo setting XmlAttribute relativeToAttribute = relativePathNode.Attributes[s_relativeTo]; CheckXmlAttributeNullOrEmpty(relativeToAttribute, s_relativeTo, relativePathNode); RelativeToSetting setting; if (!RelativeToEnumCache.GetRelativeToEnums().TryGetValue(relativeToAttribute.InnerText, out setting)) { throw new ConfigFileException(relativeToAttribute.InnerText); } definition.RelativeToSetting = setting; // If the relativeToSetting is FullyQualified and the path is empty, set it to null // to make the framework happy. if (definition.RelativeToSetting == RelativeToSetting.FullyQualified && definition.RelativePath == String.Empty) { definition.RelativePath = null; } XmlNode parentServiceTypeNode = definitionNode.SelectSingleNode("./" + s_parentServiceType); definition.ParentServiceType = (parentServiceTypeNode != null) ? parentServiceTypeNode.InnerText : null; XmlNode parentIdentifierNode = definitionNode.SelectSingleNode("./" + s_parentIdentifier); definition.ParentIdentifier = (parentIdentifierNode != null) ? XmlConvert.ToGuid(parentIdentifierNode.InnerText) : Guid.Empty; // Get all of the location mappings definition.LocationMappings = new List <LocationMapping>(); if (definition.RelativeToSetting == RelativeToSetting.FullyQualified) { XmlNodeList mappings = definitionNode.SelectNodes(".//" + s_locationMapping); foreach (XmlNode mappingNode in mappings) { LocationMapping locationMapping = new LocationMapping(); // Get the accessMapping XmlNode accessMappingNode = mappingNode.SelectSingleNode("./" + s_accessMapping); LocationXmlOperator.CheckXmlNodeNullOrEmpty(accessMappingNode, s_accessMapping, mappingNode); locationMapping.AccessMappingMoniker = accessMappingNode.InnerText; // Only process the location code if this is the client cache and there better // not be a location node if this isn't a client cache. XmlNode locationNode = mappingNode.SelectSingleNode("./" + s_location); if (m_isClientCache) { CheckXmlNodeNullOrEmpty(locationNode, s_location, mappingNode); } locationMapping.Location = (locationNode != null) ? locationNode.InnerText : null; // We will let the caller build the proper location from the proper service definitions // instead of doing it here. definition.LocationMappings.Add(locationMapping); } } // Get the resourceVersion XmlNode resourceVersionNode = definitionNode.SelectSingleNode("./" + s_resourceVersion); definition.ResourceVersion = (resourceVersionNode != null) ? XmlConvert.ToInt32(resourceVersionNode.InnerText) : 0; // Get the minVersion XmlNode minVersionNode = definitionNode.SelectSingleNode("./" + s_minVersion); definition.MinVersionString = (minVersionNode != null) ? minVersionNode.InnerText : null; // Get the maxVersion XmlNode maxVersionNode = definitionNode.SelectSingleNode("./" + s_maxVersion); definition.MaxVersionString = (maxVersionNode != null) ? maxVersionNode.InnerText : null; // Get the releasedVersion XmlNode releasedVersionNode = definitionNode.SelectSingleNode("./" + s_releasedVersion); definition.ReleasedVersionString = (releasedVersionNode != null) ? releasedVersionNode.InnerText : null; definitions.Add(definition); } } return(definitions); }
public void calcDistance() { List <string> lst1 = new List <string>(); List <string> lst2 = new List <string>(); DataTable dt = new DataTable(); string url = ""; HttpWebRequest request; WebResponse response; Stream datastream; StreamReader sreader; string responseReader; DataSet ds; List <LocationMapping> lst3 = new List <LocationMapping>(); SqlConnection cn = new SqlConnection(connectionString); cn.Open(); SqlCommand cmd = new SqlCommand("select LocationDesc from locationmaster", cn); SqlDataAdapter da = new SqlDataAdapter(cmd); da.Fill(dt); if (dt.Rows.Count > 0) { for (int i = 0; i < dt.Rows.Count; i++) { lst1.Add(dt.Rows[i]["LocationDesc"].ToString() + ", Mumbai"); lst2.Add(dt.Rows[i]["LocationDesc"].ToString() + ", Mumbai"); } for (int j = 0; j < lst1.Count; j++) { for (int k = 0; k < lst2.Count; k++) { url = @"http://maps.googleapis.com/maps/api/distancematrix/xml?origins=" + lst1[j].ToString() + "&destinations=" + lst2[k].ToString() + "&sensor=false"; request = (HttpWebRequest)WebRequest.Create(url); response = request.GetResponse(); datastream = response.GetResponseStream(); sreader = new StreamReader(datastream); responseReader = sreader.ReadToEnd(); response.Close(); ds = new DataSet(); ds.ReadXml(new XmlTextReader(new StringReader(responseReader))); if (ds.Tables.Count > 0) { if (ds.Tables["element"].Rows[0]["status"].ToString() == "OK") { LocationMapping map = new LocationMapping(); map.Source = lst1[j].ToString(); map.Destination = lst2[k].ToString(); map.Distance = (ds.Tables["distance"].Rows[0]["text"].ToString()); lst3.Add(map); //lblDist.Text = ds.Tables["distance"].Rows[0]["text"].ToString(); } } Thread.Sleep(200); } } grdMapping.DataSource = lst3; grdMapping.DataBind(); } }
static partial void RealInstanceFactory(ref LocationMapping real, [CallerMemberName] string callerName = "");
public void SuccessMatch() { // Arrange var validatorFactory = new Mock <IValidatorEngine>(); var mappingEngine = new Mock <IMappingEngine>(); var repository = new Mock <IRepository>(); var searchCache = new Mock <ISearchCache>(); var service = new LocationService(validatorFactory.Object, mappingEngine.Object, repository.Object, searchCache.Object); // Domain details var start = new DateTime(1999, 12, 31); var finish = new DateTime(2020, 1, 1); var system = new SourceSystem { Name = "Endur" }; var mapping = new LocationMapping { System = system, MappingValue = "A" }; var location = new Location { Id = 1, Validity = new DateRange(start, finish) }; //Location.AddDetails(details); location.ProcessMapping(mapping); // Contract details var identifier = new EnergyTrading.Mdm.Contracts.MdmId { SystemName = "Endur", Identifier = "A" }; var cDetails = new EnergyTrading.MDM.Contracts.Sample.LocationDetails(); mappingEngine.Setup(x => x.Map <LocationMapping, EnergyTrading.Mdm.Contracts.MdmId>(mapping)).Returns(identifier); mappingEngine.Setup(x => x.Map <Location, EnergyTrading.MDM.Contracts.Sample.LocationDetails>(location)).Returns(cDetails); validatorFactory.Setup(x => x.IsValid(It.IsAny <MappingRequest>(), It.IsAny <IList <IRule> >())).Returns(true); var list = new List <LocationMapping> { mapping }; repository.Setup(x => x.Queryable <LocationMapping>()).Returns(list.AsQueryable()); var request = new MappingRequest { SystemName = "Endur", Identifier = "A", ValidAt = SystemTime.UtcNow(), Version = 1 }; // Act var response = service.Map(request); var candidate = response.Contract; // Assert mappingEngine.Verify(x => x.Map <LocationMapping, EnergyTrading.Mdm.Contracts.MdmId>(mapping)); mappingEngine.Verify(x => x.Map <Location, EnergyTrading.MDM.Contracts.Sample.LocationDetails>(location)); repository.Verify(x => x.Queryable <LocationMapping>()); Assert.IsNotNull(candidate, "Contract null"); Assert.AreEqual(2, candidate.Identifiers.Count, "Identifier count incorrect"); // NB This is order dependent Assert.AreSame(identifier, candidate.Identifiers[1], "Different identifier assigned"); Assert.AreSame(cDetails, candidate.Details, "Different details assigned"); Assert.AreEqual(start, candidate.MdmSystemData.StartDate, "Start date differs"); Assert.AreEqual(finish, candidate.MdmSystemData.EndDate, "End date differs"); }
internal static LocationMapping FromApi(ApiLocation location) => LocationMapping.Create(location.Latitude, location.Longitude);
public void SuccessMatch() { // Arrange var validatorFactory = new Mock <IValidatorEngine>(); var mappingEngine = new Mock <IMappingEngine>(); var repository = new Mock <IRepository>(); var searchCache = new Mock <ISearchCache>(); var service = new LocationService(validatorFactory.Object, mappingEngine.Object, repository.Object, searchCache.Object); // Domain details var system = new MDM.SourceSystem { Name = "Endur" }; var mapping = new LocationMapping { System = system, MappingValue = "A" }; var targetSystem = new MDM.SourceSystem { Name = "Trayport" }; var targetMapping = new LocationMapping { System = targetSystem, MappingValue = "B", IsDefault = true }; var location = new MDM.Location { Id = 1, Timestamp = new byte[] { 1, 0, 0, 0, 0, 0, 0, 0 } }; //Location.AddDetails(details); location.ProcessMapping(mapping); location.ProcessMapping(targetMapping); // Contract details var targetIdentifier = new MdmId { SystemName = "Trayport", Identifier = "B" }; mappingEngine.Setup(x => x.Map <LocationMapping, MdmId>(targetMapping)).Returns(targetIdentifier); var list = new List <LocationMapping> { mapping }; repository.Setup(x => x.Queryable <LocationMapping>()).Returns(list.AsQueryable()); var request = new CrossMappingRequest { SystemName = "Endur", Identifier = "A", TargetSystemName = "trayport", ValidAt = SystemTime.UtcNow(), Version = 0 }; // Act var response = service.CrossMap(request); var candidate = response.Contract; // Assert Assert.IsNotNull(response, "Contract null"); Assert.IsNotNull(candidate, "Mapping null"); Assert.AreEqual(1, candidate.Mappings.Count, "Identifier count incorrect"); Assert.AreSame(targetIdentifier, candidate.Mappings[0], "Different identifier assigned"); }
static partial void RealInstanceFactory(ref LocationMapping real, string callerName) { real = (LocationMapping)FormatterServices.GetUninitializedObject(typeof(LocationMapping)); }