/// <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); } }
/// <summary> /// Creates repository (sequential) instance depend on parameter value (could be get from /// config). /// </summary> /// <param name="repositoryElement">Element from XML config.</param> /// <param name="storageSettings"> /// Storage settings for repositrory (at least contain connection string). /// </param> /// <returns>Fully initialized instance of repository interface.</returns> /// <exception cref="ArgumentOutOfRangeException"> /// <paramref name="repositoryElement" /> isn't specified in config. /// </exception> /// <exception cref="ArgumentNullException"> /// <paramref name="repositoryElement" /> or <paramref name="storageSettings" /> is /// <c>null</c>. /// </exception> public DAL.Repositories.IDataRepository CreateRepository(XElement repositoryElement, DAL.DataStorageSettings storageSettings) { repositoryElement.ThrowIfNull(nameof(repositoryElement)); storageSettings.ThrowIfNull(nameof(storageSettings)); switch (repositoryElement.Name.LocalName) { case _basicInfoRepositoryParameterName: { return(new DAL.Repositories.BasicInfoRepository(storageSettings)); } case _tmdbMovieRepositoryParameterName: { return(new DAL.Repositories.TmdbMovieRepository(storageSettings)); } default: { var ex = new ArgumentOutOfRangeException( nameof(repositoryElement), repositoryElement, "Couldn't recognize output type specified in XML config." ); _logger.Error(ex, "Passed incorrect data to method: " + $"{repositoryElement.Name.LocalName}"); throw ex; } } }