private Stream GetStringDtoWithValue(double dtoValue, string shortName, string unit) { ServerResourceDTO dto = new ServerResourceDTO(); dto.Value = dtoValue; dto.Resource_Type = new ResourceTypeDTO(); dto.Resource_Type.Short_Name = shortName; dto.Server_Resource_Unit = new ServerResourceUnitDTO(); dto.Server_Resource_Unit.Unit = unit; dto.Sample_Time = new SampleTimeDTO(); dto.Process = new ProcessDTO(); MemoryStream stream = new MemoryStream(); using (var sw = new StreamWriter(stream, new UTF8Encoding(true), 1024, true)) using (var jtw = new JsonTextWriter(sw) { Formatting = Formatting.None }) { var js = new JsonSerializer(); js.Serialize(jtw, dto); jtw.Flush(); } stream.Seek(0, SeekOrigin.Begin); return(stream); }
private HardwareInformation MapDTO2Model(ServerResourceDTO dto) { return(new HardwareInformation() { MainValue = Math.Round(dto.Value, 2), ShortName = "S." + dto.Resource_Type.Short_Name.Split('_')[0], UnitSymbol = dto.Server_Resource_Unit.Unit }); }