/
ContactsDatabase.cs
869 lines (825 loc) · 48.2 KB
/
ContactsDatabase.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
/*
* 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;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Runtime.InteropServices;
namespace Tizen.Pims.Contacts
{
/// <summary>
/// The ContactsDatabase provides methods to manage contacts information from/to the database.
/// </summary>
/// <remarks>
/// This class allows the user to access/create/update database operations for the contacts information.
/// </remarks>
/// <since_tizen> 4 </since_tizen>
public class ContactsDatabase
{
private Object thisLock = new Object();
private Interop.Database.ContactsDBStatusChangedCallback _contactsDBStatusChangedCallback;
private EventHandler<DBStatusChangedEventArgs> _dbStatusChanged;
private Dictionary<string, EventHandler<DBChangedEventArgs>> _eventHandlerMap = new Dictionary<string, EventHandler<DBChangedEventArgs>>();
private Dictionary<string, Interop.Database.ContactsDBChangedCallback> _callbackMap = new Dictionary<string, Interop.Database.ContactsDBChangedCallback>();
internal ContactsDatabase()
{
/*To be created in ContactsManager only.*/
}
/// <summary>
/// Enumeration for the contacts database status.
/// </summary>
/// <since_tizen> 4 </since_tizen>
public enum DBStatus
{
/// <summary>
/// Normal.
/// </summary>
/// <since_tizen> 4 </since_tizen>
Normal,
/// <summary>
/// Changing collation.
/// </summary>
/// <since_tizen> 4 </since_tizen>
ChangingCollation
}
/// <summary>
/// Enumeration for the contacts search range.
/// </summary>
/// <since_tizen> 4 </since_tizen>
[Flags]
public enum SearchRanges
{
/// <summary>
/// None.
/// </summary>
/// <since_tizen> 4 </since_tizen>
None = 0,
/// <summary>
/// Search record from name.
/// </summary>
/// <since_tizen> 4 </since_tizen>
Name = 0x00000001,
/// <summary>
/// Search record from number.
/// </summary>
/// <since_tizen> 4 </since_tizen>
Number = 0x00000002,
/// <summary>
/// Search record from data.
/// </summary>
/// <since_tizen> 4 </since_tizen>
Data = 0x00000004,
/// <summary>
/// Search record from email. Now, support only PersonEmail view.
/// </summary>
/// <since_tizen> 4 </since_tizen>
Email = 0x00000008,
}
/// <summary>
/// Occurs when the contacts database status is changed.
/// </summary>
/// <since_tizen> 4 </since_tizen>
public event EventHandler<DBStatusChangedEventArgs> DBStatusChanged
{
add
{
lock (thisLock)
{
if (_contactsDBStatusChangedCallback == null)
{
_contactsDBStatusChangedCallback = (DBStatus status, IntPtr userData) =>
{
DBStatusChangedEventArgs args = new DBStatusChangedEventArgs(status);
_dbStatusChanged?.Invoke(this, args);
};
}
if (_dbStatusChanged == null)
{
int error = Interop.Database.AddStatusChangedCb(_contactsDBStatusChangedCallback, IntPtr.Zero);
if ((int)ContactsError.None != error)
{
Log.Error(Globals.LogTag, "Add StatusChanged Failed with error " + error);
}
}
_dbStatusChanged += value;
}
}
remove
{
lock (thisLock)
{
_dbStatusChanged -= value;
if (_dbStatusChanged == null)
{
int error = Interop.Database.RemoveStatusChangedCb(_contactsDBStatusChangedCallback, IntPtr.Zero);
if ((int)ContactsError.None != error)
{
Log.Error(Globals.LogTag, "Remove StatusChanged Failed with error " + error);
}
}
}
}
}
/// <summary>
/// The current contacts database version.
/// </summary>
/// <value>The current contacts database version.</value>
/// <since_tizen> 4 </since_tizen>
[SuppressMessage("Microsoft.Performance", "CA1822:MarkMembersAsStatic")]
public int Version
{
get
{
int version = -1;
int error = Interop.Database.GetVersion(out version);
if ((int)ContactsError.None != error)
{
Log.Error(Globals.LogTag, "Version Failed with error " + error);
}
return version;
}
}
/// <summary>
/// The last successful changed contacts database version on the current connection.
/// </summary>
/// <value>The last successful changed contacts database version on the current connection.</value>
/// <since_tizen> 4 </since_tizen>
[SuppressMessage("Microsoft.Performance", "CA1822:MarkMembersAsStatic")]
public int LastChangeVersion
{
get
{
int version = -1;
int error = Interop.Database.GetLastChangeVersion(out version);
if ((int)ContactsError.None != error)
{
Log.Error(Globals.LogTag, "LastChangeVersion Failed with error " + error);
}
return version;
}
}
/// <summary>
/// The contacts database status.
/// </summary>
/// <value>The contacts database status.</value>
/// <since_tizen> 4 </since_tizen>
[SuppressMessage("Microsoft.Performance", "CA1822:MarkMembersAsStatic")]
public DBStatus Status
{
get
{
DBStatus status = DBStatus.Normal;
int error = Interop.Database.GetStatus(out status);
if ((int)ContactsError.None != error)
{
Log.Error(Globals.LogTag, "GetStatus Failed with error " + error);
}
return status;
}
}
/// <summary>
/// Inserts a record into the contacts database.
/// </summary>
/// <param name="record">The record to insert.</param>
/// <returns>The ID of inserted record.</returns>
/// <privilege>http://tizen.org/privilege/contact.write</privilege>
/// <privilege>http://tizen.org/privilege/callhistory.write</privilege>
/// <feature>http://tizen.org/feature/contact</feature>
/// <exception cref="InvalidOperationException">Thrown when the method failed due to an invalid operation.</exception>
/// <exception cref="NotSupportedException">Thrown when the feature is not supported.</exception>
/// <exception cref="ArgumentException">Thrown when one of the arguments provided to a method is not valid.</exception>
/// <exception cref="OutOfMemoryException">Thrown when failed due to out of memory.</exception>
/// <exception cref="UnauthorizedAccessException">Thrown when the application does not have proper privileges.</exception>
/// <since_tizen> 4 </since_tizen>
[SuppressMessage("Microsoft.Performance", "CA1822:MarkMembersAsStatic")]
public int Insert(ContactsRecord record)
{
int id = -1;
int error = Interop.Database.Insert(record._recordHandle, out id);
if ((int)ContactsError.None != error)
{
Log.Error(Globals.LogTag, "Insert Failed with error " + error);
throw ContactsErrorFactory.CheckAndCreateException(error);
}
return id;
}
/// <summary>
/// Inserts multiple records into the contacts database as a batch operation.
/// </summary>
/// <param name="list">The record list.</param>
/// <returns>The inserted record ID array.</returns>
/// <privilege>http://tizen.org/privilege/contact.write</privilege>
/// <privilege>http://tizen.org/privilege/callhistory.write</privilege>
/// <feature>http://tizen.org/feature/contact</feature>
/// <exception cref="InvalidOperationException">Thrown when the method failed due to an invalid operation.</exception>
/// <exception cref="NotSupportedException">Thrown when the feature is not supported.</exception>
/// <exception cref="ArgumentException">Thrown when one of the arguments provided to a method is not valid.</exception>
/// <exception cref="OutOfMemoryException">Thrown when failed due to out of memory.</exception>
/// <exception cref="UnauthorizedAccessException">Thrown when the application does not have proper privileges.</exception>
/// <since_tizen> 4 </since_tizen>
[SuppressMessage("Microsoft.Performance", "CA1822:MarkMembersAsStatic")]
public int[] Insert(ContactsList list)
{
IntPtr ids;
int count;
int error = Interop.Database.InsertRecords(list._listHandle, out ids, out count);
if ((int)ContactsError.None != error)
{
Log.Error(Globals.LogTag, "Insert Failed with error " + error);
throw ContactsErrorFactory.CheckAndCreateException(error);
}
int[] idArr = new int[count];
Marshal.Copy(ids, idArr, 0, count);
return idArr;
}
/// <summary>
/// Gets a record from the contacts database.
/// </summary>
/// <param name="viewUri">The view URI of a record.</param>
/// <param name="recordId">The record ID.</param>
/// <returns>The record associated with the record ID</returns>
/// <privilege>http://tizen.org/privilege/contact.read</privilege>
/// <privilege>http://tizen.org/privilege/callhistory.read</privilege>
/// <feature>http://tizen.org/feature/contact</feature>
/// <exception cref="InvalidOperationException">Thrown when the method failed due to an invalid operation.</exception>
/// <exception cref="NotSupportedException">Thrown when the feature is not supported.</exception>
/// <exception cref="ArgumentException">Thrown when one of the arguments provided to a method is not valid.</exception>
/// <exception cref="OutOfMemoryException">Thrown when failed due to out of memory.</exception>
/// <exception cref="UnauthorizedAccessException">Thrown when the application does not have proper privileges.</exception>
/// <since_tizen> 4 </since_tizen>
[SuppressMessage("Microsoft.Performance", "CA1822:MarkMembersAsStatic")]
[SuppressMessage("Microsoft.Design", "CA1054:UriParametersShouldNotBeStrings")]
public ContactsRecord Get(string viewUri, int recordId)
{
IntPtr handle;
int error = Interop.Database.Get(viewUri, recordId, out handle);
if ((int)ContactsError.None != error)
{
Log.Error(Globals.LogTag, "Get Failed with error " + error);
throw ContactsErrorFactory.CheckAndCreateException(error);
}
return new ContactsRecord(handle);
}
/// <summary>
/// Updates a record in the contacts database.
/// </summary>
/// <param name="record">The record to update.</param>
/// <privilege>http://tizen.org/privilege/contact.write</privilege>
/// <privilege>http://tizen.org/privilege/callhistory.write</privilege>
/// <feature>http://tizen.org/feature/contact</feature>
/// <exception cref="InvalidOperationException">Thrown when the method failed due to an invalid operation.</exception>
/// <exception cref="NotSupportedException">Thrown when the feature is not supported.</exception>
/// <exception cref="ArgumentException">Thrown when one of the arguments provided to a method is not valid.</exception>
/// <exception cref="OutOfMemoryException">Thrown when failed due to out of memory.</exception>
/// <exception cref="UnauthorizedAccessException">Thrown when the application does not have proper privileges.</exception>
/// <since_tizen> 4 </since_tizen>
[SuppressMessage("Microsoft.Performance", "CA1822:MarkMembersAsStatic")]
public void Update(ContactsRecord record)
{
int error = Interop.Database.Update(record._recordHandle);
if ((int)ContactsError.None != error)
{
Log.Error(Globals.LogTag, "Update Failed with error " + error);
throw ContactsErrorFactory.CheckAndCreateException(error);
}
}
/// <summary>
/// Updates multiple records in the contacts database as a batch operation.
/// </summary>
/// <param name="list">The record list.</param>
/// <privilege>http://tizen.org/privilege/contact.write</privilege>
/// <privilege>http://tizen.org/privilege/callhistory.write</privilege>
/// <feature>http://tizen.org/feature/contact</feature>
/// <exception cref="InvalidOperationException">Thrown when the method failed due to an invalid operation.</exception>
/// <exception cref="NotSupportedException">Thrown when the feature is not supported.</exception>
/// <exception cref="ArgumentException">Thrown when one of the arguments provided to a method is not valid.</exception>
/// <exception cref="OutOfMemoryException">Thrown when failed due to out of memory.</exception>
/// <exception cref="UnauthorizedAccessException">Thrown when the application does not have proper privileges.</exception>
/// <since_tizen> 4 </since_tizen>
[SuppressMessage("Microsoft.Performance", "CA1822:MarkMembersAsStatic")]
public void Update(ContactsList list)
{
int error = Interop.Database.UpdateRecords(list._listHandle);
if ((int)ContactsError.None != error)
{
Log.Error(Globals.LogTag, "Update Failed with error " + error);
throw ContactsErrorFactory.CheckAndCreateException(error);
}
}
/// <summary>
/// Deletes a record from the contacts database with the related child records.
/// </summary>
/// <param name="viewUri">The view URI of a record.</param>
/// <param name="recordId">The record ID to delete.</param>
/// <privilege>http://tizen.org/privilege/contact.write</privilege>
/// <privilege>http://tizen.org/privilege/callhistory.write</privilege>
/// <feature>http://tizen.org/feature/contact</feature>
/// <exception cref="InvalidOperationException">Thrown when the method failed due to an invalid operation.</exception>
/// <exception cref="NotSupportedException">Thrown when the feature is not supported.</exception>
/// <exception cref="ArgumentException">Thrown when one of the arguments provided to a method is not valid.</exception>
/// <exception cref="OutOfMemoryException">Thrown when failed due to out of memory.</exception>
/// <exception cref="UnauthorizedAccessException">Thrown when the application does not have proper privileges.</exception>
/// <since_tizen> 4 </since_tizen>
[SuppressMessage("Microsoft.Performance", "CA1822:MarkMembersAsStatic")]
[SuppressMessage("Microsoft.Design", "CA1054:UriParametersShouldNotBeStrings")]
public void Delete(string viewUri, int recordId)
{
int error = Interop.Database.Delete(viewUri, recordId);
if ((int)ContactsError.None != error)
{
Log.Error(Globals.LogTag, "Delete Failed with error " + error);
throw ContactsErrorFactory.CheckAndCreateException(error);
}
}
/// <summary>
/// Deletes multiple records with the related child records from the contacts database as a batch operation.
/// </summary>
/// <param name="viewUri">The view URI of the records to delete.</param>
/// <param name="idArray">The record IDs to delete.</param>
/// <privilege>http://tizen.org/privilege/contact.write</privilege>
/// <privilege>http://tizen.org/privilege/callhistory.write</privilege>
/// <feature>http://tizen.org/feature/contact</feature>
/// <exception cref="InvalidOperationException">Thrown when the method failed due to an invalid operation.</exception>
/// <exception cref="NotSupportedException">Thrown when the feature is not supported.</exception>
/// <exception cref="ArgumentException">Thrown when one of the arguments provided to a method is not valid.</exception>
/// <exception cref="OutOfMemoryException">Thrown when failed due to out of memory.</exception>
/// <exception cref="UnauthorizedAccessException">Thrown when the application does not have proper privileges.</exception>
/// <since_tizen> 4 </since_tizen>
[SuppressMessage("Microsoft.Performance", "CA1822:MarkMembersAsStatic")]
[SuppressMessage("Microsoft.Design", "CA1054:UriParametersShouldNotBeStrings")]
public void Delete(string viewUri, int[] idArray)
{
int error = Interop.Database.DeleteRecords(viewUri, idArray, idArray.Length);
if ((int)ContactsError.None != error)
{
Log.Error(Globals.LogTag, "Delete Failed with error " + error);
throw ContactsErrorFactory.CheckAndCreateException(error);
}
}
/// <summary>
/// Replaces a record in the contacts database.
/// </summary>
/// <param name="record">The record to replace.</param>
/// <param name="recordId">The record ID to be replaced.</param>
/// <privilege>http://tizen.org/privilege/contact.write</privilege>
/// <privilege>http://tizen.org/privilege/callhistory.write</privilege>
/// <feature>http://tizen.org/feature/contact</feature>
/// <exception cref="InvalidOperationException">Thrown when the method failed due to an invalid operation.</exception>
/// <exception cref="NotSupportedException">Thrown when the feature is not supported.</exception>
/// <exception cref="ArgumentException">Thrown when one of the arguments provided to a method is not valid.</exception>
/// <exception cref="OutOfMemoryException">Thrown when failed due to out of memory.</exception>
/// <exception cref="UnauthorizedAccessException">Thrown when the application does not have proper privileges.</exception>
/// <since_tizen> 4 </since_tizen>
[SuppressMessage("Microsoft.Performance", "CA1822:MarkMembersAsStatic")]
public void Replace(ContactsRecord record, int recordId)
{
int error = Interop.Database.Replace(record._recordHandle, recordId);
if ((int)ContactsError.None != error)
{
Log.Error(Globals.LogTag, "Replace Failed with error " + error);
throw ContactsErrorFactory.CheckAndCreateException(error);
}
}
/// <summary>
/// Replaces multiple records in the contacts database as a batch operation.
/// </summary>
/// <param name="list">The record list to replace.</param>
/// <param name="idArray">The record IDs to be replaced.</param>
/// <privilege>http://tizen.org/privilege/contact.write</privilege>
/// <privilege>http://tizen.org/privilege/callhistory.write</privilege>
/// <feature>http://tizen.org/feature/contact</feature>
/// <exception cref="InvalidOperationException">Thrown when the method failed due to an invalid operation.</exception>
/// <exception cref="NotSupportedException">Thrown when feature is not supported.</exception>
/// <exception cref="ArgumentException">Thrown when one of the arguments provided to a method is not valid.</exception>
/// <exception cref="OutOfMemoryException">Thrown when failed due to out of memory.</exception>
/// <exception cref="UnauthorizedAccessException">Thrown when the application does not have proper privileges.</exception>
/// <since_tizen> 4 </since_tizen>
[SuppressMessage("Microsoft.Performance", "CA1822:MarkMembersAsStatic")]
public void Replace(ContactsList list, int[] idArray)
{
int error = Interop.Database.ReplaceRecords(list._listHandle, idArray, idArray.Length);
if ((int)ContactsError.None != error)
{
Log.Error(Globals.LogTag, "Replace Failed with error " + error);
throw ContactsErrorFactory.CheckAndCreateException(error);
}
}
/// <summary>
/// Retrieves all the records as a list.
/// </summary>
/// <param name="viewUri">The view URI to get records.</param>
/// <param name="offset">The index from which results.</param>
/// <param name="limit">The number to limit results (value 0 is used for get all records).</param>
/// <returns>
/// The record list.
/// </returns>
/// <privilege>http://tizen.org/privilege/contact.read</privilege>
/// <privilege>http://tizen.org/privilege/callhistory.read</privilege>
/// <feature>http://tizen.org/feature/contact</feature>
/// <exception cref="InvalidOperationException">Thrown when the method failed due to an invalid operation.</exception>
/// <exception cref="NotSupportedException">Thrown when the feature is not supported.</exception>
/// <exception cref="ArgumentException">Thrown when one of the arguments provided to a method is not valid.</exception>
/// <exception cref="OutOfMemoryException">Thrown when failed due to out of memory.</exception>
/// <exception cref="UnauthorizedAccessException">Thrown when the application does not have proper privileges.</exception>
/// <since_tizen> 4 </since_tizen>
[SuppressMessage("Microsoft.Performance", "CA1822:MarkMembersAsStatic")]
[SuppressMessage("Microsoft.Design", "CA1054:UriParametersShouldNotBeStrings")]
public ContactsList GetAll(string viewUri, int offset, int limit)
{
IntPtr handle;
int error = Interop.Database.GetRecords(viewUri, offset, limit, out handle);
if ((int)ContactsError.None != error)
{
Log.Error(Globals.LogTag, "GetAll Failed with error " + error);
throw ContactsErrorFactory.CheckAndCreateException(error);
}
return new ContactsList(handle);
}
/// <summary>
/// Retrieves the records using a query.
/// </summary>
/// <param name="query">The query to filter the results.</param>
/// <param name="offset">The index from which to get results.</param>
/// <param name="limit">The number to limit results (value 0 is used for get all records).</param>
/// <returns>
/// The record list
/// </returns>
/// <privilege>http://tizen.org/privilege/contact.read</privilege>
/// <privilege>http://tizen.org/privilege/callhistory.read</privilege>
/// <feature>http://tizen.org/feature/contact</feature>
/// <exception cref="InvalidOperationException">Thrown when the method failed due to an invalid operation.</exception>
/// <exception cref="NotSupportedException">Thrown when the feature is not supported.</exception>
/// <exception cref="ArgumentException">Thrown when one of the arguments provided to a method is not valid.</exception>
/// <exception cref="OutOfMemoryException">Thrown when failed due to out of memory.</exception>
/// <exception cref="UnauthorizedAccessException">Thrown when the application does not have proper privileges.</exception>
/// <since_tizen> 4 </since_tizen>
[SuppressMessage("Microsoft.Performance", "CA1822:MarkMembersAsStatic")]
public ContactsList GetRecordsWithQuery(ContactsQuery query, int offset, int limit)
{
IntPtr handle;
int error = Interop.Database.GetRecords(query._queryHandle, offset, limit, out handle);
if ((int)ContactsError.None != error)
{
Log.Error(Globals.LogTag, "GetAllWithQuery Failed with error " + error);
throw ContactsErrorFactory.CheckAndCreateException(error);
}
return new ContactsList(handle);
}
/// <summary>
/// Retrieves the records changes since the given database version.
/// </summary>
/// <param name="viewUri">The view URI to get records.</param>
/// <param name="addressBookId">The address book ID to filter.</param>
/// <param name="contactsDBVersion">The contacts database version.</param>
/// <param name="currentDBVersion">The current contacts database version.</param>
/// <returns>
/// The record list.
/// </returns>
/// <privilege>http://tizen.org/privilege/contact.read</privilege>
/// <feature>http://tizen.org/feature/contact</feature>
/// <exception cref="InvalidOperationException">Thrown when the method failed due to an invalid operation.</exception>
/// <exception cref="NotSupportedException">Thrown when the feature is not supported.</exception>
/// <exception cref="ArgumentException">Thrown when one of the arguments provided to a method is not valid.</exception>
/// <exception cref="OutOfMemoryException">Thrown when failed due to out of memory.</exception>
/// <exception cref="UnauthorizedAccessException">Thrown when the application does not have proper privileges.</exception>
/// <since_tizen> 4 </since_tizen>
[SuppressMessage("Microsoft.Performance", "CA1822:MarkMembersAsStatic")]
[SuppressMessage("Microsoft.Design", "CA1054:UriParametersShouldNotBeStrings")]
public ContactsList GetChangesByVersion(string viewUri, int addressBookId, int contactsDBVersion, out int currentDBVersion)
{
IntPtr recordList;
int error = Interop.Database.GetChangesByVersion(viewUri, addressBookId, contactsDBVersion, out recordList,out currentDBVersion);
if ((int)ContactsError.None != error)
{
Log.Error(Globals.LogTag, "GetChangesByVersion Failed with error " + error);
throw ContactsErrorFactory.CheckAndCreateException(error);
}
return new ContactsList(recordList);
}
/// <summary>
/// Finds the records based on a given keyword.
/// </summary>
/// <remarks>
/// This API works only for the views below:
/// Person, PersonContact, PersonGroupRelation, PersonGroupAssigned, and PersonGroupNotAssigned.
/// </remarks>
/// <param name="viewUri">The view URI to find records.</param>
/// <param name="keyword">The keyword.</param>
/// <param name="offset">The index from which to get results.</param>
/// <param name="limit">The number to limit results (value 0 is used for get all records).</param>
/// <returns>The record list</returns>
/// <privilege>http://tizen.org/privilege/contact.read</privilege>
/// <feature>http://tizen.org/feature/contact</feature>
/// <exception cref="InvalidOperationException">Thrown when the method failed due to an invalid operation.</exception>
/// <exception cref="NotSupportedException">Thrown when the feature is not supported.</exception>
/// <exception cref="ArgumentException">Thrown when one of the arguments provided to a method is not valid.</exception>
/// <exception cref="OutOfMemoryException">Thrown when failed due to out of memory.</exception>
/// <exception cref="UnauthorizedAccessException">Thrown when the application does not have proper privileges.</exception>
/// <since_tizen> 4 </since_tizen>
[SuppressMessage("Microsoft.Performance", "CA1822:MarkMembersAsStatic")]
[SuppressMessage("Microsoft.Design", "CA1054:UriParametersShouldNotBeStrings")]
public ContactsList Search(string viewUri, string keyword, int offset, int limit)
{
IntPtr recordList;
int error = Interop.Database.Search(viewUri, keyword, offset, limit, out recordList);
if ((int)ContactsError.None != error)
{
Log.Error(Globals.LogTag, "Search Failed with error " + error);
throw ContactsErrorFactory.CheckAndCreateException(error);
}
return new ContactsList(recordList);
}
/// <summary>
/// Finds the records based on a given query and keyword.
/// </summary>
/// <remarks>
/// This API works only for the views below:
/// Person, PersonContact, PersonGroupRelation, PersonGroupAssigned, and PersonGroupNotAssigned.
/// </remarks>
/// <param name="query">The query to filter.</param>
/// <param name="keyword">The keyword.</param>
/// <param name="offset">The index from which to get results.</param>
/// <param name="limit">The number to limit results (value 0 is used for get all records).</param>
/// <returns>The record list.</returns>
/// <privilege>http://tizen.org/privilege/contact.read</privilege>
/// <feature>http://tizen.org/feature/contact</feature>
/// <exception cref="InvalidOperationException">Thrown when the method failed due to an invalid operation.</exception>
/// <exception cref="NotSupportedException">Thrown when the feature is not supported.</exception>
/// <exception cref="ArgumentException">Thrown when one of the arguments provided to a method is not valid.</exception>
/// <exception cref="OutOfMemoryException">Thrown when failed due to out of memory.</exception>
/// <exception cref="UnauthorizedAccessException">Thrown when the application does not have proper privileges.</exception>
/// <since_tizen> 4 </since_tizen>
[SuppressMessage("Microsoft.Performance", "CA1822:MarkMembersAsStatic")]
public ContactsList Search(ContactsQuery query, string keyword, int offset, int limit)
{
IntPtr recordList;
int error = Interop.Database.Search(query._queryHandle, keyword, offset, limit, out recordList);
if ((int)ContactsError.None != error)
{
Log.Error(Globals.LogTag, "Search Failed with error " + error);
throw ContactsErrorFactory.CheckAndCreateException(error);
}
return new ContactsList(recordList);
}
/// <summary>
/// Finds the records based on a keyword and range.
/// </summary>
/// <remarks>
/// This API works only for the views below:
/// Person, PersonContact, PersonGroupRelation, PersonGroupAssigned, PersonGroupNotAssigned, PersonNumber, and PersonEmail.
/// </remarks>
/// <param name="viewUri">The view URI.</param>
/// <param name="keyword">The keyword.</param>
/// <param name="offset">The index from which to get results.</param>
/// <param name="limit">The number to limit results (value 0 is used for get all records).</param>
/// <param name="range">The search range should be an element of the SearchRange or bitwise OR operation of them.</param>
/// <returns>The record list.</returns>
/// <privilege>http://tizen.org/privilege/contact.read</privilege>
/// <feature>http://tizen.org/feature/contact</feature>
/// <exception cref="InvalidOperationException">Thrown when the method failed due to an invalid operation.</exception>
/// <exception cref="NotSupportedException">Thrown when the feature is not supported.</exception>
/// <exception cref="ArgumentException">Thrown when one of the arguments provided to a method is not valid.</exception>
/// <exception cref="OutOfMemoryException">Thrown when failed due to out of memory.</exception>
/// <exception cref="UnauthorizedAccessException">Thrown when the application does not have proper privileges.</exception>
/// <since_tizen> 4 </since_tizen>
[SuppressMessage("Microsoft.Performance", "CA1822:MarkMembersAsStatic")]
[SuppressMessage("Microsoft.Design", "CA1054:UriParametersShouldNotBeStrings")]
public ContactsList Search(string viewUri, string keyword, int offset, int limit, int range)
{
IntPtr recordList;
int error = Interop.Database.Search(viewUri, keyword, offset, limit, range, out recordList);
if ((int)ContactsError.None != error)
{
Log.Error(Globals.LogTag, "Search Failed with error " + error);
throw ContactsErrorFactory.CheckAndCreateException(error);
}
return new ContactsList(recordList);
}
/// <summary>
/// Finds the records based on a given keyword for the snippet.
/// </summary>
/// <remarks>
/// This API works only for the views below:
/// Person, PersonContact, PersonGroupRelation, PersonGroupAssigned, and PersonGroupNotAssigned.
/// Because the start match and end match are needed to be composed with a keyword, this API performance is lower than Search (string viewUri, string keyword, int offset, int limit).
/// </remarks>
/// <param name="viewUri">The view URI to find records.</param>
/// <param name="keyword">The keyword.</param>
/// <param name="offset">The index from which to get results.</param>
/// <param name="limit">The number to limit results (value 0 is used for get all records).</param>
/// <param name="startMatch">The text, which is inserted into the fragment before the keyword (If NULL, default is "[".)</param>
/// <param name="endMatch">The text, which is inserted into the fragment after the keyword (If NULL, default is "]")</param>
/// <param name="tokenNumber">The one side extra number of tokens near keyword (If negative value, full sentence is printed. For example, if the token number is 3 with 'abc' keyword, snippet string will be like "my name is [abc]de and my home").</param>
/// <returns>The record list</returns>
/// <privilege>http://tizen.org/privilege/contact.read</privilege>
/// <feature>http://tizen.org/feature/contact</feature>
/// <exception cref="InvalidOperationException">Thrown when the method failed due to an invalid operation.</exception>
/// <exception cref="NotSupportedException">Thrown when the feature is not supported.</exception>
/// <exception cref="ArgumentException">Thrown when one of the arguments provided to a method is not valid.</exception>
/// <exception cref="OutOfMemoryException">Thrown when failed due to out of memory.</exception>
/// <exception cref="UnauthorizedAccessException">Thrown when the application does not have proper privileges.</exception>
/// <since_tizen> 4 </since_tizen>
[SuppressMessage("Microsoft.Performance", "CA1822:MarkMembersAsStatic")]
[SuppressMessage("Microsoft.Design", "CA1054:UriParametersShouldNotBeStrings")]
public ContactsList Search(string viewUri, string keyword, int offset, int limit, string startMatch, string endMatch, int tokenNumber)
{
IntPtr recordList;
int error = Interop.Database.Search(viewUri, keyword, offset, limit, startMatch, endMatch, tokenNumber, out recordList);
if ((int)ContactsError.None != error)
{
Log.Error(Globals.LogTag, "Search Failed with error " + error);
throw ContactsErrorFactory.CheckAndCreateException(error);
}
return new ContactsList(recordList);
}
/// <summary>
/// Finds the records based on a given query and keyword for the snippet.
/// </summary>
/// <remarks>
/// This API works only for the views below:
/// Person, PersonContact, PersonGroupRelation, PersonGroupAssigned, and PersonGroupNotAssigned.
/// Because the start match and end match are needed to be composed with a keyword, this API performance is lower than Search (ContactsQuery query, string keyword, int offset, int limit).
/// </remarks>
/// <param name="query">The query to filter.</param>
/// <param name="keyword">The keyword.</param>
/// <param name="offset">The index from which to get results.</param>
/// <param name="limit">The number to limit results (value 0 is used for get all records).</param>
/// <param name="startMatch">The text, which is inserted into the fragment before a keyword (If NULL, default is "[").</param>
/// <param name="endMatch">The text, which is inserted into the fragment after a keyword (If NULL, default is "]".)</param>
/// <param name="tokenNumber">The one side extra number of tokens near a keyword (If negative value, full sentence is printed. For example, if the token number is 3 with 'abc' keyword, snippet string will be like "my name is [abc]de and my home").</param>
/// <returns>The record list.</returns>
/// <privilege>http://tizen.org/privilege/contact.read</privilege>
/// <feature>http://tizen.org/feature/contact</feature>
/// <exception cref="InvalidOperationException">Thrown when the method failed due to an invalid operation.</exception>
/// <exception cref="NotSupportedException">Thrown when the feature is not supported.</exception>
/// <exception cref="ArgumentException">Thrown when one of the arguments provided to a method is not valid.</exception>
/// <exception cref="OutOfMemoryException">Thrown when failed due to out of memory.</exception>
/// <exception cref="UnauthorizedAccessException">Thrown when the application does not have proper privileges.</exception>
/// <since_tizen> 4 </since_tizen>
[SuppressMessage("Microsoft.Performance", "CA1822:MarkMembersAsStatic")]
public ContactsList Search(ContactsQuery query, string keyword, int offset, int limit, string startMatch, string endMatch, int tokenNumber)
{
IntPtr recordList;
int error = Interop.Database.Search(query._queryHandle, keyword, offset, limit, startMatch, endMatch, tokenNumber, out recordList);
if ((int)ContactsError.None != error)
{
Log.Error(Globals.LogTag, "Search Failed with error " + error);
throw ContactsErrorFactory.CheckAndCreateException(error);
}
return new ContactsList(recordList);
}
/// <summary>
/// Finds the records based on a keyword and range for the snippet.
/// </summary>
/// <remarks>
/// This API works only for the views below:
/// Person, PersonContact, PersonGroupRelation, PersonGroupAssigned, PersonGroupNotAssigned, PersonNumber, and PersonEmail,
/// Because the start match and end match are needed to be composed with a keyword, this API performance is lower than Search (string viewUri, string keyword, int offset, int limit, int range).
/// </remarks>
/// <param name="viewUri">The view URI.</param>
/// <param name="keyword">The keyword.</param>
/// <param name="offset">The index from which to get results.</param>
/// <param name="limit">The number to limit results (value 0 is used for get all records).</param>
/// <param name="range">The search range should be an element of the SearchRange or bitwise OR operation of them.</param>
/// <param name="startMatch">The text, which is inserted into the fragment before a keyword (If NULL, default is "[").</param>
/// <param name="endMatch">The text, which is inserted into the fragment after a keyword (If NULL, default is "]").</param>
/// <param name="tokenNumber">The one side extra number of tokens near a keyword (If negative value, full sentence is printed. For example, if a token number is 3 with 'abc' keyword, snippet string will be like "my name is [abc]de and my home").</param>
/// <returns>The record list.</returns>
/// <privilege>http://tizen.org/privilege/contact.read</privilege>
/// <feature>http://tizen.org/feature/contact</feature>
/// <exception cref="InvalidOperationException">Thrown when the method failed due to an invalid operation.</exception>
/// <exception cref="NotSupportedException">Thrown when the feature is not supported.</exception>
/// <exception cref="ArgumentException">Thrown when one of the arguments provided to a method is not valid.</exception>
/// <exception cref="OutOfMemoryException">Thrown when failed due to out of memory.</exception>
/// <exception cref="UnauthorizedAccessException">Thrown when the application does not have proper privileges.</exception>
/// <since_tizen> 4 </since_tizen>
[SuppressMessage("Microsoft.Performance", "CA1822:MarkMembersAsStatic")]
[SuppressMessage("Microsoft.Design", "CA1054:UriParametersShouldNotBeStrings")]
public ContactsList Search(string viewUri, string keyword, int offset, int limit, int range, string startMatch, string endMatch, int tokenNumber)
{
IntPtr recordList;
int error = Interop.Database.Search(viewUri, keyword, offset, limit, range, startMatch, endMatch, tokenNumber, out recordList);
if ((int)ContactsError.None != error)
{
Log.Error(Globals.LogTag, "Search Failed with error " + error);
throw ContactsErrorFactory.CheckAndCreateException(error);
}
return new ContactsList(recordList);
}
/// <summary>
/// Gets the number of records in a specific view.
/// </summary>
/// <param name="viewUri">The view URI.</param>
/// <returns>The count of records.</returns>
/// <since_tizen> 4 </since_tizen>
[SuppressMessage("Microsoft.Performance", "CA1822:MarkMembersAsStatic")]
[SuppressMessage("Microsoft.Design", "CA1054:UriParametersShouldNotBeStrings")]
public int GetCount(string viewUri)
{
int count = -1;
int error = Interop.Database.GetCount(viewUri, out count);
if ((int)ContactsError.None != error)
{
Log.Error(Globals.LogTag, "GetCount Failed with error " + error);
throw ContactsErrorFactory.CheckAndCreateException(error);
}
return count;
}
/// <summary>
/// Gets the number of records matching a query.
/// </summary>
/// <param name="query">The query used for filtering the results.</param>
/// <returns>The count of records.</returns>
/// <since_tizen> 4 </since_tizen>
[SuppressMessage("Microsoft.Performance", "CA1822:MarkMembersAsStatic")]
public int GetCount(ContactsQuery query)
{
int count = -1;
int error = Interop.Database.GetCount(query._queryHandle, out count);
if ((int)ContactsError.None != error)
{
Log.Error(Globals.LogTag, "GetCount Failed with error " + error);
throw ContactsErrorFactory.CheckAndCreateException(error);
}
return count;
}
/// <summary>
/// Registers an EventHandler to be invoked when a record changes.
/// </summary>
/// <param name="viewUri">The view URI of records whose changes are monitored.</param>
/// <param name="DBChanged">The EventHandler to register.</param>
/// <privilege>http://tizen.org/privilege/contact.read</privilege>
/// <privilege>http://tizen.org/privilege/callhistory.read</privilege>
/// <feature>http://tizen.org/feature/contact</feature>
/// <exception cref="InvalidOperationException">Thrown when the method failed due to an invalid operation.</exception>
/// <exception cref="NotSupportedException">Thrown when the feature is not supported.</exception>
/// <exception cref="ArgumentException">Thrown when one of the arguments provided to a method is not valid.</exception>
/// <exception cref="OutOfMemoryException">Thrown when failed due to out of memory.</exception>
/// <exception cref="UnauthorizedAccessException">Thrown when the application does not have proper privileges.</exception>
/// <since_tizen> 4 </since_tizen>
[SuppressMessage("Microsoft.Design", "CA1054:UriParametersShouldNotBeStrings")]
public void AddDBChangedEventHandler(string viewUri, EventHandler<DBChangedEventArgs> DBChanged)
{
if (!_callbackMap.ContainsKey(viewUri))
{
_callbackMap[viewUri] = (string uri, IntPtr userData) =>
{
DBChangedEventArgs args = new DBChangedEventArgs(uri);
_eventHandlerMap[uri]?.Invoke(this, args);
};
int error = Interop.Database.AddChangedCb(viewUri, _callbackMap[viewUri], IntPtr.Zero);
if ((int)ContactsError.None != error)
{
Log.Error(Globals.LogTag, "AddDBChangedEventHandler Failed with error " + error);
throw ContactsErrorFactory.CheckAndCreateException(error);
}
}
EventHandler<DBChangedEventArgs> handler = null;
if (!_eventHandlerMap.TryGetValue(viewUri, out handler))
_eventHandlerMap.Add(viewUri, null);
_eventHandlerMap[viewUri] = handler + DBChanged;
}
/// <summary>
/// Deregisters an EventHandler.
/// </summary>
/// <param name="viewUri">The view URI of records whose changes are monitored.</param>
/// <param name="DBChanged">The EventHandler to deregister.</param>
/// <feature>http://tizen.org/feature/contact</feature>
/// <exception cref="InvalidOperationException">Thrown when the method failed due to an invalid operation.</exception>
/// <exception cref="NotSupportedException">Thrown when the feature is not supported.</exception>
/// <exception cref="ArgumentException">Thrown when one of the arguments provided to a method is not valid.</exception>
/// <exception cref="OutOfMemoryException">Thrown when failed due to out of memory.</exception>
/// <since_tizen> 4 </since_tizen>
[SuppressMessage("Microsoft.Design", "CA1054:UriParametersShouldNotBeStrings")]
public void RemoveDBChangedEventHandler(string viewUri, EventHandler<DBChangedEventArgs> DBChanged)
{
EventHandler<DBChangedEventArgs> handler = null;
if (!_eventHandlerMap.TryGetValue(viewUri, out handler))
_eventHandlerMap.Add(viewUri, null);
else
_eventHandlerMap[viewUri] = handler - DBChanged;
if (_eventHandlerMap[viewUri] == null)
{
int error = Interop.Database.RemoveChangedCb(viewUri, _callbackMap[viewUri], IntPtr.Zero);
if ((int)ContactsError.None != error)
{
Log.Error(Globals.LogTag, "RemoveDBChangedEventHandler Failed with error " + error);
throw ContactsErrorFactory.CheckAndCreateException(error);
}
_callbackMap.Remove(viewUri);
}
}
}
}