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.Collections.Generic;
19 using System.Diagnostics.CodeAnalysis;
20 using System.Runtime.InteropServices;
22 namespace Tizen.Pims.Contacts
26 /// ContactsDatabase provides methods to manage contacts information from/to the database.
29 /// This class allows user to access/create/update db operations for contacts information.
31 /// <since_tizen> 4 </since_tizen>
32 public class ContactsDatabase
34 private Object thisLock = new Object();
35 private Interop.Database.ContactsDBStatusChangedCallback _contactsDBStatusChangedCallback;
36 private EventHandler<DBStatusChangedEventArgs> _dbStatusChanged;
37 private Dictionary<string, EventHandler<DBChangedEventArgs>> _eventHandlerMap = new Dictionary<string, EventHandler<DBChangedEventArgs>>();
38 private Dictionary<string, Interop.Database.ContactsDBChangedCallback> _callbackMap = new Dictionary<string, Interop.Database.ContactsDBChangedCallback>();
40 internal ContactsDatabase()
42 /*To be created in ContactsManager only.*/
46 /// Enumeration for contacts database status.
48 /// <since_tizen> 4 </since_tizen>
56 /// Changing collation.
62 /// Enumeration for Contacts search range.
64 /// <since_tizen> 4 </since_tizen>
66 public enum SearchRanges
73 /// Search record from name
77 /// Search record from number
81 /// Search record from data
85 /// Search record from email. Now, support only PersonEmail view
91 /// Occurs when contacts database status is changed.
93 /// <since_tizen> 4 </since_tizen>
94 public event EventHandler<DBStatusChangedEventArgs> DBStatusChanged
100 if (_contactsDBStatusChangedCallback == null)
102 _contactsDBStatusChangedCallback = (DBStatus status, IntPtr userData) =>
104 DBStatusChangedEventArgs args = new DBStatusChangedEventArgs(status);
105 _dbStatusChanged?.Invoke(this, args);
109 if (_dbStatusChanged == null)
111 int error = Interop.Database.AddStatusChangedCb(_contactsDBStatusChangedCallback, IntPtr.Zero);
112 if ((int)ContactsError.None != error)
114 Log.Error(Globals.LogTag, "Add StatusChanged Failed with error " + error);
118 _dbStatusChanged += value;
127 _dbStatusChanged -= value;
129 if (_dbStatusChanged == null)
131 int error = Interop.Database.RemoveStatusChangedCb(_contactsDBStatusChangedCallback, IntPtr.Zero);
132 if ((int)ContactsError.None != error)
134 Log.Error(Globals.LogTag, "Remove StatusChanged Failed with error " + error);
143 /// The current contacts database version.
145 /// <value>The current contacts database version.</value>
146 /// <since_tizen> 4 </since_tizen>
147 [SuppressMessage("Microsoft.Performance", "CA1822:MarkMembersAsStatic")]
153 int error = Interop.Database.GetVersion(out version);
154 if ((int)ContactsError.None != error)
156 Log.Error(Globals.LogTag, "Version Failed with error " + error);
163 /// The last successful changed contacts database version on the current connection.
165 /// <value>The last successful changed contacts database version on the current connection.</value>
166 /// <since_tizen> 4 </since_tizen>
167 [SuppressMessage("Microsoft.Performance", "CA1822:MarkMembersAsStatic")]
168 public int LastChangeVersion
173 int error = Interop.Database.GetLastChangeVersion(out version);
174 if ((int)ContactsError.None != error)
176 Log.Error(Globals.LogTag, "LastChangeVersion Failed with error " + error);
183 /// The contacts database status.
185 /// <value>The contacts database status.</value>
186 /// <since_tizen> 4 </since_tizen>
187 [SuppressMessage("Microsoft.Performance", "CA1822:MarkMembersAsStatic")]
188 public DBStatus Status
192 DBStatus status = DBStatus.Normal;
193 int error = Interop.Database.GetStatus(out status);
194 if ((int)ContactsError.None != error)
196 Log.Error(Globals.LogTag, "GetStatus Failed with error " + error);
203 /// Inserts a record into the contacts database.
205 /// <param name="record">The record to insert</param>
206 /// <returns>The ID of inserted record</returns>
207 /// <privilege>http://tizen.org/privilege/contact.write</privilege>
208 /// <privilege>http://tizen.org/privilege/callhistory.write</privilege>
209 /// <feature>http://tizen.org/feature/contact</feature>
210 /// <exception cref="InvalidOperationException">Thrown when method failed due to invalid operation</exception>
211 /// <exception cref="NotSupportedException">Thrown when feature is not supported</exception>
212 /// <exception cref="ArgumentException">Thrown when one of the arguments provided to a method is not valid</exception>
213 /// <exception cref="OutOfMemoryException">Thrown when failed due to out of memory</exception>
214 /// <exception cref="UnauthorizedAccessException">Thrown when application does not have proper privileges</exception>
215 /// <since_tizen> 4 </since_tizen>
216 [SuppressMessage("Microsoft.Performance", "CA1822:MarkMembersAsStatic")]
217 public int Insert(ContactsRecord record)
220 int error = Interop.Database.Insert(record._recordHandle, out id);
221 if ((int)ContactsError.None != error)
223 Log.Error(Globals.LogTag, "Insert Failed with error " + error);
224 throw ContactsErrorFactory.CheckAndCreateException(error);
230 /// Inserts multiple records into the contacts database as a batch operation.
232 /// <param name="list">The record list</param>
233 /// <returns>The inserted record ID array</returns>
234 /// <privilege>http://tizen.org/privilege/contact.write</privilege>
235 /// <privilege>http://tizen.org/privilege/callhistory.write</privilege>
236 /// <feature>http://tizen.org/feature/contact</feature>
237 /// <exception cref="InvalidOperationException">Thrown when method failed due to invalid operation</exception>
238 /// <exception cref="NotSupportedException">Thrown when feature is not supported</exception>
239 /// <exception cref="ArgumentException">Thrown when one of the arguments provided to a method is not valid</exception>
240 /// <exception cref="OutOfMemoryException">Thrown when failed due to out of memory</exception>
241 /// <exception cref="UnauthorizedAccessException">Thrown when application does not have proper privileges</exception>
242 /// <since_tizen> 4 </since_tizen>
243 [SuppressMessage("Microsoft.Performance", "CA1822:MarkMembersAsStatic")]
244 public int[] Insert(ContactsList list)
248 int error = Interop.Database.InsertRecords(list._listHandle, out ids, out count);
249 if ((int)ContactsError.None != error)
251 Log.Error(Globals.LogTag, "Insert Failed with error " + error);
252 throw ContactsErrorFactory.CheckAndCreateException(error);
255 int[] idArr = new int[count];
256 Marshal.Copy(ids, idArr, 0, count);
262 /// Gets a record from the contacts database.
264 /// <param name="viewUri">The view URI of a record</param>
265 /// <param name="recordId">The record ID</param>
266 /// <returns>The record associated with the record ID</returns>
267 /// <privilege>http://tizen.org/privilege/contact.read</privilege>
268 /// <privilege>http://tizen.org/privilege/callhistory.read</privilege>
269 /// <feature>http://tizen.org/feature/contact</feature>
270 /// <exception cref="InvalidOperationException">Thrown when method failed due to invalid operation</exception>
271 /// <exception cref="NotSupportedException">Thrown when feature is not supported</exception>
272 /// <exception cref="ArgumentException">Thrown when one of the arguments provided to a method is not valid</exception>
273 /// <exception cref="OutOfMemoryException">Thrown when failed due to out of memory</exception>
274 /// <exception cref="UnauthorizedAccessException">Thrown when application does not have proper privileges</exception>
275 /// <since_tizen> 4 </since_tizen>
276 [SuppressMessage("Microsoft.Performance", "CA1822:MarkMembersAsStatic")]
277 [SuppressMessage("Microsoft.Design", "CA1054:UriParametersShouldNotBeStrings")]
278 public ContactsRecord Get(string viewUri, int recordId)
281 int error = Interop.Database.Get(viewUri, recordId, out handle);
282 if ((int)ContactsError.None != error)
284 Log.Error(Globals.LogTag, "Get Failed with error " + error);
285 throw ContactsErrorFactory.CheckAndCreateException(error);
287 return new ContactsRecord(handle);
291 /// Updates a record in the contacts database.
293 /// <param name="record">The record to update</param>
294 /// <privilege>http://tizen.org/privilege/contact.write</privilege>
295 /// <privilege>http://tizen.org/privilege/callhistory.write</privilege>
296 /// <feature>http://tizen.org/feature/contact</feature>
297 /// <exception cref="InvalidOperationException">Thrown when method failed due to invalid operation</exception>
298 /// <exception cref="NotSupportedException">Thrown when feature is not supported</exception>
299 /// <exception cref="ArgumentException">Thrown when one of the arguments provided to a method is not valid</exception>
300 /// <exception cref="OutOfMemoryException">Thrown when failed due to out of memory</exception>
301 /// <exception cref="UnauthorizedAccessException">Thrown when application does not have proper privileges</exception>
302 /// <since_tizen> 4 </since_tizen>
303 [SuppressMessage("Microsoft.Performance", "CA1822:MarkMembersAsStatic")]
304 public void Update(ContactsRecord record)
306 int error = Interop.Database.Update(record._recordHandle);
307 if ((int)ContactsError.None != error)
309 Log.Error(Globals.LogTag, "Update Failed with error " + error);
310 throw ContactsErrorFactory.CheckAndCreateException(error);
315 /// Updates multiple records in the contacts database as a batch operation.
317 /// <param name="list">The record list</param>
318 /// <privilege>http://tizen.org/privilege/contact.write</privilege>
319 /// <privilege>http://tizen.org/privilege/callhistory.write</privilege>
320 /// <feature>http://tizen.org/feature/contact</feature>
321 /// <exception cref="InvalidOperationException">Thrown when method failed due to invalid operation</exception>
322 /// <exception cref="NotSupportedException">Thrown when feature is not supported</exception>
323 /// <exception cref="ArgumentException">Thrown when one of the arguments provided to a method is not valid</exception>
324 /// <exception cref="OutOfMemoryException">Thrown when failed due to out of memory</exception>
325 /// <exception cref="UnauthorizedAccessException">Thrown when application does not have proper privileges</exception>
326 /// <since_tizen> 4 </since_tizen>
327 [SuppressMessage("Microsoft.Performance", "CA1822:MarkMembersAsStatic")]
328 public void Update(ContactsList list)
330 int error = Interop.Database.UpdateRecords(list._listHandle);
331 if ((int)ContactsError.None != error)
333 Log.Error(Globals.LogTag, "Update Failed with error " + error);
334 throw ContactsErrorFactory.CheckAndCreateException(error);
339 /// Deletes a record from the contacts database with related child records.
341 /// <param name="viewUri">The view URI of a record</param>
342 /// <param name="recordId">The record ID to delete</param>
343 /// <privilege>http://tizen.org/privilege/contact.write</privilege>
344 /// <privilege>http://tizen.org/privilege/callhistory.write</privilege>
345 /// <feature>http://tizen.org/feature/contact</feature>
346 /// <exception cref="InvalidOperationException">Thrown when method failed due to invalid operation</exception>
347 /// <exception cref="NotSupportedException">Thrown when feature is not supported</exception>
348 /// <exception cref="ArgumentException">Thrown when one of the arguments provided to a method is not valid</exception>
349 /// <exception cref="OutOfMemoryException">Thrown when failed due to out of memory</exception>
350 /// <exception cref="UnauthorizedAccessException">Thrown when application does not have proper privileges</exception>
351 /// <since_tizen> 4 </since_tizen>
352 [SuppressMessage("Microsoft.Performance", "CA1822:MarkMembersAsStatic")]
353 [SuppressMessage("Microsoft.Design", "CA1054:UriParametersShouldNotBeStrings")]
354 public void Delete(string viewUri, int recordId)
356 int error = Interop.Database.Delete(viewUri, recordId);
357 if ((int)ContactsError.None != error)
359 Log.Error(Globals.LogTag, "Delete Failed with error " + error);
360 throw ContactsErrorFactory.CheckAndCreateException(error);
365 /// Deletes multiple records with related child records from the contacts database as a batch operation.
367 /// <param name="viewUri">The view URI of the records to delete</param>
368 /// <param name="idArray">The record IDs to delete</param>
369 /// <privilege>http://tizen.org/privilege/contact.write</privilege>
370 /// <privilege>http://tizen.org/privilege/callhistory.write</privilege>
371 /// <feature>http://tizen.org/feature/contact</feature>
372 /// <exception cref="InvalidOperationException">Thrown when method failed due to invalid operation</exception>
373 /// <exception cref="NotSupportedException">Thrown when feature is not supported</exception>
374 /// <exception cref="ArgumentException">Thrown when one of the arguments provided to a method is not valid</exception>
375 /// <exception cref="OutOfMemoryException">Thrown when failed due to out of memory</exception>
376 /// <exception cref="UnauthorizedAccessException">Thrown when application does not have proper privileges</exception>
377 /// <since_tizen> 4 </since_tizen>
378 [SuppressMessage("Microsoft.Performance", "CA1822:MarkMembersAsStatic")]
379 [SuppressMessage("Microsoft.Design", "CA1054:UriParametersShouldNotBeStrings")]
380 public void Delete(string viewUri, int[] idArray)
382 int error = Interop.Database.DeleteRecords(viewUri, idArray, idArray.Length);
383 if ((int)ContactsError.None != error)
385 Log.Error(Globals.LogTag, "Delete Failed with error " + error);
386 throw ContactsErrorFactory.CheckAndCreateException(error);
391 /// Replaces a record in the contacts database.
393 /// <param name="record">The record to replace</param>
394 /// <param name="recordId">the record ID to be replaced</param>
395 /// <privilege>http://tizen.org/privilege/contact.write</privilege>
396 /// <privilege>http://tizen.org/privilege/callhistory.write</privilege>
397 /// <feature>http://tizen.org/feature/contact</feature>
398 /// <exception cref="InvalidOperationException">Thrown when method failed due to invalid operation</exception>
399 /// <exception cref="NotSupportedException">Thrown when feature is not supported</exception>
400 /// <exception cref="ArgumentException">Thrown when one of the arguments provided to a method is not valid</exception>
401 /// <exception cref="OutOfMemoryException">Thrown when failed due to out of memory</exception>
402 /// <exception cref="UnauthorizedAccessException">Thrown when application does not have proper privileges</exception>
403 /// <since_tizen> 4 </since_tizen>
404 [SuppressMessage("Microsoft.Performance", "CA1822:MarkMembersAsStatic")]
405 public void Replace(ContactsRecord record, int recordId)
407 int error = Interop.Database.Replace(record._recordHandle, recordId);
408 if ((int)ContactsError.None != error)
410 Log.Error(Globals.LogTag, "Replace Failed with error " + error);
411 throw ContactsErrorFactory.CheckAndCreateException(error);
416 /// Replaces multiple records in the contacts database as a batch operation.
418 /// <param name="list">The record list to replace</param>
419 /// <param name="idArray">The record IDs to be replaced</param>
420 /// <privilege>http://tizen.org/privilege/contact.write</privilege>
421 /// <privilege>http://tizen.org/privilege/callhistory.write</privilege>
422 /// <feature>http://tizen.org/feature/contact</feature>
423 /// <exception cref="InvalidOperationException">Thrown when method failed due to invalid operation</exception>
424 /// <exception cref="NotSupportedException">Thrown when feature is not supported</exception>
425 /// <exception cref="ArgumentException">Thrown when one of the arguments provided to a method is not valid</exception>
426 /// <exception cref="OutOfMemoryException">Thrown when failed due to out of memory</exception>
427 /// <exception cref="UnauthorizedAccessException">Thrown when application does not have proper privileges</exception>
428 /// <since_tizen> 4 </since_tizen>
429 [SuppressMessage("Microsoft.Performance", "CA1822:MarkMembersAsStatic")]
430 public void Replace(ContactsList list, int[] idArray)
432 int error = Interop.Database.ReplaceRecords(list._listHandle, idArray, idArray.Length);
433 if ((int)ContactsError.None != error)
435 Log.Error(Globals.LogTag, "Replace Failed with error " + error);
436 throw ContactsErrorFactory.CheckAndCreateException(error);
441 /// Retrieves all records as a list.
443 /// <param name="viewUri">The view URI to get records</param>
444 /// <param name="offset">The index from which results</param>
445 /// <param name="limit">The number to limit results(value 0 is used for all records)</param>
449 /// <privilege>http://tizen.org/privilege/contact.read</privilege>
450 /// <privilege>http://tizen.org/privilege/callhistory.read</privilege>
451 /// <feature>http://tizen.org/feature/contact</feature>
452 /// <exception cref="InvalidOperationException">Thrown when method failed due to invalid operation</exception>
453 /// <exception cref="NotSupportedException">Thrown when feature is not supported</exception>
454 /// <exception cref="ArgumentException">Thrown when one of the arguments provided to a method is not valid</exception>
455 /// <exception cref="OutOfMemoryException">Thrown when failed due to out of memory</exception>
456 /// <exception cref="UnauthorizedAccessException">Thrown when application does not have proper privileges</exception>
457 /// <since_tizen> 4 </since_tizen>
458 [SuppressMessage("Microsoft.Performance", "CA1822:MarkMembersAsStatic")]
459 [SuppressMessage("Microsoft.Design", "CA1054:UriParametersShouldNotBeStrings")]
460 public ContactsList GetAll(string viewUri, int offset, int limit)
463 int error = Interop.Database.GetRecords(viewUri, offset, limit, out handle);
464 if ((int)ContactsError.None != error)
466 Log.Error(Globals.LogTag, "GetAll Failed with error " + error);
467 throw ContactsErrorFactory.CheckAndCreateException(error);
469 return new ContactsList(handle);
473 /// Retrieves records using a query.
475 /// <param name="query">The query to filter the results</param>
476 /// <param name="offset">The index from which to get results</param>
477 /// <param name="limit">The number to limit results(value 0 is used for get all records)</param>
481 /// <privilege>http://tizen.org/privilege/contact.read</privilege>
482 /// <privilege>http://tizen.org/privilege/callhistory.read</privilege>
483 /// <feature>http://tizen.org/feature/contact</feature>
484 /// <exception cref="InvalidOperationException">Thrown when method failed due to invalid operation</exception>
485 /// <exception cref="NotSupportedException">Thrown when feature is not supported</exception>
486 /// <exception cref="ArgumentException">Thrown when one of the arguments provided to a method is not valid</exception>
487 /// <exception cref="OutOfMemoryException">Thrown when failed due to out of memory</exception>
488 /// <exception cref="UnauthorizedAccessException">Thrown when application does not have proper privileges</exception>
489 /// <since_tizen> 4 </since_tizen>
490 [SuppressMessage("Microsoft.Performance", "CA1822:MarkMembersAsStatic")]
491 public ContactsList GetRecordsWithQuery(ContactsQuery query, int offset, int limit)
494 int error = Interop.Database.GetRecords(query._queryHandle, offset, limit, out handle);
495 if ((int)ContactsError.None != error)
497 Log.Error(Globals.LogTag, "GetAllWithQuery Failed with error " + error);
498 throw ContactsErrorFactory.CheckAndCreateException(error);
500 return new ContactsList(handle);
504 /// Retrieves records changes since the given database version.
506 /// <param name="viewUri">The view URI to get records</param>
507 /// <param name="addressBookId">The address book ID to filter</param>
508 /// <param name="contactsDBVersion">The contacts database version</param>
509 /// <param name="currentDBVersion">The current contacts database version</param>
513 /// <privilege>http://tizen.org/privilege/contact.read</privilege>
514 /// <feature>http://tizen.org/feature/contact</feature>
515 /// <exception cref="InvalidOperationException">Thrown when method failed due to invalid operation</exception>
516 /// <exception cref="NotSupportedException">Thrown when feature is not supported</exception>
517 /// <exception cref="ArgumentException">Thrown when one of the arguments provided to a method is not valid</exception>
518 /// <exception cref="OutOfMemoryException">Thrown when failed due to out of memory</exception>
519 /// <exception cref="UnauthorizedAccessException">Thrown when application does not have proper privileges</exception>
520 /// <since_tizen> 4 </since_tizen>
521 [SuppressMessage("Microsoft.Performance", "CA1822:MarkMembersAsStatic")]
522 [SuppressMessage("Microsoft.Design", "CA1054:UriParametersShouldNotBeStrings")]
523 public ContactsList GetChangesByVersion(string viewUri, int addressBookId, int contactsDBVersion, out int currentDBVersion)
526 int error = Interop.Database.GetChangesByVersion(viewUri, addressBookId, contactsDBVersion, out recordList,out currentDBVersion);
527 if ((int)ContactsError.None != error)
529 Log.Error(Globals.LogTag, "GetChangesByVersion Failed with error " + error);
530 throw ContactsErrorFactory.CheckAndCreateException(error);
532 return new ContactsList(recordList);
536 /// Finds records based on a given keyword.
539 /// This API works only for the Views below.
540 /// Person, PersonContact, PersonGroupRelation, PersonGroupAssigned and PersonGroupNotAssigned.
542 /// <param name="viewUri">The view URI to find records</param>
543 /// <param name="keyword">The keyword</param>
544 /// <param name="offset">The index from which to get results</param>
545 /// <param name="limit">The number to limit results(value 0 is used for get all records)</param>
546 /// <returns>The record list</returns>
547 /// <privilege>http://tizen.org/privilege/contact.read</privilege>
548 /// <feature>http://tizen.org/feature/contact</feature>
549 /// <exception cref="InvalidOperationException">Thrown when method failed due to invalid operation</exception>
550 /// <exception cref="NotSupportedException">Thrown when feature is not supported</exception>
551 /// <exception cref="ArgumentException">Thrown when one of the arguments provided to a method is not valid</exception>
552 /// <exception cref="OutOfMemoryException">Thrown when failed due to out of memory</exception>
553 /// <exception cref="UnauthorizedAccessException">Thrown when application does not have proper privileges</exception>
554 /// <since_tizen> 4 </since_tizen>
555 [SuppressMessage("Microsoft.Performance", "CA1822:MarkMembersAsStatic")]
556 [SuppressMessage("Microsoft.Design", "CA1054:UriParametersShouldNotBeStrings")]
557 public ContactsList Search(string viewUri, string keyword, int offset, int limit)
560 int error = Interop.Database.Search(viewUri, keyword, offset, limit, out recordList);
561 if ((int)ContactsError.None != error)
563 Log.Error(Globals.LogTag, "Search Failed with error " + error);
564 throw ContactsErrorFactory.CheckAndCreateException(error);
566 return new ContactsList(recordList);
570 /// Finds records based on given query and keyword.
573 /// This API works only for the Views below.
574 /// Person, PersonContact, PersonGroupRelation, PersonGroupAssigned and PersonGroupNotAssigned.
576 /// <param name="query">The query to filter</param>
577 /// <param name="keyword">The keyword</param>
578 /// <param name="offset">The index from which to get results</param>
579 /// <param name="limit">The number to limit results(value 0 used for get all records)</param>
580 /// <returns>The record list</returns>
581 /// <privilege>http://tizen.org/privilege/contact.read</privilege>
582 /// <feature>http://tizen.org/feature/contact</feature>
583 /// <exception cref="InvalidOperationException">Thrown when method failed due to invalid operation</exception>
584 /// <exception cref="NotSupportedException">Thrown when feature is not supported</exception>
585 /// <exception cref="ArgumentException">Thrown when one of the arguments provided to a method is not valid</exception>
586 /// <exception cref="OutOfMemoryException">Thrown when failed due to out of memory</exception>
587 /// <exception cref="UnauthorizedAccessException">Thrown when application does not have proper privileges</exception>
588 /// <since_tizen> 4 </since_tizen>
589 [SuppressMessage("Microsoft.Performance", "CA1822:MarkMembersAsStatic")]
590 public ContactsList Search(ContactsQuery query, string keyword, int offset, int limit)
593 int error = Interop.Database.Search(query._queryHandle, keyword, offset, limit, out recordList);
594 if ((int)ContactsError.None != error)
596 Log.Error(Globals.LogTag, "Search Failed with error " + error);
597 throw ContactsErrorFactory.CheckAndCreateException(error);
599 return new ContactsList(recordList);
603 /// Finds records based on a keyword and range.
606 /// This API works only for the Views below.
607 /// Person, PersonContact, PersonGroupRelation, PersonGroupAssigned, PersonGroupNotAssigned, PersonNumber and PersonEmail
609 /// <param name="viewUri">The view URI</param>
610 /// <param name="keyword">The keyword</param>
611 /// <param name="offset">The index from which to get results</param>
612 /// <param name="limit">The number to limit results(value 0 is used for get all records)</param>
613 /// <param name="range">The search range, it should be a element of SearchRange or bitwise OR operation of them</param>
614 /// <returns>The record list</returns>
615 /// <privilege>http://tizen.org/privilege/contact.read</privilege>
616 /// <feature>http://tizen.org/feature/contact</feature>
617 /// <exception cref="InvalidOperationException">Thrown when method failed due to invalid operation</exception>
618 /// <exception cref="NotSupportedException">Thrown when feature is not supported</exception>
619 /// <exception cref="ArgumentException">Thrown when one of the arguments provided to a method is not valid</exception>
620 /// <exception cref="OutOfMemoryException">Thrown when failed due to out of memory</exception>
621 /// <exception cref="UnauthorizedAccessException">Thrown when application does not have proper privileges</exception>
622 /// <since_tizen> 4 </since_tizen>
623 [SuppressMessage("Microsoft.Performance", "CA1822:MarkMembersAsStatic")]
624 [SuppressMessage("Microsoft.Design", "CA1054:UriParametersShouldNotBeStrings")]
625 public ContactsList Search(string viewUri, string keyword, int offset, int limit, int range)
628 int error = Interop.Database.Search(viewUri, keyword, offset, limit, range, out recordList);
629 if ((int)ContactsError.None != error)
631 Log.Error(Globals.LogTag, "Search Failed with error " + error);
632 throw ContactsErrorFactory.CheckAndCreateException(error);
634 return new ContactsList(recordList);
638 /// Finds records based on a given keyword for snippet
641 /// This API works only for the Views below.
642 /// Person, PersonContact, PersonGroupRelation, PersonGroupAssigned and PersonGroupNotAssigned.
643 /// Because start match and end match are needed to be composed with keyword, this API performance is lower than Search(string viewUri, string keyword, int offset, int limit).
645 /// <param name="viewUri">The view URI to find records</param>
646 /// <param name="keyword">The keyword</param>
647 /// <param name="offset">The index from which to get results</param>
648 /// <param name="limit">The number to limit results(value 0 used for get all records)</param>
649 /// <param name="startMatch">The text which is inserted into the fragment before the keyword(If NULL, default is "[")</param>
650 /// <param name="endMatch">The text which is inserted into the fragment after the keyword(If NULL, default is "]")</param>
651 /// <param name="tokenNumber">The one side extra number of tokens near keyword(If negative value, full sentence is printed. e.g. if token number is 3 with 'abc' keyword, "my name is [abc]de and my home")</param>
652 /// <returns>The record list</returns>
653 /// <privilege>http://tizen.org/privilege/contact.read</privilege>
654 /// <feature>http://tizen.org/feature/contact</feature>
655 /// <exception cref="InvalidOperationException">Thrown when method failed due to invalid operation</exception>
656 /// <exception cref="NotSupportedException">Thrown when feature is not supported</exception>
657 /// <exception cref="ArgumentException">Thrown when one of the arguments provided to a method is not valid</exception>
658 /// <exception cref="OutOfMemoryException">Thrown when failed due to out of memory</exception>
659 /// <exception cref="UnauthorizedAccessException">Thrown when application does not have proper privileges</exception>
660 /// <since_tizen> 4 </since_tizen>
661 [SuppressMessage("Microsoft.Performance", "CA1822:MarkMembersAsStatic")]
662 [SuppressMessage("Microsoft.Design", "CA1054:UriParametersShouldNotBeStrings")]
663 public ContactsList Search(string viewUri, string keyword, int offset, int limit, string startMatch, string endMatch, int tokenNumber)
666 int error = Interop.Database.Search(viewUri, keyword, offset, limit, startMatch, endMatch, tokenNumber, out recordList);
667 if ((int)ContactsError.None != error)
669 Log.Error(Globals.LogTag, "Search Failed with error " + error);
670 throw ContactsErrorFactory.CheckAndCreateException(error);
672 return new ContactsList(recordList);
676 /// Finds records based on given query and keyword for snippet.
679 /// This API works only for the Views below.
680 /// Person, PersonContact, PersonGroupRelation, PersonGroupAssigned and PersonGroupNotAssigned.
681 /// Because start match and end match are needed to be composed with keyword, this API performance is lower than Search(ContactsQuery query, string keyword, int offset, int limit).
683 /// <param name="query">The query to filter</param>
684 /// <param name="keyword">The keyword</param>
685 /// <param name="offset">The index from which to get results</param>
686 /// <param name="limit">The number to limit results(value 0 used for get all records)</param>
687 /// <param name="startMatch">The text which is inserted into the fragment before the keyword(If NULL, default is "[")</param>
688 /// <param name="endMatch">The text which is inserted into the fragment after the keyword(If NULL, default is "]")</param>
689 /// <param name="tokenNumber">The one side extra number of tokens near keyword(If negative value, full sentence is printed. e.g. if token number is 3 with 'abc' keyword, "my name is [abc]de and my home")</param>
690 /// <returns>The record list</returns>
691 /// <privilege>http://tizen.org/privilege/contact.read</privilege>
692 /// <feature>http://tizen.org/feature/contact</feature>
693 /// <exception cref="InvalidOperationException">Thrown when method failed due to invalid operation</exception>
694 /// <exception cref="NotSupportedException">Thrown when feature is not supported</exception>
695 /// <exception cref="ArgumentException">Thrown when one of the arguments provided to a method is not valid</exception>
696 /// <exception cref="OutOfMemoryException">Thrown when failed due to out of memory</exception>
697 /// <exception cref="UnauthorizedAccessException">Thrown when application does not have proper privileges</exception>
698 /// <since_tizen> 4 </since_tizen>
699 [SuppressMessage("Microsoft.Performance", "CA1822:MarkMembersAsStatic")]
700 public ContactsList Search(ContactsQuery query, string keyword, int offset, int limit, string startMatch, string endMatch, int tokenNumber)
703 int error = Interop.Database.Search(query._queryHandle, keyword, offset, limit, startMatch, endMatch, tokenNumber, out recordList);
704 if ((int)ContactsError.None != error)
706 Log.Error(Globals.LogTag, "Search Failed with error " + error);
707 throw ContactsErrorFactory.CheckAndCreateException(error);
709 return new ContactsList(recordList);
713 /// Finds records based on a keyword and range for snippet.
716 /// This API works only for the Views below.
717 /// Person, PersonContact, PersonGroupRelation, PersonGroupAssigned, PersonGroupNotAssigned, PersonNumber and PersonEmail
718 /// Because start match and end match are needed to be composed with keyword, this API performance is lower than Search(string viewUri, string keyword, int offset, int limit, int range).
720 /// <param name="viewUri">The view URI</param>
721 /// <param name="keyword">The keyword</param>
722 /// <param name="offset">The index from which to get results</param>
723 /// <param name="limit">The number to limit results(value 0 is used for get all records)</param>
724 /// <param name="range">The search range, it should be a element of SearchRange or bitwise OR operation of them</param>
725 /// <param name="startMatch">The text which is inserted into the fragment before the keyword(If NULL, default is "[")</param>
726 /// <param name="endMatch">The text which is inserted into the fragment after the keyword(If NULL, default is "]")</param>
727 /// <param name="tokenNumber">The one side extra number of tokens near keyword(If negative value, full sentence is printed. e.g. if token number is 3 with 'abc' keyword, "my name is [abc]de and my home")</param>
728 /// <returns>The record list</returns>
729 /// <privilege>http://tizen.org/privilege/contact.read</privilege>
730 /// <feature>http://tizen.org/feature/contact</feature>
731 /// <exception cref="InvalidOperationException">Thrown when method failed due to invalid operation</exception>
732 /// <exception cref="NotSupportedException">Thrown when feature is not supported</exception>
733 /// <exception cref="ArgumentException">Thrown when one of the arguments provided to a method is not valid</exception>
734 /// <exception cref="OutOfMemoryException">Thrown when failed due to out of memory</exception>
735 /// <exception cref="UnauthorizedAccessException">Thrown when application does not have proper privileges</exception>
736 /// <since_tizen> 4 </since_tizen>
737 [SuppressMessage("Microsoft.Performance", "CA1822:MarkMembersAsStatic")]
738 [SuppressMessage("Microsoft.Design", "CA1054:UriParametersShouldNotBeStrings")]
739 public ContactsList Search(string viewUri, string keyword, int offset, int limit, int range, string startMatch, string endMatch, int tokenNumber)
742 int error = Interop.Database.Search(viewUri, keyword, offset, limit, range, startMatch, endMatch, tokenNumber, out recordList);
743 if ((int)ContactsError.None != error)
745 Log.Error(Globals.LogTag, "Search Failed with error " + error);
746 throw ContactsErrorFactory.CheckAndCreateException(error);
748 return new ContactsList(recordList);
752 /// Gets the number of records in a specific view
754 /// <param name="viewUri">The view URI</param>
755 /// <returns>The count of records</returns>
756 /// <since_tizen> 4 </since_tizen>
757 [SuppressMessage("Microsoft.Performance", "CA1822:MarkMembersAsStatic")]
758 [SuppressMessage("Microsoft.Design", "CA1054:UriParametersShouldNotBeStrings")]
759 public int GetCount(string viewUri)
762 int error = Interop.Database.GetCount(viewUri, out count);
763 if ((int)ContactsError.None != error)
765 Log.Error(Globals.LogTag, "GetCount Failed with error " + error);
766 throw ContactsErrorFactory.CheckAndCreateException(error);
772 /// Gets the number of records matching a query.
774 /// <param name="query">The query used for filtering the results</param>
775 /// <returns>The count of records</returns>
776 /// <since_tizen> 4 </since_tizen>
777 [SuppressMessage("Microsoft.Performance", "CA1822:MarkMembersAsStatic")]
778 public int GetCount(ContactsQuery query)
781 int error = Interop.Database.GetCount(query._queryHandle, out count);
782 if ((int)ContactsError.None != error)
784 Log.Error(Globals.LogTag, "GetCount Failed with error " + error);
785 throw ContactsErrorFactory.CheckAndCreateException(error);
791 /// Registers a EventHandler to be invoked when a record changes.
793 /// <param name="viewUri">The view URI of records whose changes are monitored</param>
794 /// <param name="DBChanged">The EventHandler to register</param>
795 /// <privilege>http://tizen.org/privilege/contact.read</privilege>
796 /// <privilege>http://tizen.org/privilege/callhistory.read</privilege>
797 /// <feature>http://tizen.org/feature/contact</feature>
798 /// <exception cref="InvalidOperationException">Thrown when method failed due to invalid operation</exception>
799 /// <exception cref="NotSupportedException">Thrown when feature is not supported</exception>
800 /// <exception cref="ArgumentException">Thrown when one of the arguments provided to a method is not valid</exception>
801 /// <exception cref="OutOfMemoryException">Thrown when failed due to out of memory</exception>
802 /// <exception cref="UnauthorizedAccessException">Thrown when application does not have proper privileges</exception>
803 /// <since_tizen> 4 </since_tizen>
804 [SuppressMessage("Microsoft.Design", "CA1054:UriParametersShouldNotBeStrings")]
805 public void AddDBChangedEventHandler(string viewUri, EventHandler<DBChangedEventArgs> DBChanged)
807 if (!_callbackMap.ContainsKey(viewUri))
809 _callbackMap[viewUri] = (string uri, IntPtr userData) =>
811 DBChangedEventArgs args = new DBChangedEventArgs(uri);
812 _eventHandlerMap[uri]?.Invoke(this, args);
815 int error = Interop.Database.AddChangedCb(viewUri, _callbackMap[viewUri], IntPtr.Zero);
816 if ((int)ContactsError.None != error)
818 Log.Error(Globals.LogTag, "AddDBChangedEventHandler Failed with error " + error);
819 throw ContactsErrorFactory.CheckAndCreateException(error);
823 EventHandler<DBChangedEventArgs> handler = null;
824 if (!_eventHandlerMap.TryGetValue(viewUri, out handler))
825 _eventHandlerMap.Add(viewUri, null);
827 _eventHandlerMap[viewUri] = handler + DBChanged;
831 /// Deregisters a EventHandler.
833 /// <param name="viewUri">The view URI of records whose changes are monitored</param>
834 /// <param name="DBChanged">The EventHandler to deregister</param>
835 /// <feature>http://tizen.org/feature/contact</feature>
836 /// <exception cref="InvalidOperationException">Thrown when method failed due to invalid operation</exception>
837 /// <exception cref="NotSupportedException">Thrown when feature is not supported</exception>
838 /// <exception cref="ArgumentException">Thrown when one of the arguments provided to a method is not valid</exception>
839 /// <exception cref="OutOfMemoryException">Thrown when failed due to out of memory</exception>
840 /// <since_tizen> 4 </since_tizen>
841 [SuppressMessage("Microsoft.Design", "CA1054:UriParametersShouldNotBeStrings")]
842 public void RemoveDBChangedEventHandler(string viewUri, EventHandler<DBChangedEventArgs> DBChanged)
844 EventHandler<DBChangedEventArgs> handler = null;
845 if (!_eventHandlerMap.TryGetValue(viewUri, out handler))
846 _eventHandlerMap.Add(viewUri, null);
848 _eventHandlerMap[viewUri] = handler - DBChanged;
850 if (_eventHandlerMap[viewUri] == null)
852 int error = Interop.Database.RemoveChangedCb(viewUri, _callbackMap[viewUri], IntPtr.Zero);
853 if ((int)ContactsError.None != error)
855 Log.Error(Globals.LogTag, "RemoveDBChangedEventHandler Failed with error " + error);
856 throw ContactsErrorFactory.CheckAndCreateException(error);
858 _callbackMap.Remove(viewUri);