mirror of
https://github.com/PepperDash/Essentials.git
synced 2026-02-16 05:05:00 +00:00
Config validation and subsequent load working. Need to look into exceptions thrown by several devices when deserializing control properties.
This commit is contained in:
@@ -92,22 +92,24 @@ namespace PepperDash.Essentials.Core.Config
|
|||||||
{
|
{
|
||||||
Debug.Console(0, Debug.ErrorLogLevel.Notice, "Loading config file: '{0}'", filePath);
|
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);
|
Debug.Console(0, Debug.ErrorLogLevel.Notice, "Loading Schema from path: {0}", schemaFilePath);
|
||||||
|
|
||||||
|
var jsonConfig = fs.ReadToEnd();
|
||||||
|
|
||||||
if(File.Exists(schemaFilePath))
|
if(File.Exists(schemaFilePath))
|
||||||
{
|
{
|
||||||
// Attempt to validate config against schema
|
// Attempt to validate config against schema
|
||||||
ValidateSchema(fs.ReadToEnd(), schemaFilePath);
|
ValidateSchema(jsonConfig, schemaFilePath);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
Debug.Console(0, Debug.ErrorLogLevel.Warning, "No Schema found at path: {0}", schemaFilePath);
|
Debug.Console(0, Debug.ErrorLogLevel.Warning, "No Schema found at path: {0}", schemaFilePath);
|
||||||
|
|
||||||
if (localConfigFound)
|
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");
|
Debug.Console(0, Debug.ErrorLogLevel.Notice, "Successfully Loaded Local Config");
|
||||||
|
|
||||||
@@ -115,7 +117,7 @@ namespace PepperDash.Essentials.Core.Config
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
var doubleObj = JObject.Parse(fs.ReadToEnd());
|
var doubleObj = JObject.Parse(jsonConfig);
|
||||||
ConfigObject = PortalConfigReader.MergeConfigs(doubleObj).ToObject<EssentialsConfig>();
|
ConfigObject = PortalConfigReader.MergeConfigs(doubleObj).ToObject<EssentialsConfig>();
|
||||||
|
|
||||||
// Extract SystemUrl and TemplateUrl into final config output
|
// 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>
|
/// <param name="schemaFileName">File name of schema to validate against</param>
|
||||||
public static void ValidateSchema(string json, string schemaFileName)
|
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);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -61,7 +61,7 @@
|
|||||||
},
|
},
|
||||||
"required": [
|
"required": [
|
||||||
],
|
],
|
||||||
"title": "Template"
|
"title": "Basic Config"
|
||||||
},
|
},
|
||||||
"Info": {
|
"Info": {
|
||||||
"type": "object",
|
"type": "object",
|
||||||
|
|||||||
@@ -9,8 +9,14 @@ using PepperDash.Essentials.License;
|
|||||||
|
|
||||||
namespace PepperDash.Essentials.Core
|
namespace PepperDash.Essentials.Core
|
||||||
{
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Global application properties
|
||||||
|
/// </summary>
|
||||||
public static class Global
|
public static class Global
|
||||||
{
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// The control system the application is running on
|
||||||
|
/// </summary>
|
||||||
public static CrestronControlSystem ControlSystem { get; set; }
|
public static CrestronControlSystem ControlSystem { get; set; }
|
||||||
|
|
||||||
public static LicenseManager LicenseManager { 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>
|
/// <summary>
|
||||||
/// Wildcarded config file name for global reference
|
/// Wildcarded config file name for global reference
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
|||||||
@@ -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"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -148,6 +148,9 @@
|
|||||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||||
<Compile Include="VideoStatusHelpers.cs" />
|
<Compile Include="VideoStatusHelpers.cs" />
|
||||||
<None Include="app.config" />
|
<None Include="app.config" />
|
||||||
|
<EmbeddedResource Include="Config\Schema\DmChassisControllerPropertiesConfigSchema.json">
|
||||||
|
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
||||||
|
</EmbeddedResource>
|
||||||
<None Include="Properties\ControlSystem.cfg" />
|
<None Include="Properties\ControlSystem.cfg" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
|||||||
@@ -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])$"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -182,6 +182,9 @@
|
|||||||
<Compile Include="VideoCodec\ZoomRoom\ZoomRoom.cs" />
|
<Compile Include="VideoCodec\ZoomRoom\ZoomRoom.cs" />
|
||||||
<Compile Include="VideoCodec\ZoomRoom\ZoomRoomCamera.cs" />
|
<Compile Include="VideoCodec\ZoomRoom\ZoomRoomCamera.cs" />
|
||||||
<Compile Include="VideoCodec\ZoomRoom\ZoomRoomPropertiesConfig.cs" />
|
<Compile Include="VideoCodec\ZoomRoom\ZoomRoomPropertiesConfig.cs" />
|
||||||
|
<EmbeddedResource Include="Display\Schema\SamsungMDCPropertiesConfigSchema.json">
|
||||||
|
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
||||||
|
</EmbeddedResource>
|
||||||
<None Include="Properties\ControlSystem.cfg" />
|
<None Include="Properties\ControlSystem.cfg" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
|||||||
Reference in New Issue
Block a user