Release 4.0.0-preview1-00051
[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
21 /// <summary>
22 /// The Calendar Service API provides functions, enumerations used in the entire Content Service.
23 /// </summary>
24 /// <remarks>
25 /// The Calendar Service API provides functions and ienumerations used in the entire Content Service.
26 /// The Information about calendar items i.e. book, event, todo, alarm, attendee and extended are managed in the database
27 /// and operations that involve database requires an active connection with the calendar service.
28 /// </remarks>
29
30 namespace Tizen.Pims.Calendar
31 {
32     /// <summary>
33     /// CalendarDatabase provides methods to manage calendar information from/to the database.
34     /// </summary>
35     /// <remarks>
36     /// This class allows usre to access/create/update db operations for calendar information.
37     /// </remarks>
38     public class CalendarDatabase
39     {
40         /// <summary>
41         /// Delegete for detecting the calendar database changes.
42         /// </summary>
43         /// <param name="uri">The record uri</param>
44         /// <remarks>
45         /// The delegate must be registered using AddDBChangedDelegate.
46         /// It's invoked when the designated view changes.
47         /// </remarks>
48         /// <see cref="AddDBChangedDelegate"/>
49         public delegate void CalendarDBChangedDelegate(string uri);
50
51         private Object thisLock = new Object();
52         private Dictionary<string, CalendarDBChangedDelegate> _callbackMap = new Dictionary<string, CalendarDBChangedDelegate>();
53         private Dictionary<string, Interop.Calendar.Database.DBChangedCallback> _delegateMap = new Dictionary<string, Interop.Calendar.Database.DBChangedCallback>();
54         private Interop.Calendar.Database.DBChangedCallback _dbChangedDelegate;
55
56         internal CalendarDatabase()
57         {
58             ///To be created in CalendarManager only
59         }
60
61         /// <summary>
62         /// The calendar database version.
63         /// </summary>
64         public int Version
65         {
66             get
67             {
68                 int version = -1;
69                 int error = Interop.Calendar.Database.GetCurrentVersion(out version);
70                 if (CalendarError.None != (CalendarError)error)
71                 {
72                     Log.Error(Globals.LogTag, "Version Failed with error " + error);
73                 }
74                 return version;
75             }
76         }
77
78         /// <summary>
79         /// Gets last successful changed calendar database version on the current connection.
80         /// </summary>
81         /// <returns>The last successful changed calendar database version on the current connection</returns>
82         /// <privilege>http://tizen.org/privilege/calendar.read</privilege>
83         /// <exception cref="InvalidOperationException">Thrown when method failed due to invalid operation</exception>
84         /// <exception cref="OutOfMemoryException">Thrown when failed due to out of memory</exception>
85         /// <exception cref="UnauthorizedAccessException">Thrown when application does not have proper privileges</exception>
86         public int LastChangeVersion
87         {
88             get
89             {
90                 int version = -1;
91                 int error = Interop.Calendar.Database.GetLastChangeVersion(out version);
92                 if (CalendarError.None != (CalendarError)error)
93                 {
94                     Log.Error(Globals.LogTag, "LastChangeVersion Failed with error " + error);
95                 }
96                 return version;
97             }
98         }
99
100         /// <summary>
101         /// Inserts a record into the calendar database.
102         /// </summary>
103         /// <param name="record">The record to be inserted</param>
104         /// <returns>The ID of inserted record</returns>
105         /// <privilege>http://tizen.org/privilege/calendar.write</privilege>
106         /// <exception cref="InvalidOperationException">Thrown when method failed due to invalid operation</exception>
107         /// <exception cref="NotSupportedException">Thrown when an invoked method is not supported</exception>
108         /// <exception cref="ArgumentException">Thrown when one of the arguments provided to a method is not valid</exception>
109         /// <exception cref="OutOfMemoryException">Thrown when failed due to out of memory</exception>
110         /// <exception cref="UnauthorizedAccessException">Thrown when application does not have proper privileges</exception>
111         public int Insert(CalendarRecord record)
112         {
113             int id = -1;
114             int error = Interop.Calendar.Database.Insert(record._recordHandle, out id);
115             if (CalendarError.None != (CalendarError)error)
116             {
117                 Log.Error(Globals.LogTag, "Insert Failed with error " + error);
118                 throw CalendarErrorFactory.GetException(error);
119             }
120             return id;
121         }
122
123         /// <summary>
124         /// Gets a record from the calendar database.
125         /// </summary>
126         /// <param name="viewUri">The view URI of a record</param>
127         /// <param name="recordId">The record ID</param>
128         /// <returns>
129         /// The record associated with the record ID
130         /// </returns>
131         /// <privilege>http://tizen.org/privilege/calendar.read</privilege>
132         /// <exception cref="InvalidOperationException">Thrown when method failed due to invalid operation</exception>
133         /// <exception cref="NotSupportedException">Thrown when an invoked method is not supported</exception>
134         /// <exception cref="ArgumentException">Thrown when one of the arguments provided to a method is not valid</exception>
135         /// <exception cref="OutOfMemoryException">Thrown when failed due to out of memory</exception>
136         /// <exception cref="UnauthorizedAccessException">Thrown when application does not have proper privileges</exception>
137         public CalendarRecord Get(string viewUri, int recordId)
138         {
139             IntPtr handle;
140             int error = Interop.Calendar.Database.Get(viewUri, recordId, out handle);
141             if (CalendarError.None != (CalendarError)error)
142             {
143                                 if (CalendarError.DBNotFound == (CalendarError)error)
144                                 {
145                                         Log.Error(Globals.LogTag, "No data" + error);
146                                         return null;
147                                 }
148                                 Log.Error(Globals.LogTag, "Get Failed with error " + error);
149                                 throw CalendarErrorFactory.GetException(error);
150             }
151             return new CalendarRecord(handle);
152         }
153
154         /// <summary>
155         /// Updates a record in the calendar database.
156         /// </summary>
157         /// <param name="record">The record to be updated</param>
158         /// <privilege>http://tizen.org/privilege/calendar.write</privilege>
159         /// <exception cref="InvalidOperationException">Thrown when method failed due to invalid operation</exception>
160         /// <exception cref="NotSupportedException">Thrown when an invoked method is not supported</exception>
161         /// <exception cref="ArgumentException">Thrown when one of the arguments provided to a method is not valid</exception>
162         /// <exception cref="OutOfMemoryException">Thrown when failed due to out of memory</exception>
163         /// <exception cref="UnauthorizedAccessException">Thrown when application does not have proper privileges</exception>
164         public void Update(CalendarRecord record)
165         {
166             int error = Interop.Calendar.Database.Update(record._recordHandle);
167             if (CalendarError.None != (CalendarError)error)
168             {
169                 Log.Error(Globals.LogTag, "Update Failed with error " + error);
170                 throw CalendarErrorFactory.GetException(error);
171             }
172         }
173
174         /// <summary>
175         /// Deletes a record from the calendar database with related child records.
176         /// </summary>
177         /// <param name="viewUri">The view URI of a record</param>
178         /// <param name="recordId">The record ID to be deleted</param>
179         /// <privilege>http://tizen.org/privilege/calendar.write</privilege>
180         /// <exception cref="InvalidOperationException">Thrown when method failed due to invalid operation</exception>
181         /// <exception cref="NotSupportedException">Thrown when an invoked method is not supported</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         public void Delete(string viewUri, int recordId)
186         {
187             int error = Interop.Calendar.Database.Delete(viewUri, recordId);
188             if (CalendarError.None != (CalendarError)error)
189             {
190                 Log.Error(Globals.LogTag, "Delete Failed with error " + error);
191                 throw CalendarErrorFactory.GetException(error);
192             }
193         }
194
195         /// <summary>
196         /// Replaces a record in the calendar database.
197         /// </summary>
198         /// <param name="record">The record to be replaced</param>
199         /// <param name="id">the record id</param>
200         /// <privilege>http://tizen.org/privilege/calendar.write</privilege>
201         /// <exception cref="InvalidOperationException">Thrown when method failed due to invalid operation</exception>
202         /// <exception cref="NotSupportedException">Thrown when an invoked method is not supported</exception>
203         /// <exception cref="ArgumentException">Thrown when one of the arguments provided to a method is not valid</exception>
204         /// <exception cref="OutOfMemoryException">Thrown when failed due to out of memory</exception>
205         /// <exception cref="UnauthorizedAccessException">Thrown when application does not have proper privileges</exception>
206         public void Replace(CalendarRecord record, int id)
207         {
208             int error = Interop.Calendar.Database.Replace(record._recordHandle, id);
209             if (CalendarError.None != (CalendarError)error)
210             {
211                 Log.Error(Globals.LogTag, "Replace Failed with error " + error);
212                 throw CalendarErrorFactory.GetException(error);
213             }
214         }
215
216         /// <summary>
217         /// Retrieves all records as a list.
218         /// </summary>
219         /// <param name="viewUri">The view URI to get records from</param>
220         /// <param name="offset">The index from which results are received</param>
221         /// <param name="limit">The maximum number of results(value 0 is used for all records)</param>
222         /// <returns>
223         /// The record list
224         /// </returns>
225         /// <privilege>http://tizen.org/privilege/calendar.read</privilege>
226         /// <exception cref="InvalidOperationException">Thrown when method failed due to invalid operation</exception>
227         /// <exception cref="NotSupportedException">Thrown when an invoked method is not supported</exception>
228         /// <exception cref="ArgumentException">Thrown when one of the arguments provided to a method is not valid</exception>
229         /// <exception cref="OutOfMemoryException">Thrown when failed due to out of memory</exception>
230         /// <exception cref="UnauthorizedAccessException">Thrown when application does not have proper privileges</exception>
231         public CalendarList GetAll(string viewUri, int offset, int limit)
232         {
233             IntPtr handle;
234             int error = Interop.Calendar.Database.GetAllRecords(viewUri, offset, limit, out handle);
235             if (CalendarError.None != (CalendarError)error)
236             {
237                 Log.Error(Globals.LogTag, "GetAll Failed with error " + error);
238                 throw CalendarErrorFactory.GetException(error);
239             }
240             return new CalendarList(handle);
241         }
242
243         /// <summary>
244         /// Retrieves records using a query.
245         /// </summary>
246         /// <param name="query">The query used to filter results</param>
247         /// <param name="offset">The index from which results are received</param>
248         /// <param name="limit">The maximum number of results(value 0 is used for all records)</param>
249         /// <returns>
250         /// CalendarList
251         /// </returns>
252         /// <privilege>http://tizen.org/privilege/calendar.read</privilege>
253         /// <exception cref="InvalidOperationException">Thrown when method failed due to invalid operation</exception>
254         /// <exception cref="NotSupportedException">Thrown when an invoked method is not supported</exception>
255         /// <exception cref="ArgumentException">Thrown when one of the arguments provided to a method is not valid</exception>
256         /// <exception cref="OutOfMemoryException">Thrown when failed due to out of memory</exception>
257         /// <exception cref="UnauthorizedAccessException">Thrown when application does not have proper privileges</exception>
258         public CalendarList GetRecordsWithQuery(CalendarQuery query, int offset, int limit)
259         {
260             IntPtr handle;
261             int error = Interop.Calendar.Database.GetRecords(query._queryHandle, offset, limit, out handle);
262             if (CalendarError.None != (CalendarError)error)
263             {
264                 Log.Error(Globals.LogTag, "GetAllWithQuery Failed with error " + error);
265                 throw CalendarErrorFactory.GetException(error);
266             }
267             return new CalendarList(handle);
268         }
269
270         /// <summary>
271         /// Inserts multiple records into the calendar database as a batch operation.
272         /// </summary>
273         /// <param name="list">The record list</param>
274         /// <returns>
275         /// The inserted record id array
276         /// </returns>
277         /// <privilege>http://tizen.org/privilege/calendar.write</privilege>
278         /// <exception cref="InvalidOperationException">Thrown when method failed due to invalid operation</exception>
279         /// <exception cref="NotSupportedException">Thrown when an invoked method is not supported</exception>
280         /// <exception cref="ArgumentException">Thrown when one of the arguments provided to a method is not valid</exception>
281         /// <exception cref="OutOfMemoryException">Thrown when failed due to out of memory</exception>
282         /// <exception cref="UnauthorizedAccessException">Thrown when application does not have proper privileges</exception>
283         public int[] Insert(CalendarList list)
284         {
285             IntPtr ids;
286             int count;
287             int error = Interop.Calendar.Database.InsertRecords(list._listHandle, out ids, out count);
288             if (CalendarError.None != (CalendarError)error)
289             {
290                 Log.Error(Globals.LogTag, "Insert Failed with error " + error);
291                 throw CalendarErrorFactory.GetException(error);
292             }
293             int[] idArr = new int[count];
294             Marshal.Copy(ids, idArr, 0, count);
295
296             return idArr;
297         }
298
299         /// <summary>
300         /// Updates multiple records into the calendar database as a batch operation.
301         /// </summary>
302         /// <param name="list">The record list</param>
303         /// <privilege>http://tizen.org/privilege/calendar.write</privilege>
304         /// <exception cref="InvalidOperationException">Thrown when method failed due to invalid operation</exception>
305         /// <exception cref="NotSupportedException">Thrown when an invoked method is not supported</exception>
306         /// <exception cref="ArgumentException">Thrown when one of the arguments provided to a method is not valid</exception>
307         /// <exception cref="OutOfMemoryException">Thrown when failed due to out of memory</exception>
308         /// <exception cref="UnauthorizedAccessException">Thrown when application does not have proper privileges</exception>
309         public void Update(CalendarList list)
310         {
311             int error = Interop.Calendar.Database.UpdateRecords(list._listHandle);
312             if (CalendarError.None != (CalendarError)error)
313             {
314                 Log.Error(Globals.LogTag, "Update Failed with error " + error);
315                 throw CalendarErrorFactory.GetException(error);
316             }
317         }
318
319         /// <summary>
320         /// Deletes multiple records with related child records from the calendar database as a batch operation.
321         /// </summary>
322         /// <param name="viewUri">The view URI of the records to delete</param>
323         /// <param name="idArray">The record IDs to delete</param>
324         /// <privilege>http://tizen.org/privilege/calendar.write</privilege>
325         /// <exception cref="InvalidOperationException">Thrown when method failed due to invalid operation</exception>
326         /// <exception cref="NotSupportedException">Thrown when an invoked method is not supported</exception>
327         /// <exception cref="ArgumentException">Thrown when one of the arguments provided to a method is not valid</exception>
328         /// <exception cref="OutOfMemoryException">Thrown when failed due to out of memory</exception>
329         /// <exception cref="UnauthorizedAccessException">Thrown when application does not have proper privileges</exception>
330         public void Delete(string viewUri, int[] idArray)
331         {
332             int error = Interop.Calendar.Database.DeleteRecords(viewUri, idArray, idArray.Length);
333             if (CalendarError.None != (CalendarError)error)
334             {
335                 Log.Error(Globals.LogTag, "Delete Failed with error " + error);
336                 throw CalendarErrorFactory.GetException(error);
337             }
338         }
339
340         /// <summary>
341         /// Deletes multiple records with related child records from the calendar database as a batch operation.
342         /// </summary>
343         /// <param name="list">The record list</param>
344         /// <privilege>http://tizen.org/privilege/calendar.write</privilege>
345         /// <exception cref="InvalidOperationException">Thrown when method failed due to invalid operation</exception>
346         /// <exception cref="NotSupportedException">Thrown when an invoked method is not supported</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         public void Delete(CalendarList list)
351         {
352             CalendarRecord record = null;
353             if (list.Count <= 0)
354                 return;
355
356             int[] ids = new int[list.Count];
357             int i;
358             uint propertyId = 0;
359             list.MoveFirst();
360             for (i = 0; i < list.Count; i++)
361             {
362                 record = list.GetCurrentRecord();
363                 if (0 == propertyId)
364                 {
365                     if (0 == String.Compare(CalendarViews.Book.Uri, record.Uri))
366                         propertyId = CalendarViews.Book.Id;
367                     else if (0 == String.Compare(CalendarViews.Event.Uri, record.Uri))
368                         propertyId = CalendarViews.Event.Id;
369                     else if (0 == String.Compare(CalendarViews.Todo.Uri, record.Uri))
370                         propertyId = CalendarViews.Todo.Id;
371                     else if (0 == String.Compare(CalendarViews.Timezone.Uri, record.Uri))
372                         propertyId = CalendarViews.Timezone.Id;
373                     else if (0 == String.Compare(CalendarViews.Extended.Uri, record.Uri))
374                         propertyId = CalendarViews.Extended.Id;
375                     else
376                     {
377                         Log.Error(Globals.LogTag, "Invalid uri [" + record.Uri + "]");
378                         continue;
379                     }
380                 }
381                 ids[i] = record.Get<int>(propertyId);
382                 list.MoveNext();
383             }
384             Delete(record.Uri, ids);
385         }
386
387         /// <summary>
388         /// Replaces multiple records in the calendar database as a batch operation.
389         /// </summary>
390         /// <param name="list">The record list</param>
391         /// <param name="idArray">The record IDs</param>
392         /// <privilege>http://tizen.org/privilege/calendar.write</privilege>
393         /// <exception cref="InvalidOperationException">Thrown when method failed due to invalid operation</exception>
394         /// <exception cref="NotSupportedException">Thrown when an invoked method is not supported</exception>
395         /// <exception cref="ArgumentException">Thrown when one of the arguments provided to a method is not valid</exception>
396         /// <exception cref="OutOfMemoryException">Thrown when failed due to out of memory</exception>
397         /// <exception cref="UnauthorizedAccessException">Thrown when application does not have proper privileges</exception>
398         public void Replace(CalendarList list, int[] idArray)
399         {
400             int error = Interop.Calendar.Database.ReplaceRecords(list._listHandle, idArray, idArray.Length);
401             if (CalendarError.None != (CalendarError)error)
402             {
403                 Log.Error(Globals.LogTag, "Replace Failed with error " + error);
404                 throw CalendarErrorFactory.GetException(error);
405             }
406         }
407
408         /// <summary>
409         /// Retrieves records with the given calendar database version.
410         /// </summary>
411         /// <param name="viewUri">The view URI to get records from</param>
412         /// <param name="BookId">The calendar book ID to filter</param>
413         /// <param name="calendarDBVersion">The calendar database version</param>
414         /// <param name="currentDBVersion"The current calendar database versio></param>
415         /// <returns>
416         /// The record list
417         /// </returns>
418         /// <privilege>http://tizen.org/privilege/calendar.read</privilege>
419         /// <exception cref="InvalidOperationException">Thrown when method failed due to invalid operation</exception>
420         /// <exception cref="NotSupportedException">Thrown when an invoked method is not supported</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         public CalendarList GetChangesByVersion(string viewUri, int BookId, int calendarDBVersion, out int currentDBVersion)
425         {
426             IntPtr recordList;
427             int error = Interop.Calendar.Database.GetChangesByVersion(viewUri, BookId, calendarDBVersion, out recordList, out currentDBVersion);
428             if (CalendarError.None != (CalendarError)error)
429             {
430                 Log.Error(Globals.LogTag, "GetChangesByVersion Failed with error " + error);
431                 throw CalendarErrorFactory.GetException(error);
432             }
433             return new CalendarList(recordList);
434         }
435
436         /// <summary>
437         /// Gets the record count of a specific view.
438         /// </summary>
439         /// <param name="viewUri">The view URI to get records from</param>
440         /// <returns>
441         /// The count of records
442         /// </returns>
443         /// <privilege>http://tizen.org/privilege/calendar.read</privilege>
444         public int GetCount(string viewUri)
445         {
446             int count = -1;
447             int error = Interop.Calendar.Database.GetCount(viewUri, out count);
448             if (CalendarError.None != (CalendarError)error)
449             {
450                 Log.Error(Globals.LogTag, "GetCount Failed with error " + error);
451                 throw CalendarErrorFactory.GetException(error);
452             }
453             return count;
454         }
455
456         /// <summary>
457         /// Gets the record count with a query.
458         /// </summary>
459         /// <param name="query">The query used for filtering the results</param>
460         /// <returns>
461         /// The count of records
462         /// </returns>
463         /// <privilege>http://tizen.org/privilege/calendar.read</privilege>
464         public int GetCount(CalendarQuery query)
465         {
466             int count = -1;
467             int error = Interop.Calendar.Database.GetCountWithQuery(query._queryHandle, out count);
468             if (CalendarError.None != (CalendarError)error)
469             {
470                 Log.Error(Globals.LogTag, "GetCount Failed with error " + error);
471                 throw CalendarErrorFactory.GetException(error);
472             }
473             return count;
474         }
475
476         /// <summary>
477         /// Registers a callback function to be invoked when a record changes.
478         /// </summary>
479         /// <param name="viewUri">The view URI of the record to subscribe for change notifications</param>
480         /// <param name="callback">The callback function to register</param>
481         /// <privilege>http://tizen.org/privilege/calendar.read</privilege>
482         public void AddDBChangedDelegate(string viewUri, CalendarDBChangedDelegate callback)
483         {
484             Log.Debug(Globals.LogTag, "AddDBChangedDelegate");
485
486             _dbChangedDelegate = (string uri, IntPtr userData) =>
487             {
488                 _callbackMap[uri](uri);
489             };
490             int error = Interop.Calendar.Database.AddChangedCallback(viewUri, _dbChangedDelegate, IntPtr.Zero);
491             if (CalendarError.None != (CalendarError)error)
492             {
493                 Log.Error(Globals.LogTag, "AddDBChangedDelegate Failed with error " + error);
494                 throw CalendarErrorFactory.GetException(error);
495             }
496             _callbackMap[viewUri] = callback;
497             _delegateMap[viewUri] = _dbChangedDelegate;
498         }
499
500         /// <summary>
501         /// Unregisters a callback function.
502         /// </summary>
503         /// <param name="viewUri">The view URI of the record to subscribe for change notifications</param>
504         /// <param name="callback">The callback function to register</param>
505         /// <privilege>http://tizen.org/privilege/calendar.read</privilege>
506         public void RemoveDBChangedDelegate(string viewUri, CalendarDBChangedDelegate callback)
507         {
508             Log.Debug(Globals.LogTag, "RemoveDBChangedDelegate");
509
510             int error = Interop.Calendar.Database.RemoveChangedCallback(viewUri, _delegateMap[viewUri], IntPtr.Zero);
511             if (CalendarError.None != (CalendarError)error)
512             {
513                 Log.Error(Globals.LogTag, "RemoveDBChangedDelegate Failed with error " + error);
514                 throw CalendarErrorFactory.GetException(error);
515             }
516             _callbackMap.Remove(viewUri);
517             _delegateMap.Remove(viewUri);
518         }
519
520         /// <summary>
521         /// Link a record to another record.
522         /// </summary>
523         /// <param name="baseId">The base record ID</param>
524         /// <param name="recordId">The record ID to link to</param>
525         /// <privilege>http://tizen.org/privilege/calendar.write</privilege>
526         /// <exception cref="InvalidOperationException">Thrown when method failed due to invalid operation</exception>
527         /// <exception cref="NotSupportedException">Thrown when an invoked method is not supported</exception>
528         /// <exception cref="ArgumentException">Thrown when one of the arguments provided to a method is not valid</exception>
529         /// <exception cref="OutOfMemoryException">Thrown when failed due to out of memory</exception>
530         /// <exception cref="UnauthorizedAccessException">Thrown when application does not have proper privileges</exception>
531         public void LinkRecord(int baseId, int recordId)
532         {
533             Log.Debug(Globals.LogTag, "LinkRecord");
534             int error = Interop.Calendar.Database.LinkRecord(baseId, recordId);
535             if (CalendarError.None != (CalendarError)error)
536             {
537                 Log.Error(Globals.LogTag, "LinkRecor Failed with error " + error);
538                 throw CalendarErrorFactory.GetException(error);
539             }
540         }
541
542         /// <summary>
543         /// Unlink a record from base record.
544         /// </summary>
545         /// <param name="recordId">The record ID to unlink</param>
546         /// <privilege>http://tizen.org/privilege/calendar.write</privilege>
547         /// <exception cref="InvalidOperationException">Thrown when method failed due to invalid operation</exception>
548         /// <exception cref="NotSupportedException">Thrown when an invoked method is not supported</exception>
549         /// <exception cref="ArgumentException">Thrown when one of the arguments provided to a method is not valid</exception>
550         /// <exception cref="OutOfMemoryException">Thrown when failed due to out of memory</exception>
551         /// <exception cref="UnauthorizedAccessException">Thrown when application does not have proper privileges</exception>
552         public void UnlinkRecord(int recordId)
553         {
554             Log.Debug(Globals.LogTag, "UnlinkRecord");
555             int error = Interop.Calendar.Database.UnlinkRecord(recordId);
556             if (CalendarError.None != (CalendarError)error)
557             {
558                 Log.Error(Globals.LogTag, "UnlinkRecor Failed with error " + error);
559                 throw CalendarErrorFactory.GetException(error);
560             }
561         }
562     }
563 }