Changed most debugging to add log ability. Program will not run. Type load exception

This commit is contained in:
Heath Volmer
2017-04-27 15:21:08 -06:00
parent f6490feb35
commit e47748a184
17 changed files with 291 additions and 217 deletions

Binary file not shown.

View File

@@ -3,7 +3,7 @@ using System.Collections.Generic;
using System.Linq;
using System.Text;
using Crestron.SimplSharp;
using Crestron.SimplSharp.CrestronDataStore;
using Crestron.SimplSharp.CrestronLogger;
using Crestron.SimplSharp.CrestronIO;
using Newtonsoft.Json;
using PepperDash.Core.DebugThings;
@@ -11,236 +11,289 @@ using PepperDash.Core.DebugThings;
namespace PepperDash.Core
{
public static class Debug
{
/// <summary>
/// Describes the folder location where a given program stores it's debug level memory. By default, the
/// file written will be named appNdebug where N is 1-10.
/// </summary>
public static string FilePathPrefix = @"\nvram\debug\";
public static class Debug
{
/// <summary>
/// Describes the folder location where a given program stores it's debug level memory. By default, the
/// file written will be named appNdebug where N is 1-10.
/// </summary>
public static string FilePathPrefix = @"\nvram\debug\";
/// <summary>
/// The name of the file containing the current debug settings.
/// </summary>
public static string FileName = string.Format(@"app{0}Debug.json", InitialParametersClass.ApplicationNumber);
/// <summary>
/// The name of the file containing the current debug settings.
/// </summary>
public static string FileName = string.Format(@"app{0}Debug.json", InitialParametersClass.ApplicationNumber);
public static int Level { get; private set; }
public static int Level { get; private set; }
static DebugContextCollection Contexts;
static DebugContextCollection Contexts;
static int SaveTimeoutMs = 30000;
static int SaveTimeoutMs = 30000;
static CTimer SaveTimer;
static CTimer SaveTimer;
static Debug()
{
//CrestronDataStoreStatic.InitCrestronDataStore();
if (CrestronEnvironment.RuntimeEnvironment == eRuntimeEnvironment.SimplSharpPro)
{
// Add command to console
CrestronConsole.AddNewConsoleCommand(SetDebugFromConsole, "appdebug",
"appdebug:P [0-2]: Sets the application's console debug message level",
ConsoleAccessLevelEnum.AccessOperator);
}
static Debug()
{
//CrestronDataStoreStatic.InitCrestronDataStore();
if (CrestronEnvironment.RuntimeEnvironment == eRuntimeEnvironment.SimplSharpPro)
{
// Add command to console
CrestronConsole.AddNewConsoleCommand(SetDebugFromConsole, "appdebug",
"appdebug:P [0-2]: Sets the application's console debug message level",
ConsoleAccessLevelEnum.AccessOperator);
CrestronConsole.AddNewConsoleCommand(ShowDebugLog, "appdebuglog",
"appdebuglog:P [all] Dumps the custom log. Use \"all\" to show full log, otherwise last-200 entries are returned.",
ConsoleAccessLevelEnum.AccessOperator);
CrestronConsole.AddNewConsoleCommand(s => CrestronLogger.Clear(false), "appdebugclear",
"appdebugclear:P Clears the current custom log. Does not clear backup logs",
ConsoleAccessLevelEnum.AccessOperator);
}
CrestronEnvironment.ProgramStatusEventHandler += CrestronEnvironment_ProgramStatusEventHandler;
CrestronEnvironment.ProgramStatusEventHandler += CrestronEnvironment_ProgramStatusEventHandler;
LoadMemory();
Level = Contexts.GetOrCreateItem("DEFAULT").Level;
}
LoadMemory();
Level = Contexts.GetOrCreateItem("DEFAULT").Level;
/// <summary>
/// Used to save memory when shutting down
/// </summary>
/// <param name="programEventType"></param>
static void CrestronEnvironment_ProgramStatusEventHandler(eProgramStatusEventType programEventType)
{
if (programEventType == eProgramStatusEventType.Stopping)
{
if (SaveTimer != null)
{
SaveTimer.Stop();
SaveTimer = null;
}
Console(0, "Saving debug settings");
SaveMemory();
}
}
CrestronLogger.Initialize(2, LoggerModeEnum.RM); // Use RM instead of DEFAULT as not to double-up console messages.
}
/// <summary>
/// Callback for console command
/// </summary>
/// <param name="levelString"></param>
public static void SetDebugFromConsole(string levelString)
{
try
{
if (string.IsNullOrEmpty(levelString.Trim()))
{
CrestronConsole.PrintLine("AppDebug level = {0}", Level);
return;
}
/// <summary>
/// Used to save memory when shutting down
/// </summary>
/// <param name="programEventType"></param>
static void CrestronEnvironment_ProgramStatusEventHandler(eProgramStatusEventType programEventType)
{
if (programEventType == eProgramStatusEventType.Stopping)
{
if (SaveTimer != null)
{
SaveTimer.Stop();
SaveTimer = null;
}
Console(0, "Saving debug settings");
SaveMemory();
}
}
SetDebugLevel(Convert.ToInt32(levelString));
}
catch
{
CrestronConsole.PrintLine("Usage: appdebug:P [0-2]");
}
}
/// <summary>
/// Callback for console command
/// </summary>
/// <param name="levelString"></param>
public static void SetDebugFromConsole(string levelString)
{
try
{
if (string.IsNullOrEmpty(levelString.Trim()))
{
CrestronConsole.PrintLine("AppDebug level = {0}", Level);
return;
}
/// <summary>
/// Sets the debug level
/// </summary>
/// <param name="level"> Valid values 0 (no debug), 1 (critical), 2 (all messages)</param>
public static void SetDebugLevel(int level)
{
if (level <= 2)
{
Level = level;
Contexts.GetOrCreateItem("DEFAULT").Level = level;
SaveMemoryOnTimeout();
SetDebugLevel(Convert.ToInt32(levelString));
}
catch
{
CrestronConsole.PrintLine("Usage: appdebug:P [0-2]");
}
}
CrestronConsole.PrintLine("[Application {0}], Debug level set to {1}",
InitialParametersClass.ApplicationNumber, Level);
/// <summary>
/// Sets the debug level
/// </summary>
/// <param name="level"> Valid values 0 (no debug), 1 (critical), 2 (all messages)</param>
public static void SetDebugLevel(int level)
{
if (level <= 2)
{
Level = level;
Contexts.GetOrCreateItem("DEFAULT").Level = level;
SaveMemoryOnTimeout();
//var err = CrestronDataStoreStatic.SetLocalUintValue("DebugLevel", level);
//if (err != CrestronDataStore.CDS_ERROR.CDS_SUCCESS)
// CrestronConsole.PrintLine("Error saving console debug level setting: {0}", err);
}
}
CrestronConsole.PrintLine("[Application {0}], Debug level set to {1}",
InitialParametersClass.ApplicationNumber, Level);
/// <summary>
/// Prints message to console if current debug level is equal to or higher than the level of this message.
/// Uses CrestronConsole.PrintLine.
/// </summary>
/// <param name="level"></param>
/// <param name="format">Console format string</param>
/// <param name="items">Object parameters</param>
public static void Console(uint level, string format, params object[] items)
{
if (Level >= level)
CrestronConsole.PrintLine("App {0}:{1}", InitialParametersClass.ApplicationNumber,
string.Format(format, items));
}
//var err = CrestronDataStoreStatic.SetLocalUintValue("DebugLevel", level);
//if (err != CrestronDataStore.CDS_ERROR.CDS_SUCCESS)
// CrestronConsole.PrintLine("Error saving console debug level setting: {0}", err);
}
}
/// <summary>
/// Appends a device Key to the beginning of a message
/// </summary>
public static void Console(uint level, IKeyed dev, string format, params object[] items)
{
if (Level >= level)
Console(level, "[{0}] {1}", dev.Key, string.Format(format, items));
}
/// <summary>
///
/// </summary>
public static void ShowDebugLog(string s)
{
var loglist = CrestronLogger.PrintTheLog(s.ToLower() == "all");
foreach (var l in loglist)
CrestronConsole.ConsoleCommandResponse(l);
}
public static void Console(uint level, IKeyed dev, ErrorLogLevel errorLogLevel,
string format, params object[] items)
{
if (Level >= level)
{
var str = string.Format("[{0}] {1}", dev.Key, string.Format(format, items));
Console(level, str);
LogError(errorLogLevel, str);
}
}
/// <summary>
/// Prints message to console if current debug level is equal to or higher than the level of this message.
/// Uses CrestronConsole.PrintLine.
/// </summary>
/// <param name="level"></param>
/// <param name="format">Console format string</param>
/// <param name="items">Object parameters</param>
public static void Console(uint level, string format, params object[] items)
{
if (Level >= level)
CrestronConsole.PrintLine("App {0}:{1}", InitialParametersClass.ApplicationNumber,
string.Format(format, items));
}
public static void Console(uint level, ErrorLogLevel errorLogLevel,
string format, params object[] items)
{
if (Level >= level)
{
var str = string.Format(format, items);
Console(level, str);
LogError(errorLogLevel, str);
}
}
/// <summary>
/// Appends a device Key to the beginning of a message
/// </summary>
public static void Console(uint level, IKeyed dev, string format, params object[] items)
{
if (Level >= level)
Console(level, "[{0}] {1}", dev.Key, string.Format(format, items));
}
public static void LogError(ErrorLogLevel errorLogLevel, string str)
{
string msg = string.Format("App {0}:{1}", InitialParametersClass.ApplicationNumber, str);
switch (errorLogLevel)
{
case ErrorLogLevel.Error:
ErrorLog.Error(msg);
break;
case ErrorLogLevel.Warning:
ErrorLog.Warn(msg);
break;
case ErrorLogLevel.Notice:
ErrorLog.Notice(msg);
break;
}
}
public static void Console(uint level, IKeyed dev, ErrorLogLevel errorLogLevel,
string format, params object[] items)
{
if (Level >= level)
{
var str = string.Format("[{0}] {1}", dev.Key, string.Format(format, items));
Console(level, str);
LogError(errorLogLevel, str);
}
}
/// <summary>
/// Writes the memory object after timeout
/// </summary>
static void SaveMemoryOnTimeout()
{
if (SaveTimer == null)
SaveTimer = new CTimer(o =>
{
SaveTimer = null;
SaveMemory();
}, SaveTimeoutMs);
else
SaveTimer.Reset(SaveTimeoutMs);
}
public static void Console(uint level, ErrorLogLevel errorLogLevel,
string format, params object[] items)
{
if (Level >= level)
{
var str = string.Format(format, items);
Console(level, str);
LogError(errorLogLevel, str);
}
}
/// <summary>
/// Writes the memory - use SaveMemoryOnTimeout
/// </summary>
static void SaveMemory()
{
//var dir = @"\NVRAM\debug";
//if (!Directory.Exists(dir))
// Directory.Create(dir);
/// <summary>
/// Logs to both console and the custom user log (not the built-in error log). If appdebug level is set at
/// or above the level provided, then the output will be written to both console and the log. Otherwise
/// it will only be written to the log.
/// </summary>
/// <param name="level"></param>
/// <param name="format"></param>
/// <param name="items"></param>
public static void ConsoleWithLog(uint level, string format, params object[] items)
{
var str = string.Format(format, items);
if (Level >= level)
CrestronConsole.PrintLine("App {0}:{1}", InitialParametersClass.ApplicationNumber, str);
CrestronLogger.WriteToLog(str, level);
}
using (StreamWriter sw = new StreamWriter(GetMemoryFileName()))
{
var json = JsonConvert.SerializeObject(Contexts);
sw.Write(json);
sw.Flush();
}
}
/// <summary>
/// Logs to both console and the custom user log (not the built-in error log). If appdebug level is set at
/// or above the level provided, then the output will be written to both console and the log. Otherwise
/// it will only be written to the log.
/// </summary>
/// <param name="level"></param>
/// <param name="dev"></param>
/// <param name="format">String.format string</param>
/// <param name="items">Parameters for substitution in the format string.</param>
public static void ConsoleWithLog(uint level, IKeyed dev, string format, params object[] items)
{
var str = string.Format(format, items);
if (Level >= level)
ConsoleWithLog(level, "[{0}] {1}", dev.Key, str);
}
/// <summary>
///
/// </summary>
static void LoadMemory()
{
var file = GetMemoryFileName();
if (File.Exists(file))
{
using (StreamReader sr = new StreamReader(file))
{
var json = sr.ReadToEnd();
Contexts = JsonConvert.DeserializeObject<DebugContextCollection>(json);
/// <summary>
/// Prints to log and error log
/// </summary>
/// <param name="errorLogLevel"></param>
/// <param name="str"></param>
public static void LogError(ErrorLogLevel errorLogLevel, string str)
{
string msg = string.Format("App {0}:{1}", InitialParametersClass.ApplicationNumber, str);
switch (errorLogLevel)
{
case ErrorLogLevel.Error:
ErrorLog.Error(msg);
break;
case ErrorLogLevel.Warning:
ErrorLog.Warn(msg);
break;
case ErrorLogLevel.Notice:
ErrorLog.Notice(msg);
break;
}
}
if (Contexts != null)
{
Debug.Console(0, "Debug memory restored from file");
return;
}
}
}
Contexts = new DebugContextCollection();
}
/// <summary>
/// Writes the memory object after timeout
/// </summary>
static void SaveMemoryOnTimeout()
{
if (SaveTimer == null)
SaveTimer = new CTimer(o =>
{
SaveTimer = null;
SaveMemory();
}, SaveTimeoutMs);
else
SaveTimer.Reset(SaveTimeoutMs);
}
/// <summary>
/// Helper to get the file path for this app's debug memory
/// </summary>
static string GetMemoryFileName()
{
return string.Format(@"\NVRAM\debugSettings\program{0}", InitialParametersClass.ApplicationNumber);
}
/// <summary>
/// Writes the memory - use SaveMemoryOnTimeout
/// </summary>
static void SaveMemory()
{
//var dir = @"\NVRAM\debug";
//if (!Directory.Exists(dir))
// Directory.Create(dir);
using (StreamWriter sw = new StreamWriter(GetMemoryFileName()))
{
var json = JsonConvert.SerializeObject(Contexts);
sw.Write(json);
sw.Flush();
}
}
/// <summary>
///
/// </summary>
static void LoadMemory()
{
var file = GetMemoryFileName();
if (File.Exists(file))
{
using (StreamReader sr = new StreamReader(file))
{
var json = sr.ReadToEnd();
Contexts = JsonConvert.DeserializeObject<DebugContextCollection>(json);
if (Contexts != null)
{
Debug.Console(0, "Debug memory restored from file");
return;
}
}
}
Contexts = new DebugContextCollection();
}
/// <summary>
/// Helper to get the file path for this app's debug memory
/// </summary>
static string GetMemoryFileName()
{
return string.Format(@"\NVRAM\debugSettings\program{0}", InitialParametersClass.ApplicationNumber);
}
public enum ErrorLogLevel
{
Error, Warning, Notice, None
}
}
}
}

