Ejemplo n.º 1
0
        /// <inheritdoc />
        /// <exception cref="InvalidOperationException">
        /// XML configuration doesn't contain element for appraisers manager with specified name.
        /// </exception>
        public void BuildAppraisersManager()
        {
            XElement?appraiserManagerElement = _documentParser.FindElement(
                _appraisersManagerParameterName
                );

            if (appraiserManagerElement is null)
            {
                throw new InvalidOperationException(
                          $"XML document has not value for {_appraisersManagerParameterName}."
                          );
            }

            var appraisersOutput = XDocumentParser.GetAttributeValue <bool>(
                appraiserManagerElement, _appraisersOutputParameterName
                );

            _appraisersManager = new Appraisers.AppraisersManager(appraisersOutput);

            foreach (XElement element in appraiserManagerElement.Elements())
            {
                Appraisers.IAppraiser crawler = _serviceBuilder.CreateAppraiser(element);
                _appraisersManager.Add(crawler);
            }
        }
Ejemplo n.º 2
0
        /// <inheritdoc />
        /// <exception cref="InvalidOperationException">
        /// XML configuration doesn't contain element for output manager with specified name.
        /// </exception>
        public void BuildOutputManager()
        {
            XElement?outputManagerElement = _documentParser.FindElement(
                _outputManagerParameterName
                );

            if (outputManagerElement is null)
            {
                throw new InvalidOperationException(
                          $"XML document has not value for {_outputManagerParameterName}."
                          );
            }

            string defaultStorageName = XDocumentParser.GetAttributeValue(
                outputManagerElement, _defaultOutStorageNameParameterName
                );

            _outputManager = new IO.Output.OutputManager(defaultStorageName);

            foreach (XElement element in outputManagerElement.Elements())
            {
                IO.Output.IOutputter outputter = _serviceBuilder.CreateOutputter(element);
                _outputManager.Add(outputter);
            }
        }
        /// <inheritdoc />
        /// <exception cref="InvalidOperationException">
        /// XML configuration doesn't contain element for appraisers manager with specified name.
        /// </exception>
        public void BuildAppraisersManager()
        {
            XElement appraiserManagerElement = _documentParser.FindElement(
                _appraisersManagerParameterName
                );

            if (appraiserManagerElement is null)
            {
                var ex = new InvalidOperationException(
                    $"XML document hasn't value for {_appraisersManagerParameterName}."
                    );
                _logger.Error(ex, "Cannot build AppraisersManager.");
                throw ex;
            }

            var appraisersOutput = XDocumentParser.GetAttributeValue <bool>(
                appraiserManagerElement, _appraisersOutputParameterName
                );

            _appraisersManager = new Appraisers.AppraisersManagerAsync(appraisersOutput);

            foreach (var element in appraiserManagerElement.Elements())
            {
                Appraisers.AppraiserAsync crawler = _serviceBuilder.CreateAppraiser(element);
                _appraisersManager.Add(crawler);
            }
        }
