static void Main(string[] args)
        {
            // Create and load themes
            CreateDefaultThemes();
            List <Theme> themes = LoadAllThemes().ToList();

            LogoProcessor processor = new LogoProcessor {
                DesignsFolder = "..\\..\\..\\..\\Designs"
            };

            foreach (Theme theme in themes)
            {
                // Test 1: From file
                ProcessFile(processor, "1_plus_1_International", theme);

                // Test 2: From repository
                using (var repo = new LogoRepository {
                    RepositoryUrl = REPOSITORY_URL
                })
                {
                    // Parallel async processing
                    var results = repo.Download(new[] { "Das Erste hd", "sat.1", "zdf hd", "animal planet hd", "discovery channel" });
                    Task.WaitAll(results.Select(channelAndStream => ProcessStream(processor, channelAndStream.Value, channelAndStream.Key, theme)).ToArray());

                    // Synchronous processing
                    var stream = repo.Download("zdf");
                    ProcessStream(processor, stream, "zdf", theme);
                }
            }
        }
    static void Main(string[] args)
    {
      // Create and load themes
      CreateDefaultThemes();
      List<Theme> themes = LoadAllThemes().ToList();

      LogoProcessor processor = new LogoProcessor { DesignsFolder = "..\\..\\..\\..\\Designs" };

      foreach (Theme theme in themes)
      {
        // Test 1: From file
        ProcessFile(processor, "1_plus_1_International", theme);

        // Test 2: From repository
        using (var repo = new LogoRepository { RepositoryUrl = REPOSITORY_URL })
        {
          // Parallel async processing
          var results = repo.Download(new[] { "Das Erste hd", "sat.1", "zdf hd", "animal planet hd", "discovery channel" });
          Task.WaitAll(results.Select(channelAndStream => ProcessStream(processor, channelAndStream.Value, channelAndStream.Key, theme)).ToArray());

          // Synchronous processing
          var stream = repo.Download("zdf");
          ProcessStream(processor, stream, "zdf", theme);
        }
      }
    }
        /// <summary>
        /// Gets a list of <see cref="FanArtImage"/>s for a requested <paramref name="mediaType"/>, <paramref name="fanArtType"/> and <paramref name="name"/>.
        /// The name can be: Series name, Actor name, Artist name depending on the <paramref name="mediaType"/>.
        /// </summary>
        /// <param name="mediaType">Requested FanArtMediaType</param>
        /// <param name="fanArtType">Requested FanArtType</param>
        /// <param name="name">Requested name of Series, Actor, Artist...</param>
        /// <param name="maxWidth">Maximum width for image. <c>0</c> returns image in original size.</param>
        /// <param name="maxHeight">Maximum height for image. <c>0</c> returns image in original size.</param>
        /// <param name="singleRandom">If <c>true</c> only one random image URI will be returned</param>
        /// <param name="result">Result if return code is <c>true</c>.</param>
        /// <returns><c>true</c> if at least one match was found.</returns>
        public bool TryGetFanArt(string mediaType, string fanArtType, string name, int maxWidth, int maxHeight, bool singleRandom, out IList <IResourceLocator> result)
        {
            result = null;
            if (mediaType != FanArtMediaTypes.ChannelTv && mediaType != FanArtMediaTypes.ChannelRadio)
            {
                return(false);
            }

            try
            {
                string designsFolder = FileUtils.BuildAssemblyRelativePath("Designs");

                ChannelType  logoChannelType = mediaType == FanArtMediaTypes.ChannelTv ? ChannelType.Tv : ChannelType.Radio;
                ThemeHandler themeHandler    = new ThemeHandler();
                Theme        theme           = themeHandler.Load(Path.Combine(designsFolder, _settings.LogoTheme));

                string logoFolder   = Path.Combine(_dataFolder, string.Format("{0}-{1}-{2}", logoChannelType, theme.DesignName, theme.ThemeName));
                string logoFileName = Path.Combine(logoFolder, FileUtils.GetSafeFilename(string.Format("{0}.png", name)));

                if (!Directory.Exists(logoFolder))
                {
                    Directory.CreateDirectory(logoFolder);
                }

                if (File.Exists(logoFileName))
                {
                    result = new List <IResourceLocator> {
                        new ResourceLocator(ResourcePath.BuildBaseProviderPath(LocalFsResourceProviderBase.LOCAL_FS_RESOURCE_PROVIDER_ID, logoFileName))
                    };
                    return(true);
                }

                LogoProcessor processor = new LogoProcessor {
                    DesignsFolder = designsFolder
                };

                // From repository
                using (var repo = new LogoRepository {
                    RepositoryUrl = _settings.RepositoryUrl
                })
                {
                    var stream = repo.Download(name, logoChannelType, _country.TwoLetterISORegionName);
                    if (stream == null)
                    {
                        return(false);
                    }
                    using (stream)
                        if (processor.CreateLogo(theme, stream, logoFileName))
                        {
                            result = new List <IResourceLocator> {
                                new ResourceLocator(ResourcePath.BuildBaseProviderPath(LocalFsResourceProviderBase.LOCAL_FS_RESOURCE_PROVIDER_ID, logoFileName))
                            };
                            return(true);
                        }
                }
            }
            catch (Exception ex)
            {
                ServiceRegistration.Get <ILogger>().Error("SlimTv Logos: Error processing logo image.", ex);
            }
            return(false);
        }
        /// <summary>
        /// Gets a list of <see cref="FanArtImage"/>s for a requested <paramref name="mediaType"/>, <paramref name="fanArtType"/> and <paramref name="name"/>.
        /// The name can be: Series name, Actor name, Artist name depending on the <paramref name="mediaType"/>.
        /// </summary>
        /// <param name="mediaType">Requested FanArtMediaType</param>
        /// <param name="fanArtType">Requested FanArtType</param>
        /// <param name="name">Requested name of Series, Actor, Artist...</param>
        /// <param name="maxWidth">Maximum width for image. <c>0</c> returns image in original size.</param>
        /// <param name="maxHeight">Maximum height for image. <c>0</c> returns image in original size.</param>
        /// <param name="singleRandom">If <c>true</c> only one random image URI will be returned</param>
        /// <param name="result">Result if return code is <c>true</c>.</param>
        /// <returns><c>true</c> if at least one match was found.</returns>
        public bool TryGetFanArt(string mediaType, string fanArtType, string name, int maxWidth, int maxHeight, bool singleRandom, out IList <IResourceLocator> result)
        {
            result = null;
            if (mediaType != FanArtMediaTypes.ChannelTv && mediaType != FanArtMediaTypes.ChannelRadio)
            {
                return(false);
            }

            try
            {
                string designsFolder = _designsFolder ?? FileUtils.BuildAssemblyRelativePath("Designs");

                ChannelType  logoChannelType = mediaType == FanArtMediaTypes.ChannelTv ? ChannelType.Tv : ChannelType.Radio;
                ThemeHandler themeHandler    = new ThemeHandler();
                Theme        theme           = themeHandler.Load(Path.Combine(designsFolder, _settings.LogoTheme));

                string logoFolder   = Path.Combine(_dataFolder, string.Format("{0}-{1}-{2}", logoChannelType, theme.DesignName, theme.ThemeName));
                string logoFileName = Path.Combine(logoFolder, FileUtils.GetSafeFilename(string.Format("{0}.png", name)));

                if (!Directory.Exists(logoFolder))
                {
                    Directory.CreateDirectory(logoFolder);
                }

                if (File.Exists(logoFileName) && IsCacheValid(theme, logoFileName))
                {
                    return(BuildLogoResourceLocatorAndReturn(ref result, logoFileName));
                }

                LogoProcessor processor = new LogoProcessor {
                    DesignsFolder = designsFolder
                };

                // From repository
                using (var repo = new LogoRepository {
                    RepositoryUrl = _settings.RepositoryUrl
                })
                {
                    var stream = repo.Download(name, logoChannelType, _country.TwoLetterISORegionName);
                    if (stream == null)
                    {
                        return(BuildLogoResourceLocatorAndReturn(ref result, logoFileName));
                    }
                    using (stream)
                    {
                        // First download and process the new logo, but keep the existing file if something fails.
                        string tmpLogoFileName = Path.ChangeExtension(logoFileName, ".tmplogo");
                        if (processor.CreateLogo(theme, stream, tmpLogoFileName))
                        {
                            if (File.Exists(logoFileName))
                            {
                                File.Delete(logoFileName);
                            }
                            File.Move(tmpLogoFileName, logoFileName);
                        }
                        return(BuildLogoResourceLocatorAndReturn(ref result, logoFileName));
                    }
                }
            }
            catch (Exception ex)
            {
                ServiceRegistration.Get <ILogger>().Error("SlimTv Logos: Error processing logo image.", ex);
            }
            return(false);
        }