aboutsummaryrefslogtreecommitdiff
path: root/MediaBrowser.Controller/Weather
diff options
context:
space:
mode:
Diffstat (limited to 'MediaBrowser.Controller/Weather')
-rw-r--r--MediaBrowser.Controller/Weather/BaseWeatherProvider.cs34
-rw-r--r--MediaBrowser.Controller/Weather/WeatherProvider.cs (renamed from MediaBrowser.Controller/Weather/WeatherClient.cs)26
2 files changed, 38 insertions, 22 deletions
diff --git a/MediaBrowser.Controller/Weather/BaseWeatherProvider.cs b/MediaBrowser.Controller/Weather/BaseWeatherProvider.cs
new file mode 100644
index 000000000..c3d436e66
--- /dev/null
+++ b/MediaBrowser.Controller/Weather/BaseWeatherProvider.cs
@@ -0,0 +1,34 @@
+using MediaBrowser.Common.Logging;
+using MediaBrowser.Model.Weather;
+using System;
+using System.Net;
+using System.Net.Cache;
+using System.Net.Http;
+using System.Threading.Tasks;
+
+namespace MediaBrowser.Controller.Weather
+{
+ public abstract class BaseWeatherProvider : IDisposable
+ {
+ protected HttpClient HttpClient { get; private set; }
+
+ protected BaseWeatherProvider()
+ {
+ var handler = new WebRequestHandler { };
+
+ handler.AutomaticDecompression = DecompressionMethods.Deflate;
+ handler.CachePolicy = new RequestCachePolicy(RequestCacheLevel.Revalidate);
+
+ HttpClient = new HttpClient(handler);
+ }
+
+ public virtual void Dispose()
+ {
+ Logger.LogInfo("Disposing " + GetType().Name);
+
+ HttpClient.Dispose();
+ }
+
+ public abstract Task<WeatherInfo> GetWeatherInfoAsync(string zipCode);
+ }
+}
diff --git a/MediaBrowser.Controller/Weather/WeatherClient.cs b/MediaBrowser.Controller/Weather/WeatherProvider.cs
index 7226dccf0..0fc728879 100644
--- a/MediaBrowser.Controller/Weather/WeatherClient.cs
+++ b/MediaBrowser.Controller/Weather/WeatherProvider.cs
@@ -2,11 +2,9 @@
using MediaBrowser.Common.Serialization;
using MediaBrowser.Model.Weather;
using System;
+using System.ComponentModel.Composition;
using System.IO;
using System.Linq;
-using System.Net;
-using System.Net.Cache;
-using System.Net.Http;
using System.Threading.Tasks;
namespace MediaBrowser.Controller.Weather
@@ -15,21 +13,10 @@ namespace MediaBrowser.Controller.Weather
/// Based on http://www.worldweatheronline.com/free-weather-feed.aspx
/// The classes in this file are a reproduction of the json output, which will then be converted to our weather model classes
/// </summary>
- public class WeatherClient : IDisposable
+ [Export(typeof(BaseWeatherProvider))]
+ public class WeatherProvider : BaseWeatherProvider
{
- private HttpClient HttpClient { get; set; }
-
- public WeatherClient()
- {
- var handler = new WebRequestHandler { };
-
- handler.AutomaticDecompression = DecompressionMethods.Deflate;
- handler.CachePolicy = new RequestCachePolicy(RequestCacheLevel.Revalidate);
-
- HttpClient = new HttpClient(handler);
- }
-
- public async Task<WeatherInfo> GetWeatherInfoAsync(string zipCode)
+ public override async Task<WeatherInfo> GetWeatherInfoAsync(string zipCode)
{
if (string.IsNullOrWhiteSpace(zipCode))
{
@@ -73,11 +60,6 @@ namespace MediaBrowser.Controller.Weather
return info;
}
-
- public void Dispose()
- {
- HttpClient.Dispose();
- }
}
class WeatherResult