diff --git a/essentials-framework/Essentials Core/PepperDashEssentialsBase/Config/Essentials/ConfigReader.cs b/essentials-framework/Essentials Core/PepperDashEssentialsBase/Config/Essentials/ConfigReader.cs index 8c0a7ea1..4ec1f3ef 100644 --- a/essentials-framework/Essentials Core/PepperDashEssentialsBase/Config/Essentials/ConfigReader.cs +++ b/essentials-framework/Essentials Core/PepperDashEssentialsBase/Config/Essentials/ConfigReader.cs @@ -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(); + ConfigObject = JObject.Parse(jsonConfig).ToObject(); 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(); // Extract SystemUrl and TemplateUrl into final config output @@ -150,13 +152,20 @@ namespace PepperDash.Essentials.Core.Config /// File name of schema to validate against 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); + } } } diff --git a/essentials-framework/Essentials Core/PepperDashEssentialsBase/Config/Schema/EssentialsConfigSchema.json b/essentials-framework/Essentials Core/PepperDashEssentialsBase/Config/Schema/EssentialsConfigSchema.json index 198b449b..08cc249e 100644 --- a/essentials-framework/Essentials Core/PepperDashEssentialsBase/Config/Schema/EssentialsConfigSchema.json +++ b/essentials-framework/Essentials Core/PepperDashEssentialsBase/Config/Schema/EssentialsConfigSchema.json @@ -61,7 +61,7 @@ }, "required": [ ], - "title": "Template" + "title": "Basic Config" }, "Info": { "type": "object", diff --git a/essentials-framework/Essentials Core/PepperDashEssentialsBase/Global/Global.cs b/essentials-framework/Essentials Core/PepperDashEssentialsBase/Global/Global.cs index 6ce3446e..dfce11bf 100644 --- a/essentials-framework/Essentials Core/PepperDashEssentialsBase/Global/Global.cs +++ b/essentials-framework/Essentials Core/PepperDashEssentialsBase/Global/Global.cs @@ -9,8 +9,14 @@ using PepperDash.Essentials.License; namespace PepperDash.Essentials.Core { + /// + /// Global application properties + /// public static class Global { + /// + /// The control system the application is running on + /// public static CrestronControlSystem ControlSystem { get; set; } public static LicenseManager LicenseManager { get; set; } @@ -31,6 +37,19 @@ namespace PepperDash.Essentials.Core } } + /// + /// The file path prefix to the folder containing the application files (including embedded resources) + /// + 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 ); + } + } + /// /// Wildcarded config file name for global reference /// diff --git a/essentials-framework/Essentials DM/Essentials_DM/Config/Schema/DmChassisControllerPropertiesConfigSchema.json b/essentials-framework/Essentials DM/Essentials_DM/Config/Schema/DmChassisControllerPropertiesConfigSchema.json new file mode 100644 index 00000000..2676d53f --- /dev/null +++ b/essentials-framework/Essentials DM/Essentials_DM/Config/Schema/DmChassisControllerPropertiesConfigSchema.json @@ -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" + } + } + } + } +} \ No newline at end of file diff --git a/essentials-framework/Essentials DM/Essentials_DM/Essentials_DM.csproj b/essentials-framework/Essentials DM/Essentials_DM/Essentials_DM.csproj index 74f4d9b7..654159e6 100644 --- a/essentials-framework/Essentials DM/Essentials_DM/Essentials_DM.csproj +++ b/essentials-framework/Essentials DM/Essentials_DM/Essentials_DM.csproj @@ -148,6 +148,9 @@ + + Always + diff --git a/essentials-framework/Essentials Devices Common/Essentials Devices Common/Display/Schema/SamsungMDCPropertiesConfigSchema.json b/essentials-framework/Essentials Devices Common/Essentials Devices Common/Display/Schema/SamsungMDCPropertiesConfigSchema.json new file mode 100644 index 00000000..ff78a4c3 --- /dev/null +++ b/essentials-framework/Essentials Devices Common/Essentials Devices Common/Display/Schema/SamsungMDCPropertiesConfigSchema.json @@ -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])$" + } + } + } + } +} \ No newline at end of file diff --git a/essentials-framework/Essentials Devices Common/Essentials Devices Common/Essentials Devices Common.csproj b/essentials-framework/Essentials Devices Common/Essentials Devices Common/Essentials Devices Common.csproj index bed83feb..d9d6f701 100644 --- a/essentials-framework/Essentials Devices Common/Essentials Devices Common/Essentials Devices Common.csproj +++ b/essentials-framework/Essentials Devices Common/Essentials Devices Common/Essentials Devices Common.csproj @@ -182,6 +182,9 @@ + + Always + diff --git a/essentials-framework/pepperdashcore-builds b/essentials-framework/pepperdashcore-builds index aa2cbb96..b7daa148 160000 --- a/essentials-framework/pepperdashcore-builds +++ b/essentials-framework/pepperdashcore-builds @@ -1 +1 @@ -Subproject commit aa2cbb965d2777370358e749e9608dbbafccc466 +Subproject commit b7daa148176ce7e1838303dffee6f9a6c36b7a7b