added validation to the appconfig (remove code duplication)

This commit is contained in:
2018-12-28 23:58:22 +01:00
parent d45829b60c
commit f37d8d49ea
2 changed files with 31 additions and 5 deletions

View File

@@ -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; }
}
}

View File

@@ -79,7 +79,7 @@ namespace Tv7Playlist
case AppConfig.SourceTypeEnum.M3U:
services.AddTransient<IPlaylistParser, M3UParser>();
break;
case AppConfig.SourceTypeEnum.XSPF:
case AppConfig.SourceTypeEnum.Xspf:
services.AddTransient<IPlaylistParser, XspfParser>();
break;
default: