[MediaContent] Deprecate unused APIs (#5473)
[platform/core/csapi/tizenfx.git] / src / Tizen.Content.MediaContent / Tizen.Content.MediaContent / FaceInfoCommand.cs
1 /*
2  * Copyright (c) 2016 Samsung Electronics Co., Ltd All Rights Reserved
3  *
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
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
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.
15  */
16
17 using System;
18
19 namespace Tizen.Content.MediaContent
20 {
21     /// <summary>
22     /// Provides commands to manage face information in the database.
23     /// </summary>
24     /// <seealso cref="Album"/>
25     /// <since_tizen> 4 </since_tizen>
26     [Obsolete("Deprecated since API11; Will be removed in API13.")]
27     public class FaceInfoCommand : MediaCommand
28     {
29         /// <summary>
30         /// Initializes a new instance of the <see cref="FaceInfoCommand"/> class with the specified <see cref="MediaDatabase"/>.
31         /// </summary>
32         /// <param name="database">The <see cref="MediaDatabase"/> that the commands run on.</param>
33         /// <exception cref="ArgumentNullException"><paramref name="database"/> is null.</exception>
34         /// <exception cref="ObjectDisposedException"><paramref name="database"/> has already been disposed.</exception>
35         /// <since_tizen> 4 </since_tizen>
36         [Obsolete("Deprecated since API11; Will be removed in API13.")]
37         public FaceInfoCommand(MediaDatabase database) : base(database)
38         {
39         }
40
41         /// <summary>
42         /// Deletes the face information from the database.
43         /// </summary>
44         /// <privilege>http://tizen.org/privilege/content.write</privilege>
45         /// <param name="faceInfoId">The face information ID to delete.</param>
46         /// <returns>true if the matched record was found and deleted, otherwise false.</returns>
47         /// <exception cref="InvalidOperationException">The <see cref="MediaDatabase"/> is disconnected.</exception>
48         /// <exception cref="ObjectDisposedException">The <see cref="MediaDatabase"/> has already been disposed.</exception>
49         /// <exception cref="MediaDatabaseException">An error occurred while executing the command.</exception>
50         /// <exception cref="ArgumentNullException"><paramref name="faceInfoId"/> is null.</exception>
51         /// <exception cref="ArgumentException"><paramref name="faceInfoId"/> is a zero-length string, contains only white space.</exception>
52         /// <exception cref="UnauthorizedAccessException">The caller has no required privilege.</exception>
53         /// <since_tizen> 4 </since_tizen>
54         [Obsolete("Deprecated since API11; Will be removed in API13.")]
55         public bool Delete(string faceInfoId)
56         {
57             ValidateDatabase();
58
59             ValidationUtil.ValidateNotNullOrEmpty(faceInfoId, nameof(faceInfoId));
60
61             var reader = Select(new SelectArguments { FilterExpression = $"{FaceInfoColumns.Id}='{faceInfoId}'" });
62
63             if (reader.Read() == false)
64             {
65                 return false;
66             }
67
68             CommandHelper.Delete(Interop.Face.DeleteFromDb, faceInfoId);
69             return true;
70         }
71
72         /// <summary>
73         /// Retrieves the face information.
74         /// </summary>
75         /// <returns>The <see cref="MediaDataReader{TRecord}"/> containing the results.</returns>
76         /// <exception cref="InvalidOperationException">The <see cref="MediaDatabase"/> is disconnected.</exception>
77         /// <exception cref="ObjectDisposedException">The <see cref="MediaDatabase"/> has already been disposed.</exception>
78         /// <exception cref="MediaDatabaseException">An error occurred while executing the command.</exception>
79         /// <since_tizen> 4 </since_tizen>
80         [Obsolete("Deprecated since API11; Will be removed in API13.")]
81         public MediaDataReader<FaceInfo> Select()
82         {
83             return Select(null);
84         }
85
86         /// <summary>
87         /// Retrieves the face information with the <see cref="SelectArguments"/>.
88         /// </summary>
89         /// <param name="filter">The criteria to use to filter. This value can be null.</param>
90         /// <returns>The <see cref="MediaDataReader{TRecord}"/> containing the results.</returns>
91         /// <exception cref="InvalidOperationException">The <see cref="MediaDatabase"/> is disconnected.</exception>
92         /// <exception cref="ObjectDisposedException">The <see cref="MediaDatabase"/> has already been disposed.</exception>
93         /// <exception cref="MediaDatabaseException">An error occurred while executing the command.</exception>
94         /// <since_tizen> 4 </since_tizen>
95         [Obsolete("Deprecated since API11; Will be removed in API13.")]
96         public MediaDataReader<FaceInfo> Select(SelectArguments filter)
97         {
98             ValidateDatabase();
99
100             return CommandHelper.Select(filter, Interop.Face.ForeachFromDb, FaceInfo.FromHandle);
101         }
102
103         /// <summary>
104         /// Updates a tag with the specified tag.
105         /// </summary>
106         /// <privilege>http://tizen.org/privilege/content.write</privilege>
107         /// <param name="faceInfoId">The face information ID to update.</param>
108         /// <param name="tag">The tag value for update.</param>
109         /// <returns>true if the matched record was found and updated, otherwise false.</returns>
110         /// <exception cref="InvalidOperationException">The <see cref="MediaDatabase"/> is disconnected.</exception>
111         /// <exception cref="ObjectDisposedException">The <see cref="MediaDatabase"/> has already been disposed.</exception>
112         /// <exception cref="MediaDatabaseException">An error occurred while executing the command.</exception>
113         /// <exception cref="ArgumentNullException"><paramref name="faceInfoId"/> is null.</exception>
114         /// <exception cref="ArgumentException"><paramref name="faceInfoId"/> is a zero-length string, contains only white space.</exception>
115         /// <exception cref="UnauthorizedAccessException">The caller has no required privilege.</exception>
116         /// <since_tizen> 4 </since_tizen>
117         [Obsolete("Deprecated since API11; Will be removed in API13.")]
118         public bool UpdateTag(string faceInfoId, string tag)
119         {
120             ValidateDatabase();
121
122             ValidationUtil.ValidateNotNullOrEmpty(faceInfoId, nameof(faceInfoId));
123
124             if (tag == null)
125             {
126                 throw new ArgumentNullException(nameof(tag));
127             }
128
129             var handle = CommandHelper.SelectScalar(Interop.Face.ForeachFromDb, $"{FaceInfoColumns.Id}='{faceInfoId}'",
130                 Interop.Face.Clone);
131
132             if (handle == IntPtr.Zero)
133             {
134                 return false;
135             }
136
137             try
138             {
139                 Interop.Face.SetTag(handle, tag).ThrowIfError("Failed to update(setting tag)");
140
141                 Interop.Face.Update(handle).ThrowIfError("Failed to update(executing query)");
142                 return true;
143             }
144             finally
145             {
146                 Interop.Face.Destroy(handle);
147             }
148         }
149
150         /// <summary>
151         /// Inserts new face information to the database with the specified media ID, area, orientation.
152         /// </summary>
153         /// <privilege>http://tizen.org/privilege/content.write</privilege>
154         /// <param name="mediaId">The media ID to be associated with the face.</param>
155         /// <param name="area">The region of face in the media.</param>
156         /// <param name="orientation">The orientation of the specified media.</param>
157         /// <returns>The <see cref="FaceInfo"/> containing the results.</returns>
158         /// <exception cref="InvalidOperationException">The <see cref="MediaDatabase"/> is disconnected.</exception>
159         /// <exception cref="ObjectDisposedException">The <see cref="MediaDatabase"/> has already been disposed.</exception>
160         /// <exception cref="MediaDatabaseException">An error occurred while executing the command.</exception>
161         /// <exception cref="ArgumentNullException"><paramref name="mediaId"/> is null. </exception>
162         /// <exception cref="ArgumentException">
163         ///     <paramref name="mediaId"/> is a zero-length string, contains only white space.<br/>
164         ///     -or-<br/>
165         ///     <paramref name="orientation"/> is not valid enumeration.
166         /// </exception>
167         /// <exception cref="UnauthorizedAccessException">The caller has no required privilege.</exception>
168         /// <since_tizen> 6 </since_tizen>
169         [Obsolete("Deprecated since API11; Will be removed in API13.")]
170         public FaceInfo Insert(string mediaId, Rectangle area, Orientation orientation)
171         {
172             return Insert(mediaId, area, orientation, null);
173         }
174
175         /// <summary>
176         /// Inserts new face information to the database with the specified media ID, area, orientation, and tag.
177         /// </summary>
178         /// <privilege>http://tizen.org/privilege/content.write</privilege>
179         /// <param name="mediaId">The media ID to be associated with the face.</param>
180         /// <param name="area">The region of face in the media.</param>
181         /// <param name="orientation">The orientation of specified media.</param>
182         /// <param name="tag">The tag value.</param>
183         /// <returns>The <see cref="FaceInfo"/> containing the results.</returns>
184         /// <exception cref="InvalidOperationException">The <see cref="MediaDatabase"/> is disconnected.</exception>
185         /// <exception cref="ObjectDisposedException">The <see cref="MediaDatabase"/> has already been disposed.</exception>
186         /// <exception cref="MediaDatabaseException">An error occurred while executing the command.</exception>
187         /// <exception cref="ArgumentNullException"><paramref name="mediaId"/> is null. </exception>
188         /// <exception cref="ArgumentException">
189         ///     <paramref name="mediaId"/> is a zero-length string, contains only white space.<br/>
190         ///     -or-<br/>
191         ///     <paramref name="orientation"/> is not valid enumeration.
192         /// </exception>
193         /// <exception cref="UnauthorizedAccessException">The caller has no required privilege.</exception>
194         /// <since_tizen> 6 </since_tizen>
195         [Obsolete("Deprecated since API11; Will be removed in API13.")]
196         public FaceInfo Insert(string mediaId, Rectangle area, Orientation orientation, string tag)
197         {
198             ValidateDatabase();
199
200             ValidationUtil.ValidateNotNullOrEmpty(mediaId, nameof(mediaId));
201             ValidationUtil.ValidateEnum(typeof(Orientation), orientation, nameof(orientation));
202
203             Interop.Face.Create(mediaId, out IntPtr handle).ThrowIfError("Failed to create face handle");
204
205             try
206             {
207                 Interop.Face.SetFaceRect(handle, area.X, area.Y, area.Width, area.Height).
208                     ThrowIfError("Failed to set face area");
209
210                 Interop.Face.SetOrientation(handle, orientation).ThrowIfError("Failed to set face orientation");
211
212                 if (tag != null)
213                 {
214                     Interop.Face.SetTag(handle, tag).ThrowIfError("Failed to set face tag");
215                 }
216
217                 Interop.Face.Insert(handle).ThrowIfError("Failed to insert face information");
218
219                 return new FaceInfo(handle);
220             }
221             finally
222             {
223                 Interop.Face.Destroy(handle).ThrowIfError("Failed to destroy face handle");
224             }
225         }
226     }
227 }