Ejemplo n.º 4
0
        /// <inheritdoc />
        /// <exception cref="InvalidOperationException">
        /// XML configuration doesn't contain element for crawlers manager with specified name.
        /// </exception>
        public void BuildCrawlersManager()
        {
            XElement?crawlerManagerElement = _documentParser.FindElement(
                _crawlersManagerParameterName
                );

            if (crawlerManagerElement is null)
            {
                throw new InvalidOperationException(
                          $"XML document has not value for {_crawlersManagerParameterName}."
                          );
            }

            var crawlersOutput = XDocumentParser.GetAttributeValue <bool>(
                crawlerManagerElement, _crawlersOutputParameterName
                );

            _crawlersManager = new Crawlers.CrawlersManagerAsync(crawlersOutput);

            foreach (XElement element in crawlerManagerElement.Elements())
            {
                Crawlers.ICrawlerAsync crawler = _serviceBuilder.CreateCrawler(element);
                _crawlersManager.Add(crawler);
            }
        }
        /// <summary>
        /// Creates inputter (async) instance depend on parameter value (could be get from config).
        /// </summary>
        /// <param name="inputterElement">Element from XML config.</param>
        /// <returns>Fully initialized instance of inputter interface.</returns>
        /// <exception cref="ArgumentOutOfRangeException">
        /// <paramref name="inputterElement" /> isn't specified in config.
        /// </exception>
        /// <exception cref="ArgumentNullException">
        /// <paramref name="inputterElement" /> is <c>null</c>.
        /// </exception>
        public IO.Input.IInputterAsync CreateInputter(XElement inputterElement)
        {
            inputterElement.ThrowIfNull(nameof(inputterElement));

            _logger.Info("Creating intputter.");

            switch (inputterElement.Name.LocalName)
            {
            case _localFileParameterName:
            {
                string fileReaderName = XDocumentParser.GetAttributeValue(
                    inputterElement, _fileReaderParameterName + _localFileParameterName
                    );

                IO.Input.File.IFileReaderAsync fileReader =
                    CreateFileReaderAsync(fileReaderName);

                return(new IO.Input.File.LocalFileReaderAsync(fileReader));
            }

            case _googleDriveParameterName:
            {
                throw new NotImplementedException("Now GoogleDrive isn't supported.");
            }

            default:
            {
                throw new ArgumentOutOfRangeException(
                          nameof(inputterElement), inputterElement,
                          "Couldn't recognize input type specified in XML config."
                          );
            }
            }
        }
        /// <inheritdoc />
        /// <exception cref="InvalidOperationException">
        /// XML configuration doesn't contain element for output manager with specified name.
        /// </exception>
        public void BuildOutputManager()
        {
            XElement outputManagerElement = _documentParser.FindElement(
                _outputManagerParameterName
                );

            if (outputManagerElement is null)
            {
                var ex = new InvalidOperationException(
                    $"XML document hasn't value for {_outputManagerParameterName}."
                    );
                _logger.Error(ex, "Cannot build OutputManager.");
                throw ex;
            }

            string defaultStorageName = XDocumentParser.GetAttributeValue(
                outputManagerElement, _defaultOutStorageNameParameterName
                );

            _outputManager = new IO.Output.OutputManagerAsync(defaultStorageName);

            foreach (var element in outputManagerElement.Elements())
            {
                IO.Output.IOutputterAsync outputter = _serviceBuilder.CreateOutputter(element);
                _outputManager.Add(outputter);
            }
        }
Ejemplo n.º 7
0
        private static ToplistBlock ConvertXElementToBlock(XElement xmlBlock)
        {
            xmlBlock.ThrowIfNull(nameof(xmlBlock));

            string title  = XDocumentParser.GetAttributeValue(xmlBlock, nameof(ToplistBlock.Title));
            int    number = XDocumentParser.GetAttributeValue <int>(xmlBlock,
                                                                    nameof(ToplistBlock.Number));

            XElement?itemsXml = XDocumentParser.FindSubelement(xmlBlock,
                                                               nameof(ToplistBlock.Items));

            if (itemsXml is null)
            {
                throw new ArgumentException(
                          "Invalid strcuture of XML document: cannot find toplist items block.",
                          nameof(xmlBlock)
                          );
            }

            var result = new ToplistBlock(title, number);

            result.UpdateItems(
                XDocumentParser.FindSubelements(itemsXml)
                .Select(xmlItem => ConvertXElementToItem(xmlItem, result))
                .ToList()
                );

            return(result);
        }
Ejemplo n.º 8
0
        /// <inheritdoc />
        /// <exception cref="InvalidOperationException">
        /// XML configuration doesn't contain element for input manager with specified name.
        /// </exception>
        public void BuildInputManager()
        {
            XElement inputManagerElement = _documentParser.FindElement(_inputManagerParameterName);

            if (inputManagerElement is null)
            {
                var ex = new InvalidOperationException(
                    $"XML document hasn't value for {_inputManagerParameterName}."
                    );
                _logger.Error(ex, "Cannot build InputManager.");
                throw ex;
            }

            String defaultStorageName = XDocumentParser.GetAttributeValue(
                inputManagerElement, _defaultInStorageNameParameterName
                );

            _inputManager = new IO.Input.InputManager(defaultStorageName);

            foreach (var element in inputManagerElement.Elements())
            {
                IO.Input.IInputter inputter = _serviceBuilder.CreateInputter(element);
                _inputManager.Add(inputter);
            }
        }
Ejemplo n.º 9
0
        /// <inheritdoc />
        /// <exception cref="InvalidOperationException">
        /// XML configuration doesn't contain element for data base manager with specified name.
        /// </exception>
        public void BuildDataBaseManager()
        {
            XElement dataBaseManagerElement = _documentParser.FindElement(
                _dataBaseManagerParameterName
                );

            if (dataBaseManagerElement is null)
            {
                var ex = new InvalidOperationException(
                    $"XML document hasn't value for {_dataBaseManagerParameterName}."
                    );
                _logger.Error(ex, "Cannot build DataBaseManager.");
                throw ex;
            }

            string connectionString = XDocumentParser.GetAttributeValue(
                dataBaseManagerElement, _connectionStringParameterName
                );
            var dataBaseSettings = new DAL.DataStorageSettings(connectionString);

            _dataBaseManager = new DAL.DataBaseManager(
                new DAL.Repositories.ResultInfoRepository(dataBaseSettings),
                new DAL.Repositories.RatingRepository(dataBaseSettings)
                );

            foreach (var element in dataBaseManagerElement.Elements())
            {
                DAL.Repositories.IDataRepository repository = _serviceBuilder.CreateRepository(
                    element, dataBaseSettings
                    );
                _dataBaseManager.DataRepositoriesManager.Add(repository);
            }
        }