View File

@@ -0,0 +1,7 @@
3/21/2017 1:09:34 PM, Info: Initializing SIMPLSharp Services...
3/21/2017 1:09:34 PM, Info: ProjectInfo successfully initialized.
3/21/2017 1:09:59 PM, Info: Validating assembly C:\Users\hvolmer\Desktop\working\pepperdash-simplsharp-core\Pepperdash Core\Pepperdash Core\bin\PepperDash_Core.dll...
3/21/2017 1:09:59 PM, Info: Verifying assembly C:\Users\hvolmer\Desktop\working\pepperdash-simplsharp-core\Pepperdash Core\Pepperdash Core\bin\PepperDash_Core.dll
3/21/2017 1:10:00 PM, Info: Creating Archive C:\Users\hvolmer\Desktop\working\pepperdash-simplsharp-core\Pepperdash Core\Pepperdash Core\bin\PepperDash_Core.clz...
3/21/2017 1:10:00 PM, Info: Saving project information...
3/21/2017 1:14:17 PM, Info: Terminating SIMPLSharp Services

View File

@@ -0,0 +1,3 @@
3/30/2017 10:52:00 AM, Info: Initializing SIMPLSharp Services...
3/30/2017 10:52:00 AM, Info: ProjectInfo successfully initialized.
3/30/2017 11:31:42 AM, Info: Terminating SIMPLSharp Services

