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 public class FolderCommand : MediaCommand
27 /// Initializes a new instance of the <see cref="FolderCommand"/> class with the specified <see cref="MediaDatabase"/>.
29 /// <param name="database">The <see cref="MediaDatabase"/> that the commands run on.</param>
30 /// <exception cref="ArgumentNullException"><paramref name="database"/> is null.</exception>
31 /// <exception cref="ObjectDisposedException"><paramref name="database"/> has already been disposed of.</exception>
32 public FolderCommand(MediaDatabase database) : base(database)
37 /// Retrieves the number of folders.
39 /// <returns>The number of folders.</returns>
40 /// <exception cref="InvalidOperationException">The <see cref="MediaDatabase"/> is disconnected.</exception>
41 /// <exception cref="ObjectDisposedException">The <see cref="MediaDatabase"/> has already been disposed of.</exception>
42 /// <exception cref="MediaDatabaseException">An error occurred while executing the command.</exception>
49 /// Retrieves the number of folders with the <see cref="CountArguments"/>.
51 /// <param name="arguments">The criteria to use to filter. This value can be null.</param>
52 /// <returns>The number of folders.</returns>
53 /// <exception cref="InvalidOperationException">The <see cref="MediaDatabase"/> is disconnected.</exception>
54 /// <exception cref="ObjectDisposedException">The <see cref="MediaDatabase"/> has already been disposed of.</exception>
55 /// <exception cref="MediaDatabaseException">An error occurred while executing the command.</exception>
56 public int Count(CountArguments arguments)
60 return CommandHelper.Count(Interop.Folder.GetFolderCountFromDb, arguments);
64 /// Retrieves the folders.
66 /// <returns>The <see cref="MediaDataReader{TRecord}"/> containing the results.</returns>
67 /// <exception cref="InvalidOperationException">The <see cref="MediaDatabase"/> is disconnected.</exception>
68 /// <exception cref="ObjectDisposedException">The <see cref="MediaDatabase"/> has already been disposed of.</exception>
69 /// <exception cref="MediaDatabaseException">An error occurred while executing the command.</exception>
70 public MediaDataReader<Folder> Select()
72 return Select(arguments: null);
76 /// Retrieves the folders with the <see cref="SelectArguments"/>.
78 /// <param name="arguments">The criteria to use to filter. This value can be null.</param>
79 /// <returns>The <see cref="MediaDataReader{TRecord}"/> containing the results.</returns>
80 /// <exception cref="InvalidOperationException">The <see cref="MediaDatabase"/> is disconnected.</exception>
81 /// <exception cref="ObjectDisposedException">The <see cref="MediaDatabase"/> has already been disposed of.</exception>
82 /// <exception cref="MediaDatabaseException">An error occurred while executing the command.</exception>
83 public MediaDataReader<Folder> Select(SelectArguments arguments)
87 return CommandHelper.Select(arguments, Interop.Folder.ForeachFolderFromDb, Folder.FromHandle);
91 /// Retrieves the folder.
93 /// <param name="folderId">The folder ID to query with.</param>
94 /// <returns>The <see cref="Folder"/> instance if the matched record was found in the database, otherwise null.</returns>
95 /// <exception cref="InvalidOperationException">The <see cref="MediaDatabase"/> is disconnected.</exception>
96 /// <exception cref="ObjectDisposedException">The <see cref="MediaDatabase"/> has already been disposed of.</exception>
97 /// <exception cref="MediaDatabaseException">An error occurred while executing the command.</exception>
98 /// <exception cref="ArgumentNullException"><paramref name="folderId"/> is null.</exception>
99 /// <exception cref="ArgumentException"><paramref name="folderId"/> is a zero-length string, contains only white space.</exception>
100 public Folder Select(string folderId)
104 ValidationUtil.ValidateNotNullOrEmpty(folderId, nameof(folderId));
106 Interop.Folder.GetFolderFromDb(folderId, out var handle).ThrowIfError("Failed to query");
108 if (handle == IntPtr.Zero)
115 return new Folder(handle);
119 Interop.Folder.Destroy(handle);
124 /// Retrieves the number of media information under the folder.
126 /// <param name="folderId">The ID of the folder to count media in the folder.</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="MediaDatabaseException">An error occurred while executing the command.</exception>
131 /// <exception cref="ArgumentNullException"><paramref name="folderId"/> is null.</exception>
132 /// <exception cref="ArgumentException"><paramref name="folderId"/> is a zero-length string, contains only white space.</exception>
133 public int CountMedia(string folderId)
135 return CountMedia(folderId, null);
139 /// Retrieves the number of media information under the folder with the <see cref="CountArguments"/>.
141 /// <param name="folderId">The ID of the folder to count media in the folder.</param>
142 /// <param name="arguments">The criteria to use to filter. This value can be null.</param>
143 /// <returns>The number of media information.</returns>
144 /// <exception cref="InvalidOperationException">The <see cref="MediaDatabase"/> is disconnected.</exception>
145 /// <exception cref="ObjectDisposedException">The <see cref="MediaDatabase"/> has already been disposed of.</exception>
146 /// <exception cref="MediaDatabaseException">An error occurred while executing the command.</exception>
147 /// <exception cref="ArgumentNullException"><paramref name="folderId"/> is null.</exception>
148 /// <exception cref="ArgumentException"><paramref name="folderId"/> is a zero-length string, contains only white space.</exception>
149 public int CountMedia(string folderId, CountArguments arguments)
153 ValidationUtil.ValidateNotNullOrEmpty(folderId, nameof(folderId));
155 return CommandHelper.Count(Interop.Folder.GetMediaCountFromDb, folderId, arguments);
159 /// Retrieves the media information under the folder.
161 /// <param name="folderId">The ID of the folder to select media in the folder.</param>
162 /// <returns>The <see cref="MediaDataReader{TRecord}"/> containing the results.</returns>
163 /// <exception cref="InvalidOperationException">The <see cref="MediaDatabase"/> is disconnected.</exception>
164 /// <exception cref="ObjectDisposedException">The <see cref="MediaDatabase"/> has already been disposed of.</exception>
165 /// <exception cref="MediaDatabaseException">An error occurred while executing the command.</exception>
166 /// <exception cref="ArgumentNullException"><paramref name="folderId"/> is null.</exception>
167 /// <exception cref="ArgumentException"><paramref name="folderId"/> is a zero-length string, contains only white space.</exception>
168 public MediaDataReader<MediaInfo> SelectMedia(string folderId)
170 return SelectMedia(folderId, null);
174 /// Retrieves the media information under the folder with the <see cref="SelectArguments"/>.
176 /// <param name="folderId">The ID of the folder to select media in the folder.</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 /// <exception cref="ArgumentNullException"><paramref name="folderId"/> is null.</exception>
183 /// <exception cref="ArgumentException"><paramref name="folderId"/> is a zero-length string, contains only white space.</exception>
184 public MediaDataReader<MediaInfo> SelectMedia(string folderId, SelectArguments filter)
188 ValidationUtil.ValidateNotNullOrEmpty(folderId, nameof(folderId));
190 return CommandHelper.SelectMedia(Interop.Folder.ForeachMediaFromDb, folderId, filter);