/* * 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 of. /// 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 of. /// 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 of. /// 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 of. /// 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 of. /// 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); } } } }