View File

@@ -0,0 +1,11 @@
4/27/2017 2:27:13 PM, Info: Initializing SIMPLSharp Services...
4/27/2017 2:27:13 PM, Info: ProjectInfo successfully initialized.
4/27/2017 2:47:36 PM, Info: Validating assembly C:\Users\hvolmer\Desktop\working\pepperdash-simplsharp-core\Pepperdash Core\Pepperdash Core\bin\PepperDash_Core.dll...
4/27/2017 2:47:37 PM, Info: Verifying assembly C:\Users\hvolmer\Desktop\working\pepperdash-simplsharp-core\Pepperdash Core\Pepperdash Core\bin\PepperDash_Core.dll
4/27/2017 2:47:37 PM, Info: Creating Archive C:\Users\hvolmer\Desktop\working\pepperdash-simplsharp-core\Pepperdash Core\Pepperdash Core\bin\PepperDash_Core.clz...
4/27/2017 2:47:38 PM, Info: Saving project information...
4/27/2017 2:51:45 PM, Info: Validating assembly C:\Users\hvolmer\Desktop\working\pepperdash-simplsharp-core\Pepperdash Core\Pepperdash Core\bin\PepperDash_Core.dll...
4/27/2017 2:51:45 PM, Info: Verifying assembly C:\Users\hvolmer\Desktop\working\pepperdash-simplsharp-core\Pepperdash Core\Pepperdash Core\bin\PepperDash_Core.dll
4/27/2017 2:51:45 PM, Info: Creating Archive C:\Users\hvolmer\Desktop\working\pepperdash-simplsharp-core\Pepperdash Core\Pepperdash Core\bin\PepperDash_Core.clz...
4/27/2017 2:51:45 PM, Info: Saving project information...
4/27/2017 2:54:30 PM, Info: Terminating SIMPLSharp Services

View File

@@ -10,8 +10,8 @@
<ArchiveName />
</RequiredInfo>
<OptionalInfo>
<CompiledOn>3/21/2017 1:09:59 PM</CompiledOn>
<CompilerRev>1.0.6289.21898</CompilerRev>
<CompiledOn>4/27/2017 3:03:20 PM</CompiledOn>
<CompilerRev>1.0.6326.25299</CompilerRev>
</OptionalInfo>
<Plugin>
<Version>Crestron.SIMPLSharp, Version=2.0.48.0, Culture=neutral, PublicKeyToken=812d080f93e2de10</Version>

View File

@@ -1,6 +1,6 @@
MainAssembly=PepperDash_Core.dll:00d1b9d87735985f4fbe4cd55c2b5400
MainAssembly=PepperDash_Core.dll:0530e92ffa26ff73039f7720af6e8148
MainAssemblyMinFirmwareVersion=1.007.0017
MainAssemblyResource=SimplSharpData.dat:315526abf906cded47fb0c7510266a7e
MainAssemblyResource=SimplSharpData.dat:820b61c48c8a2cace82957eed4cc377c
ü
DependencySource=Newtonsoft.Json.Compact.dll:ea996aa2ec65aa1878e7c9d09e37a896
DependencyPath=PepperDash_Core.clz:Newtonsoft.Json.Compact.dll

