mirror of
https://github.com/ICDSystems/ICD.Common.Utils.git
synced 2026-02-16 21:24:58 +00:00
Slightly safer parsing of prog comments
This commit is contained in:
@@ -147,30 +147,30 @@ namespace ICD.Common.Utils
|
|||||||
{
|
{
|
||||||
Dictionary<string, string> output = new Dictionary<string, string>();
|
Dictionary<string, string> output = new Dictionary<string, string>();
|
||||||
|
|
||||||
try
|
|
||||||
{
|
|
||||||
string progInfo = string.Empty;
|
string progInfo = string.Empty;
|
||||||
string command = string.Format("progcomments:{0}", ProgramNumber);
|
string command = string.Format("progcomments:{0}", ProgramNumber);
|
||||||
|
|
||||||
if (!IcdConsole.SendControlSystemCommand(command, ref progInfo))
|
if (!IcdConsole.SendControlSystemCommand(command, ref progInfo))
|
||||||
{
|
{
|
||||||
ServiceProvider.TryGetService<ILoggerService>().AddEntry(eSeverity.Warning, "Failed to parse prog comments");
|
ServiceProvider.GetService<ILoggerService>().AddEntry(eSeverity.Warning, "Failed to parse prog comments");
|
||||||
return output;
|
return output;
|
||||||
}
|
}
|
||||||
|
|
||||||
foreach (string line in progInfo.Split(new[] {"\n\r", "\r\n", "\n", "\r"}))
|
foreach (string line in progInfo.Split(new[] {"\n\r", "\r\n", "\n", "\r"}))
|
||||||
{
|
{
|
||||||
string[] pair = line.Split(':', 2).ToArray();
|
string[] pair = line.Split(':', 2).ToArray();
|
||||||
|
|
||||||
|
if (pair.Length < 2)
|
||||||
|
{
|
||||||
|
ServiceProvider.GetService<ILoggerService>()
|
||||||
|
.AddEntry(eSeverity.Warning, "Failed to parse prog comments line - {0}", line);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
string key = pair[0].Trim();
|
string key = pair[0].Trim();
|
||||||
string value = pair[1].Trim();
|
string value = pair[1].Trim();
|
||||||
output[key] = value;
|
output[key] = value;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
catch (Exception e)
|
|
||||||
{
|
|
||||||
ServiceProvider.TryGetService<ILoggerService>()
|
|
||||||
.AddEntry(eSeverity.Error, e, "Failed to parse prog comments - {0}", e.Message);
|
|
||||||
}
|
|
||||||
|
|
||||||
return output;
|
return output;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user