public string GetForTopology(string cpuId, TopologyDto topologyDto) { using var stream = new MemoryStream(); var formatter = new BinaryFormatter(); formatter.Serialize(stream, topologyDto); stream.Position = 0; using var md5 = MD5.Create(); return($"{cpuId}_{md5.ComputeHash(stream).ToHexString()}"); }
private async Task <string> AssignTopology(string cpuId, TopologyDto topologyDto, CancellationToken cancellationToken) { var id = _idProvider.GetForTopology(cpuId, topologyDto); var topologyModel = await _topologyRepository.GetSingleAsync(id, cancellationToken); if (topologyModel == null) { topologyModel = topologyDto.ToModel(id); await _topologyRepository.CreateAsync(topologyModel, cancellationToken); } return(id); }
public static TopologyDto ToDto(this TopologyModel model) { if (model == null) { throw new ArgumentNullException(nameof(model)); } var topology = new TopologyDto { TotalDepth = model.TotalDepth, TotalLogicalCores = model.TotalLogicalCores, TotalPhysicalCores = model.TotalLogicalCores, Root = new CpuNodeDto { Name = model.Root.Name, Value = model.Root.Value, NodeType = model.Root.NodeType, OsIndex = model.Root.OsIndex } }; if (model.Root.Children != null) { topology.Root.Children = new List <CpuNodeDto>(); foreach (var child in model.Root.Children) { topology.Root.Children.Add(CreateChild(child)); } } if (model.Root.MemoryChildren != null) { topology.Root.MemoryChildren = new List <CpuNodeDto>(); foreach (var child in model.Root.MemoryChildren) { topology.Root.MemoryChildren.Add(CreateChild(child)); } } return(topology); }
public static TopologyModel ToModel(this TopologyDto topologyDto, string id) { if (topologyDto == null) { throw new ArgumentNullException(nameof(topologyDto)); } if (string.IsNullOrWhiteSpace(id)) { throw new ArgumentException("'id' cannot be empty", nameof(id)); } return(new TopologyModel { Id = id, TotalDepth = topologyDto.TotalDepth, TotalLogicalCores = topologyDto.TotalLogicalCores, TotalPhysicalCores = topologyDto.TotalLogicalCores, Root = topologyDto.Root.ToModel() }); }