mirror of
https://github.com/PepperDash/PepperDashCore.git
synced 2026-02-16 21:24:43 +00:00
Adds a debug timer feature to ensure debug can't be left on indefinitely
This commit is contained in:
@@ -18,7 +18,8 @@ namespace PepperDash.Core
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Named Keyed device interface. Forces the devie to have a Unique Key and a name.
|
/// Named Keyed device interface.
|
||||||
|
/// Forces the device to have a Unique Key and a name.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public interface IKeyName : IKeyed
|
public interface IKeyName : IKeyed
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -6,7 +6,8 @@ namespace PepperDash.Core
|
|||||||
{
|
{
|
||||||
//*********************************************************************************************************
|
//*********************************************************************************************************
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// The core event and status-bearing class that most if not all device and connectors can derive from.
|
/// The core event and status-bearing class that most if not all device
|
||||||
|
/// and connectors can derive from.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public class Device : IKeyName
|
public class Device : IKeyName
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -34,10 +34,20 @@ namespace PepperDash.Core
|
|||||||
|
|
||||||
static int SaveTimeoutMs = 30000;
|
static int SaveTimeoutMs = 30000;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Default debug timeout (30 min)
|
||||||
|
/// </summary>
|
||||||
|
static long DebugTimoutMs = 1800000;
|
||||||
|
|
||||||
public static string PepperDashCoreVersion { get; private set; }
|
public static string PepperDashCoreVersion { get; private set; }
|
||||||
|
|
||||||
static CTimer SaveTimer;
|
static CTimer SaveTimer;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Resets the debug level to 0 when the timer expires
|
||||||
|
/// </summary>
|
||||||
|
static CTimer DebugTimer;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// When true, the IncludedExcludedKeys dict will contain keys to include.
|
/// When true, the IncludedExcludedKeys dict will contain keys to include.
|
||||||
/// When false (default), IncludedExcludedKeys will contain keys to exclude.
|
/// When false (default), IncludedExcludedKeys will contain keys to exclude.
|
||||||
@@ -71,7 +81,7 @@ namespace PepperDash.Core
|
|||||||
"donotloadonnextboot:P [true/false]: Should the application load on next boot", ConsoleAccessLevelEnum.AccessOperator);
|
"donotloadonnextboot:P [true/false]: Should the application load on next boot", ConsoleAccessLevelEnum.AccessOperator);
|
||||||
|
|
||||||
CrestronConsole.AddNewConsoleCommand(SetDebugFromConsole, "appdebug",
|
CrestronConsole.AddNewConsoleCommand(SetDebugFromConsole, "appdebug",
|
||||||
"appdebug:P [0-2]: Sets the application's console debug message level",
|
"appdebug:P [level 0-2] [(min)]: Set the console debug message level",
|
||||||
ConsoleAccessLevelEnum.AccessOperator);
|
ConsoleAccessLevelEnum.AccessOperator);
|
||||||
CrestronConsole.AddNewConsoleCommand(ShowDebugLog, "appdebuglog",
|
CrestronConsole.AddNewConsoleCommand(ShowDebugLog, "appdebuglog",
|
||||||
"appdebuglog:P [all] Use \"all\" for full log.",
|
"appdebuglog:P [all] Use \"all\" for full log.",
|
||||||
@@ -130,24 +140,49 @@ namespace PepperDash.Core
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Callback for console command
|
/// Callback for console command. Starts the debug Timer
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="levelString"></param>
|
/// <param name="levelString"></param>
|
||||||
public static void SetDebugFromConsole(string levelString)
|
public static void SetDebugFromConsole(string levelString)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
|
var args = levelString.Split(' ');
|
||||||
|
|
||||||
|
var level = Convert.ToInt32(args[0]);
|
||||||
|
var timeoutMs = DebugTimoutMs;
|
||||||
|
|
||||||
|
if(args.Length > 1)
|
||||||
|
{
|
||||||
|
timeoutMs = Convert.ToInt32(args[1]) * 60000;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// Only start the timer if setting to level 1 or 2
|
||||||
|
if (level > 0 && level <= 2)
|
||||||
|
{
|
||||||
|
if (DebugTimer != null)
|
||||||
|
{
|
||||||
|
DebugTimer = new CTimer((o) => SetDebugLevel(0), timeoutMs);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
DebugTimer.Reset(timeoutMs);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
if (string.IsNullOrEmpty(levelString.Trim()))
|
if (string.IsNullOrEmpty(levelString.Trim()))
|
||||||
{
|
{
|
||||||
CrestronConsole.PrintLine("AppDebug level = {0}", Level);
|
CrestronConsole.PrintLine("AppDebug level = {0}", Level);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
SetDebugLevel(Convert.ToInt32(levelString));
|
SetDebugLevel(level, timeoutMs);
|
||||||
}
|
}
|
||||||
catch
|
catch
|
||||||
{
|
{
|
||||||
CrestronConsole.PrintLine("Usage: appdebug:P [0-2]");
|
CrestronConsole.PrintLine("Usage: appdebug:P [level: 0-2] [(timeout in minutes: 0-480)]");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -261,6 +296,13 @@ namespace PepperDash.Core
|
|||||||
{
|
{
|
||||||
if (level <= 2)
|
if (level <= 2)
|
||||||
{
|
{
|
||||||
|
if (level == 0)
|
||||||
|
{
|
||||||
|
DebugTimer.Stop();
|
||||||
|
DebugTimer.Dispose();
|
||||||
|
DebugTimer = null;
|
||||||
|
}
|
||||||
|
|
||||||
Level = level;
|
Level = level;
|
||||||
Contexts.GetOrCreateItem("DEFAULT").Level = level;
|
Contexts.GetOrCreateItem("DEFAULT").Level = level;
|
||||||
SaveMemoryOnTimeout();
|
SaveMemoryOnTimeout();
|
||||||
@@ -274,6 +316,17 @@ namespace PepperDash.Core
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static void SetDebugLevel(int level, long timeoutMs)
|
||||||
|
{
|
||||||
|
if (level <= 2 && level > 0)
|
||||||
|
{
|
||||||
|
CrestronConsole.PrintLine("[Application {0}], Debug timer will expire in {1} minutes",
|
||||||
|
InitialParametersClass.ApplicationNumber, timeoutMs / 60000);
|
||||||
|
}
|
||||||
|
|
||||||
|
SetDebugLevel(level);
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// sets the settings for a device or creates a new entry
|
/// sets the settings for a device or creates a new entry
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
|||||||
Reference in New Issue
Block a user