/* * Copyright (c) 2016 Samsung Electronics Co., Ltd All Rights Reserved * * Licensed under the Apache License, Version 2.0 (the License); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an AS IS BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ using System; namespace Tizen.Content.MediaContent { /// /// Provides commands to manage albums in the database. /// /// /// 4 public class AlbumCommand : MediaCommand { /// /// Initializes a new instance of the class with the specified . /// /// The that the commands run on. /// is null. /// has already been disposed of. /// 4 public AlbumCommand(MediaDatabase database) : base(database) { } /// /// Retrieves the number of albums. /// /// The number of albums. /// The is disconnected. /// The has already been disposed of. /// An error occurred while executing the command. /// 4 public int Count() { return Count(null); } /// /// Retrieves the number of albums with . /// /// The criteria to use to filter. This value can be null. /// The number of albums. /// The is disconnected. /// The has already been disposed of. /// An error occurred while executing the command. /// 4 public int Count(CountArguments arguments) { ValidateDatabase(); return CommandHelper.Count(Interop.Album.GetAlbumCountFromDb, arguments); } /// /// Retrieves all the albums. /// /// The containing the results. /// The is disconnected. /// The has already been disposed of. /// An error occurred while executing the command. /// 4 public MediaDataReader Select() { return Select(null); } /// /// Retrieves the albums with . /// /// The criteria to use to filter. This value can be null. /// The containing the results. /// The is disconnected. /// The has already been disposed of. /// An error occurred while executing the command. /// 4 public MediaDataReader Select(SelectArguments filter) { ValidateDatabase(); return CommandHelper.Select(filter, Interop.Album.ForeachAlbumFromDb, Album.FromHandle); } /// /// Retrieves an album with the album ID. /// /// The ID of the album to query with. /// The if exists, otherwise null. /// The is disconnected. /// The has already been disposed of. /// is equal to or less than zero. /// An error occurred while executing the command. /// 4 public Album Select(int albumId) { ValidateDatabase(); if (albumId <= 0) { throw new ArgumentOutOfRangeException(nameof(albumId), albumId, "The album id can't be equal to or less than zero."); } IntPtr handle = IntPtr.Zero; try { Interop.Album.GetAlbumFromDb(albumId, out handle).ThrowIfError("Failed to query"); return handle == IntPtr.Zero ? null : new Album(handle); } finally { Interop.Album.Destroy(handle); } } /// /// Retrieves the number of media information that belongs to the album. /// /// The ID of the album to query with. /// The number of media information. /// The is disconnected. /// The has already been disposed of. /// is equal to or less than zero. /// An error occurred while executing the command. /// 4 public int CountMember(int albumId) { return CountMember(albumId, null); } /// /// Retrieves the number of media information that belongs to the album with . /// /// The ID of the album to count media. /// The criteria to use to filter. This value can be null. /// The number of media information. /// The is disconnected. /// The has already been disposed of. /// is equal to or less than zero. /// An error occurred while executing the command. /// 4 public int CountMember(int albumId, CountArguments arguments) { ValidateDatabase(); if (albumId <= 0) { throw new ArgumentOutOfRangeException(nameof(albumId), albumId, "The album id can't be equal to or less than zero."); } return CommandHelper.Count(Interop.Album.GetMediaCountFromDb, albumId, arguments); } /// /// Retrieves the media information of the album. /// /// The ID of the album to select media. /// The containing the results. /// The is disconnected. /// The has already been disposed of. /// An error occurred while executing the command. /// 4 public MediaDataReader SelectMember(int albumId) { return SelectMember(albumId, null); } /// /// Retrieves the media information of the album with . /// /// The ID of the album to query with. /// The criteria to use to filter. This value can be null. /// The containing the results. /// The is disconnected. /// The has already been disposed of. /// An error occurred while executing the command. /// 4 public MediaDataReader SelectMember(int albumId, SelectArguments filter) { ValidateDatabase(); if (albumId <= 0) { throw new ArgumentOutOfRangeException(nameof(albumId), albumId, "The album id can't be equal to or less than zero."); } return CommandHelper.SelectMedia(Interop.Album.ForeachMediaFromDb, albumId, filter); } } }