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="OutOfMemoryException">Thrown when failed due to out of memory</exception>
267 /// <exception cref="UnauthorizedAccessException">Thrown when application does not have proper privileges</exception>
268 [SuppressMessage("Microsoft.Performance", "CA1822:MarkMembersAsStatic")]
269 public CalendarList GetRecordsWithQuery(CalendarQuery query, int offset, int limit)
272 int error = Interop.Database.GetRecords(query._queryHandle, offset, limit, out handle);
273 if (CalendarError.None != (CalendarError)error)
275 Log.Error(Globals.LogTag, "GetAllWithQuery Failed with error " + error);
276 throw CalendarErrorFactory.GetException(error);
278 return new CalendarList(handle);
282 /// Inserts multiple records into the calendar database as a batch operation.
284 /// <since_tizen> 4 </since_tizen>
285 /// <param name="list">The record list</param>
287 /// The inserted record id array
289 /// <privilege>http://tizen.org/privilege/calendar.write</privilege>
290 /// <feature>http://tizen.org/feature/calendar</feature>
291 /// <exception cref="NotSupportedException">Thrown when feature is not supported</exception>
292 /// <exception cref="InvalidOperationException">Thrown when method failed due to invalid operation</exception>
293 /// <exception cref="ArgumentException">Thrown when one of the arguments provided to a method is not valid</exception>
294 /// <exception cref="OutOfMemoryException">Thrown when failed due to out of memory</exception>
295 /// <exception cref="UnauthorizedAccessException">Thrown when application does not have proper privileges</exception>
296 [SuppressMessage("Microsoft.Performance", "CA1822:MarkMembersAsStatic")]
297 public int[] Insert(CalendarList list)
301 int error = Interop.Database.InsertRecords(list._listHandle, out ids, out count);
302 if (CalendarError.None != (CalendarError)error)
304 Log.Error(Globals.LogTag, "Insert Failed with error " + error);
305 throw CalendarErrorFactory.GetException(error);
307 int[] idArr = new int[count];
308 Marshal.Copy(ids, idArr, 0, count);
314 /// Updates multiple records into the calendar database as a batch operation.
316 /// <since_tizen> 4 </since_tizen>
317 /// <param name="list">The record list</param>
318 /// <privilege>http://tizen.org/privilege/calendar.write</privilege>
319 /// <feature>http://tizen.org/feature/calendar</feature>
320 /// <exception cref="NotSupportedException">Thrown when feature is not supported</exception>
321 /// <exception cref="InvalidOperationException">Thrown when method failed due to invalid operation</exception>
322 /// <exception cref="ArgumentException">Thrown when one of the arguments provided to a method is not valid</exception>
323 /// <exception cref="OutOfMemoryException">Thrown when failed due to out of memory</exception>
324 /// <exception cref="UnauthorizedAccessException">Thrown when application does not have proper privileges</exception>
325 [SuppressMessage("Microsoft.Performance", "CA1822:MarkMembersAsStatic")]
326 public void Update(CalendarList list)
328 int error = Interop.Database.UpdateRecords(list._listHandle);
329 if (CalendarError.None != (CalendarError)error)
331 Log.Error(Globals.LogTag, "Update Failed with error " + error);
332 throw CalendarErrorFactory.GetException(error);
337 /// Deletes multiple records with related child records from the calendar database as a batch operation.
339 /// <since_tizen> 4 </since_tizen>
340 /// <param name="viewUri">The view URI of the records to delete</param>
341 /// <param name="idArray">The record IDs to delete</param>
342 /// <privilege>http://tizen.org/privilege/calendar.write</privilege>
343 /// <feature>http://tizen.org/feature/calendar</feature>
344 /// <exception cref="NotSupportedException">Thrown when feature is not supported</exception>
345 /// <exception cref="InvalidOperationException">Thrown when method failed due to invalid operation</exception>
346 /// <exception cref="ArgumentException">Thrown when one of the arguments provided to a method is not valid</exception>
347 /// <exception cref="OutOfMemoryException">Thrown when failed due to out of memory</exception>
348 /// <exception cref="UnauthorizedAccessException">Thrown when application does not have proper privileges</exception>
349 [SuppressMessage("Microsoft.Performance", "CA1822:MarkMembersAsStatic")]
350 [SuppressMessage("Microsoft.Design", "CA1054:UriParametersShouldNotBeStrings")]
351 public void Delete(string viewUri, int[] idArray)
353 int error = Interop.Database.DeleteRecords(viewUri, idArray, idArray.Length);
354 if (CalendarError.None != (CalendarError)error)
356 Log.Error(Globals.LogTag, "Delete Failed with error " + error);
357 throw CalendarErrorFactory.GetException(error);
362 /// Deletes multiple records with related child records from the calendar database as a batch operation.
364 /// <since_tizen> 4 </since_tizen>
365 /// <param name="list">The record list</param>
366 /// <privilege>http://tizen.org/privilege/calendar.write</privilege>
367 /// <feature>http://tizen.org/feature/calendar</feature>
368 /// <exception cref="NotSupportedException">Thrown when feature is not supported</exception>
369 /// <exception cref="InvalidOperationException">Thrown when method failed due to invalid operation</exception>
370 /// <exception cref="OutOfMemoryException">Thrown when failed due to out of memory</exception>
371 /// <exception cref="UnauthorizedAccessException">Thrown when application does not have proper privileges</exception>
372 public void Delete(CalendarList list)
374 CalendarRecord record = null;
378 int[] ids = new int[list.Count];
382 for (i = 0; i < list.Count; i++)
384 record = list.GetCurrentRecord();
387 if (0 == String.Compare(CalendarViews.Book.Uri, record.Uri))
388 propertyId = CalendarViews.Book.Id;
389 else if (0 == String.Compare(CalendarViews.Event.Uri, record.Uri))
390 propertyId = CalendarViews.Event.Id;
391 else if (0 == String.Compare(CalendarViews.Todo.Uri, record.Uri))
392 propertyId = CalendarViews.Todo.Id;
393 else if (0 == String.Compare(CalendarViews.Timezone.Uri, record.Uri))
394 propertyId = CalendarViews.Timezone.Id;
395 else if (0 == String.Compare(CalendarViews.Extended.Uri, record.Uri))
396 propertyId = CalendarViews.Extended.Id;
399 Log.Error(Globals.LogTag, "Invalid uri [" + record.Uri + "]");
403 ids[i] = record.Get<int>(propertyId);
406 Delete(record.Uri, ids);
410 /// Replaces multiple records in the calendar database as a batch operation.
412 /// <since_tizen> 4 </since_tizen>
413 /// <param name="list">The record list</param>
414 /// <param name="idArray">The record IDs</param>
415 /// <privilege>http://tizen.org/privilege/calendar.write</privilege>
416 /// <feature>http://tizen.org/feature/calendar</feature>
417 /// <exception cref="NotSupportedException">Thrown when feature is not supported</exception>
418 /// <exception cref="InvalidOperationException">Thrown when method failed due to invalid operation</exception>
419 /// <exception cref="ArgumentException">Thrown when one of the arguments provided to a method is not valid</exception>
420 /// <exception cref="OutOfMemoryException">Thrown when failed due to out of memory</exception>
421 /// <exception cref="UnauthorizedAccessException">Thrown when application does not have proper privileges</exception>
422 [SuppressMessage("Microsoft.Performance", "CA1822:MarkMembersAsStatic")]
423 public void Replace(CalendarList list, int[] idArray)
425 int error = Interop.Database.ReplaceRecords(list._listHandle, idArray, idArray.Length);
426 if (CalendarError.None != (CalendarError)error)
428 Log.Error(Globals.LogTag, "Replace Failed with error " + error);
429 throw CalendarErrorFactory.GetException(error);
434 /// Retrieves records with the given calendar database version.
436 /// <since_tizen> 4 </since_tizen>
437 /// <param name="viewUri">The view URI to get records from</param>
438 /// <param name="BookId">The calendar book ID to filter</param>
439 /// <param name="calendarDBVersion">The calendar database version</param>
440 /// <param name="currentDBVersion">The current calendar database version</param>
444 /// <privilege>http://tizen.org/privilege/calendar.read</privilege>
445 /// <feature>http://tizen.org/feature/calendar</feature>
446 /// <exception cref="NotSupportedException">Thrown when feature is not supported</exception>
447 /// <exception cref="InvalidOperationException">Thrown when method failed due to invalid operation</exception>
448 /// <exception cref="ArgumentException">Thrown when one of the arguments provided to a method is not valid</exception>
449 /// <exception cref="OutOfMemoryException">Thrown when failed due to out of memory</exception>
450 /// <exception cref="UnauthorizedAccessException">Thrown when application does not have proper privileges</exception>
451 [SuppressMessage("Microsoft.Performance", "CA1822:MarkMembersAsStatic")]
452 [SuppressMessage("Microsoft.Design", "CA1054:UriParametersShouldNotBeStrings")]
453 public CalendarList GetChangesByVersion(string viewUri, int BookId, int calendarDBVersion, out int currentDBVersion)
456 int error = Interop.Database.GetChangesByVersion(viewUri, BookId, calendarDBVersion, out recordList, out currentDBVersion);
457 if (CalendarError.None != (CalendarError)error)
459 Log.Error(Globals.LogTag, "GetChangesByVersion Failed with error " + error);
460 throw CalendarErrorFactory.GetException(error);
462 return new CalendarList(recordList);
466 /// Gets the record count of a specific view.
468 /// <since_tizen> 4 </since_tizen>
469 /// <param name="viewUri">The view URI to get records from</param>
471 /// The count of records
473 /// <privilege>http://tizen.org/privilege/calendar.read</privilege>
474 [SuppressMessage("Microsoft.Design", "CA1822:MarkMembersAsStatic")]
475 [SuppressMessage("Microsoft.Design", "CA1054:UriParametersShouldNotBeStrings")]
476 public int GetCount(string viewUri)
479 int error = Interop.Database.GetCount(viewUri, out count);
480 if (CalendarError.None != (CalendarError)error)
482 Log.Error(Globals.LogTag, "GetCount Failed with error " + error);
483 throw CalendarErrorFactory.GetException(error);
489 /// Gets the record count with a query.
491 /// <since_tizen> 4 </since_tizen>
492 /// <param name="query">The query used for filtering the results</param>
494 /// The count of records
496 /// <privilege>http://tizen.org/privilege/calendar.read</privilege>
497 [SuppressMessage("Microsoft.Design", "CA1822:MarkMembersAsStatic")]
498 public int GetCount(CalendarQuery query)
501 int error = Interop.Database.GetCountWithQuery(query._queryHandle, out count);
502 if (CalendarError.None != (CalendarError)error)
504 Log.Error(Globals.LogTag, "GetCount Failed with error " + error);
505 throw CalendarErrorFactory.GetException(error);
511 /// Registers a callback function to be invoked when a record changes.
512 /// <since_tizen> 4 </since_tizen>
514 /// <param name="viewUri">The view URI of the record to subscribe for change notifications</param>
515 /// <param name="DBChanged">The EventHandler to register</param>
516 /// <privilege>http://tizen.org/privilege/calendar.read</privilege>
517 /// <feature>http://tizen.org/feature/calendar</feature>
518 /// <exception cref="NotSupportedException">Thrown when feature is not supported</exception>
519 /// <exception cref="InvalidOperationException">Thrown when method failed due to invalid operation</exception>
520 /// <exception cref="ArgumentException">Thrown when one of the arguments provided to a method is not valid</exception>
521 /// <exception cref="OutOfMemoryException">Thrown when failed due to out of memory</exception>
522 /// <exception cref="UnauthorizedAccessException">Thrown when application does not have proper privileges</exception>
523 [SuppressMessage("Microsoft.Design", "CA1054:UriParametersShouldNotBeStrings")]
524 public void AddDBChangedDelegate(string viewUri, EventHandler<DBChangedEventArgs> DBChanged)
526 Log.Debug(Globals.LogTag, "AddDBChangedDelegate");
528 if (!_callbackMap.ContainsKey(viewUri))
530 _callbackMap[viewUri] = (string uri, IntPtr userData) =>
532 DBChangedEventArgs args = new DBChangedEventArgs(uri);
533 _eventHandlerMap[uri]?.Invoke(this, args);
536 int error = Interop.Database.AddChangedCallback(viewUri, _callbackMap[viewUri], IntPtr.Zero);
537 if (CalendarError.None != (CalendarError)error)
539 Log.Error(Globals.LogTag, "AddDBChangedDelegate Failed with error " + error);
540 throw CalendarErrorFactory.GetException(error);
544 EventHandler<DBChangedEventArgs> handler = null;
545 if (!_eventHandlerMap.TryGetValue(viewUri, out handler))
546 _eventHandlerMap.Add(viewUri, null);
548 _eventHandlerMap[viewUri] = handler + DBChanged;
552 /// Deregisters a callback function.
554 /// <since_tizen> 4 </since_tizen>
555 /// <param name="viewUri">The view URI of the record to subscribe for change notifications</param>
556 /// <param name="DBChanged">The EventHandler to deregister</param>
557 /// <privilege>http://tizen.org/privilege/calendar.read</privilege>
558 /// <feature>http://tizen.org/feature/calendar</feature>
559 /// <exception cref="NotSupportedException">Thrown when feature is not supported</exception>
560 /// <exception cref="InvalidOperationException">Thrown when method failed due to invalid operation</exception>
561 /// <exception cref="OutOfMemoryException">Thrown when failed due to out of memory</exception>
562 /// <exception cref="UnauthorizedAccessException">Thrown when application does not have proper privileges</exception>
563 [SuppressMessage("Microsoft.Design", "CA1054:UriParametersShouldNotBeStrings")]
564 public void RemoveDBChangedDelegate(string viewUri, EventHandler<DBChangedEventArgs> DBChanged)
566 Log.Debug(Globals.LogTag, "RemoveDBChangedDelegate");
568 EventHandler<DBChangedEventArgs> handler = null;
569 if (!_eventHandlerMap.TryGetValue(viewUri, out handler))
570 _eventHandlerMap.Add(viewUri, null);
572 _eventHandlerMap[viewUri] = handler - DBChanged;
574 if (_eventHandlerMap[viewUri] == null)
576 int error = Interop.Database.RemoveChangedCallback(viewUri, _callbackMap[viewUri], IntPtr.Zero);
577 if (CalendarError.None != (CalendarError)error)
579 Log.Error(Globals.LogTag, "RemoveDBChangedDelegate Failed with error " + error);
580 throw CalendarErrorFactory.GetException(error);
582 _callbackMap.Remove(viewUri);
587 /// Link a record to another record.
589 /// <since_tizen> 4 </since_tizen>
590 /// <param name="baseId">The base record ID</param>
591 /// <param name="recordId">The record ID to link to</param>
592 /// <privilege>http://tizen.org/privilege/calendar.write</privilege>
593 /// <feature>http://tizen.org/feature/calendar</feature>
594 /// <exception cref="NotSupportedException">Thrown when feature is not supported</exception>
595 /// <exception cref="InvalidOperationException">Thrown when method failed due to invalid operation</exception>
596 /// <exception cref="ArgumentException">Thrown when one of the arguments provided to a method is not valid</exception>
597 /// <exception cref="OutOfMemoryException">Thrown when failed due to out of memory</exception>
598 /// <exception cref="UnauthorizedAccessException">Thrown when application does not have proper privileges</exception>
599 [SuppressMessage("Microsoft.Design", "CA1822:MarkMembersAsStatic")]
600 public void LinkRecord(int baseId, int recordId)
602 Log.Debug(Globals.LogTag, "LinkRecord");
603 int error = Interop.Database.LinkRecord(baseId, recordId);
604 if (CalendarError.None != (CalendarError)error)
606 Log.Error(Globals.LogTag, "LinkRecor Failed with error " + error);
607 throw CalendarErrorFactory.GetException(error);
612 /// Unlink a record from base record.
614 /// <since_tizen> 4 </since_tizen>
615 /// <param name="recordId">The record ID to unlink</param>
616 /// <privilege>http://tizen.org/privilege/calendar.write</privilege>
617 /// <feature>http://tizen.org/feature/calendar</feature>
618 /// <exception cref="NotSupportedException">Thrown when feature is not supported</exception>
619 /// <exception cref="InvalidOperationException">Thrown when method failed due to invalid operation</exception>
620 /// <exception cref="ArgumentException">Thrown when one of the arguments provided to a method is not valid</exception>
621 /// <exception cref="OutOfMemoryException">Thrown when failed due to out of memory</exception>
622 /// <exception cref="UnauthorizedAccessException">Thrown when application does not have proper privileges</exception>
623 [SuppressMessage("Microsoft.Performance", "CA1822:MarkMembersAsStatic")]
624 public void UnlinkRecord(int recordId)
626 Log.Debug(Globals.LogTag, "UnlinkRecord");
627 int error = Interop.Database.UnlinkRecord(recordId);
628 if (CalendarError.None != (CalendarError)error)
630 Log.Error(Globals.LogTag, "UnlinkRecor Failed with error " + error);
631 throw CalendarErrorFactory.GetException(error);