/* * Copyright (c) 2016 Samsung Electronics Co., Ltd All Rights Reserved * * Licensed under the Apache License, Version 2.0 (the License); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an AS IS BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ using System; namespace Tizen.Content.MediaContent { /// /// Provides commands to manage face information in the database. /// /// /// 4 public class FaceInfoCommand : MediaCommand { /// /// Initializes a new instance of the class with the specified . /// /// The that the commands run on. /// is null. /// has already been disposed. /// 4 public FaceInfoCommand(MediaDatabase database) : base(database) { } /// /// Deletes the face information from the database. /// /// http://tizen.org/privilege/content.write /// The face information ID to delete. /// true if the matched record was found and deleted, otherwise false. /// The is disconnected. /// The has already been disposed. /// An error occurred while executing the command. /// is null. /// is a zero-length string, contains only white space. /// The caller has no required privilege. /// 4 public bool Delete(string faceInfoId) { ValidateDatabase(); ValidationUtil.ValidateNotNullOrEmpty(faceInfoId, nameof(faceInfoId)); var reader = Select(new SelectArguments { FilterExpression = $"{FaceInfoColumns.Id}='{faceInfoId}'" }); if (reader.Read() == false) { return false; } CommandHelper.Delete(Interop.Face.DeleteFromDb, faceInfoId); return true; } /// /// Retrieves the face information. /// /// The containing the results. /// The is disconnected. /// The has already been disposed. /// An error occurred while executing the command. /// 4 public MediaDataReader Select() { return Select(null); } /// /// Retrieves the face information with the . /// /// The criteria to use to filter. This value can be null. /// The containing the results. /// The is disconnected. /// The has already been disposed. /// An error occurred while executing the command. /// 4 public MediaDataReader Select(SelectArguments filter) { ValidateDatabase(); return CommandHelper.Select(filter, Interop.Face.ForeachFromDb, FaceInfo.FromHandle); } /// /// Updates a tag with the specified tag. /// /// http://tizen.org/privilege/content.write /// The face information ID to update. /// The tag value for update. /// true if the matched record was found and updated, otherwise false. /// The is disconnected. /// The has already been disposed. /// An error occurred while executing the command. /// is null. /// is a zero-length string, contains only white space. /// The caller has no required privilege. /// 4 public bool UpdateTag(string faceInfoId, string tag) { ValidateDatabase(); ValidationUtil.ValidateNotNullOrEmpty(faceInfoId, nameof(faceInfoId)); if (tag == null) { throw new ArgumentNullException(nameof(tag)); } var handle = CommandHelper.SelectScalar(Interop.Face.ForeachFromDb, $"{FaceInfoColumns.Id}='{faceInfoId}'", Interop.Face.Clone); if (handle == IntPtr.Zero) { return false; } try { Interop.Face.SetTag(handle, tag).ThrowIfError("Failed to update(setting tag)"); Interop.Face.Update(handle).ThrowIfError("Failed to update(executing query)"); return true; } finally { Interop.Face.Destroy(handle); } } /// /// Inserts new face information to the database with the specified media ID, area, orientation. /// /// http://tizen.org/privilege/content.write /// The media ID to be associated with the face. /// The region of face in the media. /// The orientation of the specified media. /// The containing the results. /// The is disconnected. /// The has already been disposed. /// An error occurred while executing the command. /// is null. /// /// is a zero-length string, contains only white space.
/// -or-
/// is not valid enumeration. ///
/// The caller has no required privilege. /// 6 public FaceInfo Insert(string mediaId, Rectangle area, Orientation orientation) { return Insert(mediaId, area, orientation, null); } /// /// Inserts new face information to the database with the specified media ID, area, orientation, and tag. /// /// http://tizen.org/privilege/content.write /// The media ID to be associated with the face. /// The region of face in the media. /// The orientation of specified media. /// The tag value. /// The containing the results. /// The is disconnected. /// The has already been disposed. /// An error occurred while executing the command. /// is null. /// /// is a zero-length string, contains only white space.
/// -or-
/// is not valid enumeration. ///
/// The caller has no required privilege. /// 6 public FaceInfo Insert(string mediaId, Rectangle area, Orientation orientation, string tag) { ValidateDatabase(); ValidationUtil.ValidateNotNullOrEmpty(mediaId, nameof(mediaId)); ValidationUtil.ValidateEnum(typeof(Orientation), orientation, nameof(orientation)); Interop.Face.Create(mediaId, out IntPtr handle).ThrowIfError("Failed to create face handle"); try { Interop.Face.SetFaceRect(handle, area.X, area.Y, area.Width, area.Height). ThrowIfError("Failed to set face area"); Interop.Face.SetOrientation(handle, orientation).ThrowIfError("Failed to set face orientation"); if (tag != null) { Interop.Face.SetTag(handle, tag).ThrowIfError("Failed to set face tag"); } Interop.Face.Insert(handle).ThrowIfError("Failed to insert face information"); return new FaceInfo(handle); } finally { Interop.Face.Destroy(handle).ThrowIfError("Failed to destroy face handle"); } } } }