コード例 #1
0
        public long CreateLibrary(CreateLibraryDto library, string guid = null)
        {
            if (guid == null)
            {
                guid = UniqueIdUtil.GenerateUniqueId();
            }

            using (var db = DataAccessUtil.CreateSqlConnection()) {
                db.Open();
                long createdLibraryId = -1;

                using (var txn = db.BeginTransaction()) {
                    var command = new SqliteCommand();
                    command.Connection  = db;
                    command.CommandText = "INSERT INTO library VALUES(NULL, @Name, @BackgroundId, false, @UniqueId)";
                    command.Parameters.AddWithValue("@Name", library.Name);
                    command.Parameters.AddWithValue("@BackgroundId", QueryUtil.GetNullableIdForStorage(library.BackgroundImageId));
                    command.Parameters.AddWithValue("@UniqueId", guid);
                    command.Transaction = txn;
                    command.ExecuteNonQuery();
                    createdLibraryId = QueryUtil.GetLastInsertedPrimaryKey(db, txn);

                    foreach (var setting in LibrarySettings.DEFAULT_SETTINGS)
                    {
                        var createSettingsCommand = new SqliteCommand($"INSERT INTO library_setting VALUES({createdLibraryId}, '{setting.Key}', '{setting.Value}')", db, txn);
                        createSettingsCommand.ExecuteNonQuery();
                    }

                    txn.Commit();
                }

                return(createdLibraryId);
            }
        }
コード例 #2
0
        private long UpsertLibrary(ExportedLibraryDto dto)
        {
            var fileId     = mediaFileRepository.GetMediaFileLongId_FromGUID(dto.CoverFileId);
            var libraryDto = new CreateLibraryDto(dto.Name, fileId);

            return(libraryRepository.UpsertLibrary(libraryDto, dto.UniqueId, dto.Settings));
        }
コード例 #3
0
        private Library CreateAndRetrieveLibrary(string libraryName)
        {
            CreateLibraryDto libraryToCreate = new CreateLibraryDto(libraryName);
            var libraryId = repository.CreateLibrary(libraryToCreate);

            return(repository.GetLibrary(libraryId));
        }
コード例 #4
0
        public void TestCreateLibrarySettings()
        {
            CreateLibraryDto libraryToCreate = new CreateLibraryDto("Test library");
            var libraryId = repository.CreateLibrary(libraryToCreate);

            var settings = repository.GetLibrarySettings(libraryId);

            Assert.AreEqual(LibrarySettings.DEFAULT_PUBLISHER_LABEL, settings.PublisherLabel);
            Assert.AreEqual(LibrarySettings.DEFAULT_SERIES_LABEL, settings.SeriesLabel);
            Assert.AreEqual(LibrarySettings.DEFAULT_CHARACTER_LABEL, settings.CharacterLabel);
            Assert.AreEqual(LibrarySettings.DEFAULT_VIDEO_LABEL, settings.VideoLabel);
        }
コード例 #5
0
        public void TestCreateLibrary()
        {
            CreateLibraryDto libraryToCreate = new CreateLibraryDto("Test library");
            var libraryId = repository.CreateLibrary(libraryToCreate);

            var libraryRetrieved = repository.GetLibrary(libraryId);

            Assert.IsTrue(libraryRetrieved.LibraryId > -1);
            Assert.AreEqual(libraryToCreate.Name, libraryRetrieved.Name);
            Assert.IsTrue(DoSettingsForLibraryExist(libraryRetrieved.LibraryId));
            Assert.IsNotNull(libraryRetrieved.UniqueId);
        }
コード例 #6
0
        public long UpsertLibrary(CreateLibraryDto dto, string uniqueId, LibrarySettings settings)
        {
            var libraryId = GetLibraryIdFromGUID(uniqueId);

            if (libraryId == DatabaseConstants.DEFAULT_ID)
            {
                libraryId = CreateLibrary(dto, uniqueId);
            }
            else
            {
                var library = new Library(libraryId, dto.Name, dto.BackgroundImageId, false, uniqueId);
                UpdateLibrary(library);
            }

            if (settings != null)
            {
                UpdateLibrarySettings(libraryId, settings);
            }

            return(libraryId);
        }
コード例 #7
0
        public async Task <ActionResult> AddLibrary(CreateLibraryDto createLibraryDto)
        {
            if (await _unitOfWork.LibraryRepository.LibraryExists(createLibraryDto.Name))
            {
                return(BadRequest("Library name already exists. Please choose a unique name to the server."));
            }

            var library = new Library
            {
                Name    = createLibraryDto.Name,
                Type    = createLibraryDto.Type,
                Folders = createLibraryDto.Folders.Select(x => new FolderPath {
                    Path = x
                }).ToList()
            };

            _unitOfWork.LibraryRepository.Add(library);

            var admins = (await _unitOfWork.UserRepository.GetAdminUsersAsync()).ToList();

            foreach (var admin in admins)
            {
                admin.Libraries ??= new List <Library>();
                admin.Libraries.Add(library);
            }


            if (!await _unitOfWork.Complete())
            {
                return(BadRequest("There was a critical issue. Please try again."));
            }

            _logger.LogInformation("Created a new library: {LibraryName}", library.Name);
            _taskScheduler.ScanLibrary(library.Id);
            return(Ok());
        }
コード例 #8
0
        public void TestUpdateLibrarySettings()
        {
            CreateLibraryDto libraryToCreate = new CreateLibraryDto("Test library");
            var libraryId = repository.CreateLibrary(libraryToCreate);
            var settings  = repository.GetLibrarySettings(libraryId);

            var newPublisherLabel = "modified_publisher";
            var newSeriesLabel    = "modified_series";
            var newVideoLabel     = "modified_video";
            var newCharacterLabel = "modified_character";

            settings.PublisherLabel = newPublisherLabel;
            settings.SeriesLabel    = newSeriesLabel;
            settings.VideoLabel     = newVideoLabel;
            settings.CharacterLabel = newCharacterLabel;

            repository.UpdateLibrarySettings(libraryId, settings);
            settings = repository.GetLibrarySettings(libraryId);

            Assert.AreEqual(newPublisherLabel, settings.PublisherLabel);
            Assert.AreEqual(newSeriesLabel, settings.SeriesLabel);
            Assert.AreEqual(newCharacterLabel, settings.CharacterLabel);
            Assert.AreEqual(newVideoLabel, settings.VideoLabel);
        }
コード例 #9
0
        private Library CreateAndRetrieveLibrary(CreateLibraryDto libraryDto)
        {
            long libraryId = libraryRepository.CreateLibrary(libraryDto);

            return(new Library(libraryId, libraryDto));
        }