Changed parsing routine to no longer use absolute indicies for 'ParseUptime'
This commit is contained in:
Trevor Payne
2020-08-18 10:40:20 -05:00
parent f18ed56909
commit 78f9142b35

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;
@@ -103,28 +104,24 @@ namespace PepperDash.Essentials.Core.Monitoring
} }
private void ParseUptime(string response) private void ParseUptime(string response)
{
try
{ {
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 uptimeRaw = splitString.FirstOrDefault(o => o.Contains("running"));
if (!String.IsNullOrEmpty(lastStartRaw))
{
var lastStartIndex = lastStartRaw.IndexOf(':'); var lastStartIndex = lastStartRaw.IndexOf(':');
_lastStart = lastStartRaw.Substring(lastStartIndex + 1).Trim(); _lastStart = lastStartRaw.Substring(lastStartIndex + 1).Trim();
}
var uptimeRaw = splitString[0]; if (String.IsNullOrEmpty(uptimeRaw)) return;
var forIndex = uptimeRaw.IndexOf("for", StringComparison.Ordinal); var forIndex = uptimeRaw.IndexOf("for", StringComparison.Ordinal);
//4 => "for " to get what's on the right //4 => "for " to get what's on the right
_uptime = uptimeRaw.Substring(forIndex + 4); _uptime = uptimeRaw.Substring(forIndex + 4);
} }
catch (Exception e)
{
ErrorLog.Exception(String.Format("Exception unable to parse string '{1}'", response), e);
}
}
private void CrestronEnvironmentOnEthernetEventHandler(EthernetEventArgs ethernetEventArgs) private void CrestronEnvironmentOnEthernetEventHandler(EthernetEventArgs ethernetEventArgs)
{ {