Fix XML documentation warnings
[platform/core/csapi/tizenfx.git] / src / Tizen.Pims.Calendar / Tizen.Pims.Calendar / CalendarDatabase.cs
1 /*
2  * Copyright (c) 2016 Samsung Electronics Co., Ltd All Rights Reserved
3  *
4  * Licensed under the Apache License, Version 2.0 (the License);
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an AS IS BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16
17 using System;
18 using System.Collections.Generic;
19 using System.Runtime.InteropServices;
20 using System.Diagnostics.CodeAnalysis;
21
22 namespace Tizen.Pims.Calendar
23 {
24     /// <summary>
25     /// CalendarDatabase provides methods to manage calendar information from/to the database.
26     /// </summary>
27     /// <remarks>
28     /// This class allows user to access/create/update/delete db operations for calendar information.
29     /// CalendarDatabase is created by CalendarManager.
30     /// </remarks>
31     /// <since_tizen> 4 </since_tizen>
32     public class CalendarDatabase
33     {
34         private Object thisLock = new Object();
35         private Dictionary<string, EventHandler<DBChangedEventArgs>> _eventHandlerMap = new Dictionary<string, EventHandler<DBChangedEventArgs>>();
36         private Dictionary<string, Interop.Database.DBChangedCallback> _callbackMap = new Dictionary<string, Interop.Database.DBChangedCallback>();
37
38         internal CalendarDatabase()
39         {
40             /*To be created in CalendarManager only*/
41         }
42
43         /// <summary>
44         /// The calendar database version.
45         /// </summary>
46         /// <since_tizen> 4 </since_tizen>
47         /// <value>The current calendar database version.</value>
48         [SuppressMessage("Microsoft.Performance", "CA1822:MarkMembersAsStatic")]
49         public int Version
50         {
51             get
52             {
53                 int version = -1;
54                 int error = Interop.Database.GetCurrentVersion(out version);
55                 if (CalendarError.None != (CalendarError)error)
56                 {
57                     Log.Error(Globals.LogTag, "Version Failed with error " + error);
58                 }
59                 return version;
60             }
61         }
62
63         /// <summary>
64         /// Gets last successful changed calendar database version on the current connection.
65         /// </summary>
66         /// <since_tizen> 4 </since_tizen>
67         /// <returns>The last successful changed calendar database version on the current connection</returns>
68         /// <privilege>http://tizen.org/privilege/calendar.read</privilege>
69         /// <exception cref="InvalidOperationException">Thrown when method failed due to invalid operation</exception>
70         /// <exception cref="OutOfMemoryException">Thrown when failed due to out of memory</exception>
71         /// <exception cref="UnauthorizedAccessException">Thrown when application does not have proper privileges</exception>
72         /// <value>The last successful changed calendar database version on the current connection.</value>
73         [SuppressMessage("Microsoft.Performance", "CA1822:MarkMembersAsStatic")]
74         public int LastChangeVersion
75         {
76             get
77             {
78                 int version = -1;
79                 int error = Interop.Database.GetLastChangeVersion(out version);
80                 if (CalendarError.None != (CalendarError)error)
81                 {
82                     Log.Error(Globals.LogTag, "LastChangeVersion Failed with error " + error);
83                 }
84                 return version;
85             }
86         }
87
88         /// <summary>
89         /// Inserts a record into the calendar database.
90         /// </summary>
91         /// <since_tizen> 4 </since_tizen>
92         /// <param name="record">The record to be inserted</param>
93         /// <returns>The ID of inserted record</returns>
94         /// <privilege>http://tizen.org/privilege/calendar.write</privilege>
95         /// <feature>http://tizen.org/feature/calendar</feature>
96         /// <exception cref="NotSupportedException">Thrown when feature is not supported</exception>
97         /// <exception cref="InvalidOperationException">Thrown when method failed due to invalid operation</exception>
98         /// <exception cref="ArgumentException">Thrown when one of the arguments provided to a method is not valid</exception>
99         /// <exception cref="OutOfMemoryException">Thrown when failed due to out of memory</exception>
100         /// <exception cref="UnauthorizedAccessException">Thrown when application does not have proper privileges</exception>
101         [SuppressMessage("Microsoft.Performance", "CA1822:MarkMembersAsStatic")]
102         public int Insert(CalendarRecord record)
103         {
104             int id = -1;
105             int error = Interop.Database.Insert(record._recordHandle, out id);
106             if (CalendarError.None != (CalendarError)error)
107             {
108                 Log.Error(Globals.LogTag, "Insert Failed with error " + error);
109                 throw CalendarErrorFactory.GetException(error);
110             }
111             return id;
112         }
113
114         /// <summary>
115         /// Gets a record from the calendar database.
116         /// </summary>
117         /// <since_tizen> 4 </since_tizen>
118         /// <param name="viewUri">The view URI of a record</param>
119         /// <param name="recordId">The record ID</param>
120         /// <returns>
121         /// The record associated with the record ID
122         /// </returns>
123         /// <privilege>http://tizen.org/privilege/calendar.read</privilege>
124         /// <feature>http://tizen.org/feature/calendar</feature>
125         /// <exception cref="NotSupportedException">Thrown when feature is not supported</exception>
126         /// <exception cref="InvalidOperationException">Thrown when method failed due to invalid operation</exception>
127         /// <exception cref="ArgumentException">Thrown when one of the arguments provided to a method is not valid</exception>
128         /// <exception cref="OutOfMemoryException">Thrown when failed due to out of memory</exception>
129         /// <exception cref="UnauthorizedAccessException">Thrown when application does not have proper privileges</exception>
130         [SuppressMessage("Microsoft.Performance", "CA1822:MarkMembersAsStatic")]
131         [SuppressMessage("Microsoft.Design", "CA1054:UriParametersShouldNotBeStrings")]
132         public CalendarRecord Get(string viewUri, int recordId)
133         {
134             IntPtr handle;
135             int error = Interop.Database.Get(viewUri, recordId, out handle);
136             if (CalendarError.None != (CalendarError)error)
137             {
138                                 if (CalendarError.DBNotFound == (CalendarError)error)
139                                 {
140                                         Log.Error(Globals.LogTag, "No data" + error);
141                                         return null;
142                                 }
143                                 Log.Error(Globals.LogTag, "Get Failed with error " + error);
144                                 throw CalendarErrorFactory.GetException(error);
145             }
146             return new CalendarRecord(handle);
147         }
148
149         /// <summary>
150         /// Updates a record in the calendar database.
151         /// </summary>
152         /// <since_tizen> 4 </since_tizen>
153         /// <param name="record">The record to be updated</param>
154         /// <privilege>http://tizen.org/privilege/calendar.write</privilege>
155         /// <feature>http://tizen.org/feature/calendar</feature>
156         /// <exception cref="NotSupportedException">Thrown when feature is not supported</exception>
157         /// <exception cref="InvalidOperationException">Thrown when method failed due to invalid operation</exception>
158         /// <exception cref="ArgumentException">Thrown when one of the arguments provided to a method is not valid</exception>
159         /// <exception cref="OutOfMemoryException">Thrown when failed due to out of memory</exception>
160         /// <exception cref="UnauthorizedAccessException">Thrown when application does not have proper privileges</exception>
161         [SuppressMessage("Microsoft.Performance", "CA1822:MarkMembersAsStatic")]
162         public void Update(CalendarRecord record)
163         {
164             int error = Interop.Database.Update(record._recordHandle);
165             if (CalendarError.None != (CalendarError)error)
166             {
167                 Log.Error(Globals.LogTag, "Update Failed with error " + error);
168                 throw CalendarErrorFactory.GetException(error);
169             }
170         }
171
172         /// <summary>
173         /// Deletes a record from the calendar database with related child records.
174         /// </summary>
175         /// <since_tizen> 4 </since_tizen>
176         /// <param name="viewUri">The view URI of a record</param>
177         /// <param name="recordId">The record ID to be deleted</param>
178         /// <privilege>http://tizen.org/privilege/calendar.write</privilege>
179         /// <feature>http://tizen.org/feature/calendar</feature>
180         /// <exception cref="NotSupportedException">Thrown when feature is not supported</exception>
181         /// <exception cref="InvalidOperationException">Thrown when method failed due to invalid operation</exception>
182         /// <exception cref="ArgumentException">Thrown when one of the arguments provided to a method is not valid</exception>
183         /// <exception cref="OutOfMemoryException">Thrown when failed due to out of memory</exception>
184         /// <exception cref="UnauthorizedAccessException">Thrown when application does not have proper privileges</exception>
185         [SuppressMessage("Microsoft.Performance", "CA1822:MarkMembersAsStatic")]
186         [SuppressMessage("Microsoft.Design", "CA1054:UriParametersShouldNotBeStrings")]
187         public void Delete(string viewUri, int recordId)
188         {
189             int error = Interop.Database.Delete(viewUri, recordId);
190             if (CalendarError.None != (CalendarError)error)
191             {
192                 Log.Error(Globals.LogTag, "Delete Failed with error " + error);
193                 throw CalendarErrorFactory.GetException(error);
194             }
195         }
196
197         /// <summary>
198         /// Replaces a record in the calendar database.
199         /// </summary>
200         /// <since_tizen> 4 </since_tizen>
201         /// <param name="record">The record to be replaced</param>
202         /// <param name="id">the record id</param>
203         /// <privilege>http://tizen.org/privilege/calendar.write</privilege>
204         /// <feature>http://tizen.org/feature/calendar</feature>
205         /// <exception cref="NotSupportedException">Thrown when feature is not supported</exception>
206         /// <exception cref="InvalidOperationException">Thrown when method failed due to invalid operation</exception>
207         /// <exception cref="ArgumentException">Thrown when one of the arguments provided to a method is not valid</exception>
208         /// <exception cref="OutOfMemoryException">Thrown when failed due to out of memory</exception>
209         /// <exception cref="UnauthorizedAccessException">Thrown when application does not have proper privileges</exception>
210         [SuppressMessage("Microsoft.Performance", "CA1822:MarkMembersAsStatic")]
211         public void Replace(CalendarRecord record, int id)
212         {
213             int error = Interop.Database.Replace(record._recordHandle, id);
214             if (CalendarError.None != (CalendarError)error)
215             {
216                 Log.Error(Globals.LogTag, "Replace Failed with error " + error);
217                 throw CalendarErrorFactory.GetException(error);
218             }
219         }
220
221         /// <summary>
222         /// Retrieves all records as a list.
223         /// </summary>
224         /// <since_tizen> 4 </since_tizen>
225         /// <param name="viewUri">The view URI to get records from</param>
226         /// <param name="offset">The index from which results are received</param>
227         /// <param name="limit">The maximum number of results(value 0 is used for all records)</param>
228         /// <returns>
229         /// The record list
230         /// </returns>
231         /// <privilege>http://tizen.org/privilege/calendar.read</privilege>
232         /// <feature>http://tizen.org/feature/calendar</feature>
233         /// <exception cref="NotSupportedException">Thrown when feature is not supported</exception>
234         /// <exception cref="InvalidOperationException">Thrown when method failed due to invalid operation</exception>
235         /// <exception cref="ArgumentException">Thrown when one of the arguments provided to a method is not valid</exception>
236         /// <exception cref="OutOfMemoryException">Thrown when failed due to out of memory</exception>
237         /// <exception cref="UnauthorizedAccessException">Thrown when application does not have proper privileges</exception>
238         [SuppressMessage("Microsoft.Performance", "CA1822:MarkMembersAsStatic")]
239         [SuppressMessage("Microsoft.Design", "CA1054:UriParametersShouldNotBeStrings")]
240         public CalendarList GetAll(string viewUri, int offset, int limit)
241         {
242             IntPtr handle;
243             int error = Interop.Database.GetAllRecords(viewUri, offset, limit, out handle);
244             if (CalendarError.None != (CalendarError)error)
245             {
246                 Log.Error(Globals.LogTag, "GetAll Failed with error " + error);
247                 throw CalendarErrorFactory.GetException(error);
248             }
249             return new CalendarList(handle);
250         }
251
252         /// <summary>
253         /// Retrieves records using a query.
254         /// </summary>
255         /// <since_tizen> 4 </since_tizen>
256         /// <param name="query">The query used to filter results</param>
257         /// <param name="offset">The index from which results are received</param>
258         /// <param name="limit">The maximum number of results(value 0 is used for all records)</param>
259         /// <returns>
260         /// CalendarList
261         /// </returns>
262         /// <privilege>http://tizen.org/privilege/calendar.read</privilege>
263         /// <feature>http://tizen.org/feature/calendar</feature>
264         /// <exception cref="NotSupportedException">Thrown when feature is not supported</exception>
265         /// <exception cref="InvalidOperationException">Thrown when method failed due to invalid operation</exception>
266         /// <exception cref="ArgumentException">Thrown when one of the arguments provided to a method is not valid</exception>
267         /// <exception cref="OutOfMemoryException">Thrown when failed due to out of memory</exception>
268         /// <exception cref="UnauthorizedAccessException">Thrown when application does not have proper privileges</exception>
269         [SuppressMessage("Microsoft.Performance", "CA1822:MarkMembersAsStatic")]
270         public CalendarList GetRecordsWithQuery(CalendarQuery query, int offset, int limit)
271         {
272             IntPtr handle;
273             int error = Interop.Database.GetRecords(query._queryHandle, offset, limit, out handle);
274             if (CalendarError.None != (CalendarError)error)
275             {
276                 Log.Error(Globals.LogTag, "GetAllWithQuery Failed with error " + error);
277                 throw CalendarErrorFactory.GetException(error);
278             }
279             return new CalendarList(handle);
280         }
281
282         /// <summary>
283         /// Inserts multiple records into the calendar database as a batch operation.
284         /// </summary>
285         /// <since_tizen> 4 </since_tizen>
286         /// <param name="list">The record list</param>
287         /// <returns>
288         /// The inserted record id array
289         /// </returns>
290         /// <privilege>http://tizen.org/privilege/calendar.write</privilege>
291         /// <feature>http://tizen.org/feature/calendar</feature>
292         /// <exception cref="NotSupportedException">Thrown when feature is not supported</exception>
293         /// <exception cref="InvalidOperationException">Thrown when method failed due to invalid operation</exception>
294         /// <exception cref="ArgumentException">Thrown when one of the arguments provided to a method is not valid</exception>
295         /// <exception cref="OutOfMemoryException">Thrown when failed due to out of memory</exception>
296         /// <exception cref="UnauthorizedAccessException">Thrown when application does not have proper privileges</exception>
297         [SuppressMessage("Microsoft.Performance", "CA1822:MarkMembersAsStatic")]
298         public int[] Insert(CalendarList list)
299         {
300             IntPtr ids;
301             int count;
302             int error = Interop.Database.InsertRecords(list._listHandle, out ids, out count);
303             if (CalendarError.None != (CalendarError)error)
304             {
305                 Log.Error(Globals.LogTag, "Insert Failed with error " + error);
306                 throw CalendarErrorFactory.GetException(error);
307             }
308             int[] idArr = new int[count];
309             Marshal.Copy(ids, idArr, 0, count);
310
311             return idArr;
312         }
313
314         /// <summary>
315         /// Updates multiple records into the calendar database as a batch operation.
316         /// </summary>
317         /// <since_tizen> 4 </since_tizen>
318         /// <param name="list">The record list</param>
319         /// <privilege>http://tizen.org/privilege/calendar.write</privilege>
320         /// <feature>http://tizen.org/feature/calendar</feature>
321         /// <exception cref="NotSupportedException">Thrown when feature is not supported</exception>
322         /// <exception cref="InvalidOperationException">Thrown when method failed due to invalid operation</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         [SuppressMessage("Microsoft.Performance", "CA1822:MarkMembersAsStatic")]
327         public void Update(CalendarList list)
328         {
329             int error = Interop.Database.UpdateRecords(list._listHandle);
330             if (CalendarError.None != (CalendarError)error)
331             {
332                 Log.Error(Globals.LogTag, "Update Failed with error " + error);
333                 throw CalendarErrorFactory.GetException(error);
334             }
335         }
336
337         /// <summary>
338         /// Deletes multiple records with related child records from the calendar database as a batch operation.
339         /// </summary>
340         /// <since_tizen> 4 </since_tizen>
341         /// <param name="viewUri">The view URI of the records to delete</param>
342         /// <param name="idArray">The record IDs to delete</param>
343         /// <privilege>http://tizen.org/privilege/calendar.write</privilege>
344         /// <feature>http://tizen.org/feature/calendar</feature>
345         /// <exception cref="NotSupportedException">Thrown when feature is not supported</exception>
346         /// <exception cref="InvalidOperationException">Thrown when method failed due to invalid operation</exception>
347         /// <exception cref="ArgumentException">Thrown when one of the arguments provided to a method is not valid</exception>
348         /// <exception cref="OutOfMemoryException">Thrown when failed due to out of memory</exception>
349         /// <exception cref="UnauthorizedAccessException">Thrown when application does not have proper privileges</exception>
350         [SuppressMessage("Microsoft.Performance", "CA1822:MarkMembersAsStatic")]
351         [SuppressMessage("Microsoft.Design", "CA1054:UriParametersShouldNotBeStrings")]
352         public void Delete(string viewUri, int[] idArray)
353         {
354             int error = Interop.Database.DeleteRecords(viewUri, idArray, idArray.Length);
355             if (CalendarError.None != (CalendarError)error)
356             {
357                 Log.Error(Globals.LogTag, "Delete Failed with error " + error);
358                 throw CalendarErrorFactory.GetException(error);
359             }
360         }
361
362         /// <summary>
363         /// Deletes multiple records with related child records from the calendar database as a batch operation.
364         /// </summary>
365         /// <since_tizen> 4 </since_tizen>
366         /// <param name="list">The record list</param>
367         /// <privilege>http://tizen.org/privilege/calendar.write</privilege>
368         /// <feature>http://tizen.org/feature/calendar</feature>
369         /// <exception cref="NotSupportedException">Thrown when feature is not supported</exception>
370         /// <exception cref="InvalidOperationException">Thrown when method failed due to invalid operation</exception>
371         /// <exception cref="ArgumentException">Thrown when one of the arguments provided to a method is not valid</exception>
372         /// <exception cref="OutOfMemoryException">Thrown when failed due to out of memory</exception>
373         /// <exception cref="UnauthorizedAccessException">Thrown when application does not have proper privileges</exception>
374         public void Delete(CalendarList list)
375         {
376             CalendarRecord record = null;
377             if (list.Count <= 0)
378                 return;
379
380             int[] ids = new int[list.Count];
381             int i;
382             uint propertyId = 0;
383             list.MoveFirst();
384             for (i = 0; i < list.Count; i++)
385             {
386                 record = list.GetCurrentRecord();
387                 if (0 == propertyId)
388                 {
389                     if (0 == String.Compare(CalendarViews.Book.Uri, record.Uri))
390                         propertyId = CalendarViews.Book.Id;
391                     else if (0 == String.Compare(CalendarViews.Event.Uri, record.Uri))
392                         propertyId = CalendarViews.Event.Id;
393                     else if (0 == String.Compare(CalendarViews.Todo.Uri, record.Uri))
394                         propertyId = CalendarViews.Todo.Id;
395                     else if (0 == String.Compare(CalendarViews.Timezone.Uri, record.Uri))
396                         propertyId = CalendarViews.Timezone.Id;
397                     else if (0 == String.Compare(CalendarViews.Extended.Uri, record.Uri))
398                         propertyId = CalendarViews.Extended.Id;
399                     else
400                     {
401                         Log.Error(Globals.LogTag, "Invalid uri [" + record.Uri + "]");
402                         continue;
403                     }
404                 }
405                 ids[i] = record.Get<int>(propertyId);
406                 list.MoveNext();
407             }
408             Delete(record.Uri, ids);
409         }
410
411         /// <summary>
412         /// Replaces multiple records in the calendar database as a batch operation.
413         /// </summary>
414         /// <since_tizen> 4 </since_tizen>
415         /// <param name="list">The record list</param>
416         /// <param name="idArray">The record IDs</param>
417         /// <privilege>http://tizen.org/privilege/calendar.write</privilege>
418         /// <feature>http://tizen.org/feature/calendar</feature>
419         /// <exception cref="NotSupportedException">Thrown when feature is not supported</exception>
420         /// <exception cref="InvalidOperationException">Thrown when method failed due to invalid operation</exception>
421         /// <exception cref="ArgumentException">Thrown when one of the arguments provided to a method is not valid</exception>
422         /// <exception cref="OutOfMemoryException">Thrown when failed due to out of memory</exception>
423         /// <exception cref="UnauthorizedAccessException">Thrown when application does not have proper privileges</exception>
424         [SuppressMessage("Microsoft.Performance", "CA1822:MarkMembersAsStatic")]
425         public void Replace(CalendarList list, int[] idArray)
426         {
427             int error = Interop.Database.ReplaceRecords(list._listHandle, idArray, idArray.Length);
428             if (CalendarError.None != (CalendarError)error)
429             {
430                 Log.Error(Globals.LogTag, "Replace Failed with error " + error);
431                 throw CalendarErrorFactory.GetException(error);
432             }
433         }
434
435         /// <summary>
436         /// Retrieves records with the given calendar database version.
437         /// </summary>
438         /// <since_tizen> 4 </since_tizen>
439         /// <param name="viewUri">The view URI to get records from</param>
440         /// <param name="BookId">The calendar book ID to filter</param>
441         /// <param name="calendarDBVersion">The calendar database version</param>
442         /// <param name="currentDBVersion">The current calendar database version</param>
443         /// <returns>
444         /// The record list
445         /// </returns>
446         /// <privilege>http://tizen.org/privilege/calendar.read</privilege>
447         /// <feature>http://tizen.org/feature/calendar</feature>
448         /// <exception cref="NotSupportedException">Thrown when feature is not supported</exception>
449         /// <exception cref="InvalidOperationException">Thrown when method failed due to invalid operation</exception>
450         /// <exception cref="ArgumentException">Thrown when one of the arguments provided to a method is not valid</exception>
451         /// <exception cref="OutOfMemoryException">Thrown when failed due to out of memory</exception>
452         /// <exception cref="UnauthorizedAccessException">Thrown when application does not have proper privileges</exception>
453         [SuppressMessage("Microsoft.Performance", "CA1822:MarkMembersAsStatic")]
454         [SuppressMessage("Microsoft.Design", "CA1054:UriParametersShouldNotBeStrings")]
455         public CalendarList GetChangesByVersion(string viewUri, int BookId, int calendarDBVersion, out int currentDBVersion)
456         {
457             IntPtr recordList;
458             int error = Interop.Database.GetChangesByVersion(viewUri, BookId, calendarDBVersion, out recordList, out currentDBVersion);
459             if (CalendarError.None != (CalendarError)error)
460             {
461                 Log.Error(Globals.LogTag, "GetChangesByVersion Failed with error " + error);
462                 throw CalendarErrorFactory.GetException(error);
463             }
464             return new CalendarList(recordList);
465         }
466
467         /// <summary>
468         /// Gets the record count of a specific view.
469         /// </summary>
470         /// <since_tizen> 4 </since_tizen>
471         /// <param name="viewUri">The view URI to get records from</param>
472         /// <returns>
473         /// The count of records
474         /// </returns>
475         /// <privilege>http://tizen.org/privilege/calendar.read</privilege>
476         [SuppressMessage("Microsoft.Design", "CA1822:MarkMembersAsStatic")]
477         [SuppressMessage("Microsoft.Design", "CA1054:UriParametersShouldNotBeStrings")]
478         public int GetCount(string viewUri)
479         {
480             int count = -1;
481             int error = Interop.Database.GetCount(viewUri, out count);
482             if (CalendarError.None != (CalendarError)error)
483             {
484                 Log.Error(Globals.LogTag, "GetCount Failed with error " + error);
485                 throw CalendarErrorFactory.GetException(error);
486             }
487             return count;
488         }
489
490         /// <summary>
491         /// Gets the record count with a query.
492         /// </summary>
493         /// <since_tizen> 4 </since_tizen>
494         /// <param name="query">The query used for filtering the results</param>
495         /// <returns>
496         /// The count of records
497         /// </returns>
498         /// <privilege>http://tizen.org/privilege/calendar.read</privilege>
499         [SuppressMessage("Microsoft.Design", "CA1822:MarkMembersAsStatic")]
500         public int GetCount(CalendarQuery query)
501         {
502             int count = -1;
503             int error = Interop.Database.GetCountWithQuery(query._queryHandle, out count);
504             if (CalendarError.None != (CalendarError)error)
505             {
506                 Log.Error(Globals.LogTag, "GetCount Failed with error " + error);
507                 throw CalendarErrorFactory.GetException(error);
508             }
509             return count;
510         }
511
512         /// <summary>
513         /// Registers a callback function to be invoked when a record changes.
514         /// <since_tizen> 4 </since_tizen>
515         /// </summary>
516         /// <param name="viewUri">The view URI of the record to subscribe for change notifications</param>
517         /// <param name="DBChanged">The EventHandler to register</param>
518         /// <privilege>http://tizen.org/privilege/calendar.read</privilege>
519         /// <feature>http://tizen.org/feature/calendar</feature>
520         /// <exception cref="NotSupportedException">Thrown when feature is not supported</exception>
521         /// <exception cref="InvalidOperationException">Thrown when method failed due to invalid operation</exception>
522         /// <exception cref="ArgumentException">Thrown when one of the arguments provided to a method is not valid</exception>
523         /// <exception cref="OutOfMemoryException">Thrown when failed due to out of memory</exception>
524         /// <exception cref="UnauthorizedAccessException">Thrown when application does not have proper privileges</exception>
525         [SuppressMessage("Microsoft.Design", "CA1054:UriParametersShouldNotBeStrings")]
526         public void AddDBChangedDelegate(string viewUri, EventHandler<DBChangedEventArgs> DBChanged)
527         {
528             Log.Debug(Globals.LogTag, "AddDBChangedDelegate");
529
530                         if (!_callbackMap.ContainsKey(viewUri))
531                         {
532                                 _callbackMap[viewUri] = (string uri, IntPtr userData) =>
533                                 {
534                                         DBChangedEventArgs args = new DBChangedEventArgs(uri);
535                                         _eventHandlerMap[uri]?.Invoke(this, args);
536                                 };
537
538                                 int error = Interop.Database.AddChangedCallback(viewUri, _callbackMap[viewUri], IntPtr.Zero);
539                                 if (CalendarError.None != (CalendarError)error)
540                                 {
541                                         Log.Error(Globals.LogTag, "AddDBChangedDelegate Failed with error " + error);
542                                         throw CalendarErrorFactory.GetException(error);
543                                 }
544                         }
545
546                         EventHandler<DBChangedEventArgs> handler = null;
547                         if (!_eventHandlerMap.TryGetValue(viewUri, out handler))
548                                 _eventHandlerMap.Add(viewUri, null);
549
550                         _eventHandlerMap[viewUri] = handler + DBChanged;
551         }
552
553         /// <summary>
554         /// Deregisters a callback function.
555         /// </summary>
556         /// <since_tizen> 4 </since_tizen>
557         /// <param name="viewUri">The view URI of the record to subscribe for change notifications</param>
558         /// <param name="DBChanged">The EventHandler to deregister</param>
559         /// <privilege>http://tizen.org/privilege/calendar.read</privilege>
560         /// <feature>http://tizen.org/feature/calendar</feature>
561         /// <exception cref="NotSupportedException">Thrown when feature is not supported</exception>
562         /// <exception cref="InvalidOperationException">Thrown when method failed due to invalid operation</exception>
563         /// <exception cref="ArgumentException">Thrown when one of the arguments provided to a method is not valid</exception>
564         /// <exception cref="OutOfMemoryException">Thrown when failed due to out of memory</exception>
565         /// <exception cref="UnauthorizedAccessException">Thrown when application does not have proper privileges</exception>
566         [SuppressMessage("Microsoft.Design", "CA1054:UriParametersShouldNotBeStrings")]
567         public void RemoveDBChangedDelegate(string viewUri, EventHandler<DBChangedEventArgs> DBChanged)
568         {
569             Log.Debug(Globals.LogTag, "RemoveDBChangedDelegate");
570
571             EventHandler<DBChangedEventArgs> handler = null;
572             if (!_eventHandlerMap.TryGetValue(viewUri, out handler))
573                 _eventHandlerMap.Add(viewUri, null);
574             else
575                 _eventHandlerMap[viewUri] = handler - DBChanged;
576
577             if (_eventHandlerMap[viewUri] == null)
578             {
579                                 int error = Interop.Database.RemoveChangedCallback(viewUri, _callbackMap[viewUri], IntPtr.Zero);
580                                 if (CalendarError.None != (CalendarError)error)
581                                 {
582                                         Log.Error(Globals.LogTag, "RemoveDBChangedDelegate Failed with error " + error);
583                                         throw CalendarErrorFactory.GetException(error);
584                                 }
585                                 _callbackMap.Remove(viewUri);
586                         }
587         }
588
589         /// <summary>
590         /// Link a record to another record.
591         /// </summary>
592         /// <since_tizen> 4 </since_tizen>
593         /// <param name="baseId">The base record ID</param>
594         /// <param name="recordId">The record ID to link to</param>
595         /// <privilege>http://tizen.org/privilege/calendar.write</privilege>
596         /// <feature>http://tizen.org/feature/calendar</feature>
597         /// <exception cref="NotSupportedException">Thrown when feature is not supported</exception>
598         /// <exception cref="InvalidOperationException">Thrown when method failed due to invalid operation</exception>
599         /// <exception cref="ArgumentException">Thrown when one of the arguments provided to a method is not valid</exception>
600         /// <exception cref="OutOfMemoryException">Thrown when failed due to out of memory</exception>
601         /// <exception cref="UnauthorizedAccessException">Thrown when application does not have proper privileges</exception>
602         [SuppressMessage("Microsoft.Design", "CA1822:MarkMembersAsStatic")]
603         public void LinkRecord(int baseId, int recordId)
604         {
605             Log.Debug(Globals.LogTag, "LinkRecord");
606             int error = Interop.Database.LinkRecord(baseId, recordId);
607             if (CalendarError.None != (CalendarError)error)
608             {
609                 Log.Error(Globals.LogTag, "LinkRecor Failed with error " + error);
610                 throw CalendarErrorFactory.GetException(error);
611             }
612         }
613
614         /// <summary>
615         /// Unlink a record from base record.
616         /// </summary>
617         /// <since_tizen> 4 </since_tizen>
618         /// <param name="recordId">The record ID to unlink</param>
619         /// <privilege>http://tizen.org/privilege/calendar.write</privilege>
620         /// <feature>http://tizen.org/feature/calendar</feature>
621         /// <exception cref="NotSupportedException">Thrown when feature is not supported</exception>
622         /// <exception cref="InvalidOperationException">Thrown when method failed due to invalid operation</exception>
623         /// <exception cref="ArgumentException">Thrown when one of the arguments provided to a method is not valid</exception>
624         /// <exception cref="OutOfMemoryException">Thrown when failed due to out of memory</exception>
625         /// <exception cref="UnauthorizedAccessException">Thrown when application does not have proper privileges</exception>
626         [SuppressMessage("Microsoft.Performance", "CA1822:MarkMembersAsStatic")]
627         public void UnlinkRecord(int recordId)
628         {
629             Log.Debug(Globals.LogTag, "UnlinkRecord");
630             int error = Interop.Database.UnlinkRecord(recordId);
631             if (CalendarError.None != (CalendarError)error)
632             {
633                 Log.Error(Globals.LogTag, "UnlinkRecor Failed with error " + error);
634                 throw CalendarErrorFactory.GetException(error);
635             }
636         }
637     }
638 }