示例#1
0
        /// <summary>
        /// Creates XML configuration according to the specified configuration data.
        /// </summary>
        /// <param name="configRequirements">Data which describes necessary configuration.</param>
        /// <returns>XML config of service as serialized set of classes.</returns>
        public static ConfigurationXml CreateXmlConfigBasedOnRequirements(
            ConfigRequirements configRequirements)
        {
            configRequirements.ThrowIfNull(nameof(configRequirements));

            var xmlConfigCreator = new XmlConfigCreator();

            xmlConfigCreator.SetMessageHandlerType("ConsoleMessageHandler");
            xmlConfigCreator.AddMessageHandlerParameter(
                new XElement("ConsoleMessageHandlerSetUnicode", "false")
                );

            xmlConfigCreator.SetDefaultInStorageName("thing_names.csv");

            xmlConfigCreator.SetCrawlersOutputFlag(false);

            xmlConfigCreator.SetAppraisersOutputFlag(false);

            xmlConfigCreator.SetDefaultOutStorageName("appraised_things.csv");

            xmlConfigCreator.AddRepository(
                ConfigModule.GetConfigForRepository(
                    ConfigNames.Repositories.BasicInfoRepositoryName
                    )
                );

            foreach (var inputItem in configRequirements.Input)
            {
                ConfigContract.CheckAvailability(inputItem, ConfigContract.AvailableInput);

                xmlConfigCreator.AddInputter(
                    ConfigModule.GetConfigForInputter(inputItem)
                    );
            }

            foreach (var serviceItem in configRequirements.Services)
            {
                ConfigContract.CheckAvailability(serviceItem, ConfigContract.AvailableServices);

                xmlConfigCreator.AddCrawler(
                    ConfigModule.GetConfigForCrawler(serviceItem)
                    );
                xmlConfigCreator.AddRepository(
                    ConfigModule.GetConfigForRepository(serviceItem)
                    );
            }

            foreach (var appraisalItem in configRequirements.Appraisals)
            {
                ConfigContract.CheckAvailability(appraisalItem, ConfigContract.AvailableAppraisals);

                xmlConfigCreator.AddAppraiser(
                    ConfigModule.GetConfigForAppraiser(appraisalItem)
                    );
            }

            foreach (var outputItem in configRequirements.Output)
            {
                ConfigContract.CheckAvailability(outputItem, ConfigContract.AvailableOutput);

                xmlConfigCreator.AddOutputter(
                    ConfigModule.GetConfigForOutputter(outputItem)
                    );
            }

            xmlConfigCreator.SetServiceType(ServiceType.TplDataflow);

            return(xmlConfigCreator.GetResult());
        }
示例#2
0
        /// <summary>
        /// Creates default configuration of the service. If you want to customize components, use
        /// other methods to define what you want.
        /// </summary>
        /// <returns>Default XML config of service as serialized set of classes.</returns>
        public static ConfigurationXml CreateDefaultXmlConfig()
        {
            var xmlConfig = new ConfigurationXml
            {
                ShellConfig = new ShellConfig
                {
                    MessageHandler = new MessageHandlerConfig
                    {
                        MessageHandlerType       = "ConsoleMessageHandler",
                        MessageHandlerParameters = new[]
                        {
                            ConfigModule.GetConfigForMessageHandlerParameter(
                                ConfigNames.MessageHandlerParameters
                                .ConsoleMessageHandlerSetUnicodeName
                                )
                        }
                    },
                    InputManager = new InputManagerConfig
                    {
                        DefaultInStorageName = "thing_names.csv",
                        Inputters            = new[]
                        {
                            ConfigModule.GetConfigForInputter(
                                ConfigNames.Inputters.LocalFileReaderSimpleName
                                ),
                        }
                    },
                    CrawlersManager = new CrawlersManagerConfig
                    {
                        CrawlersOutputFlag = false,
                        Crawlers           = new[]
                        {
                            ConfigModule.GetConfigForCrawler(ConfigNames.Crawlers.TmdbCrawlerName),
                            ConfigModule.GetConfigForCrawler(ConfigNames.Crawlers.OmdbCrawlerName)
                        }
                    },
                    AppraisersManager = new AppraisersManagerConfig
                    {
                        AppraisersOutputFlag = false,
                        Appraisers           = new[]
                        {
                            ConfigModule.GetConfigForAppraiser(
                                ConfigNames.Appraisers.TmdbAppraiserCommonName
                                ),
                            ConfigModule.GetConfigForAppraiser(
                                ConfigNames.Appraisers.OmdbAppraiserCommonName
                                )
                        }
                    },
                    OutputManager = new OutputManagerConfig
                    {
                        DefaultOutStorageName = "appraised_thing.csv",
                        Outputters            = new[]
                        {
                            ConfigModule.GetConfigForOutputter(
                                ConfigNames.Outputters.LocalFileWriterName
                                ),
                        }
                    },
                    DataBaseManager = new DataBaseManagerConfig
                    {
                        Repositories = new[]
                        {
                            ConfigModule.GetConfigForRepository(
                                ConfigNames.Repositories.TmdbMovieRepositoryName
                                )
                        }
                    }
                },
                ServiceType = ServiceType.TplDataflow
            };

            return(xmlConfig);
        }