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>();
37 private Interop.Database.DBChangedCallback _dbChangedDelegate;
39 internal CalendarDatabase()
41 ///To be created in CalendarManager only
45 /// The calendar database version.
47 /// <since_tizen> 4 </since_tizen>
48 /// <value>The current calendar database version.</value>
49 [SuppressMessage("Microsoft.Performance", "CA1822:MarkMembersAsStatic")]
55 int error = Interop.Database.GetCurrentVersion(out version);
56 if (CalendarError.None != (CalendarError)error)
58 Log.Error(Globals.LogTag, "Version Failed with error " + error);
65 /// Gets last successful changed calendar database version on the current connection.
67 /// <since_tizen> 4 </since_tizen>
68 /// <returns>The last successful changed calendar database version on the current connection</returns>
69 /// <privilege>http://tizen.org/privilege/calendar.read</privilege>
70 /// <exception cref="InvalidOperationException">Thrown when method failed due to invalid operation</exception>
71 /// <exception cref="OutOfMemoryException">Thrown when failed due to out of memory</exception>
72 /// <exception cref="UnauthorizedAccessException">Thrown when application does not have proper privileges</exception>
73 /// <value>The last successful changed calendar database version on the current connection.</value>
74 [SuppressMessage("Microsoft.Performance", "CA1822:MarkMembersAsStatic")]
75 public int LastChangeVersion
80 int error = Interop.Database.GetLastChangeVersion(out version);
81 if (CalendarError.None != (CalendarError)error)
83 Log.Error(Globals.LogTag, "LastChangeVersion Failed with error " + error);
90 /// Inserts a record into the calendar database.
92 /// <since_tizen> 4 </since_tizen>
93 /// <param name="record">The record to be inserted</param>
94 /// <returns>The ID of inserted record</returns>
95 /// <privilege>http://tizen.org/privilege/calendar.write</privilege>
96 /// <feature>http://tizen.org/feature/calendar</feature>
97 /// <exception cref="NotSupportedException">Thrown when feature is not supported</exception>
98 /// <exception cref="InvalidOperationException">Thrown when method failed due to invalid operation</exception>
99 /// <exception cref="ArgumentException">Thrown when one of the arguments provided to a method is not valid</exception>
100 /// <exception cref="OutOfMemoryException">Thrown when failed due to out of memory</exception>
101 /// <exception cref="UnauthorizedAccessException">Thrown when application does not have proper privileges</exception>
102 [SuppressMessage("Microsoft.Performance", "CA1822:MarkMembersAsStatic")]
103 public int Insert(CalendarRecord record)
106 int error = Interop.Database.Insert(record._recordHandle, out id);
107 if (CalendarError.None != (CalendarError)error)
109 Log.Error(Globals.LogTag, "Insert Failed with error " + error);
110 throw CalendarErrorFactory.GetException(error);
116 /// Gets a record from the calendar database.
118 /// <since_tizen> 4 </since_tizen>
119 /// <param name="viewUri">The view URI of a record</param>
120 /// <param name="recordId">The record ID</param>
122 /// The record associated with the record ID
124 /// <privilege>http://tizen.org/privilege/calendar.read</privilege>
125 /// <feature>http://tizen.org/feature/calendar</feature>
126 /// <exception cref="NotSupportedException">Thrown when feature is not supported</exception>
127 /// <exception cref="InvalidOperationException">Thrown when method failed due to invalid operation</exception>
128 /// <exception cref="ArgumentException">Thrown when one of the arguments provided to a method is not valid</exception>
129 /// <exception cref="OutOfMemoryException">Thrown when failed due to out of memory</exception>
130 /// <exception cref="UnauthorizedAccessException">Thrown when application does not have proper privileges</exception>
131 [SuppressMessage("Microsoft.Performance", "CA1822:MarkMembersAsStatic")]
132 [SuppressMessage("Microsoft.Design", "CA1054:UriParametersShouldNotBeStrings")]
133 public CalendarRecord Get(string viewUri, int recordId)
136 int error = Interop.Database.Get(viewUri, recordId, out handle);
137 if (CalendarError.None != (CalendarError)error)
139 if (CalendarError.DBNotFound == (CalendarError)error)
141 Log.Error(Globals.LogTag, "No data" + error);
144 Log.Error(Globals.LogTag, "Get Failed with error " + error);
145 throw CalendarErrorFactory.GetException(error);
147 return new CalendarRecord(handle);
151 /// Updates a record in the calendar database.
153 /// <since_tizen> 4 </since_tizen>
154 /// <param name="record">The record to be updated</param>
155 /// <privilege>http://tizen.org/privilege/calendar.write</privilege>
156 /// <feature>http://tizen.org/feature/calendar</feature>
157 /// <exception cref="NotSupportedException">Thrown when feature is not supported</exception>
158 /// <exception cref="InvalidOperationException">Thrown when method failed due to invalid operation</exception>
159 /// <exception cref="ArgumentException">Thrown when one of the arguments provided to a method is not valid</exception>
160 /// <exception cref="OutOfMemoryException">Thrown when failed due to out of memory</exception>
161 /// <exception cref="UnauthorizedAccessException">Thrown when application does not have proper privileges</exception>
162 [SuppressMessage("Microsoft.Performance", "CA1822:MarkMembersAsStatic")]
163 public void Update(CalendarRecord record)
165 int error = Interop.Database.Update(record._recordHandle);
166 if (CalendarError.None != (CalendarError)error)
168 Log.Error(Globals.LogTag, "Update Failed with error " + error);
169 throw CalendarErrorFactory.GetException(error);
174 /// Deletes a record from the calendar database with related child records.
176 /// <since_tizen> 4 </since_tizen>
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 /// <feature>http://tizen.org/feature/calendar</feature>
181 /// <exception cref="NotSupportedException">Thrown when feature is not supported</exception>
182 /// <exception cref="InvalidOperationException">Thrown when method failed due to invalid operation</exception>
183 /// <exception cref="ArgumentException">Thrown when one of the arguments provided to a method is not valid</exception>
184 /// <exception cref="OutOfMemoryException">Thrown when failed due to out of memory</exception>
185 /// <exception cref="UnauthorizedAccessException">Thrown when application does not have proper privileges</exception>
186 [SuppressMessage("Microsoft.Performance", "CA1822:MarkMembersAsStatic")]
187 [SuppressMessage("Microsoft.Design", "CA1054:UriParametersShouldNotBeStrings")]
188 public void Delete(string viewUri, int recordId)
190 int error = Interop.Database.Delete(viewUri, recordId);
191 if (CalendarError.None != (CalendarError)error)
193 Log.Error(Globals.LogTag, "Delete Failed with error " + error);
194 throw CalendarErrorFactory.GetException(error);
199 /// Replaces a record in the calendar database.
201 /// <since_tizen> 4 </since_tizen>
202 /// <param name="record">The record to be replaced</param>
203 /// <param name="id">the record id</param>
204 /// <privilege>http://tizen.org/privilege/calendar.write</privilege>
205 /// <feature>http://tizen.org/feature/calendar</feature>
206 /// <exception cref="NotSupportedException">Thrown when feature is not supported</exception>
207 /// <exception cref="InvalidOperationException">Thrown when method failed due to invalid operation</exception>
208 /// <exception cref="ArgumentException">Thrown when one of the arguments provided to a method is not valid</exception>
209 /// <exception cref="OutOfMemoryException">Thrown when failed due to out of memory</exception>
210 /// <exception cref="UnauthorizedAccessException">Thrown when application does not have proper privileges</exception>
211 [SuppressMessage("Microsoft.Performance", "CA1822:MarkMembersAsStatic")]
212 public void Replace(CalendarRecord record, int id)
214 int error = Interop.Database.Replace(record._recordHandle, id);
215 if (CalendarError.None != (CalendarError)error)
217 Log.Error(Globals.LogTag, "Replace Failed with error " + error);
218 throw CalendarErrorFactory.GetException(error);
223 /// Retrieves all records as a list.
225 /// <since_tizen> 4 </since_tizen>
226 /// <param name="viewUri">The view URI to get records from</param>
227 /// <param name="offset">The index from which results are received</param>
228 /// <param name="limit">The maximum number of results(value 0 is used for all records)</param>
232 /// <privilege>http://tizen.org/privilege/calendar.read</privilege>
233 /// <feature>http://tizen.org/feature/calendar</feature>
234 /// <exception cref="NotSupportedException">Thrown when feature is not supported</exception>
235 /// <exception cref="InvalidOperationException">Thrown when method failed due to invalid operation</exception>
236 /// <exception cref="ArgumentException">Thrown when one of the arguments provided to a method is not valid</exception>
237 /// <exception cref="OutOfMemoryException">Thrown when failed due to out of memory</exception>
238 /// <exception cref="UnauthorizedAccessException">Thrown when application does not have proper privileges</exception>
239 [SuppressMessage("Microsoft.Performance", "CA1822:MarkMembersAsStatic")]
240 [SuppressMessage("Microsoft.Design", "CA1054:UriParametersShouldNotBeStrings")]
241 public CalendarList GetAll(string viewUri, int offset, int limit)
244 int error = Interop.Database.GetAllRecords(viewUri, offset, limit, out handle);
245 if (CalendarError.None != (CalendarError)error)
247 Log.Error(Globals.LogTag, "GetAll Failed with error " + error);
248 throw CalendarErrorFactory.GetException(error);
250 return new CalendarList(handle);
254 /// Retrieves records using a query.
256 /// <since_tizen> 4 </since_tizen>
257 /// <param name="query">The query used to filter results</param>
258 /// <param name="offset">The index from which results are received</param>
259 /// <param name="limit">The maximum number of results(value 0 is used for all records)</param>
263 /// <privilege>http://tizen.org/privilege/calendar.read</privilege>
264 /// <feature>http://tizen.org/feature/calendar</feature>
265 /// <exception cref="NotSupportedException">Thrown when feature is not supported</exception>
266 /// <exception cref="InvalidOperationException">Thrown when method failed due to invalid operation</exception>
267 /// <exception cref="ArgumentException">Thrown when one of the arguments provided to a method is not valid</exception>
268 /// <exception cref="OutOfMemoryException">Thrown when failed due to out of memory</exception>
269 /// <exception cref="UnauthorizedAccessException">Thrown when application does not have proper privileges</exception>
270 [SuppressMessage("Microsoft.Performance", "CA1822:MarkMembersAsStatic")]
271 public CalendarList GetRecordsWithQuery(CalendarQuery query, int offset, int limit)
274 int error = Interop.Database.GetRecords(query._queryHandle, offset, limit, out handle);
275 if (CalendarError.None != (CalendarError)error)
277 Log.Error(Globals.LogTag, "GetAllWithQuery Failed with error " + error);
278 throw CalendarErrorFactory.GetException(error);
280 return new CalendarList(handle);
284 /// Inserts multiple records into the calendar database as a batch operation.
286 /// <since_tizen> 4 </since_tizen>
287 /// <param name="list">The record list</param>
289 /// The inserted record id array
291 /// <privilege>http://tizen.org/privilege/calendar.write</privilege>
292 /// <feature>http://tizen.org/feature/calendar</feature>
293 /// <exception cref="NotSupportedException">Thrown when feature is not supported</exception>
294 /// <exception cref="InvalidOperationException">Thrown when method failed due to invalid operation</exception>
295 /// <exception cref="ArgumentException">Thrown when one of the arguments provided to a method is not valid</exception>
296 /// <exception cref="OutOfMemoryException">Thrown when failed due to out of memory</exception>
297 /// <exception cref="UnauthorizedAccessException">Thrown when application does not have proper privileges</exception>
298 [SuppressMessage("Microsoft.Performance", "CA1822:MarkMembersAsStatic")]
299 public int[] Insert(CalendarList list)
303 int error = Interop.Database.InsertRecords(list._listHandle, out ids, out count);
304 if (CalendarError.None != (CalendarError)error)
306 Log.Error(Globals.LogTag, "Insert Failed with error " + error);
307 throw CalendarErrorFactory.GetException(error);
309 int[] idArr = new int[count];
310 Marshal.Copy(ids, idArr, 0, count);
316 /// Updates multiple records into the calendar database as a batch operation.
318 /// <since_tizen> 4 </since_tizen>
319 /// <param name="list">The record list</param>
320 /// <privilege>http://tizen.org/privilege/calendar.write</privilege>
321 /// <feature>http://tizen.org/feature/calendar</feature>
322 /// <exception cref="NotSupportedException">Thrown when feature is not supported</exception>
323 /// <exception cref="InvalidOperationException">Thrown when method failed due to invalid operation</exception>
324 /// <exception cref="ArgumentException">Thrown when one of the arguments provided to a method is not valid</exception>
325 /// <exception cref="OutOfMemoryException">Thrown when failed due to out of memory</exception>
326 /// <exception cref="UnauthorizedAccessException">Thrown when application does not have proper privileges</exception>
327 [SuppressMessage("Microsoft.Performance", "CA1822:MarkMembersAsStatic")]
328 public void Update(CalendarList list)
330 int error = Interop.Database.UpdateRecords(list._listHandle);
331 if (CalendarError.None != (CalendarError)error)
333 Log.Error(Globals.LogTag, "Update Failed with error " + error);
334 throw CalendarErrorFactory.GetException(error);
339 /// Deletes multiple records with related child records from the calendar database as a batch operation.
341 /// <since_tizen> 4 </since_tizen>
342 /// <param name="viewUri">The view URI of the records to delete</param>
343 /// <param name="idArray">The record IDs to delete</param>
344 /// <privilege>http://tizen.org/privilege/calendar.write</privilege>
345 /// <feature>http://tizen.org/feature/calendar</feature>
346 /// <exception cref="NotSupportedException">Thrown when feature is not supported</exception>
347 /// <exception cref="InvalidOperationException">Thrown when method failed due to invalid operation</exception>
348 /// <exception cref="ArgumentException">Thrown when one of the arguments provided to a method is not valid</exception>
349 /// <exception cref="OutOfMemoryException">Thrown when failed due to out of memory</exception>
350 /// <exception cref="UnauthorizedAccessException">Thrown when application does not have proper privileges</exception>
351 [SuppressMessage("Microsoft.Performance", "CA1822:MarkMembersAsStatic")]
352 [SuppressMessage("Microsoft.Design", "CA1054:UriParametersShouldNotBeStrings")]
353 public void Delete(string viewUri, int[] idArray)
355 int error = Interop.Database.DeleteRecords(viewUri, idArray, idArray.Length);
356 if (CalendarError.None != (CalendarError)error)
358 Log.Error(Globals.LogTag, "Delete Failed with error " + error);
359 throw CalendarErrorFactory.GetException(error);
364 /// Deletes multiple records with related child records from the calendar database as a batch operation.
366 /// <since_tizen> 4 </since_tizen>
367 /// <param name="list">The record list</param>
368 /// <privilege>http://tizen.org/privilege/calendar.write</privilege>
369 /// <feature>http://tizen.org/feature/calendar</feature>
370 /// <exception cref="NotSupportedException">Thrown when feature is not supported</exception>
371 /// <exception cref="InvalidOperationException">Thrown when method failed due to invalid operation</exception>
372 /// <exception cref="ArgumentException">Thrown when one of the arguments provided to a method is not valid</exception>
373 /// <exception cref="OutOfMemoryException">Thrown when failed due to out of memory</exception>
374 /// <exception cref="UnauthorizedAccessException">Thrown when application does not have proper privileges</exception>
375 public void Delete(CalendarList list)
377 CalendarRecord record = null;
381 int[] ids = new int[list.Count];
385 for (i = 0; i < list.Count; i++)
387 record = list.GetCurrentRecord();
390 if (0 == String.Compare(CalendarViews.Book.Uri, record.Uri))
391 propertyId = CalendarViews.Book.Id;
392 else if (0 == String.Compare(CalendarViews.Event.Uri, record.Uri))
393 propertyId = CalendarViews.Event.Id;
394 else if (0 == String.Compare(CalendarViews.Todo.Uri, record.Uri))
395 propertyId = CalendarViews.Todo.Id;
396 else if (0 == String.Compare(CalendarViews.Timezone.Uri, record.Uri))
397 propertyId = CalendarViews.Timezone.Id;
398 else if (0 == String.Compare(CalendarViews.Extended.Uri, record.Uri))
399 propertyId = CalendarViews.Extended.Id;
402 Log.Error(Globals.LogTag, "Invalid uri [" + record.Uri + "]");
406 ids[i] = record.Get<int>(propertyId);
409 Delete(record.Uri, ids);
413 /// Replaces multiple records in the calendar database as a batch operation.
415 /// <since_tizen> 4 </since_tizen>
416 /// <param name="list">The record list</param>
417 /// <param name="idArray">The record IDs</param>
418 /// <privilege>http://tizen.org/privilege/calendar.write</privilege>
419 /// <feature>http://tizen.org/feature/calendar</feature>
420 /// <exception cref="NotSupportedException">Thrown when feature is not supported</exception>
421 /// <exception cref="InvalidOperationException">Thrown when method failed due to invalid operation</exception>
422 /// <exception cref="ArgumentException">Thrown when one of the arguments provided to a method is not valid</exception>
423 /// <exception cref="OutOfMemoryException">Thrown when failed due to out of memory</exception>
424 /// <exception cref="UnauthorizedAccessException">Thrown when application does not have proper privileges</exception>
425 [SuppressMessage("Microsoft.Performance", "CA1822:MarkMembersAsStatic")]
426 public void Replace(CalendarList list, int[] idArray)
428 int error = Interop.Database.ReplaceRecords(list._listHandle, idArray, idArray.Length);
429 if (CalendarError.None != (CalendarError)error)
431 Log.Error(Globals.LogTag, "Replace Failed with error " + error);
432 throw CalendarErrorFactory.GetException(error);
437 /// Retrieves records with the given calendar database version.
439 /// <since_tizen> 4 </since_tizen>
440 /// <param name="viewUri">The view URI to get records from</param>
441 /// <param name="BookId">The calendar book ID to filter</param>
442 /// <param name="calendarDBVersion">The calendar database version</param>
443 /// <param name="currentDBVersion">The current calendar database version</param>
447 /// <privilege>http://tizen.org/privilege/calendar.read</privilege>
448 /// <feature>http://tizen.org/feature/calendar</feature>
449 /// <exception cref="NotSupportedException">Thrown when feature is not supported</exception>
450 /// <exception cref="InvalidOperationException">Thrown when method failed due to invalid operation</exception>
451 /// <exception cref="ArgumentException">Thrown when one of the arguments provided to a method is not valid</exception>
452 /// <exception cref="OutOfMemoryException">Thrown when failed due to out of memory</exception>
453 /// <exception cref="UnauthorizedAccessException">Thrown when application does not have proper privileges</exception>
454 [SuppressMessage("Microsoft.Performance", "CA1822:MarkMembersAsStatic")]
455 [SuppressMessage("Microsoft.Design", "CA1054:UriParametersShouldNotBeStrings")]
456 public CalendarList GetChangesByVersion(string viewUri, int BookId, int calendarDBVersion, out int currentDBVersion)
459 int error = Interop.Database.GetChangesByVersion(viewUri, BookId, calendarDBVersion, out recordList, out currentDBVersion);
460 if (CalendarError.None != (CalendarError)error)
462 Log.Error(Globals.LogTag, "GetChangesByVersion Failed with error " + error);
463 throw CalendarErrorFactory.GetException(error);
465 return new CalendarList(recordList);
469 /// Gets the record count of a specific view.
471 /// <since_tizen> 4 </since_tizen>
472 /// <param name="viewUri">The view URI to get records from</param>
474 /// The count of records
476 /// <privilege>http://tizen.org/privilege/calendar.read</privilege>
477 [SuppressMessage("Microsoft.Design", "CA1822:MarkMembersAsStatic")]
478 [SuppressMessage("Microsoft.Design", "CA1054:UriParametersShouldNotBeStrings")]
479 public int GetCount(string viewUri)
482 int error = Interop.Database.GetCount(viewUri, out count);
483 if (CalendarError.None != (CalendarError)error)
485 Log.Error(Globals.LogTag, "GetCount Failed with error " + error);
486 throw CalendarErrorFactory.GetException(error);
492 /// Gets the record count with a query.
494 /// <since_tizen> 4 </since_tizen>
495 /// <param name="query">The query used for filtering the results</param>
497 /// The count of records
499 /// <privilege>http://tizen.org/privilege/calendar.read</privilege>
500 [SuppressMessage("Microsoft.Design", "CA1822:MarkMembersAsStatic")]
501 public int GetCount(CalendarQuery query)
504 int error = Interop.Database.GetCountWithQuery(query._queryHandle, out count);
505 if (CalendarError.None != (CalendarError)error)
507 Log.Error(Globals.LogTag, "GetCount Failed with error " + error);
508 throw CalendarErrorFactory.GetException(error);
514 /// Registers a callback function to be invoked when a record changes.
515 /// <since_tizen> 4 </since_tizen>
517 /// <param name="viewUri">The view URI of the record to subscribe for change notifications</param>
518 /// <param name="DBChanged">The EventHandler to register</param>
519 /// <privilege>http://tizen.org/privilege/calendar.read</privilege>
520 /// <feature>http://tizen.org/feature/calendar</feature>
521 /// <exception cref="NotSupportedException">Thrown when feature is not supported</exception>
522 /// <exception cref="InvalidOperationException">Thrown when method failed due to invalid operation</exception>
523 /// <exception cref="ArgumentException">Thrown when one of the arguments provided to a method is not valid</exception>
524 /// <exception cref="OutOfMemoryException">Thrown when failed due to out of memory</exception>
525 /// <exception cref="UnauthorizedAccessException">Thrown when application does not have proper privileges</exception>
526 [SuppressMessage("Microsoft.Design", "CA1054:UriParametersShouldNotBeStrings")]
527 public void AddDBChangedDelegate(string viewUri, EventHandler<DBChangedEventArgs> DBChanged)
529 Log.Debug(Globals.LogTag, "AddDBChangedDelegate");
531 if (!_callbackMap.ContainsKey(viewUri))
533 _callbackMap[viewUri] = (string uri, IntPtr userData) =>
535 DBChangedEventArgs args = new DBChangedEventArgs(uri);
536 _eventHandlerMap[uri]?.Invoke(this, args);
539 int error = Interop.Database.AddChangedCallback(viewUri, _dbChangedDelegate, IntPtr.Zero);
540 if (CalendarError.None != (CalendarError)error)
542 Log.Error(Globals.LogTag, "AddDBChangedDelegate Failed with error " + error);
543 throw CalendarErrorFactory.GetException(error);
547 EventHandler<DBChangedEventArgs> handler = null;
548 if (!_eventHandlerMap.TryGetValue(viewUri, out handler))
549 _eventHandlerMap.Add(viewUri, null);
551 _eventHandlerMap[viewUri] = handler + DBChanged;
555 /// Deregisters a callback function.
557 /// <since_tizen> 4 </since_tizen>
558 /// <param name="viewUri">The view URI of the record to subscribe for change notifications</param>
559 /// <param name="DBChanged">The EventHandler to deregister</param>
560 /// <privilege>http://tizen.org/privilege/calendar.read</privilege>
561 /// <feature>http://tizen.org/feature/calendar</feature>
562 /// <exception cref="NotSupportedException">Thrown when feature is not supported</exception>
563 /// <exception cref="InvalidOperationException">Thrown when method failed due to invalid operation</exception>
564 /// <exception cref="ArgumentException">Thrown when one of the arguments provided to a method is not valid</exception>
565 /// <exception cref="OutOfMemoryException">Thrown when failed due to out of memory</exception>
566 /// <exception cref="UnauthorizedAccessException">Thrown when application does not have proper privileges</exception>
567 [SuppressMessage("Microsoft.Design", "CA1054:UriParametersShouldNotBeStrings")]
568 public void RemoveDBChangedDelegate(string viewUri, EventHandler<DBChangedEventArgs> DBChanged)
570 Log.Debug(Globals.LogTag, "RemoveDBChangedDelegate");
572 EventHandler<DBChangedEventArgs> handler = null;
573 if (!_eventHandlerMap.TryGetValue(viewUri, out handler))
574 _eventHandlerMap.Add(viewUri, null);
576 _eventHandlerMap[viewUri] = handler - DBChanged;
578 if (_eventHandlerMap[viewUri] == null)
580 int error = Interop.Database.RemoveChangedCallback(viewUri, _callbackMap[viewUri], IntPtr.Zero);
581 if (CalendarError.None != (CalendarError)error)
583 Log.Error(Globals.LogTag, "RemoveDBChangedDelegate Failed with error " + error);
584 throw CalendarErrorFactory.GetException(error);
586 _callbackMap.Remove(viewUri);
591 /// Link a record to another record.
593 /// <since_tizen> 4 </since_tizen>
594 /// <param name="baseId">The base record ID</param>
595 /// <param name="recordId">The record ID to link to</param>
596 /// <privilege>http://tizen.org/privilege/calendar.write</privilege>
597 /// <feature>http://tizen.org/feature/calendar</feature>
598 /// <exception cref="NotSupportedException">Thrown when feature is not supported</exception>
599 /// <exception cref="InvalidOperationException">Thrown when method failed due to invalid operation</exception>
600 /// <exception cref="ArgumentException">Thrown when one of the arguments provided to a method is not valid</exception>
601 /// <exception cref="OutOfMemoryException">Thrown when failed due to out of memory</exception>
602 /// <exception cref="UnauthorizedAccessException">Thrown when application does not have proper privileges</exception>
603 [SuppressMessage("Microsoft.Design", "CA1822:MarkMembersAsStatic")]
604 public void LinkRecord(int baseId, int recordId)
606 Log.Debug(Globals.LogTag, "LinkRecord");
607 int error = Interop.Database.LinkRecord(baseId, recordId);
608 if (CalendarError.None != (CalendarError)error)
610 Log.Error(Globals.LogTag, "LinkRecor Failed with error " + error);
611 throw CalendarErrorFactory.GetException(error);
616 /// Unlink a record from base record.
618 /// <since_tizen> 4 </since_tizen>
619 /// <param name="recordId">The record ID to unlink</param>
620 /// <privilege>http://tizen.org/privilege/calendar.write</privilege>
621 /// <feature>http://tizen.org/feature/calendar</feature>
622 /// <exception cref="NotSupportedException">Thrown when feature is not supported</exception>
623 /// <exception cref="InvalidOperationException">Thrown when method failed due to invalid operation</exception>
624 /// <exception cref="ArgumentException">Thrown when one of the arguments provided to a method is not valid</exception>
625 /// <exception cref="OutOfMemoryException">Thrown when failed due to out of memory</exception>
626 /// <exception cref="UnauthorizedAccessException">Thrown when application does not have proper privileges</exception>
627 [SuppressMessage("Microsoft.Performance", "CA1822:MarkMembersAsStatic")]
628 public void UnlinkRecord(int recordId)
630 Log.Debug(Globals.LogTag, "UnlinkRecord");
631 int error = Interop.Database.UnlinkRecord(recordId);
632 if (CalendarError.None != (CalendarError)error)
634 Log.Error(Globals.LogTag, "UnlinkRecor Failed with error " + error);
635 throw CalendarErrorFactory.GetException(error);