From 90251d92df93db0ab0c75a8dec35fc42d57bf38a Mon Sep 17 00:00:00 2001 From: Neil Dorin Date: Mon, 26 Aug 2024 12:47:31 -0600 Subject: [PATCH] fix: adds condition to handle legacy and current portal URL structures and adds null check for getting list types in basic config helper methods --- .../Config/BasicConfig.cs | 8 ++--- .../Config/Essentials/EssentialsConfig.cs | 30 ++++++++++++++----- 2 files changed, 27 insertions(+), 11 deletions(-) diff --git a/src/PepperDash.Essentials.Core/Config/BasicConfig.cs b/src/PepperDash.Essentials.Core/Config/BasicConfig.cs index 59ea9bae..0e3e1e35 100644 --- a/src/PepperDash.Essentials.Core/Config/BasicConfig.cs +++ b/src/PepperDash.Essentials.Core/Config/BasicConfig.cs @@ -55,7 +55,7 @@ namespace PepperDash.Essentials.Core.Config /// public Dictionary GetSourceListForKey(string key) { - if (string.IsNullOrEmpty(key) || !SourceLists.ContainsKey(key)) + if (SourceLists == null || string.IsNullOrEmpty(key) || !SourceLists.ContainsKey(key)) return null; return SourceLists[key]; @@ -68,7 +68,7 @@ namespace PepperDash.Essentials.Core.Config /// DestinationList if the key exists, null otherwise public Dictionary GetDestinationListForKey(string key) { - if (string.IsNullOrEmpty(key) || !DestinationLists.ContainsKey(key)) + if (DestinationLists == null || string.IsNullOrEmpty(key) || !DestinationLists.ContainsKey(key)) { return null; } @@ -83,7 +83,7 @@ namespace PepperDash.Essentials.Core.Config /// AudioControlPointList if the key exists, null otherwise public AudioControlPointListItem GetAudioControlPointListForKey(string key) { - if (string.IsNullOrEmpty(key) || !AudioControlPointLists.ContainsKey(key)) + if (AudioControlPointLists == null || string.IsNullOrEmpty(key) || !AudioControlPointLists.ContainsKey(key)) return null; return AudioControlPointLists[key]; @@ -94,7 +94,7 @@ namespace PepperDash.Essentials.Core.Config /// public Dictionary GetCameraListForKey(string key) { - if (string.IsNullOrEmpty(key) || !CameraLists.ContainsKey(key)) + if (CameraLists == null || string.IsNullOrEmpty(key) || !CameraLists.ContainsKey(key)) return null; return CameraLists[key]; diff --git a/src/PepperDash.Essentials.Core/Config/Essentials/EssentialsConfig.cs b/src/PepperDash.Essentials.Core/Config/Essentials/EssentialsConfig.cs index dac5a35c..b42ec94c 100644 --- a/src/PepperDash.Essentials.Core/Config/Essentials/EssentialsConfig.cs +++ b/src/PepperDash.Essentials.Core/Config/Essentials/EssentialsConfig.cs @@ -31,9 +31,17 @@ namespace PepperDash.Essentials.Core.Config if (string.IsNullOrEmpty(SystemUrl)) return "missing url"; - var result = Regex.Match(SystemUrl, @"https?:\/\/.*\/systems\/(.*)\/#.*"); - string uuid = result.Groups[1].Value; - return uuid; + if (SystemUrl.Contains("#")) + { + var result = Regex.Match(SystemUrl, @"https?:\/\/.*\/systems\/(.*)\/#.*"); + string uuid = result.Groups[1].Value; + return uuid; + } else + { + var result = Regex.Match(SystemUrl, @"https?:\/\/.*\/systems\/(.*)\/.*"); + string uuid = result.Groups[1].Value; + return uuid; + } } } @@ -44,10 +52,18 @@ namespace PepperDash.Essentials.Core.Config { if (string.IsNullOrEmpty(TemplateUrl)) return "missing template url"; - - var result = Regex.Match(TemplateUrl, @"https?:\/\/.*\/templates\/(.*)\/#.*"); - string uuid = result.Groups[1].Value; - return uuid; + + if (TemplateUrl.Contains("#")) + { + var result = Regex.Match(TemplateUrl, @"https?:\/\/.*\/templates\/(.*)\/#.*"); + string uuid = result.Groups[1].Value; + return uuid; + } else + { + var result = Regex.Match(TemplateUrl, @"https?:\/\/.*\/system-templates\/(.*)\/system-template-versions\/(.*)\/.*"); + string uuid = result.Groups[2].Value; + return uuid; + } } }