diff --git a/LinkCrawler/LinkCrawler/App.config b/LinkCrawler/LinkCrawler/App.config index 458b482..d79a89c 100644 --- a/LinkCrawler/LinkCrawler/App.config +++ b/LinkCrawler/LinkCrawler/App.config @@ -1,8 +1,11 @@  - - - + +
+ + + + @@ -10,7 +13,6 @@ - @@ -22,4 +24,9 @@ Url: {0} Statuscode: {1} The link is placed on this page: {2}" /> + + + + + \ No newline at end of file diff --git a/LinkCrawler/LinkCrawler/Utils/Outputs/CsvOutput.cs b/LinkCrawler/LinkCrawler/Utils/Outputs/CsvOutput.cs index 637edb9..6e59dff 100644 --- a/LinkCrawler/LinkCrawler/Utils/Outputs/CsvOutput.cs +++ b/LinkCrawler/LinkCrawler/Utils/Outputs/CsvOutput.cs @@ -12,11 +12,6 @@ public class CsvOutput : IOutput, IDisposable public CsvOutput(ISettings settings) { - if (!settings.CsvEnabled) - { - return; - } - _settings = settings; Setup(); } diff --git a/LinkCrawler/LinkCrawler/Utils/Settings/Constants.cs b/LinkCrawler/LinkCrawler/Utils/Settings/Constants.cs index 12f0c41..13375dc 100644 --- a/LinkCrawler/LinkCrawler/Utils/Settings/Constants.cs +++ b/LinkCrawler/LinkCrawler/Utils/Settings/Constants.cs @@ -12,7 +12,6 @@ public static class AppSettings public const string SlackWebHookBotName = "Slack.WebHook.Bot.Name"; public const string SlackWebHookBotIconEmoji = "Slack.WebHook.Bot.IconEmoji"; public const string SlackWebHookBotMessageFormat = "Slack.WebHook.Bot.MessageFormat"; - public const string CsvEnabled = "Csv.Enabled"; public const string CsvFilePath = "Csv.FilePath"; public const string CsvOverwrite = "Csv.Overwrite"; public const string CsvDelimiter = "Csv.Delimiter"; @@ -33,3 +32,4 @@ public static class Html } } } + \ No newline at end of file diff --git a/LinkCrawler/LinkCrawler/Utils/Settings/ISettings.cs b/LinkCrawler/LinkCrawler/Utils/Settings/ISettings.cs index 92890e6..8f82816 100644 --- a/LinkCrawler/LinkCrawler/Utils/Settings/ISettings.cs +++ b/LinkCrawler/LinkCrawler/Utils/Settings/ISettings.cs @@ -20,8 +20,6 @@ public interface ISettings string SlackWebHookBotMessageFormat { get; } - bool CsvEnabled { get; } - string CsvFilePath { get; } bool CsvOverwrite { get; } diff --git a/LinkCrawler/LinkCrawler/Utils/Settings/Settings.cs b/LinkCrawler/LinkCrawler/Utils/Settings/Settings.cs index be67439..b9a6c7d 100644 --- a/LinkCrawler/LinkCrawler/Utils/Settings/Settings.cs +++ b/LinkCrawler/LinkCrawler/Utils/Settings/Settings.cs @@ -30,9 +30,6 @@ public class Settings : ISettings public string SlackWebHookBotMessageFormat => ConfigurationManager.AppSettings[Constants.AppSettings.SlackWebHookBotMessageFormat]; - public bool CsvEnabled => - ConfigurationManager.AppSettings[Constants.AppSettings.CsvEnabled].ToBool(); - public string CsvFilePath => ConfigurationManager.AppSettings[Constants.AppSettings.CsvFilePath]; diff --git a/LinkCrawler/LinkCrawler/Utils/StructureMapRegistry.cs b/LinkCrawler/LinkCrawler/Utils/StructureMapRegistry.cs index 20f1141..257b5fe 100644 --- a/LinkCrawler/LinkCrawler/Utils/StructureMapRegistry.cs +++ b/LinkCrawler/LinkCrawler/Utils/StructureMapRegistry.cs @@ -1,4 +1,8 @@ -using LinkCrawler.Utils.Outputs; +using System; +using System.Collections; +using System.Configuration; +using System.Linq; +using LinkCrawler.Utils.Outputs; using StructureMap.Configuration.DSL; using StructureMap.Graph; @@ -12,8 +16,41 @@ public StructureMapRegistry() { scan.TheCallingAssembly(); scan.WithDefaultConventions(); - scan.AddAllTypesOf(); }); + + var providers = (ConfigurationManager.GetSection("outputProviders") as Hashtable)? + .Cast() + .ToDictionary(d => d.Key.ToString(), d => d.Value.ToString()); + + if (providers != null) + { + var pluginType = typeof(IOutput); + + foreach (var provider in providers) + { + var concreteType = Type.GetType(provider.Value); + + if (concreteType == null) + { + throw new ConfigurationErrorsException(string.Format( + "Output provider '{0}' not found: {1}", + provider.Key, + provider.Value + )); + } + + if (!concreteType.GetInterfaces().Contains(pluginType)) + { + throw new ConfigurationErrorsException(string.Format( + "Output provider '{0}' does not implement IOutput: {1}", + provider.Key, + provider.Value + )); + } + + For(pluginType).Add(concreteType).Named(provider.Key); + } + } } } }