Skip to content

Commit

Permalink
Provider handling class refactoring and cleanup
Browse files Browse the repository at this point in the history
Bring together provider related code from the Data class and the static
plugin class into a new Provider class.  This contains both the static
initialization code to find the providers and the properties and methods
needed to store and expose the provider data and instance creation.  This
also allows access to the provider class, name, description, icon and
options handler without having to create an instance of the provider each
time one of these is required.  Also, store the loaded assemblies rather
than the path to them as this is cleaner and should improve performance.
  • Loading branch information
ribbons committed Aug 8, 2013
1 parent 02f243b commit 990b916
Show file tree
Hide file tree
Showing 9 changed files with 205 additions and 278 deletions.
6 changes: 3 additions & 3 deletions Classes/DownloadHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -144,15 +144,15 @@ private void DownloadProgThread()
this.Progress(this.episodeInfo.Epid, 0, ProgressType.Downloading);
}

if (!Plugins.PluginExists(this.pluginId))
if (!Provider.Exists(this.pluginId))
{
this.DownloadError(ErrorType.LocalProblem, "The plugin provider required to download this episode is not currently available. Please try updating the Radio Downloader providers or cancelling the download.");
return;
}

lock (this.pluginInstanceLock)
{
this.pluginInstance = Plugins.GetPluginInstance(this.pluginId);
this.pluginInstance = Provider.GetFromId(this.pluginId).CreateInstance();
this.pluginInstance.Progress += this.DownloadPluginInst_Progress;
}

Expand Down Expand Up @@ -293,7 +293,7 @@ private void DownloadError(Exception unhandled)

unhandled.Data.Add("Episode", epDetails);
unhandled.Data.Add("Programme", progDetails);
unhandled.Data.Add("Provider", Plugins.PluginInfo(this.pluginId));
unhandled.Data.Add("Provider", this.pluginInstance.ToString());

Model.Download.SetErrorred(this.episodeInfo.Epid, ErrorType.UnknownError, new ErrorReporting("Download Error", unhandled));
this.DownloadFinished();
Expand Down
48 changes: 4 additions & 44 deletions Classes/Data.cs → Classes/FindNew.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* This file is part of Radio Downloader.
* Copyright © 2007-2012 Matt Robinson
* Copyright © 2007-2013 Matt Robinson
*
* This program is free software: you can redistribute it and/or modify it under the terms of the GNU General
* Public License as published by the Free Software Foundation, either version 3 of the License, or (at your
Expand All @@ -18,19 +18,16 @@ namespace RadioDld
{
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Threading;
using System.Windows.Forms;

internal static class Data
internal static class FindNew
{
private static Thread episodeListThread;

private static object episodeListThreadLock = new object();
private static IRadioProvider findNewPluginInst;

public delegate void ProviderAddedEventHandler(Guid providerId);

public delegate void FindNewViewChangeEventHandler(object viewData);

public delegate void FindNewFailedEventHandler();
Expand All @@ -39,8 +36,6 @@ internal static class Data

public delegate void EpisodeAddedEventHandler(int epid);

public static event ProviderAddedEventHandler ProviderAdded;

public static event FindNewViewChangeEventHandler FindNewViewChange;

public static event FindNewFailedEventHandler FindNewFailed;
Expand All @@ -51,9 +46,9 @@ internal static class Data

public static Panel GetFindNewPanel(Guid pluginID, object view)
{
if (Plugins.PluginExists(pluginID))
if (Provider.Exists(pluginID))
{
findNewPluginInst = Plugins.GetPluginInstance(pluginID);
findNewPluginInst = Provider.GetFromId(pluginID).CreateInstance();
findNewPluginInst.FindNewException += FindNewPluginInst_FindNewException;
findNewPluginInst.FindNewViewChange += FindNewPluginInst_FindNewViewChange;
findNewPluginInst.FoundNew += FindNewPluginInst_FoundNew;
Expand All @@ -65,20 +60,6 @@ public static Panel GetFindNewPanel(Guid pluginID, object view)
}
}

public static void InitProviderList()
{
Guid[] pluginIdList = null;
pluginIdList = Plugins.GetPluginIdList();

foreach (Guid pluginId in pluginIdList)
{
if (ProviderAdded != null)
{
ProviderAdded(pluginId);
}
}
}

public static void InitEpisodeList(int progid)
{
lock (episodeListThreadLock)
Expand All @@ -97,19 +78,6 @@ public static void CancelEpisodeListing()
}
}

public static ProviderData FetchProviderData(Guid providerId)
{
IRadioProvider providerInstance = Plugins.GetPluginInstance(providerId);

ProviderData info = new ProviderData();
info.Name = providerInstance.ProviderName;
info.Description = providerInstance.ProviderDescription;
info.Icon = providerInstance.ProviderIcon;
info.ShowOptionsHandler = providerInstance.GetShowOptionsHandler();

return info;
}

private static void FindNewPluginInst_FindNewException(Exception exception, bool unhandled)
{
if (unhandled)
Expand Down Expand Up @@ -230,13 +198,5 @@ private static void InitEpisodeListThread(int progid)
return;
}
}

public struct ProviderData
{
public string Name;
public string Description;
public Bitmap Icon;
public EventHandler ShowOptionsHandler;
}
}
}
4 changes: 2 additions & 2 deletions Classes/Model/Episode.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* This file is part of Radio Downloader.
* Copyright © 2007-2012 Matt Robinson
* Copyright © 2007-2013 Matt Robinson
*
* This program is free software: you can redistribute it and/or modify it under the terms of the GNU General
* Public License as published by the Free Software Foundation, either version 3 of the License, or (at your
Expand Down Expand Up @@ -288,7 +288,7 @@ protected void FetchData(SQLiteMonDataReader reader)
}
}

