2 * Copyright (c) 2016 Samsung Electronics Co., Ltd All Rights Reserved
4 * Licensed under the Apache License, Version 2.0 (the License);
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an AS IS BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
19 namespace Tizen.Content.MediaContent
22 /// Provides commands to manage albums in the database.
24 /// <seealso cref="Album"/>
25 public class AlbumCommand : MediaCommand
28 /// Initializes a new instance of the <see cref="AlbumCommand"/> class with the specified <see cref="MediaDatabase"/>.
30 /// <param name="database">The <see cref="MediaDatabase"/> that the commands run on.</param>
31 /// <exception cref="ArgumentNullException"><paramref name="database"/> is null.</exception>
32 /// <exception cref="ObjectDisposedException"><paramref name="database"/> has already been disposed of.</exception>
33 public AlbumCommand(MediaDatabase database) : base(database)
38 /// Retrieves the number of albums.
40 /// <returns>The number of albums.</returns>
41 /// <exception cref="InvalidOperationException">The <see cref="MediaDatabase"/> is disconnected.</exception>
42 /// <exception cref="ObjectDisposedException">The <see cref="MediaDatabase"/> has already been disposed of.</exception>
43 /// <exception cref="MediaDatabaseException">An error occurred while executing the command.</exception>
50 /// Retrieves the number of albums with <see cref="CountArguments"/>.
52 /// <param name="arguments">The criteria to use to filter. This value can be null.</param>
53 /// <returns>The number of albums.</returns>
54 /// <exception cref="InvalidOperationException">The <see cref="MediaDatabase"/> is disconnected.</exception>
55 /// <exception cref="ObjectDisposedException">The <see cref="MediaDatabase"/> has already been disposed of.</exception>
56 /// <exception cref="MediaDatabaseException">An error occurred while executing the command.</exception>
57 public int Count(CountArguments arguments)
61 return CommandHelper.Count(Interop.Album.GetAlbumCountFromDb, arguments);
65 /// Retrieves all the albums.
67 /// <returns>The <see cref="MediaDataReader{TRecord}"/> containing the results.</returns>
68 /// <exception cref="InvalidOperationException">The <see cref="MediaDatabase"/> is disconnected.</exception>
69 /// <exception cref="ObjectDisposedException">The <see cref="MediaDatabase"/> has already been disposed of.</exception>
70 /// <exception cref="MediaDatabaseException">An error occurred while executing the command.</exception>
71 public MediaDataReader<Album> Select()
77 /// Retrieves the albums with <see cref="SelectArguments"/>.
79 /// <param name="filter">The criteria to use to filter. This value can be null.</param>
80 /// <returns>The <see cref="MediaDataReader{TRecord}"/> containing the results.</returns>
81 /// <exception cref="InvalidOperationException">The <see cref="MediaDatabase"/> is disconnected.</exception>
82 /// <exception cref="ObjectDisposedException">The <see cref="MediaDatabase"/> has already been disposed of.</exception>
83 /// <exception cref="MediaDatabaseException">An error occurred while executing the command.</exception>
84 public MediaDataReader<Album> Select(SelectArguments filter)
88 return CommandHelper.Select(filter, Interop.Album.ForeachAlbumFromDb, Album.FromHandle);
92 /// Retrieves an album with the album ID.
94 /// <param name="albumId">The ID of the album to query with.</param>
95 /// <returns>The <see cref="Album"/> if <paramref name="albumId"/> exists, otherwise null.</returns>
96 /// <exception cref="InvalidOperationException">The <see cref="MediaDatabase"/> is disconnected.</exception>
97 /// <exception cref="ObjectDisposedException">The <see cref="MediaDatabase"/> has already been disposed of.</exception>
98 /// <exception cref="ArgumentOutOfRangeException"><paramref name="albumId"/> is equal to or less than zero.</exception>
99 /// <exception cref="MediaDatabaseException">An error occurred while executing the command.</exception>
100 public Album Select(int albumId)
106 throw new ArgumentOutOfRangeException(nameof(albumId), albumId,
107 "The album id can't be equal to or less than zero.");
110 IntPtr handle = IntPtr.Zero;
113 Interop.Album.GetAlbumFromDb(albumId, out handle).ThrowIfError("Failed to query");
115 return handle == IntPtr.Zero ? null : new Album(handle);
119 Interop.Album.Destroy(handle);
124 /// Retrieves the number of media information that belongs to the album.
126 /// <param name="albumId">The ID of the album to query with.</param>
127 /// <returns>The number of media information.</returns>
128 /// <exception cref="InvalidOperationException">The <see cref="MediaDatabase"/> is disconnected.</exception>
129 /// <exception cref="ObjectDisposedException">The <see cref="MediaDatabase"/> has already been disposed of.</exception>
130 /// <exception cref="ArgumentOutOfRangeException"><paramref name="albumId"/> is equal to or less than zero.</exception>
131 /// <exception cref="MediaDatabaseException">An error occurred while executing the command.</exception>
132 public int CountMember(int albumId)
134 return CountMember(albumId, null);
138 /// Retrieves the number of media information that belongs to the album with <see cref="CountArguments"/>.
140 /// <param name="albumId">The ID of the album to count media.</param>
141 /// <param name="arguments">The criteria to use to filter. This value can be null.</param>
142 /// <returns>The number of media information.</returns>
143 /// <exception cref="InvalidOperationException">The <see cref="MediaDatabase"/> is disconnected.</exception>
144 /// <exception cref="ObjectDisposedException">The <see cref="MediaDatabase"/> has already been disposed of.</exception>
145 /// <exception cref="ArgumentOutOfRangeException"><paramref name="albumId"/> is equal to or less than zero.</exception>
146 /// <exception cref="MediaDatabaseException">An error occurred while executing the command.</exception>
147 public int CountMember(int albumId, CountArguments arguments)
153 throw new ArgumentOutOfRangeException(nameof(albumId), albumId,
154 "The album id can't be equal to or less than zero.");
157 return CommandHelper.Count(Interop.Album.GetMediaCountFromDb, albumId, arguments);
161 /// Retrieves the media information of the album.
163 /// <param name="albumId">The ID of the album to select media.</param>
164 /// <returns>The <see cref="MediaDataReader{TRecord}"/> containing the results.</returns>
165 /// <exception cref="InvalidOperationException">The <see cref="MediaDatabase"/> is disconnected.</exception>
166 /// <exception cref="ObjectDisposedException">The <see cref="MediaDatabase"/> has already been disposed of.</exception>
167 /// <exception cref="MediaDatabaseException">An error occurred while executing the command.</exception>
168 public MediaDataReader<MediaInfo> SelectMember(int albumId)
170 return SelectMember(albumId, null);
174 /// Retrieves the media information of the album with <see cref="SelectArguments"/>.
176 /// <param name="albumId">The ID of the album to query with.</param>
177 /// <param name="filter">The criteria to use to filter. This value can be null.</param>
178 /// <returns>The <see cref="MediaDataReader{TRecord}"/> containing the results.</returns>
179 /// <exception cref="InvalidOperationException">The <see cref="MediaDatabase"/> is disconnected.</exception>
180 /// <exception cref="ObjectDisposedException">The <see cref="MediaDatabase"/> has already been disposed of.</exception>
181 /// <exception cref="MediaDatabaseException">An error occurred while executing the command.</exception>
182 public MediaDataReader<MediaInfo> SelectMember(int albumId, SelectArguments filter)
188 throw new ArgumentOutOfRangeException(nameof(albumId), albumId,
189 "The album id can't be equal to or less than zero.");
192 return CommandHelper.SelectMedia(Interop.Album.ForeachMediaFromDb, albumId, filter);