From f37d8d49eac4080e30e235f25634f938f11158c3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Philipp=20H=C3=A4felfinger?= Date: Fri, 28 Dec 2018 23:58:22 +0100 Subject: [PATCH] added validation to the appconfig (remove code duplication) --- Tv7Playlist/AppConfig.cs | 34 ++++++++++++++++++++++++++++++---- Tv7Playlist/Startup.cs | 2 +- 2 files changed, 31 insertions(+), 5 deletions(-) diff --git a/Tv7Playlist/AppConfig.cs b/Tv7Playlist/AppConfig.cs index d081480..f92f998 100644 --- a/Tv7Playlist/AppConfig.cs +++ b/Tv7Playlist/AppConfig.cs @@ -1,3 +1,5 @@ +using System; + namespace Tv7Playlist { public class AppConfig @@ -5,12 +7,36 @@ namespace Tv7Playlist public enum SourceTypeEnum { M3U, - XSPF + Xspf } - - public string TV7Url { get; set; } + + private string _tv7Url; + private string _udpxyUrl; + + public string TV7Url + { + get => _tv7Url; + set + { + if (!Uri.IsWellFormedUriString(value, UriKind.Absolute)) + throw new ApplicationException($"The TV7Url is set to {value}. This is not a well formed uri!"); + _tv7Url = value; + } + } + public SourceTypeEnum SourceType { get; set; } - public string UdpxyUrl { get; set; } + + public string UdpxyUrl + { + get => _udpxyUrl; + set + { + if (!Uri.IsWellFormedUriString(value, UriKind.Absolute)) + throw new ApplicationException($"The proxyUrl is set to {value}. This is not a well formed uri!"); + _udpxyUrl = value; + } + } + public string DownloadFileName { get; set; } } } \ No newline at end of file diff --git a/Tv7Playlist/Startup.cs b/Tv7Playlist/Startup.cs index b33efc2..a43f8c3 100644 --- a/Tv7Playlist/Startup.cs +++ b/Tv7Playlist/Startup.cs @@ -79,7 +79,7 @@ namespace Tv7Playlist case AppConfig.SourceTypeEnum.M3U: services.AddTransient(); break; - case AppConfig.SourceTypeEnum.XSPF: + case AppConfig.SourceTypeEnum.Xspf: services.AddTransient(); break; default: