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 information in the database.
24 /// <seealso cref="Album"/>
25 /// <since_tizen> 4 </since_tizen>
26 public class FaceInfoCommand : MediaCommand
29 /// Initializes a new instance of the <see cref="FaceInfoCommand"/> class with the specified <see cref="MediaDatabase"/>.
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 of.</exception>
34 /// <since_tizen> 4 </since_tizen>
35 public FaceInfoCommand(MediaDatabase database) : base(database)
40 /// Deletes the face information from the database.
42 /// <privilege>http://tizen.org/privilege/content.write</privilege>
43 /// <param name="faceInfoId">The face information ID to delete.</param>
44 /// <returns>true if the matched record was found and deleted, otherwise false.</returns>
45 /// <exception cref="InvalidOperationException">The <see cref="MediaDatabase"/> is disconnected.</exception>
46 /// <exception cref="ObjectDisposedException">The <see cref="MediaDatabase"/> has already been disposed of.</exception>
47 /// <exception cref="MediaDatabaseException">An error occurred while executing the command.</exception>
48 /// <exception cref="ArgumentNullException"><paramref name="faceInfoId"/> is null.</exception>
49 /// <exception cref="ArgumentException"><paramref name="faceInfoId"/> is a zero-length string, contains only white space.</exception>
50 /// <exception cref="UnauthorizedAccessException">The caller has no required privilege.</exception>
51 /// <since_tizen> 4 </since_tizen>
52 public bool Delete(string faceInfoId)
56 ValidationUtil.ValidateNotNullOrEmpty(faceInfoId, nameof(faceInfoId));
58 var reader = Select(new SelectArguments { FilterExpression = $"{FaceInfoColumns.Id}='{faceInfoId}'" });
60 if (reader.Read() == false)
65 CommandHelper.Delete(Interop.Face.DeleteFromDb, faceInfoId);
70 /// Retrieves the face information.
72 /// <returns>The <see cref="MediaDataReader{TRecord}"/> containing the results.</returns>
73 /// <exception cref="InvalidOperationException">The <see cref="MediaDatabase"/> is disconnected.</exception>
74 /// <exception cref="ObjectDisposedException">The <see cref="MediaDatabase"/> has already been disposed of.</exception>
75 /// <exception cref="MediaDatabaseException">An error occurred while executing the command.</exception>
76 /// <since_tizen> 4 </since_tizen>
77 public MediaDataReader<FaceInfo> Select()
83 /// Retrieves the face information with the <see cref="SelectArguments"/>.
85 /// <param name="filter">The criteria to use to filter. This value can be null.</param>
86 /// <returns>The <see cref="MediaDataReader{TRecord}"/> containing the results.</returns>
87 /// <exception cref="InvalidOperationException">The <see cref="MediaDatabase"/> is disconnected.</exception>
88 /// <exception cref="ObjectDisposedException">The <see cref="MediaDatabase"/> has already been disposed of.</exception>
89 /// <exception cref="MediaDatabaseException">An error occurred while executing the command.</exception>
90 /// <since_tizen> 4 </since_tizen>
91 public MediaDataReader<FaceInfo> Select(SelectArguments filter)
95 return CommandHelper.Select(filter, Interop.Face.ForeachFromDb, FaceInfo.FromHandle);
99 /// Updates a tag with the specified tag.
101 /// <privilege>http://tizen.org/privilege/content.write</privilege>
102 /// <param name="faceInfoId">The face information ID to update.</param>
103 /// <param name="tag">The tag value for update.</param>
104 /// <returns>true if the matched record was found and updated, otherwise false.</returns>
105 /// <exception cref="InvalidOperationException">The <see cref="MediaDatabase"/> is disconnected.</exception>
106 /// <exception cref="ObjectDisposedException">The <see cref="MediaDatabase"/> has already been disposed of.</exception>
107 /// <exception cref="MediaDatabaseException">An error occurred while executing the command.</exception>
108 /// <exception cref="ArgumentNullException"><paramref name="faceInfoId"/> is null.</exception>
109 /// <exception cref="ArgumentException"><paramref name="faceInfoId"/> is a zero-length string, contains only white space.</exception>
110 /// <exception cref="UnauthorizedAccessException">The caller has no required privilege.</exception>
111 /// <since_tizen> 4 </since_tizen>
112 public bool UpdateTag(string faceInfoId, string tag)
116 ValidationUtil.ValidateNotNullOrEmpty(faceInfoId, nameof(faceInfoId));
120 throw new ArgumentNullException(nameof(tag));
123 var handle = CommandHelper.SelectScalar(Interop.Face.ForeachFromDb, $"{FaceInfoColumns.Id}='{faceInfoId}'",
126 if (handle == IntPtr.Zero)
133 Interop.Face.SetTag(handle, tag).ThrowIfError("Failed to update(setting tag)");
135 Interop.Face.Update(handle).ThrowIfError("Failed to update(executing query)");
140 Interop.Face.Destroy(handle);