From 8b7effd6ff1694688e93d03a48c5dcddb4efe4f0 Mon Sep 17 00:00:00 2001 From: LukePulverenti Luke Pulverenti luke pulverenti Date: Tue, 18 Sep 2012 15:33:57 -0400 Subject: Moved discovery of loggers and weather providers to MEF. Also added support for third-party image processors, also discovered through MEF. --- .../Drawing/BaseImageProcessor.cs | 33 ++++ MediaBrowser.Controller/Drawing/DrawingUtils.cs | 81 ++++++++ MediaBrowser.Controller/Drawing/ImageProcessor.cs | 148 +++++++++++++++ MediaBrowser.Controller/Kernel.cs | 46 ++--- .../MediaBrowser.Controller.csproj | 7 +- .../Weather/BaseWeatherProvider.cs | 34 ++++ MediaBrowser.Controller/Weather/WeatherClient.cs | 207 --------------------- MediaBrowser.Controller/Weather/WeatherProvider.cs | 189 +++++++++++++++++++ 8 files changed, 508 insertions(+), 237 deletions(-) create mode 100644 MediaBrowser.Controller/Drawing/BaseImageProcessor.cs create mode 100644 MediaBrowser.Controller/Drawing/DrawingUtils.cs create mode 100644 MediaBrowser.Controller/Drawing/ImageProcessor.cs create mode 100644 MediaBrowser.Controller/Weather/BaseWeatherProvider.cs delete mode 100644 MediaBrowser.Controller/Weather/WeatherClient.cs create mode 100644 MediaBrowser.Controller/Weather/WeatherProvider.cs (limited to 'MediaBrowser.Controller') diff --git a/MediaBrowser.Controller/Drawing/BaseImageProcessor.cs b/MediaBrowser.Controller/Drawing/BaseImageProcessor.cs new file mode 100644 index 000000000..a2b223a70 --- /dev/null +++ b/MediaBrowser.Controller/Drawing/BaseImageProcessor.cs @@ -0,0 +1,33 @@ +using MediaBrowser.Controller.Entities; +using MediaBrowser.Model.Entities; +using System.Drawing; + +namespace MediaBrowser.Controller.Drawing +{ + /// + /// Provides a base image processor class that plugins can use to process images as they are being writen to http responses + /// Since this is completely modular with MEF, a plugin only needs to have a subclass in their assembly with the following attribute on the class: + /// [Export(typeof(BaseImageProcessor))] + /// This will require a reference to System.ComponentModel.Composition + /// + public abstract class BaseImageProcessor + { + /// + /// Processes the primary image for a BaseEntity (Person, Studio, User, etc) + /// + /// The bitmap holding the original image, after re-sizing + /// The graphics surface on which the output is drawn + /// The entity that owns the image + public abstract void ProcessImage(Bitmap bitmap, Graphics graphics, BaseEntity entity); + + /// + /// Processes an image for a BaseItem + /// + /// The bitmap holding the original image, after re-sizing + /// The graphics surface on which the output is drawn + /// The entity that owns the image + /// The image type + /// The image index (currently only used with backdrops) + public abstract void ProcessImage(Bitmap bitmap, Graphics graphics, BaseItem entity, ImageType imageType, int imageIndex); + } +} diff --git a/MediaBrowser.Controller/Drawing/DrawingUtils.cs b/MediaBrowser.Controller/Drawing/DrawingUtils.cs new file mode 100644 index 000000000..8e2f829b9 --- /dev/null +++ b/MediaBrowser.Controller/Drawing/DrawingUtils.cs @@ -0,0 +1,81 @@ +using System; +using System.Drawing; + +namespace MediaBrowser.Controller.Drawing +{ + public static class DrawingUtils + { + /// + /// Resizes a set of dimensions + /// + public static Size Resize(int currentWidth, int currentHeight, int? width, int? height, int? maxWidth, int? maxHeight) + { + return Resize(new Size(currentWidth, currentHeight), width, height, maxWidth, maxHeight); + } + + /// + /// Resizes a set of dimensions + /// + /// The original size object + /// A new fixed width, if desired + /// A new fixed neight, if desired + /// A max fixed width, if desired + /// A max fixed height, if desired + /// A new size object + public static Size Resize(Size size, int? width, int? height, int? maxWidth, int? maxHeight) + { + decimal newWidth = size.Width; + decimal newHeight = size.Height; + + if (width.HasValue && height.HasValue) + { + newWidth = width.Value; + newHeight = height.Value; + } + + else if (height.HasValue) + { + newWidth = GetNewWidth(newHeight, newWidth, height.Value); + newHeight = height.Value; + } + + else if (width.HasValue) + { + newHeight = GetNewHeight(newHeight, newWidth, width.Value); + newWidth = width.Value; + } + + if (maxHeight.HasValue && maxHeight < newHeight) + { + newWidth = GetNewWidth(newHeight, newWidth, maxHeight.Value); + newHeight = maxHeight.Value; + } + + if (maxWidth.HasValue && maxWidth < newWidth) + { + newHeight = GetNewHeight(newHeight, newWidth, maxWidth.Value); + newWidth = maxWidth.Value; + } + + return new Size(Convert.ToInt32(newWidth), Convert.ToInt32(newHeight)); + } + + private static decimal GetNewWidth(decimal currentHeight, decimal currentWidth, int newHeight) + { + decimal scaleFactor = newHeight; + scaleFactor /= currentHeight; + scaleFactor *= currentWidth; + + return scaleFactor; + } + + private static decimal GetNewHeight(decimal currentHeight, decimal currentWidth, int newWidth) + { + decimal scaleFactor = newWidth; + scaleFactor /= currentWidth; + scaleFactor *= currentHeight; + + return scaleFactor; + } + } +} diff --git a/MediaBrowser.Controller/Drawing/ImageProcessor.cs b/MediaBrowser.Controller/Drawing/ImageProcessor.cs new file mode 100644 index 000000000..b7815750b --- /dev/null +++ b/MediaBrowser.Controller/Drawing/ImageProcessor.cs @@ -0,0 +1,148 @@ +using MediaBrowser.Controller.Entities; +using MediaBrowser.Model.Entities; +using System; +using System.Drawing; +using System.Drawing.Drawing2D; +using System.Drawing.Imaging; +using System.IO; +using System.Linq; + +namespace MediaBrowser.Controller.Drawing +{ + public static class ImageProcessor + { + /// + /// Processes an image by resizing to target dimensions + /// + /// The stream containing the source image + /// The stream to save the new image to + /// Use if a fixed width is required. Aspect ratio will be preserved. + /// Use if a fixed height is required. Aspect ratio will be preserved. + /// Use if a max width is required. Aspect ratio will be preserved. + /// Use if a max height is required. Aspect ratio will be preserved. + /// Quality level, from 0-100. Currently only applies to JPG. The default value should suffice. + /// The entity that owns the image + /// The image type + /// The image index (currently only used with backdrops) + public static void ProcessImage(Stream sourceImageStream, Stream toStream, int? width, int? height, int? maxWidth, int? maxHeight, int? quality, BaseEntity entity, ImageType imageType, int imageIndex) + { + Image originalImage = Image.FromStream(sourceImageStream); + + // Determine the output size based on incoming parameters + Size newSize = DrawingUtils.Resize(originalImage.Size, width, height, maxWidth, maxHeight); + + Bitmap thumbnail; + + // Graphics.FromImage will throw an exception if the PixelFormat is Indexed, so we need to handle that here + if (originalImage.PixelFormat.HasFlag(PixelFormat.Indexed)) + { + thumbnail = new Bitmap(originalImage, newSize.Width, newSize.Height); + } + else + { + thumbnail = new Bitmap(newSize.Width, newSize.Height, originalImage.PixelFormat); + } + + // Preserve the original resolution + thumbnail.SetResolution(originalImage.HorizontalResolution, originalImage.VerticalResolution); + + Graphics thumbnailGraph = Graphics.FromImage(thumbnail); + + thumbnailGraph.CompositingQuality = CompositingQuality.HighQuality; + thumbnailGraph.SmoothingMode = SmoothingMode.HighQuality; + thumbnailGraph.InterpolationMode = InterpolationMode.HighQualityBicubic; + thumbnailGraph.PixelOffsetMode = PixelOffsetMode.HighQuality; + thumbnailGraph.CompositingMode = CompositingMode.SourceOver; + + thumbnailGraph.DrawImage(originalImage, 0, 0, newSize.Width, newSize.Height); + + // Run Kernel image processors + if (Kernel.Instance.ImageProcessors.Any()) + { + ExecuteAdditionalImageProcessors(thumbnail, thumbnailGraph, entity, imageType, imageIndex); + } + + // Write to the output stream + SaveImage(originalImage.RawFormat, thumbnail, toStream, quality); + + thumbnailGraph.Dispose(); + thumbnail.Dispose(); + originalImage.Dispose(); + } + + /// + /// Executes additional image processors that are registered with the Kernel + /// + /// The bitmap holding the original image, after re-sizing + /// The graphics surface on which the output is drawn + /// The entity that owns the image + /// The image type + /// The image index (currently only used with backdrops) + private static void ExecuteAdditionalImageProcessors(Bitmap bitmap, Graphics graphics, BaseEntity entity, ImageType imageType, int imageIndex) + { + var baseItem = entity as BaseItem; + + if (baseItem != null) + { + foreach (var processor in Kernel.Instance.ImageProcessors) + { + processor.ProcessImage(bitmap, graphics, baseItem, imageType, imageIndex); + } + } + else + { + foreach (var processor in Kernel.Instance.ImageProcessors) + { + processor.ProcessImage(bitmap, graphics, entity); + } + } + } + + public static void SaveImage(ImageFormat originalImageRawFormat, Image newImage, Stream toStream, int? quality) + { + // Use special save methods for jpeg and png that will result in a much higher quality image + // All other formats use the generic Image.Save + if (ImageFormat.Jpeg.Equals(originalImageRawFormat)) + { + SaveJpeg(newImage, toStream, quality); + } + else if (ImageFormat.Png.Equals(originalImageRawFormat)) + { + newImage.Save(toStream, ImageFormat.Png); + } + else + { + newImage.Save(toStream, originalImageRawFormat); + } + } + + public static void SaveJpeg(Image image, Stream target, int? quality) + { + if (!quality.HasValue) + { + quality = 90; + } + + using (var encoderParameters = new EncoderParameters(1)) + { + encoderParameters.Param[0] = new EncoderParameter(Encoder.Quality, quality.Value); + image.Save(target, GetImageCodecInfo("image/jpeg"), encoderParameters); + } + } + + public static ImageCodecInfo GetImageCodecInfo(string mimeType) + { + ImageCodecInfo[] info = ImageCodecInfo.GetImageEncoders(); + + for (int i = 0; i < info.Length; i++) + { + ImageCodecInfo ici = info[i]; + if (ici.MimeType.Equals(mimeType, StringComparison.OrdinalIgnoreCase)) + { + return ici; + } + } + return info[1]; + } + } +} diff --git a/MediaBrowser.Controller/Kernel.cs b/MediaBrowser.Controller/Kernel.cs index 682abb632..4c0dc6965 100644 --- a/MediaBrowser.Controller/Kernel.cs +++ b/MediaBrowser.Controller/Kernel.cs @@ -1,5 +1,6 @@ using MediaBrowser.Common.Kernel; using MediaBrowser.Common.Logging; +using MediaBrowser.Controller.Drawing; using MediaBrowser.Controller.Entities; using MediaBrowser.Controller.Entities.TV; using MediaBrowser.Controller.IO; @@ -27,7 +28,6 @@ namespace MediaBrowser.Controller public static Kernel Instance { get; private set; } public ItemController ItemController { get; private set; } - public WeatherClient WeatherClient { get; private set; } public IEnumerable Users { get; private set; } public Folder RootFolder { get; private set; } @@ -47,6 +47,12 @@ namespace MediaBrowser.Controller get { return KernelContext.Server; } } + /// + /// Gets the list of currently registered weather prvoiders + /// + [ImportMany(typeof(BaseWeatherProvider))] + public IEnumerable WeatherProviders { get; private set; } + /// /// Gets the list of currently registered metadata prvoiders /// @@ -71,6 +77,12 @@ namespace MediaBrowser.Controller /// internal IBaseItemResolver[] EntityResolvers { get; private set; } + /// + /// Gets the list of currently registered entity resolvers + /// + [ImportMany(typeof(BaseImageProcessor))] + internal IEnumerable ImageProcessors { get; private set; } + /// /// Creates a kernel based on a Data path, which is akin to our current programdata path /// @@ -85,13 +97,15 @@ namespace MediaBrowser.Controller /// protected override void InitializeInternal(IProgress progress) { + base.InitializeInternal(progress); + ItemController = new ItemController(); DirectoryWatchers = new DirectoryWatchers(); ItemController.PreBeginResolvePath += ItemController_PreBeginResolvePath; ItemController.BeginResolvePath += ItemController_BeginResolvePath; - base.InitializeInternal(progress); + ExtractFFMpeg(); } /// @@ -101,14 +115,11 @@ namespace MediaBrowser.Controller { await base.ReloadInternal(progress).ConfigureAwait(false); - ReloadWeatherClient(); - - ExtractFFMpeg(); - ReportProgress(progress, "Loading Users"); ReloadUsers(); ReportProgress(progress, "Loading Media Library"); + await ReloadRoot(allowInternetProviders: false).ConfigureAwait(false); } @@ -121,8 +132,6 @@ namespace MediaBrowser.Controller DirectoryWatchers.Stop(); - DisposeWeatherClient(); - ItemController.PreBeginResolvePath -= ItemController_PreBeginResolvePath; ItemController.BeginResolvePath -= ItemController_BeginResolvePath; } @@ -413,26 +422,5 @@ namespace MediaBrowser.Controller } } } - - /// - /// Disposes the current WeatherClient - /// - private void DisposeWeatherClient() - { - if (WeatherClient != null) - { - WeatherClient.Dispose(); - } - } - - /// - /// Disposes the current WeatherClient and creates a new one - /// - private void ReloadWeatherClient() - { - DisposeWeatherClient(); - - WeatherClient = new WeatherClient(); - } } } diff --git a/MediaBrowser.Controller/MediaBrowser.Controller.csproj b/MediaBrowser.Controller/MediaBrowser.Controller.csproj index 8d1f4965a..131825af3 100644 --- a/MediaBrowser.Controller/MediaBrowser.Controller.csproj +++ b/MediaBrowser.Controller/MediaBrowser.Controller.csproj @@ -36,6 +36,7 @@ + @@ -58,6 +59,9 @@ + + + @@ -107,7 +111,8 @@ - + + 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 GetWeatherInfoAsync(string zipCode); + } +} diff --git a/MediaBrowser.Controller/Weather/WeatherClient.cs b/MediaBrowser.Controller/Weather/WeatherClient.cs deleted file mode 100644 index 7226dccf0..000000000 --- a/MediaBrowser.Controller/Weather/WeatherClient.cs +++ /dev/null @@ -1,207 +0,0 @@ -using MediaBrowser.Common.Logging; -using MediaBrowser.Common.Serialization; -using MediaBrowser.Model.Weather; -using System; -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 -{ - /// - /// 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 - /// - public class WeatherClient : IDisposable - { - 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 GetWeatherInfoAsync(string zipCode) - { - if (string.IsNullOrWhiteSpace(zipCode)) - { - return null; - } - - const int numDays = 5; - const string apiKey = "24902f60f1231941120109"; - - string url = "http://free.worldweatheronline.com/feed/weather.ashx?q=" + zipCode + "&format=json&num_of_days=" + numDays + "&key=" + apiKey; - - Logger.LogInfo("Accessing weather from " + url); - - using (Stream stream = await HttpClient.GetStreamAsync(url).ConfigureAwait(false)) - { - WeatherData data = JsonSerializer.DeserializeFromStream(stream).data; - - return GetWeatherInfo(data); - } - } - - /// - /// Converst the json output to our WeatherInfo model class - /// - private WeatherInfo GetWeatherInfo(WeatherData data) - { - var info = new WeatherInfo(); - - if (data.current_condition != null) - { - if (data.current_condition.Any()) - { - info.CurrentWeather = data.current_condition.First().ToWeatherStatus(); - } - } - - if (data.weather != null) - { - info.Forecasts = data.weather.Select(w => w.ToWeatherForecast()).ToArray(); - } - - return info; - } - - public void Dispose() - { - HttpClient.Dispose(); - } - } - - class WeatherResult - { - public WeatherData data { get; set; } - } - - public class WeatherData - { - public WeatherCondition[] current_condition { get; set; } - public DailyWeatherInfo[] weather { get; set; } - } - - public class WeatherCondition - { - public string temp_C { get; set; } - public string temp_F { get; set; } - public string humidity { get; set; } - public string weatherCode { get; set; } - - public WeatherStatus ToWeatherStatus() - { - return new WeatherStatus - { - TemperatureCelsius = int.Parse(temp_C), - TemperatureFahrenheit = int.Parse(temp_F), - Humidity = int.Parse(humidity), - Condition = DailyWeatherInfo.GetCondition(weatherCode) - }; - } - } - - public class DailyWeatherInfo - { - public string date { get; set; } - public string precipMM { get; set; } - public string tempMaxC { get; set; } - public string tempMaxF { get; set; } - public string tempMinC { get; set; } - public string tempMinF { get; set; } - public string weatherCode { get; set; } - public string winddir16Point { get; set; } - public string winddirDegree { get; set; } - public string winddirection { get; set; } - public string windspeedKmph { get; set; } - public string windspeedMiles { get; set; } - - public WeatherForecast ToWeatherForecast() - { - return new WeatherForecast - { - Date = DateTime.Parse(date), - HighTemperatureCelsius = int.Parse(tempMaxC), - HighTemperatureFahrenheit = int.Parse(tempMaxF), - LowTemperatureCelsius = int.Parse(tempMinC), - LowTemperatureFahrenheit = int.Parse(tempMinF), - Condition = GetCondition(weatherCode) - }; - } - - public static WeatherConditions GetCondition(string weatherCode) - { - switch (weatherCode) - { - case "362": - case "365": - case "320": - case "317": - case "182": - return WeatherConditions.Sleet; - case "338": - case "335": - case "332": - case "329": - case "326": - case "323": - case "377": - case "374": - case "371": - case "368": - case "395": - case "392": - case "350": - case "227": - case "179": - return WeatherConditions.Snow; - case "314": - case "311": - case "308": - case "305": - case "302": - case "299": - case "296": - case "293": - case "284": - case "281": - case "266": - case "263": - case "359": - case "356": - case "353": - case "185": - case "176": - return WeatherConditions.Rain; - case "260": - case "248": - return WeatherConditions.Fog; - case "389": - case "386": - case "200": - return WeatherConditions.Thunderstorm; - case "230": - return WeatherConditions.Blizzard; - case "143": - return WeatherConditions.Mist; - case "122": - return WeatherConditions.Overcast; - case "119": - return WeatherConditions.Cloudy; - case "115": - return WeatherConditions.PartlyCloudy; - default: - return WeatherConditions.Sunny; - } - } - } -} diff --git a/MediaBrowser.Controller/Weather/WeatherProvider.cs b/MediaBrowser.Controller/Weather/WeatherProvider.cs new file mode 100644 index 000000000..0fc728879 --- /dev/null +++ b/MediaBrowser.Controller/Weather/WeatherProvider.cs @@ -0,0 +1,189 @@ +using MediaBrowser.Common.Logging; +using MediaBrowser.Common.Serialization; +using MediaBrowser.Model.Weather; +using System; +using System.ComponentModel.Composition; +using System.IO; +using System.Linq; +using System.Threading.Tasks; + +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 + /// + [Export(typeof(BaseWeatherProvider))] + public class WeatherProvider : BaseWeatherProvider + { + public override async Task GetWeatherInfoAsync(string zipCode) + { + if (string.IsNullOrWhiteSpace(zipCode)) + { + return null; + } + + const int numDays = 5; + const string apiKey = "24902f60f1231941120109"; + + string url = "http://free.worldweatheronline.com/feed/weather.ashx?q=" + zipCode + "&format=json&num_of_days=" + numDays + "&key=" + apiKey; + + Logger.LogInfo("Accessing weather from " + url); + + using (Stream stream = await HttpClient.GetStreamAsync(url).ConfigureAwait(false)) + { + WeatherData data = JsonSerializer.DeserializeFromStream(stream).data; + + return GetWeatherInfo(data); + } + } + + /// + /// Converst the json output to our WeatherInfo model class + /// + private WeatherInfo GetWeatherInfo(WeatherData data) + { + var info = new WeatherInfo(); + + if (data.current_condition != null) + { + if (data.current_condition.Any()) + { + info.CurrentWeather = data.current_condition.First().ToWeatherStatus(); + } + } + + if (data.weather != null) + { + info.Forecasts = data.weather.Select(w => w.ToWeatherForecast()).ToArray(); + } + + return info; + } + } + + class WeatherResult + { + public WeatherData data { get; set; } + } + + public class WeatherData + { + public WeatherCondition[] current_condition { get; set; } + public DailyWeatherInfo[] weather { get; set; } + } + + public class WeatherCondition + { + public string temp_C { get; set; } + public string temp_F { get; set; } + public string humidity { get; set; } + public string weatherCode { get; set; } + + public WeatherStatus ToWeatherStatus() + { + return new WeatherStatus + { + TemperatureCelsius = int.Parse(temp_C), + TemperatureFahrenheit = int.Parse(temp_F), + Humidity = int.Parse(humidity), + Condition = DailyWeatherInfo.GetCondition(weatherCode) + }; + } + } + + public class DailyWeatherInfo + { + public string date { get; set; } + public string precipMM { get; set; } + public string tempMaxC { get; set; } + public string tempMaxF { get; set; } + public string tempMinC { get; set; } + public string tempMinF { get; set; } + public string weatherCode { get; set; } + public string winddir16Point { get; set; } + public string winddirDegree { get; set; } + public string winddirection { get; set; } + public string windspeedKmph { get; set; } + public string windspeedMiles { get; set; } + + public WeatherForecast ToWeatherForecast() + { + return new WeatherForecast + { + Date = DateTime.Parse(date), + HighTemperatureCelsius = int.Parse(tempMaxC), + HighTemperatureFahrenheit = int.Parse(tempMaxF), + LowTemperatureCelsius = int.Parse(tempMinC), + LowTemperatureFahrenheit = int.Parse(tempMinF), + Condition = GetCondition(weatherCode) + }; + } + + public static WeatherConditions GetCondition(string weatherCode) + { + switch (weatherCode) + { + case "362": + case "365": + case "320": + case "317": + case "182": + return WeatherConditions.Sleet; + case "338": + case "335": + case "332": + case "329": + case "326": + case "323": + case "377": + case "374": + case "371": + case "368": + case "395": + case "392": + case "350": + case "227": + case "179": + return WeatherConditions.Snow; + case "314": + case "311": + case "308": + case "305": + case "302": + case "299": + case "296": + case "293": + case "284": + case "281": + case "266": + case "263": + case "359": + case "356": + case "353": + case "185": + case "176": + return WeatherConditions.Rain; + case "260": + case "248": + return WeatherConditions.Fog; + case "389": + case "386": + case "200": + return WeatherConditions.Thunderstorm; + case "230": + return WeatherConditions.Blizzard; + case "143": + return WeatherConditions.Mist; + case "122": + return WeatherConditions.Overcast; + case "119": + return WeatherConditions.Cloudy; + case "115": + return WeatherConditions.PartlyCloudy; + default: + return WeatherConditions.Sunny; + } + } + } +} -- cgit v1.2.3