mirror of
https://github.com/PepperDash/PepperDashCore.git
synced 2026-02-16 05:04:48 +00:00
Adds PropertiesConfigBase and adds Summary Help and JsonProperty definitions to config properties classes
This commit is contained in:
@@ -4,49 +4,201 @@ using System.Linq;
|
|||||||
using System.Text;
|
using System.Text;
|
||||||
using Crestron.SimplSharp;
|
using Crestron.SimplSharp;
|
||||||
using Newtonsoft.Json;
|
using Newtonsoft.Json;
|
||||||
|
using Newtonsoft.Json.Schema;
|
||||||
|
|
||||||
namespace PepperDash.Core
|
namespace PepperDash.Core
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
///
|
/// Defines the means of communicating with and controlling a device
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public class ControlPropertiesConfig
|
public class ControlPropertiesConfig :PropertiesConfigBase
|
||||||
{
|
{
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// The control method for the device
|
||||||
|
/// </summary>
|
||||||
|
[JsonProperty("method", Required = Required.Always)]
|
||||||
public eControlMethod Method { get; set; }
|
public eControlMethod Method { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// The key of the device where the control port can be found
|
||||||
|
/// </summary>
|
||||||
|
[JsonProperty("controlPortDevKey")]
|
||||||
public string ControlPortDevKey { get; set; }
|
public string ControlPortDevKey { get; set; }
|
||||||
|
|
||||||
[JsonProperty(NullValueHandling = NullValueHandling.Ignore)] // In case "null" is present in config on this value
|
/// <summary>
|
||||||
|
/// Number of the control port on the parent device specified by ControlPortDevKey
|
||||||
|
/// </summary>
|
||||||
|
[JsonProperty("controlPortNumber", NullValueHandling = NullValueHandling.Ignore)] // In case "null" is present in config on this value
|
||||||
public uint ControlPortNumber { get; set; }
|
public uint ControlPortNumber { get; set; }
|
||||||
|
|
||||||
[JsonProperty(NullValueHandling = NullValueHandling.Ignore)] // In case "null" is present in config on this value
|
/// <summary>
|
||||||
|
/// Name of the control port on the parent device specified by ControlPortDevKey
|
||||||
|
/// </summary>
|
||||||
|
[JsonProperty("controlPortName", NullValueHandling = NullValueHandling.Ignore)] // In case "null" is present in config on this value
|
||||||
public string ControlPortName { get; set; }
|
public string ControlPortName { get; set; }
|
||||||
|
|
||||||
|
|
||||||
public TcpSshPropertiesConfig TcpSshProperties { get; set; }
|
public TcpSshPropertiesConfig TcpSshProperties { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Name of the IR file
|
||||||
|
/// </summary>
|
||||||
|
[JsonProperty("irFile")]
|
||||||
public string IrFile { get; set; }
|
public string IrFile { get; set; }
|
||||||
|
|
||||||
//public ComPortConfig ComParams { get; set; }
|
/// <summary>
|
||||||
|
/// IpId of the device
|
||||||
//[JsonConverter(typeof(ComSpecJsonConverter))]
|
/// </summary>
|
||||||
//public ComPort.ComPortSpec ComParams { get; set; }
|
[JsonProperty("ipid")]
|
||||||
|
|
||||||
public string IpId { get; set; }
|
public string IpId { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// uint representation of the IpId property
|
||||||
|
/// </summary>
|
||||||
[JsonIgnore]
|
[JsonIgnore]
|
||||||
public uint IpIdInt { get { return Convert.ToUInt32(IpId, 16); } }
|
public uint IpIdInt { get { return Convert.ToUInt32(IpId, 16); } }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Character that delimits the end of a line in multiline repsonses
|
||||||
|
/// </summary>
|
||||||
|
[JsonProperty("endofLineChar")]
|
||||||
public char EndOfLineChar { get; set; }
|
public char EndOfLineChar { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
/// String that delimits the end of a line in multiline responses.
|
||||||
/// Defaults to Environment.NewLine;
|
/// Defaults to Environment.NewLine;
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
[JsonProperty("endofLineString")]
|
||||||
public string EndOfLineString { get; set; }
|
public string EndOfLineString { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Regex pattern that defines the prompt indicating a device is ready for communication
|
||||||
|
/// </summary>
|
||||||
|
[JsonProperty("deviceReadyResponsePattern")]
|
||||||
public string DeviceReadyResponsePattern { get; set; }
|
public string DeviceReadyResponsePattern { get; set; }
|
||||||
|
|
||||||
public ControlPropertiesConfig()
|
public ControlPropertiesConfig()
|
||||||
{
|
{
|
||||||
|
SchemaJson = @"
|
||||||
|
{
|
||||||
|
'definitions': {},
|
||||||
|
'$schema': 'http://json-schema.org/draft-07/schema#',
|
||||||
|
'$id': 'http://example.com/root.json',
|
||||||
|
'type': 'object',
|
||||||
|
'title': 'The Root Schema',
|
||||||
|
'properties': {
|
||||||
|
'tcpSshProperties': {
|
||||||
|
'$id': '#/properties/tcpSshProperties',
|
||||||
|
'type': 'object',
|
||||||
|
'title': 'The Tcpsshproperties Schema',
|
||||||
|
'default': null
|
||||||
|
},
|
||||||
|
'method': {
|
||||||
|
'$id': '#/properties/method',
|
||||||
|
'type': 'string',
|
||||||
|
'title': 'The Method Schema',
|
||||||
|
'default': '',
|
||||||
|
'examples': [
|
||||||
|
'ssh'
|
||||||
|
],
|
||||||
|
'pattern': '^(.*)$'
|
||||||
|
},
|
||||||
|
'controlPortDevKey': {
|
||||||
|
'$id': '#/properties/controlPortDevKey',
|
||||||
|
'type': 'string',
|
||||||
|
'title': 'The Controlportdevkey Schema',
|
||||||
|
'default': '',
|
||||||
|
'examples': [
|
||||||
|
'processor'
|
||||||
|
],
|
||||||
|
'pattern': '^(.*)$'
|
||||||
|
},
|
||||||
|
'controlPortNumber': {
|
||||||
|
'$id': '#/properties/controlPortNumber',
|
||||||
|
'type': 'integer',
|
||||||
|
'title': 'The Controlportnumber Schema',
|
||||||
|
'default': 0,
|
||||||
|
'examples': [
|
||||||
|
1
|
||||||
|
]
|
||||||
|
},
|
||||||
|
'controlPortName': {
|
||||||
|
'$id': '#/properties/controlPortName',
|
||||||
|
'type': 'string',
|
||||||
|
'title': 'The Controlportname Schema',
|
||||||
|
'default': '',
|
||||||
|
'examples': [
|
||||||
|
'hdmi1'
|
||||||
|
],
|
||||||
|
'pattern': '^(.*)$'
|
||||||
|
},
|
||||||
|
'irFile': {
|
||||||
|
'$id': '#/properties/irFile',
|
||||||
|
'type': 'string',
|
||||||
|
'title': 'The Irfile Schema',
|
||||||
|
'default': '',
|
||||||
|
'examples': [
|
||||||
|
'Comcast Motorola DVR.ir'
|
||||||
|
],
|
||||||
|
'pattern': '^(.*)$'
|
||||||
|
},
|
||||||
|
'ipid': {
|
||||||
|
'$id': '#/properties/ipid',
|
||||||
|
'type': 'string',
|
||||||
|
'title': 'The Ipid Schema',
|
||||||
|
'default': '',
|
||||||
|
'examples': [
|
||||||
|
'13'
|
||||||
|
],
|
||||||
|
'pattern': '^(.*)$'
|
||||||
|
},
|
||||||
|
'endOfLineChar': {
|
||||||
|
'$id': '#/properties/endOfLineChar',
|
||||||
|
'type': 'string',
|
||||||
|
'title': 'The Endoflinechar Schema',
|
||||||
|
'default': '',
|
||||||
|
'examples': [
|
||||||
|
'\\x0d'
|
||||||
|
],
|
||||||
|
'pattern': '^(.*)$'
|
||||||
|
},
|
||||||
|
'endOfLineString': {
|
||||||
|
'$id': '#/properties/endOfLineString',
|
||||||
|
'type': 'string',
|
||||||
|
'title': 'The Endoflinestring Schema',
|
||||||
|
'default': '',
|
||||||
|
'examples': [
|
||||||
|
'\n'
|
||||||
|
],
|
||||||
|
'pattern': '^(.*)$'
|
||||||
|
},
|
||||||
|
'deviceReadyResponsePattern': {
|
||||||
|
'$id': '#/properties/deviceReadyResponsePattern',
|
||||||
|
'type': 'string',
|
||||||
|
'title': 'The Devicereadyresponsepattern Schema',
|
||||||
|
'default': '',
|
||||||
|
'examples': [
|
||||||
|
'.*>'
|
||||||
|
],
|
||||||
|
'pattern': '^(.*)$'
|
||||||
|
}
|
||||||
|
},
|
||||||
|
'required': [
|
||||||
|
'method',
|
||||||
|
'controlPortDevKey',
|
||||||
|
'controlPortNumber',
|
||||||
|
'controlPortName',
|
||||||
|
'irFile',
|
||||||
|
'ipid',
|
||||||
|
'endOfLineChar',
|
||||||
|
'endOfLineString',
|
||||||
|
'deviceReadyResponsePattern'
|
||||||
|
]
|
||||||
|
}
|
||||||
|
";
|
||||||
|
|
||||||
|
|
||||||
EndOfLineString = CrestronEnvironment.NewLine;
|
EndOfLineString = CrestronEnvironment.NewLine;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -425,56 +425,6 @@ namespace PepperDash.Core
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Configuration properties for TCP/SSH Connections
|
|
||||||
/// </summary>
|
|
||||||
public class TcpSshPropertiesConfig
|
|
||||||
{
|
|
||||||
/// <summary>
|
|
||||||
/// Address to connect to
|
|
||||||
/// </summary>
|
|
||||||
[JsonProperty(Required = Required.Always)]
|
|
||||||
public string Address { get; set; }
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Port to connect to
|
|
||||||
/// </summary>
|
|
||||||
[JsonProperty(Required = Required.Always)]
|
|
||||||
public int Port { get; set; }
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Username credential
|
|
||||||
/// </summary>
|
|
||||||
public string Username { get; set; }
|
|
||||||
/// <summary>
|
|
||||||
/// Passord credential
|
|
||||||
/// </summary>
|
|
||||||
public string Password { get; set; }
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Defaults to 32768
|
|
||||||
/// </summary>
|
|
||||||
public int BufferSize { get; set; }
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Defaults to true
|
|
||||||
/// </summary>
|
|
||||||
public bool AutoReconnect { get; set; }
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Defaults to 5000ms
|
|
||||||
/// </summary>
|
|
||||||
public int AutoReconnectIntervalMs { get; set; }
|
|
||||||
|
|
||||||
public TcpSshPropertiesConfig()
|
|
||||||
{
|
|
||||||
BufferSize = 32768;
|
|
||||||
AutoReconnect = true;
|
|
||||||
AutoReconnectIntervalMs = 5000;
|
|
||||||
Username = "";
|
|
||||||
Password = "";
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
147
Pepperdash Core/Pepperdash Core/Comm/TcpSshPropertiesConfig.cs
Normal file
147
Pepperdash Core/Pepperdash Core/Comm/TcpSshPropertiesConfig.cs
Normal file
@@ -0,0 +1,147 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using Crestron.SimplSharp;
|
||||||
|
|
||||||
|
using Newtonsoft.Json;
|
||||||
|
|
||||||
|
namespace PepperDash.Core
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Configuration properties for TCP/SSH Connections
|
||||||
|
/// </summary>
|
||||||
|
[JsonProperty("tcpSshProperties")]
|
||||||
|
public class TcpSshPropertiesConfig : PropertiesConfigBase
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Address to connect to
|
||||||
|
/// </summary>
|
||||||
|
[JsonProperty("address", Required = Required.Always)]
|
||||||
|
public string Address { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Port to connect to
|
||||||
|
/// </summary>
|
||||||
|
[JsonProperty("port", Required = Required.Always)]
|
||||||
|
public int Port { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Username credential. Defaults to ""
|
||||||
|
/// </summary>
|
||||||
|
public string Username { get; set; }
|
||||||
|
/// <summary>
|
||||||
|
/// Passord credential. Defaults to ""
|
||||||
|
/// </summary>
|
||||||
|
public string Password { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Buffer size. Defaults to 32768
|
||||||
|
/// </summary>
|
||||||
|
public int BufferSize { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Indicates if automatic reconnection attemtps should be made.Defaults to true.
|
||||||
|
/// Uses AutoReconnectIntervalMs to determine frequency of attempts.
|
||||||
|
/// </summary>
|
||||||
|
public bool AutoReconnect { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Defaults to 5000ms. Requires AutoReconnect to be true.
|
||||||
|
/// </summary>
|
||||||
|
public int AutoReconnectIntervalMs { get; set; }
|
||||||
|
|
||||||
|
public TcpSshPropertiesConfig()
|
||||||
|
{
|
||||||
|
SchemaJson = @"
|
||||||
|
{
|
||||||
|
'definitions': {},
|
||||||
|
'$schema': 'http://json-schema.org/draft-07/schema#',
|
||||||
|
'$id': 'http://example.com/root.json',
|
||||||
|
'type': 'object',
|
||||||
|
'title': 'The Root Schema',
|
||||||
|
'properties': {
|
||||||
|
'username': {
|
||||||
|
'$id': '#/properties/username',
|
||||||
|
'type': 'string',
|
||||||
|
'title': 'The Username Schema',
|
||||||
|
'default': '',
|
||||||
|
'examples': [
|
||||||
|
'admin'
|
||||||
|
],
|
||||||
|
'pattern': '^(.*)$'
|
||||||
|
},
|
||||||
|
'port': {
|
||||||
|
'$id': '#/properties/port',
|
||||||
|
'type': 'integer',
|
||||||
|
'title': 'The Port Schema',
|
||||||
|
'default': 0,
|
||||||
|
'examples': [
|
||||||
|
22
|
||||||
|
]
|
||||||
|
},
|
||||||
|
'address': {
|
||||||
|
'$id': '#/properties/address',
|
||||||
|
'type': 'string',
|
||||||
|
'title': 'The Address Schema',
|
||||||
|
'default': '',
|
||||||
|
'examples': [
|
||||||
|
'10.11.50.135'
|
||||||
|
],
|
||||||
|
'pattern': '^(.*)$'
|
||||||
|
},
|
||||||
|
'password': {
|
||||||
|
'$id': '#/properties/password',
|
||||||
|
'type': 'string',
|
||||||
|
'title': 'The Password Schema',
|
||||||
|
'default': '',
|
||||||
|
'examples': [
|
||||||
|
'password'
|
||||||
|
],
|
||||||
|
'pattern': '^(.*)$'
|
||||||
|
},
|
||||||
|
'autoReconnect': {
|
||||||
|
'$id': '#/properties/autoReconnect',
|
||||||
|
'type': 'boolean',
|
||||||
|
'title': 'The Autoreconnect Schema',
|
||||||
|
'default': false,
|
||||||
|
'examples': [
|
||||||
|
true
|
||||||
|
]
|
||||||
|
},
|
||||||
|
'autoReconnectIntervalMs': {
|
||||||
|
'$id': '#/properties/autoReconnectIntervalMs',
|
||||||
|
'type': 'integer',
|
||||||
|
'title': 'The Autoreconnectintervalms Schema',
|
||||||
|
'default': 0,
|
||||||
|
'examples': [
|
||||||
|
2000
|
||||||
|
]
|
||||||
|
},
|
||||||
|
'bufferSize': {
|
||||||
|
'$id': '#/properties/bufferSize',
|
||||||
|
'type': 'integer',
|
||||||
|
'title': 'The Buffersize Schema',
|
||||||
|
'default': 0,
|
||||||
|
'examples': [
|
||||||
|
32768
|
||||||
|
]
|
||||||
|
}
|
||||||
|
},
|
||||||
|
'required': [
|
||||||
|
'port',
|
||||||
|
'address'
|
||||||
|
]
|
||||||
|
}
|
||||||
|
";
|
||||||
|
|
||||||
|
|
||||||
|
BufferSize = 32768;
|
||||||
|
AutoReconnect = true;
|
||||||
|
AutoReconnectIntervalMs = 5000;
|
||||||
|
Username = "";
|
||||||
|
Password = "";
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,47 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using Crestron.SimplSharp;
|
||||||
|
|
||||||
|
using Newtonsoft.Json;
|
||||||
|
using Newtonsoft.Json.Schema;
|
||||||
|
|
||||||
|
namespace PepperDash.Core
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Base class for all properties config classes to derive from
|
||||||
|
/// </summary>
|
||||||
|
public abstract class PropertiesConfigBase
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// The schema json string for the class
|
||||||
|
/// </summary>
|
||||||
|
public string SchemaJson { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Constructor
|
||||||
|
/// </summary>
|
||||||
|
public PropertiesConfigBase()
|
||||||
|
{
|
||||||
|
SchemaJson = null;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Parses SchemaJson
|
||||||
|
/// </summary>
|
||||||
|
/// <returns>A JsonSchema</returns>
|
||||||
|
public JsonSchema ParseSchema()
|
||||||
|
{
|
||||||
|
if (!string.IsNullOrEmpty(SchemaJson))
|
||||||
|
{
|
||||||
|
JsonSchema schema = JsonSchema.Parse(SchemaJson);
|
||||||
|
|
||||||
|
return schema;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
return null;
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -91,7 +91,8 @@ namespace PepperDash.Core
|
|||||||
Level = context.Level;
|
Level = context.Level;
|
||||||
DoNotLoadOnNextBoot = context.DoNotLoadOnNextBoot;
|
DoNotLoadOnNextBoot = context.DoNotLoadOnNextBoot;
|
||||||
|
|
||||||
CrestronConsole.PrintLine(string.Format("Program {0} will not load config after next boot. Use console command go:{0} to load the config manually", InitialParametersClass.ApplicationNumber));
|
if(DoNotLoadOnNextBoot)
|
||||||
|
CrestronConsole.PrintLine(string.Format("Program {0} will not load config after next boot. Use console command go:{0} to load the config manually", InitialParametersClass.ApplicationNumber));
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -84,7 +84,9 @@
|
|||||||
<Compile Include="Comm\GenericUdpServer.cs" />
|
<Compile Include="Comm\GenericUdpServer.cs" />
|
||||||
<Compile Include="Comm\TcpClientConfigObject.cs" />
|
<Compile Include="Comm\TcpClientConfigObject.cs" />
|
||||||
<Compile Include="Comm\TcpServerConfigObject.cs" />
|
<Compile Include="Comm\TcpServerConfigObject.cs" />
|
||||||
|
<Compile Include="Comm\TcpSshPropertiesConfig.cs" />
|
||||||
<Compile Include="Config\PortalConfigReader.cs" />
|
<Compile Include="Config\PortalConfigReader.cs" />
|
||||||
|
<Compile Include="Config\PropertiesConfigBase.cs" />
|
||||||
<Compile Include="CoreInterfaces.cs" />
|
<Compile Include="CoreInterfaces.cs" />
|
||||||
<Compile Include="EventArgs.cs" />
|
<Compile Include="EventArgs.cs" />
|
||||||
<Compile Include="GenericRESTfulCommunications\Constants.cs" />
|
<Compile Include="GenericRESTfulCommunications\Constants.cs" />
|
||||||
|
|||||||
Reference in New Issue
Block a user