mirror of
https://github.com/PepperDash/Essentials.git
synced 2026-02-15 20:54:55 +00:00
Resolves #368
Changed parsing routine to no longer use absolute indicies for 'ParseUptime'
This commit is contained in:
@@ -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,32 +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)
|
||||||
{
|
{
|
||||||
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];
|
|
||||||
|
|
||||||
var forIndex = uptimeRaw.IndexOf("for", StringComparison.Ordinal);
|
|
||||||
|
|
||||||
//4 => "for " to get what's on the right
|
|
||||||
_uptime = uptimeRaw.Substring(forIndex + 4);
|
|
||||||
}
|
}
|
||||||
catch (Exception e)
|
|
||||||
{
|
if (String.IsNullOrEmpty(uptimeRaw)) return;
|
||||||
ErrorLog.Exception(String.Format("Exception unable to parse string '{1}'", response), e);
|
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;
|
||||||
|
|||||||
Reference in New Issue
Block a user