[MediaContent] Deprecate underutilized fields (#5850)
[platform/core/csapi/tizenfx.git] / src / Tizen.Content.MediaContent / Tizen.Content.MediaContent / FolderCommand.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 folders and query related media items in the database.
23     /// </summary>
24     /// <since_tizen> 4 </since_tizen>
25     public class FolderCommand : MediaCommand
26     {
27         /// <summary>
28         /// Initializes a new instance of the <see cref="FolderCommand"/> class with the specified <see cref="MediaDatabase"/>.
29         /// </summary>
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.</exception>
33         /// <since_tizen> 4 </since_tizen>
34         public FolderCommand(MediaDatabase database) : base(database)
35         {
36         }
37
38         /// <summary>
39         /// Retrieves the number of folders.
40         /// </summary>
41         /// <returns>The number of folders.</returns>
42         /// <exception cref="InvalidOperationException">The <see cref="MediaDatabase"/> is disconnected.</exception>
43         /// <exception cref="ObjectDisposedException">The <see cref="MediaDatabase"/> has already been disposed.</exception>
44         /// <exception cref="MediaDatabaseException">An error occurred while executing the command.</exception>
45         /// <since_tizen> 4 </since_tizen>
46         public int Count()
47         {
48             return Count(null);
49         }
50
51         /// <summary>
52         /// Retrieves the number of folders with the <see cref="CountArguments"/>.
53         /// </summary>
54         /// <param name="arguments">The criteria to use to filter. This value can be null.</param>
55         /// <returns>The number of folders.</returns>
56         /// <exception cref="InvalidOperationException">The <see cref="MediaDatabase"/> is disconnected.</exception>
57         /// <exception cref="ObjectDisposedException">The <see cref="MediaDatabase"/> has already been disposed.</exception>
58         /// <exception cref="MediaDatabaseException">An error occurred while executing the command.</exception>
59         /// <since_tizen> 4 </since_tizen>
60         public int Count(CountArguments arguments)
61         {
62             ValidateDatabase();
63
64             return CommandHelper.Count(Interop.Folder.GetFolderCountFromDb, arguments);
65         }
66
67         /// <summary>
68         /// Retrieves the folders.
69         /// </summary>
70         /// <returns>The <see cref="MediaDataReader{TRecord}"/> containing the results.</returns>
71         /// <exception cref="InvalidOperationException">The <see cref="MediaDatabase"/> is disconnected.</exception>
72         /// <exception cref="ObjectDisposedException">The <see cref="MediaDatabase"/> has already been disposed.</exception>
73         /// <exception cref="MediaDatabaseException">An error occurred while executing the command.</exception>
74         /// <since_tizen> 4 </since_tizen>
75         public MediaDataReader<Folder> Select()
76         {
77             return Select(arguments: null);
78         }
79
80         /// <summary>
81         /// Retrieves the folders with the <see cref="SelectArguments"/>.
82         /// </summary>
83         /// <param name="arguments">The criteria to use to filter. This value can be null.</param>
84         /// <returns>The <see cref="MediaDataReader{TRecord}"/> containing the results.</returns>
85         /// <exception cref="InvalidOperationException">The <see cref="MediaDatabase"/> is disconnected.</exception>
86         /// <exception cref="ObjectDisposedException">The <see cref="MediaDatabase"/> has already been disposed.</exception>
87         /// <exception cref="MediaDatabaseException">An error occurred while executing the command.</exception>
88         /// <since_tizen> 4 </since_tizen>
89         public MediaDataReader<Folder> Select(SelectArguments arguments)
90         {
91             ValidateDatabase();
92
93             return CommandHelper.Select(arguments, Interop.Folder.ForeachFolderFromDb, Folder.FromHandle);
94         }
95
96         /// <summary>
97         /// Retrieves the folder.
98         /// </summary>
99         /// <param name="folderId">The folder ID to query with.</param>
100         /// <returns>The <see cref="Folder"/> instance if the matched record was found in the database, otherwise null.</returns>
101         /// <exception cref="InvalidOperationException">The <see cref="MediaDatabase"/> is disconnected.</exception>
102         /// <exception cref="ObjectDisposedException">The <see cref="MediaDatabase"/> has already been disposed.</exception>
103         /// <exception cref="MediaDatabaseException">An error occurred while executing the command.</exception>
104         /// <exception cref="ArgumentNullException"><paramref name="folderId"/> is null.</exception>
105         /// <exception cref="ArgumentException"><paramref name="folderId"/> is a zero-length string, contains only white space.</exception>
106         /// <since_tizen> 4 </since_tizen>
107         public Folder Select(string folderId)
108         {
109             ValidateDatabase();
110
111             ValidationUtil.ValidateNotNullOrEmpty(folderId, nameof(folderId));
112
113             Interop.Folder.GetFolderFromDb(folderId, out var handle).ThrowIfError("Failed to query");
114
115             if (handle == IntPtr.Zero)
116             {
117                 return null;
118             }
119
120             try
121             {
122                 return new Folder(handle);
123             }
124             finally
125             {
126                 Interop.Folder.Destroy(handle);
127             }
128         }
129
130         /// <summary>
131         /// Retrieves the number of media information under the folder.
132         /// </summary>
133         /// <param name="folderId">The ID of the folder to count media in the folder.</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="MediaDatabaseException">An error occurred while executing the command.</exception>
138         /// <exception cref="ArgumentNullException"><paramref name="folderId"/> is null.</exception>
139         /// <exception cref="ArgumentException"><paramref name="folderId"/> is a zero-length string, contains only white space.</exception>
140         /// <since_tizen> 4 </since_tizen>
141         public int CountMedia(string folderId)
142         {
143             return CountMedia(folderId, null);
144         }
145
146         /// <summary>
147         /// Retrieves the number of media information under the folder with the <see cref="CountArguments"/>.
148         /// </summary>
149         /// <param name="folderId">The ID of the folder to count media in the folder.</param>
150         /// <param name="arguments">The criteria to use to filter. This value can be null.</param>
151         /// <returns>The number of media information.</returns>
152         /// <exception cref="InvalidOperationException">The <see cref="MediaDatabase"/> is disconnected.</exception>
153         /// <exception cref="ObjectDisposedException">The <see cref="MediaDatabase"/> has already been disposed.</exception>
154         /// <exception cref="MediaDatabaseException">An error occurred while executing the command.</exception>
155         /// <exception cref="ArgumentNullException"><paramref name="folderId"/> is null.</exception>
156         /// <exception cref="ArgumentException"><paramref name="folderId"/> is a zero-length string, contains only white space.</exception>
157         /// <since_tizen> 4 </since_tizen>
158         public int CountMedia(string folderId, CountArguments arguments)
159         {
160             ValidateDatabase();
161
162             ValidationUtil.ValidateNotNullOrEmpty(folderId, nameof(folderId));
163
164             return CommandHelper.Count(Interop.Folder.GetMediaCountFromDb, folderId, arguments);
165         }
166
167         /// <summary>
168         /// Retrieves the media information under the folder.
169         /// </summary>
170         /// <param name="folderId">The ID of the folder to select media in the folder.</param>
171         /// <returns>The <see cref="MediaDataReader{TRecord}"/> containing the results.</returns>
172         /// <exception cref="InvalidOperationException">The <see cref="MediaDatabase"/> is disconnected.</exception>
173         /// <exception cref="ObjectDisposedException">The <see cref="MediaDatabase"/> has already been disposed.</exception>
174         /// <exception cref="MediaDatabaseException">An error occurred while executing the command.</exception>
175         /// <exception cref="ArgumentNullException"><paramref name="folderId"/> is null.</exception>
176         /// <exception cref="ArgumentException"><paramref name="folderId"/> is a zero-length string, contains only white space.</exception>
177         /// <since_tizen> 4 </since_tizen>
178         public MediaDataReader<MediaInfo> SelectMedia(string folderId)
179         {
180             return SelectMedia(folderId, null);
181         }
182
183         /// <summary>
184         /// Retrieves the media information under the folder with the <see cref="SelectArguments"/>.
185         /// </summary>
186         /// <param name="folderId">The ID of the folder to select media in the folder.</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         /// <exception cref="ArgumentNullException"><paramref name="folderId"/> is null.</exception>
193         /// <exception cref="ArgumentException"><paramref name="folderId"/> is a zero-length string, contains only white space.</exception>
194         /// <since_tizen> 4 </since_tizen>
195         public MediaDataReader<MediaInfo> SelectMedia(string folderId, SelectArguments filter)
196         {
197             ValidateDatabase();
198
199             ValidationUtil.ValidateNotNullOrEmpty(folderId, nameof(folderId));
200
201             return CommandHelper.SelectMedia(Interop.Folder.ForeachMediaFromDb, folderId, filter);
202         }
203     }
204 }