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 folders and query related media items in the database.
24 /// <since_tizen> 4 </since_tizen>
25 public class FolderCommand : MediaCommand
28 /// Initializes a new instance of the <see cref="FolderCommand"/> 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.</exception>
33 /// <since_tizen> 4 </since_tizen>
34 public FolderCommand(MediaDatabase database) : base(database)
39 /// Retrieves the number of folders.
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>
52 /// Retrieves the number of folders with the <see cref="CountArguments"/>.
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)
64 return CommandHelper.Count(Interop.Folder.GetFolderCountFromDb, arguments);
68 /// Retrieves the folders.
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()
77 return Select(arguments: null);
81 /// Retrieves the folders with the <see cref="SelectArguments"/>.
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)
93 return CommandHelper.Select(arguments, Interop.Folder.ForeachFolderFromDb, Folder.FromHandle);
97 /// Retrieves the folder.
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)
111 ValidationUtil.ValidateNotNullOrEmpty(folderId, nameof(folderId));
113 Interop.Folder.GetFolderFromDb(folderId, out var handle).ThrowIfError("Failed to query");
115 if (handle == IntPtr.Zero)
122 return new Folder(handle);
126 Interop.Folder.Destroy(handle);
131 /// Retrieves the number of media information under the folder.
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)
143 return CountMedia(folderId, null);
147 /// Retrieves the number of media information under the folder with the <see cref="CountArguments"/>.
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)
162 ValidationUtil.ValidateNotNullOrEmpty(folderId, nameof(folderId));
164 return CommandHelper.Count(Interop.Folder.GetMediaCountFromDb, folderId, arguments);
168 /// Retrieves the media information under the folder.
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)
180 return SelectMedia(folderId, null);
184 /// Retrieves the media information under the folder with the <see cref="SelectArguments"/>.
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)
199 ValidationUtil.ValidateNotNullOrEmpty(folderId, nameof(folderId));
201 return CommandHelper.SelectMedia(Interop.Folder.ForeachMediaFromDb, folderId, filter);