Config validation and subsequent load working. Need to look into exceptions thrown by several devices when deserializing control properties.

This commit is contained in:
Neil Dorin
2020-01-21 17:39:57 -07:00
parent bd7831146d
commit 740c944f54
8 changed files with 142 additions and 11 deletions

View File

@@ -92,22 +92,24 @@ namespace PepperDash.Essentials.Core.Config
{
Debug.Console(0, Debug.ErrorLogLevel.Notice, "Loading config file: '{0}'", filePath);
var directoryPrefix = Crestron.SimplSharp.CrestronIO.Directory.GetApplicationRootDirectory();
var directoryPrefix = string.Format("{0}Config{1}Schema{1}", Global.ApplicationDirectoryPrefix, Global.DirectorySeparator);
var schemaFilePath = directoryPrefix + Global.DirectorySeparator + "Config" + Global.DirectorySeparator + "Schema" + Global.DirectorySeparator + "EssentialsConfigSchema.json";
var schemaFilePath = directoryPrefix + "EssentialsConfigSchema.json";
Debug.Console(0, Debug.ErrorLogLevel.Notice, "Loading Schema from path: {0}", schemaFilePath);
var jsonConfig = fs.ReadToEnd();
if(File.Exists(schemaFilePath))
{
// Attempt to validate config against schema
ValidateSchema(fs.ReadToEnd(), schemaFilePath);
ValidateSchema(jsonConfig, schemaFilePath);
}
else
Debug.Console(0, Debug.ErrorLogLevel.Warning, "No Schema found at path: {0}", schemaFilePath);
if (localConfigFound)
{
ConfigObject = JObject.Parse(fs.ReadToEnd()).ToObject<EssentialsConfig>();
ConfigObject = JObject.Parse(jsonConfig).ToObject<EssentialsConfig>();
Debug.Console(0, Debug.ErrorLogLevel.Notice, "Successfully Loaded Local Config");
@@ -115,7 +117,7 @@ namespace PepperDash.Essentials.Core.Config
}
else
{
var doubleObj = JObject.Parse(fs.ReadToEnd());
var doubleObj = JObject.Parse(jsonConfig);
ConfigObject = PortalConfigReader.MergeConfigs(doubleObj).ToObject<EssentialsConfig>();
// Extract SystemUrl and TemplateUrl into final config output
@@ -150,13 +152,20 @@ namespace PepperDash.Essentials.Core.Config
/// <param name="schemaFileName">File name of schema to validate against</param>
public static void ValidateSchema(string json, string schemaFileName)
{
JToken config = JToken.Parse(json);
Debug.Console(0, Debug.ErrorLogLevel.Notice, "Validating Config File against Schema...");
JObject config = JObject.Parse(json);
using (StreamReader fs = new StreamReader(schemaFileName))
using (StreamReader fileStream = new StreamReader(schemaFileName))
{
JsonSchema schema = JsonSchema.Parse(fs.ReadToEnd());
JsonSchema schema = JsonSchema.Parse(fileStream.ReadToEnd());
config.Validate(schema, Json_ValidationEventHandler);
if (config.IsValid(schema))
Debug.Console(0, Debug.ErrorLogLevel.Notice, "Configuration successfully Validated Against Schema");
else
{
Debug.Console(0, Debug.ErrorLogLevel.Warning, "Validation Errors Found in Configuration:");
config.Validate(schema, Json_ValidationEventHandler);
}
}
}

View File

@@ -61,7 +61,7 @@
},
"required": [
],
"title": "Template"
"title": "Basic Config"
},
"Info": {
"type": "object",

View File

@@ -9,8 +9,14 @@ using PepperDash.Essentials.License;
namespace PepperDash.Essentials.Core
{
/// <summary>
/// Global application properties
/// </summary>
public static class Global
{
/// <summary>
/// The control system the application is running on
/// </summary>
public static CrestronControlSystem ControlSystem { get; set; }
public static LicenseManager LicenseManager { get; set; }
@@ -31,6 +37,19 @@ namespace PepperDash.Essentials.Core
}
}
/// <summary>
/// The file path prefix to the folder containing the application files (including embedded resources)
/// </summary>
public static string ApplicationDirectoryPrefix
{
get
{
string fmt = "00.##";
var appNumber = InitialParametersClass.ApplicationNumber.ToString(fmt);
return string.Format("{0}{1}Simpl{1}app{2}{1}", Crestron.SimplSharp.CrestronIO.Directory.GetApplicationRootDirectory(), Global.DirectorySeparator,appNumber );
}
}
/// <summary>
/// Wildcarded config file name for global reference
/// </summary>

View File

@@ -0,0 +1,74 @@
{
"$schema": "http://json-schema.org/draft-07/schema#",
"title": "DmChassisController Properties Config Schema",
"description": "",
"$ref":"EssentialsConfigSchema.json/definitions/Device",
"properties":{
"properties":{
"$ref":"#/definitions/propertiesConfig"
}
},
"definitions": {
"propertiesConfig": {
"type":"object",
"additionalProperties": true,
"properties": {
"control":{
"type":"object",
"$ref":"ControlPropertiesConfigSchema.json#definitions/ControlPropertiesConfig"
},
"volumeControls":{
"type":"object",
"additionalProperties": {
"type":"object",
"$ref": "#definitions/dmAudioCardPropertiesConfig"
}
},
"inputSlots":{
"type":"object",
"additionalProperties": {
"type":"string"
}
},
"outputSlots":{
"type":"object",
"additionalProperties": {
"type":"string"
}
},
"inputNames":{
"type":"object",
"additionalProperties": {
"type":"string"
}
},
"outputNames":{
"type":"object",
"additionalProperties": {
"type":"string"
}
},
"noRouteText":{
"type":"string"
},
"inputSlotSupportsHdcp2":{
"type":"object",
"additionalProperties": {
"type":"boolean"
}
}
}
},
"dmAudioCardPropertiesConfig":{
"type":"object",
"properties": {
"OutLevel":{
"type":"integer"
},
"isVolumeControlPoint":{
"type":"boolean"
}
}
}
}
}

View File

@@ -148,6 +148,9 @@
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="VideoStatusHelpers.cs" />
<None Include="app.config" />
<EmbeddedResource Include="Config\Schema\DmChassisControllerPropertiesConfigSchema.json">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</EmbeddedResource>
<None Include="Properties\ControlSystem.cfg" />
</ItemGroup>
<ItemGroup>

View File

@@ -0,0 +1,23 @@
{
"$schema": "http://json-schema.org/draft-07/schema#",
"title": "SamsungMDC Properties Config Schema",
"description": "",
"$ref":"EssentialsConfigSchema.json/definitions/Device",
"properties":{
"properties":{
"$ref":"#/definitions/propertiesConfig"
}
},
"definitions": {
"propertiesConfig": {
"type":"object",
"additionalProperties": true,
"properties": {
"id":{
"type":"string",
"pattern": "^([0-9]|0[1-9]|[2-9][0-9])$"
}
}
}
}
}

View File

@@ -182,6 +182,9 @@
<Compile Include="VideoCodec\ZoomRoom\ZoomRoom.cs" />
<Compile Include="VideoCodec\ZoomRoom\ZoomRoomCamera.cs" />
<Compile Include="VideoCodec\ZoomRoom\ZoomRoomPropertiesConfig.cs" />
<EmbeddedResource Include="Display\Schema\SamsungMDCPropertiesConfigSchema.json">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</EmbeddedResource>
<None Include="Properties\ControlSystem.cfg" />
</ItemGroup>
<ItemGroup>