namespace VideoBrowser.Core
{
using System.Collections.Generic;
using VideoBrowser.If;
///
/// Defines the
///
public class UrlHandlerProvider
{
#region Constructors
///
/// Initializes a new instance of the class.
///
public UrlHandlerProvider()
{
this.UrlHandlerDict = new Dictionary();
this.AddHandler(new YoutubeUrlHandler());
}
#endregion Constructors
#region Properties
///
/// Gets the NoneUrlHandler
///
internal static IUrlHandler NoneUrlHandler { get; } = new NoneUrlHandler();
///
/// Gets the UrlHandlerDict
///
private IDictionary UrlHandlerDict { get; }
#endregion Properties
#region Methods
///
/// The GetUrlHandler
///
/// The url
/// The
internal IUrlHandler GetUrlHandler(string url)
{
if (string.IsNullOrEmpty(url))
{
return null;
}
foreach (var handlerPair in this.UrlHandlerDict)
{
if (url.Contains(handlerPair.Key))
{
return handlerPair.Value;
}
}
return NoneUrlHandler;
}
///
/// The AddHandler
///
/// The handler
private void AddHandler(IUrlHandler handler)
{
this.UrlHandlerDict.Add(handler.DomainName, handler);
}
#endregion Methods
}
}