Merge pull request #369 from PepperDash/bugfix/SystemMonitor-IndexOutOfRange

Fix system monitor index out of range exception
This commit is contained in:
Trevor Payne
2020-08-18 16:26:45 -05:00
committed by GitHub
4 changed files with 58 additions and 22 deletions

View File

@@ -91,6 +91,9 @@ namespace PepperDash.Essentials
}, "portalinfo", "Shows portal URLS from configuration", ConsoleAccessLevelEnum.AccessOperator);
CrestronConsole.AddNewConsoleCommand(DeviceManager.GetRoutingPorts,
"getroutingports", "Reports all routing ports, if any. Requires a device key", ConsoleAccessLevelEnum.AccessOperator);
if (!Debug.DoNotLoadOnNextBoot)
{
GoWithLoad();

View File

@@ -337,7 +337,36 @@ namespace PepperDash.Essentials.Core
return;
}
com.SimulateReceive(match.Groups[2].Value);
}
}
/// <summary>
/// Prints a list of routing inputs and outputs by device key.
/// </summary>
/// <param name="s">Device key from which to report data</param>
public static void GetRoutingPorts(string s)
{
var device = GetDeviceForKey(s);
if (device == null) return;
var inputPorts = (device as IRoutingInputsOutputs).InputPorts;
var outputPorts = (device as IRoutingInputsOutputs).OutputPorts;
if (inputPorts != null)
{
Debug.Console(0, "Device {0} has {1} Input Ports:", s, inputPorts.Count);
foreach (var routingInputPort in inputPorts)
{
Debug.Console(0, "{0}", routingInputPort.Key);
}
}
if (outputPorts != null)
{
Debug.Console(0, "Device {0} has {1} Output Ports:", s, outputPorts.Count);
foreach (var routingOutputPort in outputPorts)
{
Debug.Console(0, "{0}", routingOutputPort.Key);
}
}
}
/// <summary>
/// Attempts to set the debug level of a device

View File

@@ -1,5 +1,6 @@
using System;
using System.Collections.Generic;
using System.Collections.Generic;
using System.Linq;
using Crestron.SimplSharp;
using Crestron.SimplSharpPro.DeviceSupport;
using Crestron.SimplSharpPro.Diagnostics;
@@ -100,25 +101,28 @@ namespace PepperDash.Essentials.Core.Monitoring
UptimeFeedback.FireUpdate();
LastStartFeedback.FireUpdate();
}
private void ParseUptime(string response)
{
var splitString = response.Trim().Split('\r', '\n');
var lastStartRaw = splitString[2];
var lastStartIndex = lastStartRaw.IndexOf(':');
_lastStart = lastStartRaw.Substring(lastStartIndex + 1).Trim();
var uptimeRaw = splitString[0];
var forIndex = uptimeRaw.IndexOf("for", StringComparison.Ordinal);
//4 => "for " to get what's on the right
_uptime = uptimeRaw.Substring(forIndex + 4);
}
}
private void ParseUptime(string response)
{
var splitString = response.Trim().Split('\r', '\n');
var lastStartRaw = splitString.FirstOrDefault(o => o.Contains("started"));
var uptimeRaw = splitString.FirstOrDefault(o => o.Contains("running"));
if (!String.IsNullOrEmpty(lastStartRaw))
{
var lastStartIndex = lastStartRaw.IndexOf(':');
_lastStart = lastStartRaw.Substring(lastStartIndex + 1).Trim();
}
if (String.IsNullOrEmpty(uptimeRaw)) return;
var forIndex = uptimeRaw.IndexOf("for", StringComparison.Ordinal);
//4 => "for " to get what's on the right
_uptime = uptimeRaw.Substring(forIndex + 4);
}
private void CrestronEnvironmentOnEthernetEventHandler(EthernetEventArgs ethernetEventArgs)
{
if (ethernetEventArgs.EthernetEventType != eEthernetEventType.LinkUp) return;