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.
18 using System.Diagnostics.CodeAnalysis;
20 namespace Tizen.Pims.Contacts
23 /// A filter includes the conditions for the search
25 /// <since_tizen> 4 </since_tizen>
26 public class ContactsFilter:IDisposable
28 internal IntPtr _filterHandle;
31 /// Creates a filter with a condition for a string type property.
33 /// <param name="viewUri">The view URI of a filter</param>
34 /// <param name="propertyId">The property ID to add a condition</param>
35 /// <param name="matchType">The match flag</param>
36 /// <param name="matchValue">The match value</param>
37 /// <feature>http://tizen.org/feature/contact</feature>
38 /// <exception cref="NotSupportedException">Thrown when feature is not supported</exception>
39 /// <exception cref="ArgumentException">Thrown when one of the arguments provided to a method is not valid</exception>
40 /// <exception cref="OutOfMemoryException">Thrown when failed due to out of memory</exception>
41 /// <since_tizen> 4 </since_tizen>
42 [SuppressMessage("Microsoft.Design", "CA1054:UriParametersShouldNotBeStrings")]
43 public ContactsFilter(string viewUri, uint propertyId, StringMatchType matchType, string matchValue)
45 int error = Interop.Filter.ContactsFilterCreate(viewUri, out _filterHandle);
46 if ((int)ContactsError.None != error)
48 Log.Error(Globals.LogTag, "ContactsFilter Failed with error " + error);
49 throw ContactsErrorFactory.CheckAndCreateException(error);
52 error = Interop.Filter.ContactsFilterAddStr(_filterHandle, propertyId, matchType, matchValue);
53 if ((int)ContactsError.None != error)
55 Interop.Filter.ContactsFilterDestroy(_filterHandle);
56 Log.Error(Globals.LogTag, "ContactsFilter Failed with error " + error);
57 throw ContactsErrorFactory.CheckAndCreateException(error);
62 /// Creates a filter with a condition for an integer type property.
64 /// <param name="viewUri">The view URI of a filter</param>
65 /// <param name="propertyId">The property ID to add a condition</param>
66 /// <param name="matchType">The match flag</param>
67 /// <param name="matchValue">The match value</param>
68 /// <feature>http://tizen.org/feature/contact</feature>
69 /// <exception cref="NotSupportedException">Thrown when feature is not supported</exception>
70 /// <exception cref="ArgumentException">Thrown when one of the arguments provided to a method is not valid</exception>
71 /// <exception cref="OutOfMemoryException">Thrown when failed due to out of memory</exception>
72 /// <since_tizen> 4 </since_tizen>
73 [SuppressMessage("Microsoft.Design", "CA1054:UriParametersShouldNotBeStrings")]
74 public ContactsFilter(string viewUri, uint propertyId, IntegerMatchType matchType, int matchValue)
76 int error = Interop.Filter.ContactsFilterCreate(viewUri, out _filterHandle);
77 if ((int)ContactsError.None != error)
79 Log.Error(Globals.LogTag, "ContactsFilter Failed with error " + error);
80 throw ContactsErrorFactory.CheckAndCreateException(error);
83 error = Interop.Filter.ContactsFilterAddInt(_filterHandle, propertyId, matchType, matchValue);
84 if ((int)ContactsError.None != error)
86 Interop.Filter.ContactsFilterDestroy(_filterHandle);
87 Log.Error(Globals.LogTag, "ContactsFilter Failed with error " + error);
88 throw ContactsErrorFactory.CheckAndCreateException(error);
93 /// Creates a filter with a condition for a long type property.
95 /// <param name="viewUri">The view URI of a filter</param>
96 /// <param name="propertyId">The property ID to add a condition</param>
97 /// <param name="matchType">The match flag</param>
98 /// <param name="matchValue">The match value</param>
99 /// <feature>http://tizen.org/feature/contact</feature>
100 /// <exception cref="NotSupportedException">Thrown when feature is not supported</exception>
101 /// <exception cref="ArgumentException">Thrown when one of the arguments provided to a method is not valid</exception>
102 /// <exception cref="OutOfMemoryException">Thrown when failed due to out of memory</exception>
103 /// <since_tizen> 4 </since_tizen>
104 [SuppressMessage("Microsoft.Design", "CA1054:UriParametersShouldNotBeStrings")]
105 public ContactsFilter(string viewUri, uint propertyId, IntegerMatchType matchType, long matchValue)
107 int error = Interop.Filter.ContactsFilterCreate(viewUri, out _filterHandle);
108 if ((int)ContactsError.None != error)
110 Log.Error(Globals.LogTag, "ContactsFilter Failed with error " + error);
111 throw ContactsErrorFactory.CheckAndCreateException(error);
114 error = Interop.Filter.ContactsFilterAddLli(_filterHandle, propertyId, matchType, matchValue);
115 if ((int)ContactsError.None != error)
117 Interop.Filter.ContactsFilterDestroy(_filterHandle);
118 Log.Error(Globals.LogTag, "ContactsFilter Failed with error " + error);
119 throw ContactsErrorFactory.CheckAndCreateException(error);
124 /// Creates a filter with a condition for a double type property.
126 /// <param name="viewUri">The view URI of a filter</param>
127 /// <param name="propertyId">The property ID to add a condition</param>
128 /// <param name="matchType">The match flag</param>
129 /// <param name="matchValue">The match value</param>
130 /// <feature>http://tizen.org/feature/contact</feature>
131 /// <exception cref="NotSupportedException">Thrown when feature is not supported</exception>
132 /// <exception cref="ArgumentException">Thrown when one of the arguments provided to a method is not valid</exception>
133 /// <exception cref="OutOfMemoryException">Thrown when failed due to out of memory</exception>
134 /// <since_tizen> 4 </since_tizen>
135 [SuppressMessage("Microsoft.Design", "CA1054:UriParametersShouldNotBeStrings")]
136 public ContactsFilter(string viewUri, uint propertyId, IntegerMatchType matchType, double matchValue)
138 int error = Interop.Filter.ContactsFilterCreate(viewUri, out _filterHandle);
139 if ((int)ContactsError.None != error)
141 Log.Error(Globals.LogTag, "ContactsFilter Failed with error " + error);
142 throw ContactsErrorFactory.CheckAndCreateException(error);
145 error = Interop.Filter.ContactsFilterAddDouble(_filterHandle, propertyId, matchType, matchValue);
146 if ((int)ContactsError.None != error)
148 Interop.Filter.ContactsFilterDestroy(_filterHandle);
149 Log.Error(Globals.LogTag, "ContactsFilter Failed with error " + error);
150 throw ContactsErrorFactory.CheckAndCreateException(error);
155 /// Creates a filter with a condition for a boolean type property.
157 /// <param name="viewUri">The view URI of a filter</param>
158 /// <param name="propertyId">The property ID to add a condition</param>
159 /// <param name="matchValue">The match value</param>
160 /// <feature>http://tizen.org/feature/contact</feature>
161 /// <exception cref="NotSupportedException">Thrown when feature is not supported</exception>
162 /// <exception cref="ArgumentException">Thrown when one of the arguments provided to a method is not valid</exception>
163 /// <exception cref="OutOfMemoryException">Thrown when failed due to out of memory</exception>
164 /// <since_tizen> 4 </since_tizen>
165 [SuppressMessage("Microsoft.Design", "CA1054:UriParametersShouldNotBeStrings")]
166 public ContactsFilter(string viewUri, uint propertyId, bool matchValue)
168 int error = Interop.Filter.ContactsFilterCreate(viewUri, out _filterHandle);
169 if ((int)ContactsError.None != error)
171 Log.Error(Globals.LogTag, "ContactsFilter Failed with error " + error);
172 throw ContactsErrorFactory.CheckAndCreateException(error);
175 error = Interop.Filter.ContactsFilterAddBool(_filterHandle, propertyId, matchValue);
176 if ((int)ContactsError.None != error)
178 Interop.Filter.ContactsFilterDestroy(_filterHandle);
179 Log.Error(Globals.LogTag, "ContactsFilter Failed with error " + error);
180 throw ContactsErrorFactory.CheckAndCreateException(error);
187 /// <since_tizen> 4 </since_tizen>
194 /// Enumeration for the filter match type of a string.
196 /// <since_tizen> 4 </since_tizen>
197 public enum StringMatchType
200 /// Full string, case-sensitive
204 /// Full string, case-insensitive
208 /// Sub string, case-insensitive
212 /// Start with, case-insensitive
216 /// End with, case-insensitive
226 /// Enumeration for the filter match type of an integer.
228 /// <since_tizen> 4 </since_tizen>
229 public enum IntegerMatchType
252 /// <>, this flag can yield poor performance
262 /// Enumeration for a filter operator.
264 /// <since_tizen> 4 </since_tizen>
265 public enum LogicalOperator
277 #region IDisposable Support
278 private bool disposedValue = false; // To detect redundant calls
281 /// Releases all resources used by the ContactsFilter.
283 /// <param name="disposing">Disposing by User</param>
284 /// <since_tizen> 4 </since_tizen>
285 protected virtual void Dispose(bool disposing)
290 //Release your own managed resources here.
291 //You should release all of your own disposable objects here
296 int error = Interop.Filter.ContactsFilterDestroy(_filterHandle);
297 if ((int)ContactsError.None != error)
299 Log.Error(Globals.LogTag, "ContactsFilterDestroy Failed with error " + error);
302 disposedValue = true;
307 /// Releases all resources used by the ContactsFilter.
308 /// It should be called after finished using of the object.
310 /// <since_tizen> 4 </since_tizen>
311 public void Dispose()
314 GC.SuppressFinalize(this);
319 /// Adds a condition for a string type property.
321 /// <param name="logicalOperator">The operator type</param>
322 /// <param name="propertyId">The property ID to add a condition</param>
323 /// <param name="matchType">The match flag</param>
324 /// <param name="matchValue">The match value</param>
325 /// <feature>http://tizen.org/feature/contact</feature>
326 /// <exception cref="NotSupportedException">Thrown when feature is not supported</exception>
327 /// <exception cref="ArgumentException">Thrown when one of the arguments provided to a method is not valid</exception>
328 /// <since_tizen> 4 </since_tizen>
329 public void AddCondition(LogicalOperator logicalOperator, uint propertyId, StringMatchType matchType, string matchValue)
331 int error = Interop.Filter.ContactsFilterAddOperator(_filterHandle, logicalOperator);
332 if ((int)ContactsError.None != error)
334 Log.Error(Globals.LogTag, "AddCondition Failed with error " + error);
335 throw ContactsErrorFactory.CheckAndCreateException(error);
338 error = Interop.Filter.ContactsFilterAddStr(_filterHandle, propertyId, matchType, matchValue);
339 if ((int)ContactsError.None != error)
341 Log.Error(Globals.LogTag, "AddCondition Failed with error " + error);
342 throw ContactsErrorFactory.CheckAndCreateException(error);
347 /// Adds a condition for a integer type property.
349 /// <param name="logicalOperator">The operator type</param>
350 /// <param name="propertyId">The property ID to add a condition</param>
351 /// <param name="matchType">The match flag</param>
352 /// <param name="matchValue">The match value</param>
353 /// <feature>http://tizen.org/feature/contact</feature>
354 /// <exception cref="NotSupportedException">Thrown when feature is not supported</exception>
355 /// <exception cref="ArgumentException">Thrown when one of the arguments provided to a method is not valid</exception>
356 /// <since_tizen> 4 </since_tizen>
357 public void AddCondition(LogicalOperator logicalOperator, uint propertyId, IntegerMatchType matchType, int matchValue)
359 int error = Interop.Filter.ContactsFilterAddOperator(_filterHandle, logicalOperator);
360 if ((int)ContactsError.None != error)
362 Log.Error(Globals.LogTag, "AddCondition Failed with error " + error);
363 throw ContactsErrorFactory.CheckAndCreateException(error);
366 error = Interop.Filter.ContactsFilterAddInt(_filterHandle, propertyId, matchType, matchValue);
367 if ((int)ContactsError.None != error)
369 Log.Error(Globals.LogTag, "AddCondition Failed with error " + error);
370 throw ContactsErrorFactory.CheckAndCreateException(error);
375 /// Adds a condition for a long type property.
377 /// <param name="logicalOperator">The operator type</param>
378 /// <param name="propertyId">The property ID to add a condition</param>
379 /// <param name="matchType">The match flag</param>
380 /// <param name="matchValue">The match value</param>
381 /// <feature>http://tizen.org/feature/contact</feature>
382 /// <exception cref="NotSupportedException">Thrown when feature is not supported</exception>
383 /// <exception cref="ArgumentException">Thrown when one of the arguments provided to a method is not valid</exception>
384 /// <since_tizen> 4 </since_tizen>
385 public void AddCondition(LogicalOperator logicalOperator, uint propertyId, IntegerMatchType matchType, long matchValue)
387 int error = Interop.Filter.ContactsFilterAddOperator(_filterHandle, logicalOperator);
388 if ((int)ContactsError.None != error)
390 Log.Error(Globals.LogTag, "AddCondition Failed with error " + error);
391 throw ContactsErrorFactory.CheckAndCreateException(error);
394 error = Interop.Filter.ContactsFilterAddLli(_filterHandle, propertyId, matchType, matchValue);
395 if ((int)ContactsError.None != error)
397 Log.Error(Globals.LogTag, "AddCondition Failed with error " + error);
398 throw ContactsErrorFactory.CheckAndCreateException(error);
403 /// Adds a condition for a double type property.
405 /// <param name="logicalOperator">The operator type</param>
406 /// <param name="propertyId">The property ID to add a condition</param>
407 /// <param name="matchType">The match flag</param>
408 /// <param name="matchValue">The match value</param>
409 /// <feature>http://tizen.org/feature/contact</feature>
410 /// <exception cref="NotSupportedException">Thrown when feature is not supported</exception>
411 /// <exception cref="ArgumentException">Thrown when one of the arguments provided to a method is not valid</exception>
412 /// <since_tizen> 4 </since_tizen>
413 public void AddCondition(LogicalOperator logicalOperator, uint propertyId, IntegerMatchType matchType, double matchValue)
415 int error = Interop.Filter.ContactsFilterAddOperator(_filterHandle, logicalOperator);
416 if ((int)ContactsError.None != error)
418 Log.Error(Globals.LogTag, "AddCondition Failed with error " + error);
419 throw ContactsErrorFactory.CheckAndCreateException(error);
422 error = Interop.Filter.ContactsFilterAddDouble(_filterHandle, propertyId, matchType, matchValue);
423 if ((int)ContactsError.None != error)
425 Log.Error(Globals.LogTag, "AddCondition Failed with error " + error);
426 throw ContactsErrorFactory.CheckAndCreateException(error);
431 /// Adds a condition for a boolean type property.
433 /// <param name="logicalOperator">The operator type</param>
434 /// <param name="propertyId">The property ID to add a condition</param>
435 /// <param name="matchValue">The match value</param>
436 /// <feature>http://tizen.org/feature/contact</feature>
437 /// <exception cref="NotSupportedException">Thrown when feature is not supported</exception>
438 /// <exception cref="ArgumentException">Thrown when one of the arguments provided to a method is not valid</exception>
439 /// <since_tizen> 4 </since_tizen>
440 public void AddCondition(LogicalOperator logicalOperator, uint propertyId, bool matchValue)
442 int error = Interop.Filter.ContactsFilterAddOperator(_filterHandle, logicalOperator);
443 if ((int)ContactsError.None != error)
445 Log.Error(Globals.LogTag, "AddCondition Failed with error " + error);
446 throw ContactsErrorFactory.CheckAndCreateException(error);
449 error = Interop.Filter.ContactsFilterAddBool(_filterHandle, propertyId, matchValue);
450 if ((int)ContactsError.None != error)
452 Log.Error(Globals.LogTag, "AddCondition Failed with error " + error);
453 throw ContactsErrorFactory.CheckAndCreateException(error);
458 /// Adds a child filter to a parent filter.
460 /// <param name="logicalOperator">The operator type</param>
461 /// <param name="filter">The child filter</param>
462 /// <feature>http://tizen.org/feature/contact</feature>
463 /// <exception cref="NotSupportedException">Thrown when feature is not supported</exception>
464 /// <exception cref="ArgumentException">Thrown when one of the arguments provided to a method is not valid</exception>
465 /// <since_tizen> 4 </since_tizen>
466 public void AddFilter(LogicalOperator logicalOperator, ContactsFilter filter)
468 int error = Interop.Filter.ContactsFilterAddOperator(_filterHandle, logicalOperator);
469 if ((int)ContactsError.None != error)
471 Log.Error(Globals.LogTag, "AddFilter Failed with error " + error);
472 throw ContactsErrorFactory.CheckAndCreateException(error);
475 error = Interop.Filter.ContactsFilterAddFilter(_filterHandle, filter._filterHandle);
476 if ((int)ContactsError.None != error)
478 Log.Error(Globals.LogTag, "AddFilter Failed with error " + error);
479 throw ContactsErrorFactory.CheckAndCreateException(error);