configuration json register detail access
This commit is contained in:
@@ -1,52 +1,55 @@
|
||||
namespace CommonConsole
|
||||
{
|
||||
using CommonMessurementUnits;
|
||||
using Newtonsoft.Json;
|
||||
using System;
|
||||
using Newtonsoft.Json.Converters;
|
||||
|
||||
using System.Globalization;
|
||||
using System.IO;
|
||||
|
||||
public class Program
|
||||
{
|
||||
public static void Main(string[] args)
|
||||
{
|
||||
int x = 3;
|
||||
Console.WriteLine($"From Int32: {x}");
|
||||
byte[] xb = x.GetBytes();
|
||||
Console.WriteLine($"Bits: {string.Join("", xb.GetBits())}");
|
||||
Console.WriteLine($"Hex bytes: {xb.ToHex()}");
|
||||
int y = BitConverter.ToInt32(xb, 0);
|
||||
Console.WriteLine($"To Int32: {y}");
|
||||
Console.WriteLine();
|
||||
var content = File.ReadAllText("../../configuration.json");
|
||||
var configuration = JsonConvert.DeserializeObject<JsonConfiguration>(content);
|
||||
|
||||
byte sectionId = 10;
|
||||
byte registerId = 2;
|
||||
int version = 20;
|
||||
|
||||
var model = new TestClass
|
||||
/// Getting application section from the configuration
|
||||
var sectionById = configuration[sectionId];
|
||||
|
||||
if (!string.IsNullOrWhiteSpace(sectionById.Name))
|
||||
{
|
||||
Current = 130,
|
||||
Flow = 40,
|
||||
Pressure = 250000,
|
||||
Temperature = 21,
|
||||
Time = 960,
|
||||
Volume = 40,
|
||||
};
|
||||
/// ??? When requested by name creates new Section if name not exists in the keys collection.
|
||||
var sectionByName = configuration[sectionById.Name];
|
||||
}
|
||||
|
||||
var modelJson = JsonConvert.SerializeObject(model, Formatting.Indented);
|
||||
var testModel = JsonConvert.DeserializeObject<TestClass>(modelJson);
|
||||
/// Geting register by sectionId and registerId
|
||||
var registerById = configuration[sectionId][registerId];
|
||||
|
||||
Console.WriteLine($"To Json: {modelJson}");
|
||||
Console.WriteLine($"From Json: {JsonConvert.SerializeObject(testModel, Formatting.Indented)}");
|
||||
if (!string.IsNullOrWhiteSpace(registerById.Name))
|
||||
{
|
||||
/// ??? When requested by name creates new Register for the section if name not exists in the keys collection.
|
||||
var registerByName = configuration[sectionId][registerById.Name];
|
||||
}
|
||||
|
||||
var valueByV = configuration[sectionId][registerId][version];
|
||||
}
|
||||
}
|
||||
|
||||
public class TestClass
|
||||
{
|
||||
public Current Current { get; set; }
|
||||
|
||||
public Flow Flow { get; set; }
|
||||
|
||||
public Pressure Pressure { get; set; }
|
||||
|
||||
public Temperature Temperature { get; set; }
|
||||
|
||||
public Time Time { get; set; }
|
||||
|
||||
public Volume Volume { get; set; }
|
||||
private static JsonSerializerSettings settings => new JsonSerializerSettings
|
||||
{
|
||||
MetadataPropertyHandling = MetadataPropertyHandling.Ignore,
|
||||
DateParseHandling = DateParseHandling.None,
|
||||
Converters =
|
||||
{
|
||||
new AccessConverter(),
|
||||
new IsoDateTimeConverter
|
||||
{
|
||||
DateTimeStyles = DateTimeStyles.AssumeUniversal
|
||||
}
|
||||
},
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user