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 face infos in the database.
24 /// <seealso cref="Album"/>
25 public class FaceInfoCommand : MediaCommand
28 /// Initializes a new instance of the <see cref="FaceInfoCommand"/> class with the specified <see cref="MediaDatabase"/>.
30 /// <param name="database">A <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 of.</exception>
33 public FaceInfoCommand(MediaDatabase database) : base(database)
38 /// Deletes a face info from the database.
40 /// <privilege>http://tizen.org/privilege/content.write</privilege>
41 /// <param name="faceInfoId">The face info id to delete.</param>
42 /// <returns>true if the matched record was found and deleted, otherwise false.</returns>
43 /// <exception cref="InvalidOperationException">The <see cref="MediaDatabase"/> is disconnected.</exception>
44 /// <exception cref="ObjectDisposedException">The <see cref="MediaDatabase"/> has already been disposed of.</exception>
45 /// <exception cref="MediaDatabaseException">An error occurred while executing the command.</exception>
46 /// <exception cref="ArgumentNullException"><paramref name="faceInfoId"/> is null.</exception>
47 /// <exception cref="ArgumentException"><paramref name="faceInfoId"/> is a zero-length string, contains only white space.</exception>
48 /// <exception cref="UnauthorizedAccessException">The caller has no required privilege.</exception>
49 public bool Delete(string faceInfoId)
53 ValidationUtil.ValidateNotNullOrEmpty(faceInfoId, nameof(faceInfoId));
55 var reader = Select(new SelectArguments { FilterExpression = $"{FaceInfoColumns.Id}='{faceInfoId}'" });
57 if (reader.Read() == false)
62 CommandHelper.Delete(Interop.Face.DeleteFromDb, faceInfoId);
67 /// Retrieves the face info.
69 /// <returns>The <see cref="MediaDataReader{TRecord}"/> containing the results.</returns>
70 /// <exception cref="InvalidOperationException">The <see cref="MediaDatabase"/> is disconnected.</exception>
71 /// <exception cref="ObjectDisposedException">The <see cref="MediaDatabase"/> has already been disposed of.</exception>
72 /// <exception cref="MediaDatabaseException">An error occurred while executing the command.</exception>
73 public MediaDataReader<FaceInfo> Select()
79 /// Retrieves the face info with <see cref="SelectArguments"/>.
81 /// <param name="filter">The criteria to use to filter. This value can be null.</param>
82 /// <returns>The <see cref="MediaDataReader{TRecord}"/> containing the results.</returns>
83 /// <exception cref="InvalidOperationException">The <see cref="MediaDatabase"/> is disconnected.</exception>
84 /// <exception cref="ObjectDisposedException">The <see cref="MediaDatabase"/> has already been disposed of.</exception>
85 /// <exception cref="MediaDatabaseException">An error occurred while executing the command.</exception>
86 public MediaDataReader<FaceInfo> Select(SelectArguments filter)
90 return CommandHelper.Select(filter, Interop.Face.ForeachFromDb, FaceInfo.FromHandle);
94 /// Updates a tag with the specified tag.
96 /// <privilege>http://tizen.org/privilege/content.write</privilege>
97 /// <param name="faceInfoId">The face info id to update.</param>
98 /// <param name="tag">The tag value for update.</param>
99 /// <returns>true if the matched record was found and updated, otherwise false.</returns>
100 /// <remarks>Only values set in <see cref="PlaylistUpdateValues"/> are updated.</remarks>
101 /// <exception cref="InvalidOperationException">The <see cref="MediaDatabase"/> is disconnected.</exception>
102 /// <exception cref="ObjectDisposedException">The <see cref="MediaDatabase"/> has already been disposed of.</exception>
103 /// <exception cref="MediaDatabaseException">An error occurred while executing the command.</exception>
104 /// <exception cref="ArgumentNullException"><paramref name="faceInfoId"/> is null.</exception>
105 /// <exception cref="ArgumentException"><paramref name="faceInfoId"/> is a zero-length string, contains only white space.</exception>
106 /// <exception cref="UnauthorizedAccessException">The caller has no required privilege.</exception>
107 public bool UpdateTag(string faceInfoId, string tag)
111 ValidationUtil.ValidateNotNullOrEmpty(faceInfoId, nameof(faceInfoId));
115 throw new ArgumentNullException(nameof(tag));
118 var handle = CommandHelper.SelectScalar(Interop.Face.ForeachFromDb, $"{FaceInfoColumns.Id}='{faceInfoId}'",
121 if (handle == IntPtr.Zero)
128 Interop.Face.SetTag(handle, tag).ThrowIfError("Failed to update(setting tag)");
130 Interop.Face.Update(handle).ThrowIfError("Failed to update(executing query)");
135 Interop.Face.Destroy(handle);