View File

@@ -8,16 +8,6 @@ C:\Users\hvolm\Desktop\working\pepperdash-simplsharp-core\Pepperdash Core\Pepper
C:\Users\hvolm\Desktop\working\pepperdash-simplsharp-core\Pepperdash Core\Pepperdash Core\obj\Debug\ResolveAssemblyReference.cache
C:\Users\hvolm\Desktop\working\pepperdash-simplsharp-core\Pepperdash Core\Pepperdash Core\obj\Debug\PepperDash_Core.dll
C:\Users\hvolm\Desktop\working\pepperdash-simplsharp-core\Pepperdash Core\Pepperdash Core\obj\Debug\PepperDash_Core.pdb
C:\Users\hvolmer\Desktop\working\pepperdash-simplsharp-core\Pepperdash Core\Pepperdash Core\bin\PepperDash_Core.dll
C:\Users\hvolmer\Desktop\working\pepperdash-simplsharp-core\Pepperdash Core\Pepperdash Core\bin\PepperDash_Core.pdb
C:\Users\hvolmer\Desktop\working\pepperdash-simplsharp-core\Pepperdash Core\Pepperdash Core\bin\SimplSharpCustomAttributesInterface.dll
C:\Users\hvolmer\Desktop\working\pepperdash-simplsharp-core\Pepperdash Core\Pepperdash Core\bin\SimplSharpHelperInterface.dll
C:\Users\hvolmer\Desktop\working\pepperdash-simplsharp-core\Pepperdash Core\Pepperdash Core\bin\SimplSharpNewtonsoft.dll
C:\Users\hvolmer\Desktop\working\pepperdash-simplsharp-core\Pepperdash Core\Pepperdash Core\bin\SimplSharpSQLHelperInterface.dll
C:\Users\hvolmer\Desktop\working\pepperdash-simplsharp-core\Pepperdash Core\Pepperdash Core\bin\SimplSharpReflectionInterface.dll
C:\Users\hvolmer\Desktop\working\pepperdash-simplsharp-core\Pepperdash Core\Pepperdash Core\obj\Debug\ResolveAssemblyReference.cache
C:\Users\hvolmer\Desktop\working\pepperdash-simplsharp-core\Pepperdash Core\Pepperdash Core\obj\Debug\PepperDash_Core.dll
C:\Users\hvolmer\Desktop\working\pepperdash-simplsharp-core\Pepperdash Core\Pepperdash Core\obj\Debug\PepperDash_Core.pdb
C:\P\BitBucket\pepperdash-simplsharp-core\Pepperdash Core\Pepperdash Core\bin\PepperDash_Core.dll
C:\P\BitBucket\pepperdash-simplsharp-core\Pepperdash Core\Pepperdash Core\bin\PepperDash_Core.pdb
C:\P\BitBucket\pepperdash-simplsharp-core\Pepperdash Core\Pepperdash Core\bin\SimplSharpCustomAttributesInterface.dll
@@ -28,3 +18,13 @@ C:\P\BitBucket\pepperdash-simplsharp-core\Pepperdash Core\Pepperdash Core\bin\Si
C:\P\BitBucket\pepperdash-simplsharp-core\Pepperdash Core\Pepperdash Core\obj\Debug\ResolveAssemblyReference.cache
C:\P\BitBucket\pepperdash-simplsharp-core\Pepperdash Core\Pepperdash Core\obj\Debug\PepperDash_Core.dll
C:\P\BitBucket\pepperdash-simplsharp-core\Pepperdash Core\Pepperdash Core\obj\Debug\PepperDash_Core.pdb
C:\Users\hvolmer\Desktop\working\pepperdash-simplsharp-core\Pepperdash Core\Pepperdash Core\bin\PepperDash_Core.dll
C:\Users\hvolmer\Desktop\working\pepperdash-simplsharp-core\Pepperdash Core\Pepperdash Core\bin\PepperDash_Core.pdb
C:\Users\hvolmer\Desktop\working\pepperdash-simplsharp-core\Pepperdash Core\Pepperdash Core\bin\SimplSharpCustomAttributesInterface.dll
C:\Users\hvolmer\Desktop\working\pepperdash-simplsharp-core\Pepperdash Core\Pepperdash Core\bin\SimplSharpHelperInterface.dll
C:\Users\hvolmer\Desktop\working\pepperdash-simplsharp-core\Pepperdash Core\Pepperdash Core\bin\SimplSharpNewtonsoft.dll
C:\Users\hvolmer\Desktop\working\pepperdash-simplsharp-core\Pepperdash Core\Pepperdash Core\bin\SimplSharpSQLHelperInterface.dll
C:\Users\hvolmer\Desktop\working\pepperdash-simplsharp-core\Pepperdash Core\Pepperdash Core\bin\SimplSharpReflectionInterface.dll
C:\Users\hvolmer\Desktop\working\pepperdash-simplsharp-core\Pepperdash Core\Pepperdash Core\obj\Debug\ResolveAssemblyReference.cache
C:\Users\hvolmer\Desktop\working\pepperdash-simplsharp-core\Pepperdash Core\Pepperdash Core\obj\Debug\PepperDash_Core.dll
C:\Users\hvolmer\Desktop\working\pepperdash-simplsharp-core\Pepperdash Core\Pepperdash Core\obj\Debug\PepperDash_Core.pdb