diff --git a/Pepperdash Core/Pepperdash Core/Device.cs b/Pepperdash Core/Pepperdash Core/Device.cs index fe209f8..ee756a0 100644 --- a/Pepperdash Core/Pepperdash Core/Device.cs +++ b/Pepperdash Core/Pepperdash Core/Device.cs @@ -9,8 +9,10 @@ namespace PepperDash.Core /// The core event and status-bearing class that most if not all device /// and connectors can derive from. /// - public class Device : IKeyName + public class Device : IDebuggable { + public DeviceDebug Debug { get; private set; } + /// /// Unique Key /// @@ -46,12 +48,18 @@ namespace PepperDash.Core /// public Device(string key) { + Debug = new DeviceDebug(this); Key = key; if (key.Contains('.')) Debug.Console(0, this, "WARNING: Device name's should not include '.'"); Name = ""; } + /// + /// Optional constructor for all Devices with Name + /// + /// + /// public Device(string key, string name) : this(key) { Name = name; @@ -64,6 +72,10 @@ namespace PepperDash.Core // Config = config; //} + /// + /// Adds an action to be executed in the pre-activation phase + /// + /// Action to execute public void AddPreActivationAction(Action act) { if (_PreActivationActions == null) @@ -71,6 +83,11 @@ namespace PepperDash.Core _PreActivationActions.Add(act); } + /// + /// Adds an action to be executed in the post-activation phase + /// + /// Action to execute + public void AddPostActivationAction(Action act) { if (_PostActivationActions == null) @@ -78,6 +95,9 @@ namespace PepperDash.Core _PostActivationActions.Add(act); } + /// + /// Exectues the pre-activation actions + /// public void PreActivate() { if (_PreActivationActions != null) @@ -99,6 +119,9 @@ namespace PepperDash.Core return result; } + /// + /// Executes the post-activation actions + /// public void PostActivate() { if (_PostActivationActions != null) diff --git a/Pepperdash Core/Pepperdash Core/Logging/Debug.cs b/Pepperdash Core/Pepperdash Core/Logging/Debug.cs index 898495f..a844e39 100644 --- a/Pepperdash Core/Pepperdash Core/Logging/Debug.cs +++ b/Pepperdash Core/Pepperdash Core/Logging/Debug.cs @@ -13,7 +13,7 @@ using PepperDash.Core.DebugThings; namespace PepperDash.Core { - public static class Debug + internal static class Debug { /// /// Describes the folder location where a given program stores it's debug level memory. By default, the @@ -70,9 +70,12 @@ namespace PepperDash.Core static Debug() { // Get the assembly version and print it to console and the log - var version = Assembly.GetExecutingAssembly().GetName().Version; - PepperDashCoreVersion = string.Format("{0}.{1}.{2}.{3}", version.Major, version.Minor, version.Build, version.Revision); + var fullVersion = Assembly.GetExecutingAssembly().GetCustomAttributes(typeof(AssemblyInformationalVersionAttribute), false); + + AssemblyInformationalVersionAttribute fullVersionAtt = fullVersion[0] as AssemblyInformationalVersionAttribute; + + PepperDashCoreVersion = fullVersionAtt.InformationalVersion; var msg = string.Format("[App {0}] Using PepperDash_Core v{1}", InitialParametersClass.ApplicationNumber, PepperDashCoreVersion); @@ -553,9 +556,11 @@ namespace PepperDash.Core return string.Format(@"\NVRAM\debugSettings\program{0}", InitialParametersClass.ApplicationNumber); } - public enum ErrorLogLevel - { - Error, Warning, Notice, None - } } + + public enum ErrorLogLevel + { + Error, Warning, Notice, None + } + } \ No newline at end of file diff --git a/Pepperdash Core/Pepperdash Core/Logging/DebugContext.cs b/Pepperdash Core/Pepperdash Core/Logging/DebugContext.cs index 62ed96a..50fb43c 100644 --- a/Pepperdash Core/Pepperdash Core/Logging/DebugContext.cs +++ b/Pepperdash Core/Pepperdash Core/Logging/DebugContext.cs @@ -149,7 +149,7 @@ namespace PepperDash.Core Console(level, "[{0}] {1}", dev.Key, string.Format(format, items)); } - public void Console(uint level, IKeyed dev, Debug.ErrorLogLevel errorLogLevel, + public void Console(uint level, IKeyed dev, ErrorLogLevel errorLogLevel, string format, params object[] items) { if (SaveData.Level >= level) @@ -160,7 +160,7 @@ namespace PepperDash.Core } } - public void Console(uint level, Debug.ErrorLogLevel errorLogLevel, + public void Console(uint level, ErrorLogLevel errorLogLevel, string format, params object[] items) { if (SaveData.Level >= level) @@ -171,18 +171,18 @@ namespace PepperDash.Core } } - public void LogError(Debug.ErrorLogLevel errorLogLevel, string str) + public void LogError(ErrorLogLevel errorLogLevel, string str) { string msg = string.Format("App {0}:{1}", InitialParametersClass.ApplicationNumber, str); switch (errorLogLevel) { - case Debug.ErrorLogLevel.Error: + case ErrorLogLevel.Error: ErrorLog.Error(msg); break; - case Debug.ErrorLogLevel.Warning: + case ErrorLogLevel.Warning: ErrorLog.Warn(msg); break; - case Debug.ErrorLogLevel.Notice: + case ErrorLogLevel.Notice: ErrorLog.Notice(msg); break; } diff --git a/Pepperdash Core/Pepperdash Core/Logging/IDebuggable.cs b/Pepperdash Core/Pepperdash Core/Logging/IDebuggable.cs new file mode 100644 index 0000000..19884f3 --- /dev/null +++ b/Pepperdash Core/Pepperdash Core/Logging/IDebuggable.cs @@ -0,0 +1,83 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using Crestron.SimplSharp; +using Crestron.SimplSharp.CrestronLogger; + +namespace PepperDash.Core +{ + /// + /// Indicates a class capabel of console debugging and logging + /// + public interface IDebuggable : IKeyName + { + /// + /// The class that handles console debugging and logging + /// + DeviceDebug Debug { get; } + } + + /// + /// A class to handle implementation of IDebuggable + /// + public class DeviceDebug + { + Device _parentDevice; + + /// + /// The current Debug Level for the device instance + /// + public int DebugLevel; + + public DeviceDebug(Device parentDevice) + { + _parentDevice = parentDevice; + } + + public void Console(uint level, string format, params object[] items) + { + if (DebugLevel >= level) + { + Debug.Console(level, format, items); + } + } + + public void Console(uint level, IKeyed dev, string format, params object[] items) + { + if (DebugLevel >= level) + { + Debug.Console(level, _parentDevice, format, items); + } + } + + public void Console(uint level, ErrorLogLevel errorLogLevel, string format, params object[] items) + { + if (DebugLevel >= level) + { + Debug.Console(level, errorLogLevel, format, items); + } + } + + public void ConsoleWithLog(uint level, string format, params object[] items) + { + if (DebugLevel >= level) + { + Debug.Console(level, format, items); + } + } + + public void ConsoleWithLog(uint level, IKeyed dev, string format, params object[] items) + { + if (DebugLevel >= level) + { + Debug.Console(level, _parentDevice, format, items); + } + } + + public void LogError(ErrorLogLevel errorLogLevel, string str) + { + Debug.LogError(errorLogLevel, str); + } + } +} \ No newline at end of file diff --git a/Pepperdash Core/Pepperdash Core/PepperDash_Core.csproj b/Pepperdash Core/Pepperdash Core/PepperDash_Core.csproj index d4fbf18..8f38f28 100644 --- a/Pepperdash Core/Pepperdash Core/PepperDash_Core.csproj +++ b/Pepperdash Core/Pepperdash Core/PepperDash_Core.csproj @@ -110,6 +110,7 @@ +