[NUI] TCSACR-226 code change (#1032)
[platform/core/csapi/tizenfx.git] / src / Tizen.Content.MediaContent / Tizen.Content.MediaContent / AlbumCommand.cs
1 /*
2  * Copyright (c) 2016 Samsung Electronics Co., Ltd All Rights Reserved
3  *
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
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
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.
15  */
16
17 using System;
18
19 namespace Tizen.Content.MediaContent
20 {
21     /// <summary>
22     /// Provides commands to manage albums in the database.
23     /// </summary>
24     /// <seealso cref="Album"/>
25     /// <since_tizen> 4 </since_tizen>
26     public class AlbumCommand : MediaCommand
27     {
28         /// <summary>
29         /// Initializes a new instance of the <see cref="AlbumCommand"/> class with the specified <see cref="MediaDatabase"/>.
30         /// </summary>
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)
36         {
37         }
38
39         /// <summary>
40         /// Retrieves the number of albums.
41         /// </summary>
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>
47         public int Count()
48         {
49             return Count(null);
50         }
51
52         /// <summary>
53         /// Retrieves the number of albums with <see cref="CountArguments"/>.
54         /// </summary>
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)
62         {
63             ValidateDatabase();
64
65             return CommandHelper.Count(Interop.Album.GetAlbumCountFromDb, arguments);
66         }
67
68         /// <summary>
69         /// Retrieves all the albums.
70         /// </summary>
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()
77         {
78             return Select(null);
79         }
80
81         /// <summary>
82         /// Retrieves the albums with <see cref="SelectArguments"/>.
83         /// </summary>
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)
91         {
92             ValidateDatabase();
93
94             return CommandHelper.Select(filter, Interop.Album.ForeachAlbumFromDb, Album.FromHandle);
95         }
96
97         /// <summary>
98         /// Retrieves an album with the album ID.
99         /// </summary>
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)
108         {
109             ValidateDatabase();
110
111             if (albumId <= 0)
112             {
113                 throw new ArgumentOutOfRangeException(nameof(albumId), albumId,
114                     "The album id can't be equal to or less than zero.");
115             }
116
117             IntPtr handle = IntPtr.Zero;
118             try
119             {
120                 Interop.Album.GetAlbumFromDb(albumId, out handle).ThrowIfError("Failed to query");
121
122                 return handle == IntPtr.Zero ? null : new Album(handle);
123             }
124             finally
125             {
126                 Interop.Album.Destroy(handle);
127             }
128         }
129
130         /// <summary>
131         /// Retrieves the number of media information that belongs to the album.
132         /// </summary>
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)
141         {
142             return CountMember(albumId, null);
143         }
144
145         /// <summary>
146         /// Retrieves the number of media information that belongs to the album with <see cref="CountArguments"/>.
147         /// </summary>
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)
157         {
158             ValidateDatabase();
159
160             if (albumId <= 0)
161             {
162                 throw new ArgumentOutOfRangeException(nameof(albumId), albumId,
163                     "The album id can't be equal to or less than zero.");
164             }
165
166             return CommandHelper.Count(Interop.Album.GetMediaCountFromDb, albumId, arguments);
167         }
168
169         /// <summary>
170         /// Retrieves the media information of the album.
171         /// </summary>
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)
179         {
180             return SelectMember(albumId, null);
181         }
182
183         /// <summary>
184         /// Retrieves the media information of the album with <see cref="SelectArguments"/>.
185         /// </summary>
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)
194         {
195             ValidateDatabase();
196
197             if (albumId <= 0)
198             {
199                 throw new ArgumentOutOfRangeException(nameof(albumId), albumId,
200                     "The album id can't be equal to or less than zero.");
201             }
202
203             return CommandHelper.SelectMedia(Interop.Album.ForeachMediaFromDb, albumId, filter);
204         }
205     }
206 }