#pragma warning disable CA1307 // Specify StringComparison - string.GetHashCode(StringComparison) not available in all projects that reference this shared project protected override void ComputeHashCodePartsSpecific(ArrayBuilder <int> builder) { builder.Add(TypeToTrackMetadataName.GetHashCode()); builder.Add(ConstructorMapper.GetHashCode()); builder.Add(PropertyMappers.GetHashCode()); builder.Add(HazardousUsageEvaluators.GetHashCode()); }
#pragma warning disable CA1307 // Specify StringComparison - string.GetHashCode(StringComparison) not available in all projects that reference this shared project protected override void ComputeHashCodePartsSpecific(Action <int> addPart) { addPart(TypeToTrackMetadataName.GetHashCode()); addPart(ConstructorMapper.GetHashCode()); addPart(PropertyMappers.GetHashCode()); addPart(HazardousUsageEvaluators.GetHashCode()); }
public void MapFromJsonString_ShouldDecodeProperties_FromJsonStructure() { var propertyJsonString = Resources.Property_JsonStructure; var properties = PropertyMappers.MapFromJsonString(propertyJsonString).ToList(); var expected = new Dictionary <string, JToken>() { { "flatProperty", "someValue" }, { "golem.srv.comp.container.docker.image", new JArray("golemfactory/ffmpeg") }, { "golem.srv.comp.container.docker.benchmark{golemfactory/ffmpeg}", 7 }, { "golem.srv.comp.container.docker.benchmark{*}", null }, { "golem.inf.cpu.cores", 4 }, { "golem.inf.cpu.threads", 8 }, { "golem.inf.mem.gib", 16 }, { "golem.inf.storage.gib", 30 }, { "golem.com.payment.scheme", "after" }, { "golem.com.pricing.model", "linear" }, { "golem.com.pricing.est{*}", null }, { "golem.usage.vector", new JArray("golem.usage.duration_sec") } }.ToList(); CollectionAssert.AreEquivalent(expected.Select(item => item.Key + "|" + item.Value?.ToString()).ToList(), properties.Select(item => item.Key + "|" + item.Value?.ToString()).ToList()); }
public void MapFromJsonString_ShouldDecodeEmptyProperties() { var propertyJsonString = "{}"; var properties = PropertyMappers.MapFromJsonString(propertyJsonString); CollectionAssert.AreEquivalent(new Dictionary <string, string>().ToList(), properties.ToList()); }
public object MapNode(NodeMappingContext context) { if (context == null) { throw new ArgumentNullException("context"); } object destination = Activator.CreateInstance(DestinationType); PropertyInfo[] includedPaths = null; // Check included paths are actually required if (context.Paths != null) { includedPaths = GetImmediateProperties(DestinationType, context.Paths); foreach (var path in includedPaths) { var propertyMapper = PropertyMappers.SingleOrDefault(x => x.DestinationInfo.Name == path.Name); if (propertyMapper == null) { throw new InvalidPathException( string.Format( "The property '{0}' on '{1}' is not mapped - check your mappings.", path.Name, path.PropertyType.FullName )); } else if (!propertyMapper.RequiresInclude) { throw new InvalidPathException( string.Format( @"The property '{0}' on '{1}' does not require an explicit include (do not include it as a path, it will be populated automatically).", path.Name, path.PropertyType.FullName )); } } } foreach (var propertyMapper in PropertyMappers) { if (context.Paths == null || // include all paths !propertyMapper.RequiresInclude || // map all automatic paths includedPaths.Any(x => x.Name == propertyMapper.DestinationInfo.Name)) // map explicit paths { var destinationValue = propertyMapper.MapProperty(context); propertyMapper.DestinationInfo.SetValue(destination, destinationValue, null); } } return(destination); }
public virtual IActionResult CreateProposalDemand([FromBody] Proposal demandProposal, [FromRoute][Required] string subscriptionId, [FromRoute][Required] string proposalId) { var clientContext = this.HttpContext.Items["ClientContext"] as GolemClientMockAPI.Entities.ClientContext; var subscription = this.SubscriptionRepository.GetDemandSubscription(subscriptionId); if (subscription == null) { return(StatusCode(404, new ErrorMessage() { })); // Not Found } if (clientContext.NodeId != subscription.Demand.NodeId) { return(StatusCode(401, new ErrorMessage() { })); // Unauthorized } var demandEntity = new GolemClientMockAPI.Entities.Demand() { NodeId = clientContext.NodeId, Constraints = demandProposal.Constraints, Properties = PropertyMappers.MapFromJsonString(demandProposal.Properties?.ToString()) }; try { var demandProposalEntity = this.MarketProcessor.CreateDemandProposal(subscriptionId, proposalId, demandEntity); this._logger.LogWithProperties(LogLevel.Information, clientContext?.NodeId, "Requestor", subscription?.Id, $"CreateProposalDemand (Offer Proposal Id: {proposalId}, created Demand Proposal Id: {demandProposalEntity.Id})"); return(StatusCode(201, demandProposalEntity.Id)); } catch (Exception exc) { return(StatusCode(404, new ErrorMessage() { Message = $"creating demand proposal: {proposalId}, {demandEntity} error: {exc.Message}" })); // Not Found } }
/// <summary> /// Inserts a property mapper, /// </summary> /// <param name="propertyMapper"></param> public void InsertPropertyMapper(PropertyMapperBase propertyMapper) { if (propertyMapper == null) { throw new ArgumentNullException("propertyMapper"); } RemovePropertyMapper(propertyMapper.DestinationInfo); PropertyMappers.Add(propertyMapper); if (Engine.CacheProvider != null) { Engine.CacheProvider.Clear(); } }
public void RemovePropertyMapper(PropertyInfo destinationProperty) { if (destinationProperty == null) { throw new ArgumentNullException("destinationProperty"); } var existingMapper = PropertyMappers .SingleOrDefault(x => x.DestinationInfo.Name == destinationProperty.Name); if (existingMapper != null) { PropertyMappers.Remove(existingMapper); } if (Engine.CacheProvider != null) { Engine.CacheProvider.Clear(); } }
public void MapFromJsonString_ShouldDecodeProperties_FromJsonFlat() { var propertyJsonString = Resources.Property_JsonFlat; var properties = PropertyMappers.MapFromJsonString(propertyJsonString); CollectionAssert.AreEquivalent(new Dictionary <string, string>() { { "golem.srv.comp.container.docker.image", "[\"golemfactory/ffmpeg\"]" }, { "golem.srv.comp.container.docker.benchmark{golemfactory/ffmpeg}", "7" }, { "golem.srv.comp.container.docker.benchmark{*}", null }, { "golem.inf.cpu.cores", "4" }, { "golem.inf.cpu.threads", "8" }, { "golem.inf.mem.gib", "16" }, { "golem.inf.storage.gib", "30" }, { "golem.com.payment.scheme", "\"after\"" }, { "golem.com.pricing.model", "\"linear\"" }, { "golem.com.pricing.est{*}", null }, { "golem.usage.vector", "[\"golem.usage.duration_sec\"]" } }.ToList(), properties.ToList()); }
public NodeStats GetNodeDetails(string nodeId) { var result = this.Subscriptions.Values .Where(sub => { if (sub is OfferSubscription) { return((sub as OfferSubscription).Offer.NodeId == nodeId); } else { return((sub as DemandSubscription).Demand.NodeId == nodeId); } }) .GroupBy(sub => { if (sub is OfferSubscription) { return((sub as OfferSubscription).Offer.NodeId); } else { return((sub as DemandSubscription).Demand.NodeId); } }) .Select(subGrp => new NodeStats() { NodeId = nodeId, SubscriptionCount = subGrp.Count(), Subscriptions = subGrp.Select(sub => { if (sub is OfferSubscription) { var off = sub as OfferSubscription; return(new SubscriptionStats() { Constraints = off.Offer.Constraints, Properties = PropertyMappers.MapToJsonString(off.Offer.Properties), SubscriptionId = off.Id }); } else { var dem = sub as DemandSubscription; return(new SubscriptionStats() { Constraints = dem.Demand.Constraints, Properties = PropertyMappers.MapToJsonString(dem.Demand.Properties), SubscriptionId = dem.Id }); } }), Connected = subGrp.Min(sub => sub.CreatedDate), LastActive = subGrp.Max(sub => sub.LastActiveDate) } ) .FirstOrDefault(); return(result); }