/// <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); } }
/// <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); } }
internal static void Main() { Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); Application.ThreadException += GlobalExceptionHandler; Application.SetUnhandledExceptionMode(UnhandledExceptionMode.CatchException); AppDomain.CurrentDomain.UnhandledException += GlobalExceptionHandler; IXDocumentParser xDocParser = new XDocumentParser(); IWordBank <Question> wordBank = new XmlWordBank(xDocParser); wordBank.InitialiseWordBank(Repository.Properties.Resources.wordsDefault); var speechSynthesizer = new SpeechSynthesizer { Volume = 100, Rate = -3, }; speechSynthesizer.SelectVoiceByHints(VoiceGender.Male); Application.Run(new Main(wordBank, speechSynthesizer)); }
/// <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); } }
/// <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); } }
public void Init() { _xmlString = Properties.Resources.words_testFile; _xDocumentParser = new XDocumentParser(); _sut = new XmlWordBank(_xDocumentParser); }
/// <summary> /// Creates message (sequential) handler instance depend on parameter value (could be get /// from config). /// </summary> /// <param name="messageHandlerElement">Element from XML config.</param> /// <returns>Fully initialized instance of message handler class.</returns> /// <exception cref="ArgumentOutOfRangeException"> /// <paramref name="messageHandlerElement" /> isn't specified in XML config. /// </exception> /// <exception cref="ArgumentNullException"> /// <paramref name="messageHandlerElement" /> or its attribute with handler name is /// <c>null</c>. /// </exception> public Communication.IMessageHandler CreateMessageHandler(XElement messageHandlerElement) { messageHandlerElement.ThrowIfNull(nameof(messageHandlerElement)); var handlerElement = messageHandlerElement.Attribute(_messageHandlerTypeParameterName); handlerElement.ThrowIfNull(nameof(handlerElement)); switch (handlerElement.Value) { case _consoleMessageHandlerParameterName: { var messageHandlerParametersElement = XDocumentParser.FindSubelement( messageHandlerElement, _setUnicodeParameterName ); var setUnicode = XDocumentParser.GetElementValue <bool>( messageHandlerParametersElement ); return(new Communication.ConsoleMessageHandler(setUnicode)); } default: { var ex = new ArgumentOutOfRangeException( nameof(messageHandlerElement), messageHandlerElement, "Couldn't recognize message handler type specified in XML config." ); _logger.Error(ex, "Passed incorrect data to method: " + $"{handlerElement.Value}"); throw ex; } } }
/// <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); } }
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); }
/// <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); } }
/// <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); } }
/// <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 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); } }
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)); }
internal IReadOnlyList <ToplistBlock> ConvertXElementsToBlocks() { IReadOnlyList <XElement> xmlBlocks = XDocumentParser.FindSubelements(Blocks).ToList(); var blocks = new List <ToplistBlock>(xmlBlocks.Count); foreach (XElement xmlBlock in xmlBlocks) { blocks.Add(ConvertXElementToBlock(xmlBlock)); } return(blocks); }
/// <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 message (sequential) handler instance depend on parameter value (could be get /// from config). /// </summary> /// <param name="messageHandlerElement">Element from XML config.</param> /// <returns>Fully initialized instance of message handler class.</returns> /// <exception cref="ArgumentOutOfRangeException"> /// <paramref name="messageHandlerElement" /> isn't specified in XML config. /// </exception> /// <exception cref="ArgumentNullException"> /// <paramref name="messageHandlerElement" /> or its attribute with handler name is /// <c>null</c>. /// </exception> public Communication.IMessageHandler CreateMessageHandler(XElement messageHandlerElement) { messageHandlerElement.ThrowIfNull(nameof(messageHandlerElement)); _logger.Info("Creating message handler."); var handlerElement = messageHandlerElement.Attribute(_messageHandlerTypeParameterName); handlerElement.ThrowIfNull(nameof(handlerElement)); switch (handlerElement.Value) { case _consoleMessageHandlerParameterName: { XElement?messageHandlerParametersElement = XDocumentParser.FindSubelement( messageHandlerElement, _setUnicodeParameterName ); if (messageHandlerParametersElement is null) { throw new ArgumentException( "Invalid structure of XML document: cannot find message handler " + "parameters block.", nameof(messageHandlerElement) ); } var setUnicode = XDocumentParser.GetElementValue <bool>( messageHandlerParametersElement ); return(new Communication.ConsoleMessageHandler(setUnicode)); } default: { throw new ArgumentOutOfRangeException( nameof(messageHandlerElement), messageHandlerElement, "Couldn't recognize message handler 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; } } }
/// <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); } }
/// <summary> /// Initializes builder instance and associates <see cref="XDocumentParser" /> which /// provides deferred parsing of XML configuration. /// </summary> /// <param name="configuration">XML configuration of <see cref="Shell" /> class.</param> public ShellBuilderFromXDocument(XDocument configuration) { _documentParser = new XDocumentParser( new XDocument(configuration.Root.Element(_rootElementName)) ); }
public void TearDown() { _xmlString = null; _xDocumentParser = null; _sut = null; }