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.</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.</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.</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.</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.</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);
145 /// Inserts new face information to the database with the specified media ID, area, orientation.
147 /// <privilege>http://tizen.org/privilege/content.write</privilege>
148 /// <param name="mediaId">The media ID to be associated with the face.</param>
149 /// <param name="area">The region of face in the media.</param>
150 /// <param name="orientation">The orientation of the specified media.</param>
151 /// <returns>The <see cref="FaceInfo"/> containing the results.</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="mediaId"/> is null. </exception>
156 /// <exception cref="ArgumentException">
157 /// <paramref name="mediaId"/> is a zero-length string, contains only white space.<br/>
159 /// <paramref name="orientation"/> is not valid enumeration.
161 /// <exception cref="UnauthorizedAccessException">The caller has no required privilege.</exception>
162 /// <since_tizen> 6 </since_tizen>
163 public FaceInfo Insert(string mediaId, Rectangle area, Orientation orientation)
165 return Insert(mediaId, area, orientation, null);
169 /// Inserts new face information to the database with the specified media ID, area, orientation, and tag.
171 /// <privilege>http://tizen.org/privilege/content.write</privilege>
172 /// <param name="mediaId">The media ID to be associated with the face.</param>
173 /// <param name="area">The region of face in the media.</param>
174 /// <param name="orientation">The orientation of specified media.</param>
175 /// <param name="tag">The tag value.</param>
176 /// <returns>The <see cref="FaceInfo"/> containing the results.</returns>
177 /// <exception cref="InvalidOperationException">The <see cref="MediaDatabase"/> is disconnected.</exception>
178 /// <exception cref="ObjectDisposedException">The <see cref="MediaDatabase"/> has already been disposed.</exception>
179 /// <exception cref="MediaDatabaseException">An error occurred while executing the command.</exception>
180 /// <exception cref="ArgumentNullException"><paramref name="mediaId"/> is null. </exception>
181 /// <exception cref="ArgumentException">
182 /// <paramref name="mediaId"/> is a zero-length string, contains only white space.<br/>
184 /// <paramref name="orientation"/> is not valid enumeration.
186 /// <exception cref="UnauthorizedAccessException">The caller has no required privilege.</exception>
187 /// <since_tizen> 6 </since_tizen>
188 public FaceInfo Insert(string mediaId, Rectangle area, Orientation orientation, string tag)
192 ValidationUtil.ValidateNotNullOrEmpty(mediaId, nameof(mediaId));
193 ValidationUtil.ValidateEnum(typeof(Orientation), orientation, nameof(orientation));
195 Interop.Face.Create(mediaId, out IntPtr handle).ThrowIfError("Failed to create face handle");
199 Interop.Face.SetFaceRect(handle, area.X, area.Y, area.Width, area.Height).
200 ThrowIfError("Failed to set face area");
202 Interop.Face.SetOrientation(handle, orientation).ThrowIfError("Failed to set face orientation");
206 Interop.Face.SetTag(handle, tag).ThrowIfError("Failed to set face tag");
209 Interop.Face.Insert(handle).ThrowIfError("Failed to insert face information");
211 return new FaceInfo(handle);
215 Interop.Face.Destroy(handle).ThrowIfError("Failed to destroy face handle");