Ejemplo n.º 10
0
        /// <inheritdoc />
        /// <exception cref="InvalidOperationException">
        /// XML configuration doesn't contain element for crawlers manager with specified name.
        /// </exception>
        public void BuildCrawlersManager()
        {
            XElement crawlerManagerElement = _documentParser.FindElement(
                _crawlersManagerParameterName
                );

            if (crawlerManagerElement is null)
            {
                var ex = new InvalidOperationException(
                    $"XML document hasn't value for {_crawlersManagerParameterName}."
                    );
                _logger.Error(ex, "Cannot build CrawlersManager.");
                throw ex;
            }

            var crawlersOutput = XDocumentParser.GetAttributeValue <Boolean>(
                crawlerManagerElement, _crawlersOutputParameterName
                );

            _crawlersManager = new Crawlers.CrawlersManager(crawlersOutput);

            foreach (var element in crawlerManagerElement.Elements())
            {
                Crawlers.Crawler crawler = _serviceBuilder.CreateCrawler(element);
                _crawlersManager.Add(crawler);
            }
        }
Ejemplo n.º 11
0
        private static ToplistItem ConvertXElementToItem(XElement xmlItem, ToplistBlock parentBlock)
        {
            xmlItem.ThrowIfNull(nameof(xmlItem));

            string name           = XDocumentParser.GetAttributeValue(xmlItem, nameof(ToplistItem.Name));
            int    parsedPosition = XDocumentParser.GetAttributeValue <int>(
                xmlItem, nameof(ToplistItem.Position)
                );
            int?position = parsedPosition == -1 ? (int?)null : parsedPosition;

            return(new ToplistItem(name, position, parentBlock));
        }
        /// <summary>
        /// Creates crawler (async) instance depend on parameter value (could be get from config).
        /// </summary>
        /// <param name="crawlerElement">Element from XML config.</param>
        /// <returns>Fully initialized instance of crawler class.</returns>
        /// <exception cref="ArgumentOutOfRangeException">
        /// <paramref name="crawlerElement" /> isn't specified in config.
        /// </exception>
        /// <exception cref="ArgumentNullException">
        /// <paramref name="crawlerElement" /> is <c>null</c>.
        /// </exception>
        public Crawlers.CrawlerAsync CreateCrawler(XElement crawlerElement)
        {
            crawlerElement.ThrowIfNull(nameof(crawlerElement));

            switch (crawlerElement.Name.LocalName)
            {
            case _tmdbCrawlerParameterName:
            {
                string apiKey = XDocumentParser.GetAttributeValue(
                    crawlerElement, _tmdbApiKeyParameterName
                    );
                var maxRetryCount = XDocumentParser.GetAttributeValue <int>(
                    crawlerElement, _tmdbMaxRetryCountParameterName
                    );

                return(new Crawlers.TmdbCrawlerAsync(apiKey, maxRetryCount));
            }

            case _omdbCrawlerParameterName:
            {
                string apiKey = XDocumentParser.GetAttributeValue(
                    crawlerElement, _omdbApiKeyParameterName
                    );

                return(new Crawlers.OmdbCrawlerAsync(apiKey));
            }

            case _steamCrawlerParameterName:
            {
                string apiKey = XDocumentParser.GetAttributeValue(
                    crawlerElement, _steamApiKeyParameterName
                    );

                return(new Crawlers.SteamCrawlerAsync(apiKey));
            }

            default:
            {
                var ex = new ArgumentOutOfRangeException(
                    nameof(crawlerElement), crawlerElement,
                    "Couldn't recognize crawler type specified in XML config."
                    );
                _logger.Error(ex, "Passed incorrect data to method: " +
                              $"{crawlerElement.Name.LocalName}");
                throw ex;
            }
            }
        }
        /// <summary>
        /// Creates crawler (async) instance depend on parameter value (could be get from config).
        /// </summary>
        /// <param name="crawlerElement">Element from XML config.</param>
        /// <returns>Fully initialized instance of crawler class.</returns>
        /// <exception cref="ArgumentOutOfRangeException">
        /// <paramref name="crawlerElement" /> isn't specified in config.
        /// </exception>
        /// <exception cref="ArgumentNullException">
        /// <paramref name="crawlerElement" /> is <c>null</c>.
        /// </exception>
        public Crawlers.ICrawlerAsync CreateCrawler(XElement crawlerElement)
        {
            crawlerElement.ThrowIfNull(nameof(crawlerElement));

            _logger.Info("Creating crawler.");

            switch (crawlerElement.Name.LocalName)
            {
            case _tmdbCrawlerParameterName:
            {
                string apiKey = XDocumentParser.GetAttributeValue(
                    crawlerElement, _tmdbApiKeyParameterName
                    );
                var maxRetryCount = XDocumentParser.GetAttributeValue <int>(
                    crawlerElement, _tmdbMaxRetryCountParameterName
                    );

                return(new Crawlers.Movie.Tmdb.TmdbCrawlerAsync(apiKey, maxRetryCount));
            }

            case _omdbCrawlerParameterName:
            {
                string apiKey = XDocumentParser.GetAttributeValue(
                    crawlerElement, _omdbApiKeyParameterName
                    );

                return(new Crawlers.Movie.Omdb.OmdbCrawlerAsync(apiKey));
            }

            case _steamCrawlerParameterName:
            {
                string apiKey = XDocumentParser.GetAttributeValue(
                    crawlerElement, _steamApiKeyParameterName
                    );

                return(new Crawlers.Game.Steam.SteamCrawlerAsync(apiKey));
            }

            default:
            {
                throw new ArgumentOutOfRangeException(
                          nameof(crawlerElement), crawlerElement,
                          "Couldn't recognize crawler type specified in XML config."
                          );
            }
            }
        }
        /// <summary>
        /// Creates inputter (sequential) instance depend on parameter value (could be get from
        /// config).
        /// </summary>
        /// <param name="inputterElement">Element from XML config.</param>
        /// <returns>Fully initialized instance of inputter interface.</returns>
        /// <exception cref="ArgumentOutOfRangeException">
        /// <paramref name="inputterElement" /> isn't specified in config.
        /// </exception>
        /// <exception cref="ArgumentNullException">
        /// <paramref name="inputterElement" /> is <c>null</c>.
        /// </exception>
        public IO.Input.IInputter CreateInputter(XElement inputterElement)
        {
            inputterElement.ThrowIfNull(nameof(inputterElement));

            switch (inputterElement.Name.LocalName)
            {
            case _localFileParameterName:
            {
                string fileReaderName = XDocumentParser.GetAttributeValue(
                    inputterElement, _fileReaderParameterName + _localFileParameterName
                    );

                IO.Input.IFileReader fileReader = CreateFileReader(fileReaderName);

                return(new IO.Input.LocalFileReader(fileReader));
            }

            case _googleDriveParameterName:
            {
                string fileReaderName = XDocumentParser.GetAttributeValue(
                    inputterElement, _fileReaderParameterName + _googleDriveParameterName
                    );

                IO.Input.IFileReader fileReader = CreateFileReader(fileReaderName);

                return(new IO.Input.GoogleDriveReader(_driveService, fileReader));
            }

            default:
            {
                var ex = new ArgumentOutOfRangeException(
                    nameof(inputterElement), inputterElement,
                    "Couldn't recognize input type specified in XML config."
                    );
                _logger.Error(ex, "Passed incorrect data to method: " +
                              $"{inputterElement.Name.LocalName}");
                throw ex;
            }
            }
        }
Ejemplo n.º 15
0
        /// <inheritdoc />
        /// <exception cref="InvalidOperationException">
        /// XML configuration doesn't contain element for input manager with specified name.
        /// </exception>
        public void BuildInputManager()
        {
            XElement?inputManagerElement = _documentParser.FindElement(_inputManagerParameterName);

            if (inputManagerElement is null)
            {
                throw new InvalidOperationException(
                          $"XML document has not value for {_inputManagerParameterName}."
                          );
            }

            string defaultStorageName = XDocumentParser.GetAttributeValue(
                inputManagerElement, _defaultInStorageNameParameterName
                );

            _inputManager = new IO.Input.InputManagerAsync(defaultStorageName);

            foreach (XElement element in inputManagerElement.Elements())
            {
                IO.Input.IInputterAsync inputter = _serviceBuilder.CreateInputter(element);
                _inputManager.Add(inputter);
            }
        }