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); }, "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) if (!Debug.DoNotLoadOnNextBoot)
{ {
GoWithLoad(); GoWithLoad();

View File

@@ -337,7 +337,36 @@ namespace PepperDash.Essentials.Core
return; return;
} }
com.SimulateReceive(match.Groups[2].Value); 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> /// <summary>
/// Attempts to set the debug level of a device /// Attempts to set the debug level of a device

View File

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