/// <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) { throw new InvalidOperationException( $"XML document has not value for {_dataBaseManagerParameterName}." ); } var dataBaseOptions = Configuration.ConfigOptions.GetOptions <DAL.DataBaseOptions>(); _dataBaseManager = new DAL.DataBaseManager( new DAL.Repositories.ResultInfoRepository(dataBaseOptions), new DAL.Repositories.RatingRepository(dataBaseOptions) ); foreach (XElement element in dataBaseManagerElement.Elements()) { DAL.Repositories.IDataRepository repository = _serviceBuilder.CreateRepository( element, dataBaseOptions ); _dataBaseManager.DataRepositoriesManager.Add(repository); } }
/// <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); } }