Endpoint: /api/jsonconfiguration - reads json configuration from the root of the IIS App

This commit is contained in:
Stoyan Zlatev
2023-09-01 09:31:14 +02:00
parent 3e36514085
commit 539ed9e3ed
5 changed files with 17024 additions and 12 deletions
@@ -70,7 +70,7 @@
.DeserializeObject<IDictionary<string, AppSection>>(configurationJson, settings)
?? new Dictionary<string, AppSection>();
}
catch (Exception)
catch (Exception e)
{
sections = new Dictionary<string, AppSection>();
}
@@ -88,21 +88,53 @@
AppName = appName
});
foreach (var registerKVP in sectionKVP.Value.Registers)
var section = sectionKVP.Value;
if (section is null)
{
foreach (var detail in registerKVP.Value.Details)
continue;
}
var registers = section.Registers;
if (registers is null)
{
continue;
}
foreach (var registerKVP in registers)
{
var register = registerKVP.Value;
if (register is null)
{
continue;
}
var details = register.Details;
if (details is null)
{
continue;
}
var regId = register.Id;
foreach (var detail in details)
{
var values = detail.Values;
this.ConfigRegistersDefinitions.Add(new RegisterDefinition
{
AppAddress = appId,
AppName = appName,
DataType = this.GetType(detail.Type),
Default = detail?.Values?.Default,
Default = values?.Default is long d ? d : default(long?),
IsAvailable = default(bool),
Maximum = detail?.Values?.Maximum,
Minimum = detail?.Values?.Minimum,
RegAddressInApp = registerKVP.Value.Id,
// RegisterAddress = default(byte[]),
Maximum = values?.Maximum is long max ? max : default(long?),
Minimum = values?.Minimum is long min ? min : default(long?),
RegAddressInApp = regId,
// RegisterAddress = new byte[] { appId, regId },
RegisterDetail = detail,
RegisterName = registerKVP.Key,
RestoreCapability = new StaticType(detail.StaticType)
@@ -2,10 +2,10 @@
{
public class Value
{
public long? Minimum { get; set; }
public object Minimum { get; set; }
public long? Maximum { get; set; }
public object Maximum { get; set; }
public long? Default { get; set; }
public object Default { get; set; }
}
}
@@ -1,7 +1,9 @@
namespace Xylem.Common.Service.MeterProcessState.Controllers
{
using Newtonsoft.Json;
using System.IO;
using System.Web;
using System.Web.Http;
using Xylem.Common.Hardware.WaterMeter.Genesis.GenesisCore;
@@ -11,7 +13,11 @@
[HttpGet]
public IHttpActionResult Get()
{
var file = "configuration.json";
var dir = HttpContext.Current.Request.MapPath("../");
Directory.CreateDirectory(dir);
var file = Path.Combine(dir, "configuration.json");
if (!File.Exists(file))
{
@@ -327,6 +327,7 @@
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
<Content Include="bin\configuration.json" />
<Content Include="configuration.json" />
<None Include="Properties\PublishProfiles\a.pubxml" />
<Content Include="README.md" />
<None Include="Scripts\jquery-1.10.2.intellisense.js" />
File diff suppressed because it is too large Load Diff