2 * Copyright (c) 2016 Samsung Electronics Co., Ltd All Rights Reserved
4 * Licensed under the Apache License, Version 2.0 (the License);
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an AS IS BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
18 using System.Collections.Generic;
19 using System.Runtime.InteropServices;
20 using System.Diagnostics.CodeAnalysis;
22 namespace Tizen.Pims.Calendar
25 /// CalendarDatabase provides methods to manage calendar information from/to the database.
28 /// This class allows user to access/create/update/delete db operations for calendar information.
29 /// CalendarDatabase is created by CalendarManager.
31 /// <since_tizen> 4 </since_tizen>
32 public class CalendarDatabase
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>();
38 internal CalendarDatabase()
40 /*To be created in CalendarManager only*/
44 /// The calendar database version.
46 /// <since_tizen> 4 </since_tizen>
47 /// <value>The current calendar database version.</value>
48 [SuppressMessage("Microsoft.Performance", "CA1822:MarkMembersAsStatic")]
54 int error = Interop.Database.GetCurrentVersion(out version);
55 if (CalendarError.None != (CalendarError)error)
57 Log.Error(Globals.LogTag, "Version Failed with error " + error);
64 /// Gets last successful changed calendar database version on the current connection.
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
79 int error = Interop.Database.GetLastChangeVersion(out version);
80 if (CalendarError.None != (CalendarError)error)
82 Log.Error(Globals.LogTag, "LastChangeVersion Failed with error " + error);
89 /// Inserts a record into the calendar database.
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)
105 int error = Interop.Database.Insert(record._recordHandle, out id);
106 if (CalendarError.None != (CalendarError)error)
108 Log.Error(Globals.LogTag, "Insert Failed with error " + error);
109 throw CalendarErrorFactory.GetException(error);
115 /// Gets a record from the calendar database.
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>
121 /// The record associated with the record ID
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)
135 int error = Interop.Database.Get(viewUri, recordId, out handle);
136 if (CalendarError.None != (CalendarError)error)
138 if (CalendarError.DBNotFound == (CalendarError)error)
140 Log.Error(Globals.LogTag, "No data" + error);
143 Log.Error(Globals.LogTag, "Get Failed with error " + error);
144 throw CalendarErrorFactory.GetException(error);
146 return new CalendarRecord(handle);
150 /// Updates a record in the calendar database.
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)
164 int error = Interop.Database.Update(record._recordHandle);
165 if (CalendarError.None != (CalendarError)error)
167 Log.Error(Globals.LogTag, "Update Failed with error " + error);
168 throw CalendarErrorFactory.GetException(error);
173 /// Deletes a record from the calendar database with related child records.
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)
189 int error = Interop.Database.Delete(viewUri, recordId);
190 if (CalendarError.None != (CalendarError)error)
192 Log.Error(Globals.LogTag, "Delete Failed with error " + error);
193 throw CalendarErrorFactory.GetException(error);
198 /// Replaces a record in the calendar database.
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)
213 int error = Interop.Database.Replace(record._recordHandle, id);
214 if (CalendarError.None != (CalendarError)error)
216 Log.Error(Globals.LogTag, "Replace Failed with error " + error);
217 throw CalendarErrorFactory.GetException(error);
222 /// Retrieves all records as a list.
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>
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)
243 int error = Interop.Database.GetAllRecords(viewUri, offset, limit, out handle);
244 if (CalendarError.None != (CalendarError)error)
246 Log.Error(Globals.LogTag, "GetAll Failed with error " + error);
247 throw CalendarErrorFactory.GetException(error);
249 return new CalendarList(handle);
253 /// Retrieves records using a query.
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>
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)
273 int error = Interop.Database.GetRecords(query._queryHandle, offset, limit, out handle);
274 if (CalendarError.None != (CalendarError)error)
276 Log.Error(Globals.LogTag, "GetAllWithQuery Failed with error " + error);
277 throw CalendarErrorFactory.GetException(error);
279 return new CalendarList(handle);
283 /// Inserts multiple records into the calendar database as a batch operation.
285 /// <since_tizen> 4 </since_tizen>
286 /// <param name="list">The record list</param>
288 /// The inserted record id array
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)
302 int error = Interop.Database.InsertRecords(list._listHandle, out ids, out count);
303 if (CalendarError.None != (CalendarError)error)
305 Log.Error(Globals.LogTag, "Insert Failed with error " + error);
306 throw CalendarErrorFactory.GetException(error);
308 int[] idArr = new int[count];
309 Marshal.Copy(ids, idArr, 0, count);
315 /// Updates multiple records into the calendar database as a batch operation.
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)
329 int error = Interop.Database.UpdateRecords(list._listHandle);
330 if (CalendarError.None != (CalendarError)error)
332 Log.Error(Globals.LogTag, "Update Failed with error " + error);
333 throw CalendarErrorFactory.GetException(error);
338 /// Deletes multiple records with related child records from the calendar database as a batch operation.
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)
354 int error = Interop.Database.DeleteRecords(viewUri, idArray, idArray.Length);
355 if (CalendarError.None != (CalendarError)error)
357 Log.Error(Globals.LogTag, "Delete Failed with error " + error);
358 throw CalendarErrorFactory.GetException(error);
363 /// Deletes multiple records with related child records from the calendar database as a batch operation.
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)
376 CalendarRecord record = null;
380 int[] ids = new int[list.Count];
384 for (i = 0; i < list.Count; i++)
386 record = list.GetCurrentRecord();
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;
401 Log.Error(Globals.LogTag, "Invalid uri [" + record.Uri + "]");
405 ids[i] = record.Get<int>(propertyId);
408 Delete(record.Uri, ids);
412 /// Replaces multiple records in the calendar database as a batch operation.
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)
427 int error = Interop.Database.ReplaceRecords(list._listHandle, idArray, idArray.Length);
428 if (CalendarError.None != (CalendarError)error)
430 Log.Error(Globals.LogTag, "Replace Failed with error " + error);
431 throw CalendarErrorFactory.GetException(error);
436 /// Retrieves records with the given calendar database version.
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>
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)
458 int error = Interop.Database.GetChangesByVersion(viewUri, BookId, calendarDBVersion, out recordList, out currentDBVersion);
459 if (CalendarError.None != (CalendarError)error)
461 Log.Error(Globals.LogTag, "GetChangesByVersion Failed with error " + error);
462 throw CalendarErrorFactory.GetException(error);
464 return new CalendarList(recordList);
468 /// Gets the record count of a specific view.
470 /// <since_tizen> 4 </since_tizen>
471 /// <param name="viewUri">The view URI to get records from</param>
473 /// The count of records
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)
481 int error = Interop.Database.GetCount(viewUri, out count);
482 if (CalendarError.None != (CalendarError)error)
484 Log.Error(Globals.LogTag, "GetCount Failed with error " + error);
485 throw CalendarErrorFactory.GetException(error);
491 /// Gets the record count with a query.
493 /// <since_tizen> 4 </since_tizen>
494 /// <param name="query">The query used for filtering the results</param>
496 /// The count of records
498 /// <privilege>http://tizen.org/privilege/calendar.read</privilege>
499 [SuppressMessage("Microsoft.Design", "CA1822:MarkMembersAsStatic")]
500 public int GetCount(CalendarQuery query)
503 int error = Interop.Database.GetCountWithQuery(query._queryHandle, out count);
504 if (CalendarError.None != (CalendarError)error)
506 Log.Error(Globals.LogTag, "GetCount Failed with error " + error);
507 throw CalendarErrorFactory.GetException(error);
513 /// Registers a callback function to be invoked when a record changes.
514 /// <since_tizen> 4 </since_tizen>
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)
528 Log.Debug(Globals.LogTag, "AddDBChangedDelegate");
530 if (!_callbackMap.ContainsKey(viewUri))
532 _callbackMap[viewUri] = (string uri, IntPtr userData) =>
534 DBChangedEventArgs args = new DBChangedEventArgs(uri);
535 _eventHandlerMap[uri]?.Invoke(this, args);
538 int error = Interop.Database.AddChangedCallback(viewUri, _callbackMap[viewUri], IntPtr.Zero);
539 if (CalendarError.None != (CalendarError)error)
541 Log.Error(Globals.LogTag, "AddDBChangedDelegate Failed with error " + error);
542 throw CalendarErrorFactory.GetException(error);
546 EventHandler<DBChangedEventArgs> handler = null;
547 if (!_eventHandlerMap.TryGetValue(viewUri, out handler))
548 _eventHandlerMap.Add(viewUri, null);
550 _eventHandlerMap[viewUri] = handler + DBChanged;
554 /// Deregisters a callback function.
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)
569 Log.Debug(Globals.LogTag, "RemoveDBChangedDelegate");
571 EventHandler<DBChangedEventArgs> handler = null;
572 if (!_eventHandlerMap.TryGetValue(viewUri, out handler))
573 _eventHandlerMap.Add(viewUri, null);
575 _eventHandlerMap[viewUri] = handler - DBChanged;
577 if (_eventHandlerMap[viewUri] == null)
579 int error = Interop.Database.RemoveChangedCallback(viewUri, _callbackMap[viewUri], IntPtr.Zero);
580 if (CalendarError.None != (CalendarError)error)
582 Log.Error(Globals.LogTag, "RemoveDBChangedDelegate Failed with error " + error);
583 throw CalendarErrorFactory.GetException(error);
585 _callbackMap.Remove(viewUri);
590 /// Link a record to another record.
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)
605 Log.Debug(Globals.LogTag, "LinkRecord");
606 int error = Interop.Database.LinkRecord(baseId, recordId);
607 if (CalendarError.None != (CalendarError)error)
609 Log.Error(Globals.LogTag, "LinkRecor Failed with error " + error);
610 throw CalendarErrorFactory.GetException(error);
615 /// Unlink a record from base record.
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)
629 Log.Debug(Globals.LogTag, "UnlinkRecord");
630 int error = Interop.Database.UnlinkRecord(recordId);
631 if (CalendarError.None != (CalendarError)error)
633 Log.Error(Globals.LogTag, "UnlinkRecor Failed with error " + error);
634 throw CalendarErrorFactory.GetException(error);