namespace VideoBrowser.Core
{
using System;
using System.ComponentModel;
using VideoBrowser.Extensions;
using VideoBrowser.If;
///
/// Defines the
///
public class UrlReader : INotifyPropertyChanged, IDisposable
{
#region Fields
private string _url;
private IUrlHandler _urlHandler;
#endregion Fields
#region Constructors
///
/// Initializes a new instance of the class.
///
internal UrlReader()
{
this.UrlHandlerProvider = new UrlHandlerProvider();
this.UrlHandler = UrlHandlerProvider.NoneUrlHandler;
this.PropertyChanged += this.OnPropertyChanged;
}
#endregion Constructors
#region Events
///
/// Defines the PropertyChanged
///
public event PropertyChangedEventHandler PropertyChanged;
#endregion Events
#region Properties
///
/// Gets or sets the Url
///
public string Url { get => this._url; set => this.Set(this.PropertyChanged, ref this._url, value); }
///
/// Gets the UrlHandler
/// Gets or sets the UrlHandler
///
public IUrlHandler UrlHandler
{
get => this._urlHandler;
private set
{
if (value == null)
{
return;
}
this.Set(this.PropertyChanged, ref this._urlHandler, value);
}
}
///
/// Gets the UrlHandlerProvider
///
public UrlHandlerProvider UrlHandlerProvider { get; }
///
/// Gets a value indicating whether IsDownloadable
///
internal bool IsDownloadable => this.UrlHandler != null ? this.UrlHandler.IsDownloadable : false;
#endregion Properties
#region Methods
///
/// The Dispose
///
public void Dispose()
{
this.PropertyChanged -= this.OnPropertyChanged;
}
///
/// The OnPropertyChanged
///
/// The sender
/// The e
private void OnPropertyChanged(object sender, PropertyChangedEventArgs e)
{
switch (e.PropertyName)
{
case nameof(this.Url):
this.UrlHandler = this.UrlHandlerProvider.GetUrlHandler(this.Url);
this.UrlHandler.FullUrl = this.Url;
break;
default:
break;
}
}
#endregion Methods
}
}