IRadioProvider providerInst = Plugins.GetPluginInstance(pluginId);
IRadioProvider providerInst = Provider.GetFromId(pluginId).CreateInstance();
EpisodeInfo episodeInfo;

try
Expand Down
22 changes: 11 additions & 11 deletions Classes/Model/Programme.cs
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ public static List<Programme> FetchAllWithDownloads()

public static int? FetchInfo(Guid pluginId, string progExtId)
{
if (!Plugins.PluginExists(pluginId))
if (!Provider.Exists(pluginId))
{
return null;
}
Expand Down Expand Up @@ -211,7 +211,7 @@ public static List<string> GetAvailableEpisodes(int progid, bool fetchAll)
}
}

if (!Plugins.PluginExists(providerId))
if (!Provider.Exists(providerId))
{
return null;
}
Expand All @@ -237,7 +237,7 @@ public static List<string> GetAvailableEpisodes(int progid, bool fetchAll)
List<string> allEpExtIds = new List<string>();
int page = 1;

IRadioProvider providerInst = Plugins.GetPluginInstance(providerId);
IRadioProvider providerInst = Provider.GetFromId(providerId).CreateInstance();
AvailableEpisodes available;

do
Expand Down Expand Up @@ -369,11 +369,11 @@ protected void FetchData(SQLiteMonDataReader reader)
this.SingleEpisode = reader.GetBoolean(reader.GetOrdinal("singleepisode"));

Guid pluginId = new Guid(reader.GetString(reader.GetOrdinal("pluginid")));
IRadioProvider providerInst = Plugins.GetPluginInstance(pluginId);
Provider provider = Provider.GetFromId(pluginId);

if (providerInst != null)
if (provider != null)
{
this.ProviderName = providerInst.ProviderName;
this.ProviderName = provider.Name;
}
else
{
Expand All @@ -388,12 +388,12 @@ protected void FetchData(SQLiteMonDataReader reader)

private static int? UpdateInfo(Guid pluginId, string progExtId)
{
if (!Plugins.PluginExists(pluginId))
if (!Provider.Exists(pluginId))
{
return null;
}

IRadioProvider pluginInstance = Plugins.GetPluginInstance(pluginId);
IRadioProvider pluginInstance = Provider.GetFromId(pluginId).CreateInstance();
ProgrammeInfo progInfo;

try
Expand Down Expand Up @@ -486,9 +486,9 @@ private static void UpdateInfoIfRequiredAsync(int progid)
{
providerId = new Guid(reader.GetString(reader.GetOrdinal("pluginid")));

if (Plugins.PluginExists(providerId))
if (Provider.Exists(providerId))
{
IRadioProvider pluginInstance = Plugins.GetPluginInstance(providerId);
IRadioProvider pluginInstance = Provider.GetFromId(providerId).CreateInstance();

if (reader.GetDateTime(reader.GetOrdinal("lastupdate")).AddDays(pluginInstance.ProgInfoUpdateFreqDays) < DateTime.Now)
{
Expand All @@ -513,4 +513,4 @@ private static void UpdateInfoIfRequiredAsync(int progid)
}
}
}
}
}
165 changes: 0 additions & 165 deletions Classes/Plugins.cs

This file was deleted.

Loading

0 comments on commit 990b916

Please sign in to comment.