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 /// <since_tizen> 4 </since_tizen>
26 public class AlbumCommand : MediaCommand
29 /// Initializes a new instance of the <see cref="AlbumCommand"/> class with the specified <see cref="MediaDatabase"/>.
31 /// <param name="database">The <see cref="MediaDatabase"/> that the commands run on.</param>
32 /// <exception cref="ArgumentNullException"><paramref name="database"/> is null.</exception>
33 /// <exception cref="ObjectDisposedException"><paramref name="database"/> has already been disposed.</exception>
34 /// <since_tizen> 4 </since_tizen>
35 public AlbumCommand(MediaDatabase database) : base(database)
40 /// Retrieves the number of albums.
42 /// <returns>The number of albums.</returns>
43 /// <exception cref="InvalidOperationException">The <see cref="MediaDatabase"/> is disconnected.</exception>
44 /// <exception cref="ObjectDisposedException">The <see cref="MediaDatabase"/> has already been disposed.</exception>
45 /// <exception cref="MediaDatabaseException">An error occurred while executing the command.</exception>
46 /// <since_tizen> 4 </since_tizen>
53 /// Retrieves the number of albums with <see cref="CountArguments"/>.
55 /// <param name="arguments">The criteria to use to filter. This value can be null.</param>
56 /// <returns>The number of albums.</returns>
57 /// <exception cref="InvalidOperationException">The <see cref="MediaDatabase"/> is disconnected.</exception>
58 /// <exception cref="ObjectDisposedException">The <see cref="MediaDatabase"/> has already been disposed.</exception>
59 /// <exception cref="MediaDatabaseException">An error occurred while executing the command.</exception>
60 /// <since_tizen> 4 </since_tizen>
61 public int Count(CountArguments arguments)
65 return CommandHelper.Count(Interop.Album.GetAlbumCountFromDb, arguments);
69 /// Retrieves all the albums.
71 /// <returns>The <see cref="MediaDataReader{TRecord}"/> containing the results.</returns>
72 /// <exception cref="InvalidOperationException">The <see cref="MediaDatabase"/> is disconnected.</exception>
73 /// <exception cref="ObjectDisposedException">The <see cref="MediaDatabase"/> has already been disposed.</exception>
74 /// <exception cref="MediaDatabaseException">An error occurred while executing the command.</exception>
75 /// <since_tizen> 4 </since_tizen>
76 public MediaDataReader<Album> Select()
82 /// Retrieves the albums with <see cref="SelectArguments"/>.
84 /// <param name="filter">The criteria to use to filter. This value can be null.</param>
85 /// <returns>The <see cref="MediaDataReader{TRecord}"/> containing the results.</returns>
86 /// <exception cref="InvalidOperationException">The <see cref="MediaDatabase"/> is disconnected.</exception>
87 /// <exception cref="ObjectDisposedException">The <see cref="MediaDatabase"/> has already been disposed.</exception>
88 /// <exception cref="MediaDatabaseException">An error occurred while executing the command.</exception>
89 /// <since_tizen> 4 </since_tizen>
90 public MediaDataReader<Album> Select(SelectArguments filter)
94 return CommandHelper.Select(filter, Interop.Album.ForeachAlbumFromDb, Album.FromHandle);
98 /// Retrieves an album with the album ID.
100 /// <param name="albumId">The ID of the album to query with.</param>
101 /// <returns>The <see cref="Album"/> if <paramref name="albumId"/> exists, otherwise null.</returns>
102 /// <exception cref="InvalidOperationException">The <see cref="MediaDatabase"/> is disconnected.</exception>
103 /// <exception cref="ObjectDisposedException">The <see cref="MediaDatabase"/> has already been disposed.</exception>
104 /// <exception cref="ArgumentOutOfRangeException"><paramref name="albumId"/> is equal to or less than zero.</exception>
105 /// <exception cref="MediaDatabaseException">An error occurred while executing the command.</exception>
106 /// <since_tizen> 4 </since_tizen>
107 public Album Select(int albumId)
113 throw new ArgumentOutOfRangeException(nameof(albumId), albumId,
114 "The album id can't be equal to or less than zero.");
117 IntPtr handle = IntPtr.Zero;
120 Interop.Album.GetAlbumFromDb(albumId, out handle).ThrowIfError("Failed to query");
122 return handle == IntPtr.Zero ? null : new Album(handle);
126 Interop.Album.Destroy(handle);
131 /// Retrieves the number of media information that belongs to the album.
133 /// <param name="albumId">The ID of the album to query with.</param>
134 /// <returns>The number of media information.</returns>
135 /// <exception cref="InvalidOperationException">The <see cref="MediaDatabase"/> is disconnected.</exception>
136 /// <exception cref="ObjectDisposedException">The <see cref="MediaDatabase"/> has already been disposed.</exception>
137 /// <exception cref="ArgumentOutOfRangeException"><paramref name="albumId"/> is equal to or less than zero.</exception>
138 /// <exception cref="MediaDatabaseException">An error occurred while executing the command.</exception>
139 /// <since_tizen> 4 </since_tizen>
140 public int CountMember(int albumId)
142 return CountMember(albumId, null);
146 /// Retrieves the number of media information that belongs to the album with <see cref="CountArguments"/>.
148 /// <param name="albumId">The ID of the album to count media.</param>
149 /// <param name="arguments">The criteria to use to filter. This value can be null.</param>
150 /// <returns>The number of media information.</returns>
151 /// <exception cref="InvalidOperationException">The <see cref="MediaDatabase"/> is disconnected.</exception>
152 /// <exception cref="ObjectDisposedException">The <see cref="MediaDatabase"/> has already been disposed.</exception>
153 /// <exception cref="ArgumentOutOfRangeException"><paramref name="albumId"/> is equal to or less than zero.</exception>
154 /// <exception cref="MediaDatabaseException">An error occurred while executing the command.</exception>
155 /// <since_tizen> 4 </since_tizen>
156 public int CountMember(int albumId, CountArguments arguments)
162 throw new ArgumentOutOfRangeException(nameof(albumId), albumId,
163 "The album id can't be equal to or less than zero.");
166 return CommandHelper.Count(Interop.Album.GetMediaCountFromDb, albumId, arguments);
170 /// Retrieves the media information of the album.
172 /// <param name="albumId">The ID of the album to select media.</param>
173 /// <returns>The <see cref="MediaDataReader{TRecord}"/> containing the results.</returns>
174 /// <exception cref="InvalidOperationException">The <see cref="MediaDatabase"/> is disconnected.</exception>
175 /// <exception cref="ObjectDisposedException">The <see cref="MediaDatabase"/> has already been disposed.</exception>
176 /// <exception cref="MediaDatabaseException">An error occurred while executing the command.</exception>
177 /// <since_tizen> 4 </since_tizen>
178 public MediaDataReader<MediaInfo> SelectMember(int albumId)
180 return SelectMember(albumId, null);
184 /// Retrieves the media information of the album with <see cref="SelectArguments"/>.
186 /// <param name="albumId">The ID of the album to query with.</param>
187 /// <param name="filter">The criteria to use to filter. This value can be null.</param>
188 /// <returns>The <see cref="MediaDataReader{TRecord}"/> containing the results.</returns>
189 /// <exception cref="InvalidOperationException">The <see cref="MediaDatabase"/> is disconnected.</exception>
190 /// <exception cref="ObjectDisposedException">The <see cref="MediaDatabase"/> has already been disposed.</exception>
191 /// <exception cref="MediaDatabaseException">An error occurred while executing the command.</exception>
192 /// <since_tizen> 4 </since_tizen>
193 public MediaDataReader<MediaInfo> SelectMember(int albumId, SelectArguments filter)
199 throw new ArgumentOutOfRangeException(nameof(albumId), albumId,
200 "The album id can't be equal to or less than zero.");
203 return CommandHelper.SelectMedia(Interop.Album.ForeachMediaFromDb, albumId, filter);