/// <summary> /// Initializes a new instance of the <see cref="SqliteItemRepository"/> class. /// </summary> /// <param name="appPaths">The app paths.</param> /// <param name="jsonSerializer">The json serializer.</param> /// <param name="logManager">The log manager.</param> /// <exception cref="System.ArgumentNullException"> /// appPaths /// or /// jsonSerializer /// </exception> public SqliteItemRepository(IApplicationPaths appPaths, IJsonSerializer jsonSerializer, ILogManager logManager) { if (appPaths == null) { throw new ArgumentNullException("appPaths"); } if (jsonSerializer == null) { throw new ArgumentNullException("jsonSerializer"); } _appPaths = appPaths; _jsonSerializer = jsonSerializer; _criticReviewsPath = Path.Combine(_appPaths.DataPath, "critic-reviews"); _logger = logManager.GetLogger(GetType().Name); var chapterDbFile = Path.Combine(_appPaths.DataPath, "chapters.db"); var chapterConnection = SqliteExtensions.ConnectToDb(chapterDbFile, _logger).Result; _chapterRepository = new SqliteChapterRepository(chapterConnection, logManager); var mediaStreamsDbFile = Path.Combine(_appPaths.DataPath, "mediainfo.db"); var mediaStreamsConnection = SqliteExtensions.ConnectToDb(mediaStreamsDbFile, _logger).Result; _mediaStreamsRepository = new SqliteMediaStreamsRepository(mediaStreamsConnection, logManager); var providerInfosDbFile = Path.Combine(_appPaths.DataPath, "providerinfo.db"); var providerInfoConnection = SqliteExtensions.ConnectToDb(providerInfosDbFile, _logger).Result; _providerInfoRepository = new SqliteProviderInfoRepository(providerInfoConnection, logManager); }
/// <summary> /// Releases unmanaged and - optionally - managed resources. /// </summary> /// <param name="dispose"><c>true</c> to release both managed and unmanaged resources; <c>false</c> to release only unmanaged resources.</param> protected virtual void Dispose(bool dispose) { if (dispose) { try { lock (_disposeLock) { if (_shrinkMemoryTimer != null) { _shrinkMemoryTimer.Dispose(); _shrinkMemoryTimer = null; } if (_connection != null) { if (_connection.IsOpen()) { _connection.Close(); } _connection.Dispose(); _connection = null; } if (_chapterRepository != null) { _chapterRepository.Dispose(); _chapterRepository = null; } if (_mediaStreamsRepository != null) { _mediaStreamsRepository.Dispose(); _mediaStreamsRepository = null; } if (_providerInfoRepository != null) { _providerInfoRepository.Dispose(); _providerInfoRepository = null; } } } catch (Exception ex) { _logger.ErrorException("Error disposing database", ex); } } }