From a4328096bdcf092f0363ce6ab5fdbf653c71cc89 Mon Sep 17 00:00:00 2001 From: Chris Cameron Date: Thu, 27 Jul 2017 14:50:08 -0400 Subject: [PATCH] Slightly safer parsing of prog comments --- ICD.Common.Utils/ProgramUtils.cs | 40 ++++++++++++++++---------------- 1 file changed, 20 insertions(+), 20 deletions(-) diff --git a/ICD.Common.Utils/ProgramUtils.cs b/ICD.Common.Utils/ProgramUtils.cs index b065bd5..2d17aca 100644 --- a/ICD.Common.Utils/ProgramUtils.cs +++ b/ICD.Common.Utils/ProgramUtils.cs @@ -147,29 +147,29 @@ namespace ICD.Common.Utils { Dictionary output = new Dictionary(); - try + string progInfo = string.Empty; + string command = string.Format("progcomments:{0}", ProgramNumber); + + if (!IcdConsole.SendControlSystemCommand(command, ref progInfo)) { - string progInfo = string.Empty; - string command = string.Format("progcomments:{0}", ProgramNumber); - - if (!IcdConsole.SendControlSystemCommand(command, ref progInfo)) - { - ServiceProvider.TryGetService().AddEntry(eSeverity.Warning, "Failed to parse prog comments"); - return output; - } - - foreach (string line in progInfo.Split(new[] {"\n\r", "\r\n", "\n", "\r"})) - { - string[] pair = line.Split(':', 2).ToArray(); - string key = pair[0].Trim(); - string value = pair[1].Trim(); - output[key] = value; - } + ServiceProvider.GetService().AddEntry(eSeverity.Warning, "Failed to parse prog comments"); + return output; } - catch (Exception e) + + foreach (string line in progInfo.Split(new[] {"\n\r", "\r\n", "\n", "\r"})) { - ServiceProvider.TryGetService() - .AddEntry(eSeverity.Error, e, "Failed to parse prog comments - {0}", e.Message); + string[] pair = line.Split(':', 2).ToArray(); + + if (pair.Length < 2) + { + ServiceProvider.GetService() + .AddEntry(eSeverity.Warning, "Failed to parse prog comments line - {0}", line); + continue; + } + + string key = pair[0].Trim(); + string value = pair[1].Trim(); + output[key] = value; } return output;