-
Notifications
You must be signed in to change notification settings - Fork 242
/
CalendarDatabase.cs
635 lines (603 loc) · 33.9 KB
/
CalendarDatabase.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
/*
* 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.Runtime.InteropServices;
using System.Diagnostics.CodeAnalysis;
namespace Tizen.Pims.Calendar
{
/// <summary>
/// The CalendarDatabase provides methods to manage calendar information from/to the database.
/// </summary>
/// <remarks>
/// This class allows user to access/create/update/delete database operations for the calendar information.
/// The CalendarDatabase is created by the CalendarManager.
/// </remarks>
/// <since_tizen> 4 </since_tizen>
public class CalendarDatabase
{
private Object thisLock = new Object();
private Dictionary<string, EventHandler<DBChangedEventArgs>> _eventHandlerMap = new Dictionary<string, EventHandler<DBChangedEventArgs>>();
private Dictionary<string, Interop.Database.DBChangedCallback> _callbackMap = new Dictionary<string, Interop.Database.DBChangedCallback>();
internal CalendarDatabase()
{
/*To be created in CalendarManager only*/
}
/// <summary>
/// The calendar database version.
/// </summary>
/// <since_tizen> 4 </since_tizen>
/// <value>The current calendar database version.</value>
[SuppressMessage("Microsoft.Performance", "CA1822:MarkMembersAsStatic")]
public int Version
{
get
{
int version = -1;
int error = Interop.Database.GetCurrentVersion(out version);
if (CalendarError.None != (CalendarError)error)
{
Log.Error(Globals.LogTag, "Version Failed with error " + error);
}
return version;
}
}
/// <summary>
/// Gets the last successful changed calendar database version on the current connection.
/// </summary>
/// <since_tizen> 4 </since_tizen>
/// <returns>The last successful changed calendar database version on the current connection.</returns>
/// <privilege>http://tizen.org/privilege/calendar.read</privilege>
/// <exception cref="InvalidOperationException">Thrown when the method failed due to an invalid operation.</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>
/// <value>The last successful changed calendar database version on the current connection.</value>
[SuppressMessage("Microsoft.Performance", "CA1822:MarkMembersAsStatic")]
public int LastChangeVersion
{
get
{
int version = -1;
int error = Interop.Database.GetLastChangeVersion(out version);
if (CalendarError.None != (CalendarError)error)
{
Log.Error(Globals.LogTag, "LastChangeVersion Failed with error " + error);
}
return version;
}
}
/// <summary>
/// Inserts a record into the calendar database.
/// </summary>
/// <since_tizen> 4 </since_tizen>
/// <param name="record">The record to be inserted.</param>
/// <returns>The ID of inserted record.</returns>
/// <privilege>http://tizen.org/privilege/calendar.write</privilege>
/// <feature>http://tizen.org/feature/calendar</feature>
/// <exception cref="NotSupportedException">Thrown when the feature is not supported.</exception>
/// <exception cref="InvalidOperationException">Thrown when the method failed due to an invalid operation.</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>
[SuppressMessage("Microsoft.Performance", "CA1822:MarkMembersAsStatic")]
public int Insert(CalendarRecord record)
{
int id = -1;
int error = Interop.Database.Insert(record._recordHandle, out id);
if (CalendarError.None != (CalendarError)error)
{
Log.Error(Globals.LogTag, "Insert Failed with error " + error);
throw CalendarErrorFactory.GetException(error);
}
return id;
}
/// <summary>
/// Gets a record from the calendar database.
/// </summary>
/// <since_tizen> 4 </since_tizen>
/// <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/calendar.read</privilege>
/// <feature>http://tizen.org/feature/calendar</feature>
/// <exception cref="NotSupportedException">Thrown when feature is not supported.</exception>
/// <exception cref="InvalidOperationException">Thrown when the method failed due to an invalid operation.</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>
[SuppressMessage("Microsoft.Performance", "CA1822:MarkMembersAsStatic")]
[SuppressMessage("Microsoft.Design", "CA1054:UriParametersShouldNotBeStrings")]
public CalendarRecord Get(string viewUri, int recordId)
{
IntPtr handle;
int error = Interop.Database.Get(viewUri, recordId, out handle);
if (CalendarError.None != (CalendarError)error)
{
if (CalendarError.DBNotFound == (CalendarError)error)
{
Log.Error(Globals.LogTag, "No data" + error);
return null;
}
Log.Error(Globals.LogTag, "Get Failed with error " + error);
throw CalendarErrorFactory.GetException(error);
}
return new CalendarRecord(handle);
}
/// <summary>
/// Updates a record in the calendar database.
/// </summary>
/// <since_tizen> 4 </since_tizen>
/// <param name="record">The record to be updated.</param>
/// <privilege>http://tizen.org/privilege/calendar.write</privilege>
/// <feature>http://tizen.org/feature/calendar</feature>
/// <exception cref="NotSupportedException">Thrown when the feature is not supported.</exception>
/// <exception cref="InvalidOperationException">Thrown when the method failed due to an invalid operation.</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>
[SuppressMessage("Microsoft.Performance", "CA1822:MarkMembersAsStatic")]
public void Update(CalendarRecord record)
{
int error = Interop.Database.Update(record._recordHandle);
if (CalendarError.None != (CalendarError)error)
{
Log.Error(Globals.LogTag, "Update Failed with error " + error);
throw CalendarErrorFactory.GetException(error);
}
}
/// <summary>
/// Deletes a record from the calendar database with related child records.
/// </summary>
/// <since_tizen> 4 </since_tizen>
/// <param name="viewUri">The view URI of a record.</param>
/// <param name="recordId">The record ID to be deleted.</param>
/// <privilege>http://tizen.org/privilege/calendar.write</privilege>
/// <feature>http://tizen.org/feature/calendar</feature>
/// <exception cref="NotSupportedException">Thrown when the feature is not supported.</exception>
/// <exception cref="InvalidOperationException">Thrown when the method failed due to an invalid operation.</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>
[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 (CalendarError.None != (CalendarError)error)
{
Log.Error(Globals.LogTag, "Delete Failed with error " + error);
throw CalendarErrorFactory.GetException(error);
}
}
/// <summary>
/// Replaces a record in the calendar database.
/// </summary>
/// <since_tizen> 4 </since_tizen>
/// <param name="record">The record to be replaced.</param>
/// <param name="id">The record ID.</param>
/// <privilege>http://tizen.org/privilege/calendar.write</privilege>
/// <feature>http://tizen.org/feature/calendar</feature>
/// <exception cref="NotSupportedException">Thrown when the feature is not supported.</exception>
/// <exception cref="InvalidOperationException">Thrown when the method failed due to an invalid operation.</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>
[SuppressMessage("Microsoft.Performance", "CA1822:MarkMembersAsStatic")]
public void Replace(CalendarRecord record, int id)
{
int error = Interop.Database.Replace(record._recordHandle, id);
if (CalendarError.None != (CalendarError)error)
{
Log.Error(Globals.LogTag, "Replace Failed with error " + error);
throw CalendarErrorFactory.GetException(error);
}
}
/// <summary>
/// Retrieves all the records as a list.
/// </summary>
/// <since_tizen> 4 </since_tizen>
/// <param name="viewUri">The view URI to get records from.</param>
/// <param name="offset">The index from which results are received.</param>
/// <param name="limit">The maximum number of results (value 0 is used for all the records).</param>
/// <returns>
/// The record list.
/// </returns>
/// <privilege>http://tizen.org/privilege/calendar.read</privilege>
/// <feature>http://tizen.org/feature/calendar</feature>
/// <exception cref="NotSupportedException">Thrown when the feature is not supported.</exception>
/// <exception cref="InvalidOperationException">Thrown when the method failed due to an invalid operation.</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>
[SuppressMessage("Microsoft.Performance", "CA1822:MarkMembersAsStatic")]
[SuppressMessage("Microsoft.Design", "CA1054:UriParametersShouldNotBeStrings")]
public CalendarList GetAll(string viewUri, int offset, int limit)
{
IntPtr handle;
int error = Interop.Database.GetAllRecords(viewUri, offset, limit, out handle);
if (CalendarError.None != (CalendarError)error)
{
Log.Error(Globals.LogTag, "GetAll Failed with error " + error);
throw CalendarErrorFactory.GetException(error);
}
return new CalendarList(handle);
}
/// <summary>
/// Retrieves the records using a query.
/// </summary>
/// <since_tizen> 4 </since_tizen>
/// <param name="query">The query used to filter results.</param>
/// <param name="offset">The index from which results are received.</param>
/// <param name="limit">The maximum number of results (value 0 is used for all the records).</param>
/// <returns>
/// CalendarList.
/// </returns>
/// <privilege>http://tizen.org/privilege/calendar.read</privilege>
/// <feature>http://tizen.org/feature/calendar</feature>
/// <exception cref="NotSupportedException">Thrown when the feature is not supported.</exception>
/// <exception cref="InvalidOperationException">Thrown when the method failed due to an invalid operation.</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>
[SuppressMessage("Microsoft.Performance", "CA1822:MarkMembersAsStatic")]
public CalendarList GetRecordsWithQuery(CalendarQuery query, int offset, int limit)
{
IntPtr handle;
int error = Interop.Database.GetRecords(query._queryHandle, offset, limit, out handle);
if (CalendarError.None != (CalendarError)error)
{
Log.Error(Globals.LogTag, "GetAllWithQuery Failed with error " + error);
throw CalendarErrorFactory.GetException(error);
}
return new CalendarList(handle);
}
/// <summary>
/// Inserts multiple records into the calendar database as a batch operation.
/// </summary>
/// <since_tizen> 4 </since_tizen>
/// <param name="list">The record list.</param>
/// <returns>
/// The inserted record ID array.
/// </returns>
/// <privilege>http://tizen.org/privilege/calendar.write</privilege>
/// <feature>http://tizen.org/feature/calendar</feature>
/// <exception cref="NotSupportedException">Thrown when the feature is not supported.</exception>
/// <exception cref="InvalidOperationException">Thrown when the method failed due to an invalid operation.</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>
[SuppressMessage("Microsoft.Performance", "CA1822:MarkMembersAsStatic")]
public int[] Insert(CalendarList list)
{
IntPtr ids;
int count;
int error = Interop.Database.InsertRecords(list._listHandle, out ids, out count);
if (CalendarError.None != (CalendarError)error)
{
Log.Error(Globals.LogTag, "Insert Failed with error " + error);
throw CalendarErrorFactory.GetException(error);
}
int[] idArr = new int[count];
Marshal.Copy(ids, idArr, 0, count);
return idArr;
}
/// <summary>
/// Updates multiple records into the calendar database as a batch operation.
/// </summary>
/// <since_tizen> 4 </since_tizen>
/// <param name="list">The record list.</param>
/// <privilege>http://tizen.org/privilege/calendar.write</privilege>
/// <feature>http://tizen.org/feature/calendar</feature>
/// <exception cref="NotSupportedException">Thrown when the feature is not supported.</exception>
/// <exception cref="InvalidOperationException">Thrown when the method failed due to an invalid operation.</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>
[SuppressMessage("Microsoft.Performance", "CA1822:MarkMembersAsStatic")]
public void Update(CalendarList list)
{
int error = Interop.Database.UpdateRecords(list._listHandle);
if (CalendarError.None != (CalendarError)error)
{
Log.Error(Globals.LogTag, "Update Failed with error " + error);
throw CalendarErrorFactory.GetException(error);
}
}
/// <summary>
/// Deletes multiple records with the related child records from the calendar database as a batch operation.
/// </summary>
/// <since_tizen> 4 </since_tizen>
/// <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/calendar.write</privilege>
/// <feature>http://tizen.org/feature/calendar</feature>
/// <exception cref="NotSupportedException">Thrown when the feature is not supported.</exception>
/// <exception cref="InvalidOperationException">Thrown when the method failed due to an invalid operation.</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>
[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 (CalendarError.None != (CalendarError)error)
{
Log.Error(Globals.LogTag, "Delete Failed with error " + error);
throw CalendarErrorFactory.GetException(error);
}
}
/// <summary>
/// Deletes multiple records with the related child records from the calendar database as a batch operation.
/// </summary>
/// <since_tizen> 4 </since_tizen>
/// <param name="list">The record list.</param>
/// <privilege>http://tizen.org/privilege/calendar.write</privilege>
/// <feature>http://tizen.org/feature/calendar</feature>
/// <exception cref="NotSupportedException">Thrown when the feature is not supported.</exception>
/// <exception cref="InvalidOperationException">Thrown when the method failed due to an invalid operation.</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>
public void Delete(CalendarList list)
{
CalendarRecord record = null;
if (list.Count <= 0)
return;
int[] ids = new int[list.Count];
int i;
uint propertyId = 0;
list.MoveFirst();
for (i = 0; i < list.Count; i++)
{
record = list.GetCurrentRecord();
if (0 == propertyId)
{
if (0 == String.Compare(CalendarViews.Book.Uri, record.Uri))
propertyId = CalendarViews.Book.Id;
else if (0 == String.Compare(CalendarViews.Event.Uri, record.Uri))
propertyId = CalendarViews.Event.Id;
else if (0 == String.Compare(CalendarViews.Todo.Uri, record.Uri))
propertyId = CalendarViews.Todo.Id;
else if (0 == String.Compare(CalendarViews.Timezone.Uri, record.Uri))
propertyId = CalendarViews.Timezone.Id;
else if (0 == String.Compare(CalendarViews.Extended.Uri, record.Uri))
propertyId = CalendarViews.Extended.Id;
else
{
Log.Error(Globals.LogTag, "Invalid uri [" + record.Uri + "]");
continue;
}
}
ids[i] = record.Get<int>(propertyId);
list.MoveNext();
}
Delete(record.Uri, ids);
}
/// <summary>
/// Replaces multiple records in the calendar database as a batch operation.
/// </summary>
/// <since_tizen> 4 </since_tizen>
/// <param name="list">The record list.</param>
/// <param name="idArray">The record IDs.</param>
/// <privilege>http://tizen.org/privilege/calendar.write</privilege>
/// <feature>http://tizen.org/feature/calendar</feature>
/// <exception cref="NotSupportedException">Thrown when the feature is not supported.</exception>
/// <exception cref="InvalidOperationException">Thrown when the method failed due to an invalid operation.</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>
[SuppressMessage("Microsoft.Performance", "CA1822:MarkMembersAsStatic")]
public void Replace(CalendarList list, int[] idArray)
{
int error = Interop.Database.ReplaceRecords(list._listHandle, idArray, idArray.Length);
if (CalendarError.None != (CalendarError)error)
{
Log.Error(Globals.LogTag, "Replace Failed with error " + error);
throw CalendarErrorFactory.GetException(error);
}
}
/// <summary>
/// Retrieves the records with the given calendar database version.
/// </summary>
/// <since_tizen> 4 </since_tizen>
/// <param name="viewUri">The view URI to get records from.</param>
/// <param name="BookId">The calendar book ID to filter.</param>
/// <param name="calendarDBVersion">The calendar database version.</param>
/// <param name="currentDBVersion">The current calendar database version.</param>
/// <returns>
/// The record list.
/// </returns>
/// <privilege>http://tizen.org/privilege/calendar.read</privilege>
/// <feature>http://tizen.org/feature/calendar</feature>
/// <exception cref="NotSupportedException">Thrown when the feature is not supported.</exception>
/// <exception cref="InvalidOperationException">Thrown when the method failed due to an invalid operation.</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>
[SuppressMessage("Microsoft.Performance", "CA1822:MarkMembersAsStatic")]
[SuppressMessage("Microsoft.Design", "CA1054:UriParametersShouldNotBeStrings")]
public CalendarList GetChangesByVersion(string viewUri, int BookId, int calendarDBVersion, out int currentDBVersion)
{
IntPtr recordList;
int error = Interop.Database.GetChangesByVersion(viewUri, BookId, calendarDBVersion, out recordList, out currentDBVersion);
if (CalendarError.None != (CalendarError)error)
{
Log.Error(Globals.LogTag, "GetChangesByVersion Failed with error " + error);
throw CalendarErrorFactory.GetException(error);
}
return new CalendarList(recordList);
}
/// <summary>
/// Gets the record count of a specific view.
/// </summary>
/// <since_tizen> 4 </since_tizen>
/// <param name="viewUri">The view URI to get records from.</param>
/// <returns>
/// The count of records.
/// </returns>
/// <privilege>http://tizen.org/privilege/calendar.read</privilege>
[SuppressMessage("Microsoft.Design", "CA1822:MarkMembersAsStatic")]
[SuppressMessage("Microsoft.Design", "CA1054:UriParametersShouldNotBeStrings")]
public int GetCount(string viewUri)
{
int count = -1;
int error = Interop.Database.GetCount(viewUri, out count);
if (CalendarError.None != (CalendarError)error)
{
Log.Error(Globals.LogTag, "GetCount Failed with error " + error);
throw CalendarErrorFactory.GetException(error);
}
return count;
}
/// <summary>
/// Gets the record count with a query.
/// </summary>
/// <since_tizen> 4 </since_tizen>
/// <param name="query">The query used for filtering the results.</param>
/// <returns>
/// The count of records.
/// </returns>
/// <privilege>http://tizen.org/privilege/calendar.read</privilege>
[SuppressMessage("Microsoft.Design", "CA1822:MarkMembersAsStatic")]
public int GetCount(CalendarQuery query)
{
int count = -1;
int error = Interop.Database.GetCountWithQuery(query._queryHandle, out count);
if (CalendarError.None != (CalendarError)error)
{
Log.Error(Globals.LogTag, "GetCount Failed with error " + error);
throw CalendarErrorFactory.GetException(error);
}
return count;
}
/// <summary>
/// Registers a callback function to be invoked when a record changes.
/// </summary>
/// <since_tizen> 4 </since_tizen>
/// <param name="viewUri">The view URI of the record to subscribe for change notifications.</param>
/// <param name="DBChanged">The EventHandler to register.</param>
/// <privilege>http://tizen.org/privilege/calendar.read</privilege>
/// <feature>http://tizen.org/feature/calendar</feature>
/// <exception cref="NotSupportedException">Thrown when the feature is not supported.</exception>
/// <exception cref="InvalidOperationException">Thrown when the method failed due to an invalid operation.</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>
[SuppressMessage("Microsoft.Design", "CA1054:UriParametersShouldNotBeStrings")]
public void AddDBChangedDelegate(string viewUri, EventHandler<DBChangedEventArgs> DBChanged)
{
Log.Debug(Globals.LogTag, "AddDBChangedDelegate");
if (!_callbackMap.ContainsKey(viewUri))
{
_callbackMap[viewUri] = (string uri, IntPtr userData) =>
{
DBChangedEventArgs args = new DBChangedEventArgs(uri);
_eventHandlerMap[uri]?.Invoke(this, args);
};
int error = Interop.Database.AddChangedCallback(viewUri, _callbackMap[viewUri], IntPtr.Zero);
if (CalendarError.None != (CalendarError)error)
{
Log.Error(Globals.LogTag, "AddDBChangedDelegate Failed with error " + error);
throw CalendarErrorFactory.GetException(error);
}
}
EventHandler<DBChangedEventArgs> handler = null;
if (!_eventHandlerMap.TryGetValue(viewUri, out handler))
_eventHandlerMap.Add(viewUri, null);
_eventHandlerMap[viewUri] = handler + DBChanged;
}
/// <summary>
/// Deregisters a callback function.
/// </summary>
/// <since_tizen> 4 </since_tizen>
/// <param name="viewUri">The view URI of the record to subscribe for change notifications.</param>
/// <param name="DBChanged">The EventHandler to deregister.</param>
/// <privilege>http://tizen.org/privilege/calendar.read</privilege>
/// <feature>http://tizen.org/feature/calendar</feature>
/// <exception cref="NotSupportedException">Thrown when the feature is not supported.</exception>
/// <exception cref="InvalidOperationException">Thrown when the method failed due to an invalid operation.</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>
[SuppressMessage("Microsoft.Design", "CA1054:UriParametersShouldNotBeStrings")]
public void RemoveDBChangedDelegate(string viewUri, EventHandler<DBChangedEventArgs> DBChanged)
{
Log.Debug(Globals.LogTag, "RemoveDBChangedDelegate");
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.RemoveChangedCallback(viewUri, _callbackMap[viewUri], IntPtr.Zero);
if (CalendarError.None != (CalendarError)error)
{
Log.Error(Globals.LogTag, "RemoveDBChangedDelegate Failed with error " + error);
throw CalendarErrorFactory.GetException(error);
}
_callbackMap.Remove(viewUri);
}
}
/// <summary>
/// Links a record to another record.
/// </summary>
/// <since_tizen> 4 </since_tizen>
/// <param name="baseId">The base record ID.</param>
/// <param name="recordId">The record ID to link to.</param>
/// <privilege>http://tizen.org/privilege/calendar.write</privilege>
/// <feature>http://tizen.org/feature/calendar</feature>
/// <exception cref="NotSupportedException">Thrown when the feature is not supported.</exception>
/// <exception cref="InvalidOperationException">Thrown when the method failed due to an invalid operation.</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>
[SuppressMessage("Microsoft.Design", "CA1822:MarkMembersAsStatic")]
public void LinkRecord(int baseId, int recordId)
{
Log.Debug(Globals.LogTag, "LinkRecord");
int error = Interop.Database.LinkRecord(baseId, recordId);
if (CalendarError.None != (CalendarError)error)
{
Log.Error(Globals.LogTag, "LinkRecor Failed with error " + error);
throw CalendarErrorFactory.GetException(error);
}
}
/// <summary>
/// Unlinks a record from the base record.
/// </summary>
/// <since_tizen> 4 </since_tizen>
/// <param name="recordId">The record ID to unlink.</param>
/// <privilege>http://tizen.org/privilege/calendar.write</privilege>
/// <feature>http://tizen.org/feature/calendar</feature>
/// <exception cref="NotSupportedException">Thrown when the feature is not supported.</exception>
/// <exception cref="InvalidOperationException">Thrown when the method failed due to an invalid operation.</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>
[SuppressMessage("Microsoft.Performance", "CA1822:MarkMembersAsStatic")]
public void UnlinkRecord(int recordId)
{
Log.Debug(Globals.LogTag, "UnlinkRecord");
int error = Interop.Database.UnlinkRecord(recordId);
if (CalendarError.None != (CalendarError)error)
{
Log.Error(Globals.LogTag, "UnlinkRecor Failed with error " + error);
throw CalendarErrorFactory.GetException(error);
}
}
}
}