X-Git-Url: http://review.tizen.org/git/?a=blobdiff_plain;f=src%2FTizen.Pims.Calendar%2FTizen.Pims.Calendar%2FCalendarDatabase.cs;h=c088bd50ca4a6bb011f540e23e1a0d304aedadea;hb=fc16884c591d4161bce1d0fdc979fc25706feb54;hp=30c95b2b05c886b55cbdc9df313b95cbcd50f45c;hpb=3ac720fecc1f4a5981c227c8b75fd24ddd3ab470;p=platform%2Fcore%2Fcsapi%2Ftizenfx.git
diff --git a/src/Tizen.Pims.Calendar/Tizen.Pims.Calendar/CalendarDatabase.cs b/src/Tizen.Pims.Calendar/Tizen.Pims.Calendar/CalendarDatabase.cs
index 30c95b2..c088bd5 100644
--- a/src/Tizen.Pims.Calendar/Tizen.Pims.Calendar/CalendarDatabase.cs
+++ b/src/Tizen.Pims.Calendar/Tizen.Pims.Calendar/CalendarDatabase.cs
@@ -22,36 +22,28 @@ using System.Diagnostics.CodeAnalysis;
namespace Tizen.Pims.Calendar
{
///
- /// Delegate for detecting the calendar database changes.
- ///
- /// The record uri
- ///
- /// The delegate must be registered using AddDBChangedDelegate.
- /// It's invoked when the designated view changes.
- ///
- public delegate void CalendarDBChanged(string uri);
-
- ///
/// CalendarDatabase provides methods to manage calendar information from/to the database.
///
///
- /// This class allows user to access/create/update db operations for calendar information.
+ /// This class allows user to access/create/update/delete db operations for calendar information.
+ /// CalendarDatabase is created by CalendarManager.
///
+ /// 4
public class CalendarDatabase
{
private Object thisLock = new Object();
- private Dictionary _callbackMap = new Dictionary();
- private Dictionary _delegateMap = new Dictionary();
- private Interop.Database.DBChangedCallback _dbChangedDelegate;
+ private Dictionary> _eventHandlerMap = new Dictionary>();
+ private Dictionary _callbackMap = new Dictionary();
internal CalendarDatabase()
{
- ///To be created in CalendarManager only
+ /*To be created in CalendarManager only*/
}
///
/// The calendar database version.
///
+ /// 4
/// The current calendar database version.
[SuppressMessage("Microsoft.Performance", "CA1822:MarkMembersAsStatic")]
public int Version
@@ -71,6 +63,7 @@ namespace Tizen.Pims.Calendar
///
/// Gets last successful changed calendar database version on the current connection.
///
+ /// 4
/// The last successful changed calendar database version on the current connection
/// http://tizen.org/privilege/calendar.read
/// Thrown when method failed due to invalid operation
@@ -95,11 +88,13 @@ namespace Tizen.Pims.Calendar
///
/// Inserts a record into the calendar database.
///
+ /// 4
/// The record to be inserted
/// The ID of inserted record
/// http://tizen.org/privilege/calendar.write
+ /// http://tizen.org/feature/calendar
+ /// Thrown when feature is not supported
/// Thrown when method failed due to invalid operation
- /// Thrown when an invoked method is not supported
/// Thrown when one of the arguments provided to a method is not valid
/// Thrown when failed due to out of memory
/// Thrown when application does not have proper privileges
@@ -119,14 +114,16 @@ namespace Tizen.Pims.Calendar
///
/// Gets a record from the calendar database.
///
+ /// 4
/// The view URI of a record
/// The record ID
///
/// The record associated with the record ID
///
/// http://tizen.org/privilege/calendar.read
+ /// http://tizen.org/feature/calendar
+ /// Thrown when feature is not supported
/// Thrown when method failed due to invalid operation
- /// Thrown when an invoked method is not supported
/// Thrown when one of the arguments provided to a method is not valid
/// Thrown when failed due to out of memory
/// Thrown when application does not have proper privileges
@@ -152,10 +149,12 @@ namespace Tizen.Pims.Calendar
///
/// Updates a record in the calendar database.
///
+ /// 4
/// The record to be updated
/// http://tizen.org/privilege/calendar.write
+ /// http://tizen.org/feature/calendar
+ /// Thrown when feature is not supported
/// Thrown when method failed due to invalid operation
- /// Thrown when an invoked method is not supported
/// Thrown when one of the arguments provided to a method is not valid
/// Thrown when failed due to out of memory
/// Thrown when application does not have proper privileges
@@ -173,11 +172,13 @@ namespace Tizen.Pims.Calendar
///
/// Deletes a record from the calendar database with related child records.
///
+ /// 4
/// The view URI of a record
/// The record ID to be deleted
/// http://tizen.org/privilege/calendar.write
+ /// http://tizen.org/feature/calendar
+ /// Thrown when feature is not supported
/// Thrown when method failed due to invalid operation
- /// Thrown when an invoked method is not supported
/// Thrown when one of the arguments provided to a method is not valid
/// Thrown when failed due to out of memory
/// Thrown when application does not have proper privileges
@@ -196,11 +197,13 @@ namespace Tizen.Pims.Calendar
///
/// Replaces a record in the calendar database.
///
+ /// 4
/// The record to be replaced
/// the record id
/// http://tizen.org/privilege/calendar.write
+ /// http://tizen.org/feature/calendar
+ /// Thrown when feature is not supported
/// Thrown when method failed due to invalid operation
- /// Thrown when an invoked method is not supported
/// Thrown when one of the arguments provided to a method is not valid
/// Thrown when failed due to out of memory
/// Thrown when application does not have proper privileges
@@ -218,6 +221,7 @@ namespace Tizen.Pims.Calendar
///
/// Retrieves all records as a list.
///
+ /// 4
/// The view URI to get records from
/// The index from which results are received
/// The maximum number of results(value 0 is used for all records)
@@ -225,8 +229,9 @@ namespace Tizen.Pims.Calendar
/// The record list
///
/// http://tizen.org/privilege/calendar.read
+ /// http://tizen.org/feature/calendar
+ /// Thrown when feature is not supported
/// Thrown when method failed due to invalid operation
- /// Thrown when an invoked method is not supported
/// Thrown when one of the arguments provided to a method is not valid
/// Thrown when failed due to out of memory
/// Thrown when application does not have proper privileges
@@ -247,6 +252,7 @@ namespace Tizen.Pims.Calendar
///
/// Retrieves records using a query.
///
+ /// 4
/// The query used to filter results
/// The index from which results are received
/// The maximum number of results(value 0 is used for all records)
@@ -254,9 +260,9 @@ namespace Tizen.Pims.Calendar
/// CalendarList
///
/// http://tizen.org/privilege/calendar.read
+ /// http://tizen.org/feature/calendar
+ /// Thrown when feature is not supported
/// Thrown when method failed due to invalid operation
- /// Thrown when an invoked method is not supported
- /// Thrown when one of the arguments provided to a method is not valid
/// Thrown when failed due to out of memory
/// Thrown when application does not have proper privileges
[SuppressMessage("Microsoft.Performance", "CA1822:MarkMembersAsStatic")]
@@ -275,13 +281,15 @@ namespace Tizen.Pims.Calendar
///
/// Inserts multiple records into the calendar database as a batch operation.
///
+ /// 4
/// The record list
///
/// The inserted record id array
///
/// http://tizen.org/privilege/calendar.write
+ /// http://tizen.org/feature/calendar
+ /// Thrown when feature is not supported
/// Thrown when method failed due to invalid operation
- /// Thrown when an invoked method is not supported
/// Thrown when one of the arguments provided to a method is not valid
/// Thrown when failed due to out of memory
/// Thrown when application does not have proper privileges
@@ -305,10 +313,12 @@ namespace Tizen.Pims.Calendar
///
/// Updates multiple records into the calendar database as a batch operation.
///
+ /// 4
/// The record list
/// http://tizen.org/privilege/calendar.write
+ /// http://tizen.org/feature/calendar
+ /// Thrown when feature is not supported
/// Thrown when method failed due to invalid operation
- /// Thrown when an invoked method is not supported
/// Thrown when one of the arguments provided to a method is not valid
/// Thrown when failed due to out of memory
/// Thrown when application does not have proper privileges
@@ -326,11 +336,13 @@ namespace Tizen.Pims.Calendar
///
/// Deletes multiple records with related child records from the calendar database as a batch operation.
///
+ /// 4
/// The view URI of the records to delete
/// The record IDs to delete
/// http://tizen.org/privilege/calendar.write
+ /// http://tizen.org/feature/calendar
+ /// Thrown when feature is not supported
/// Thrown when method failed due to invalid operation
- /// Thrown when an invoked method is not supported
/// Thrown when one of the arguments provided to a method is not valid
/// Thrown when failed due to out of memory
/// Thrown when application does not have proper privileges
@@ -349,11 +361,12 @@ namespace Tizen.Pims.Calendar
///
/// Deletes multiple records with related child records from the calendar database as a batch operation.
///
+ /// 4
/// The record list
/// http://tizen.org/privilege/calendar.write
+ /// http://tizen.org/feature/calendar
+ /// Thrown when feature is not supported
/// Thrown when method failed due to invalid operation
- /// Thrown when an invoked method is not supported
- /// Thrown when one of the arguments provided to a method is not valid
/// Thrown when failed due to out of memory
/// Thrown when application does not have proper privileges
public void Delete(CalendarList list)
@@ -396,11 +409,13 @@ namespace Tizen.Pims.Calendar
///
/// Replaces multiple records in the calendar database as a batch operation.
///
+ /// 4
/// The record list
/// The record IDs
/// http://tizen.org/privilege/calendar.write
+ /// http://tizen.org/feature/calendar
+ /// Thrown when feature is not supported
/// Thrown when method failed due to invalid operation
- /// Thrown when an invoked method is not supported
/// Thrown when one of the arguments provided to a method is not valid
/// Thrown when failed due to out of memory
/// Thrown when application does not have proper privileges
@@ -418,6 +433,7 @@ namespace Tizen.Pims.Calendar
///
/// Retrieves records with the given calendar database version.
///
+ /// 4
/// The view URI to get records from
/// The calendar book ID to filter
/// The calendar database version
@@ -426,8 +442,9 @@ namespace Tizen.Pims.Calendar
/// The record list
///
/// http://tizen.org/privilege/calendar.read
+ /// http://tizen.org/feature/calendar
+ /// Thrown when feature is not supported
/// Thrown when method failed due to invalid operation
- /// Thrown when an invoked method is not supported
/// Thrown when one of the arguments provided to a method is not valid
/// Thrown when failed due to out of memory
/// Thrown when application does not have proper privileges
@@ -448,6 +465,7 @@ namespace Tizen.Pims.Calendar
///
/// Gets the record count of a specific view.
///
+ /// 4
/// The view URI to get records from
///
/// The count of records
@@ -470,6 +488,7 @@ namespace Tizen.Pims.Calendar
///
/// Gets the record count with a query.
///
+ /// 4
/// The query used for filtering the results
///
/// The count of records
@@ -490,58 +509,90 @@ namespace Tizen.Pims.Calendar
///
/// Registers a callback function to be invoked when a record changes.
+ /// 4
///
/// The view URI of the record to subscribe for change notifications
- /// The callback function to register
+ /// The EventHandler to register
/// http://tizen.org/privilege/calendar.read
+ /// http://tizen.org/feature/calendar
+ /// Thrown when feature is not supported
+ /// Thrown when method failed due to invalid operation
+ /// Thrown when one of the arguments provided to a method is not valid
+ /// Thrown when failed due to out of memory
+ /// Thrown when application does not have proper privileges
[SuppressMessage("Microsoft.Design", "CA1054:UriParametersShouldNotBeStrings")]
- public void AddDBChangedDelegate(string viewUri, CalendarDBChanged callback)
+ public void AddDBChangedDelegate(string viewUri, EventHandler DBChanged)
{
Log.Debug(Globals.LogTag, "AddDBChangedDelegate");
- _dbChangedDelegate = (string uri, IntPtr userData) =>
- {
- _callbackMap[uri](uri);
- };
- int error = Interop.Database.AddChangedCallback(viewUri, _dbChangedDelegate, IntPtr.Zero);
- if (CalendarError.None != (CalendarError)error)
- {
- Log.Error(Globals.LogTag, "AddDBChangedDelegate Failed with error " + error);
- throw CalendarErrorFactory.GetException(error);
- }
- _callbackMap[viewUri] += callback;
- _delegateMap[viewUri] = _dbChangedDelegate;
+ if (!_callbackMap.ContainsKey(viewUri))
+ {
+ _callbackMap[viewUri] = (string uri, IntPtr userData) =>
+ {
+ DBChangedEventArgs args = new DBChangedEventArgs(uri);
+ _eventHandlerMap[uri]?.Invoke(this, args);
+ };
+
+ int error = Interop.Database.AddChangedCallback(viewUri, _callbackMap[viewUri], IntPtr.Zero);
+ if (CalendarError.None != (CalendarError)error)
+ {
+ Log.Error(Globals.LogTag, "AddDBChangedDelegate Failed with error " + error);
+ throw CalendarErrorFactory.GetException(error);
+ }
+ }
+
+ EventHandler handler = null;
+ if (!_eventHandlerMap.TryGetValue(viewUri, out handler))
+ _eventHandlerMap.Add(viewUri, null);
+
+ _eventHandlerMap[viewUri] = handler + DBChanged;
}
///
/// Deregisters a callback function.
///
+ /// 4
/// The view URI of the record to subscribe for change notifications
- /// The callback function to register
+ /// The EventHandler to deregister
/// http://tizen.org/privilege/calendar.read
+ /// http://tizen.org/feature/calendar
+ /// Thrown when feature is not supported
+ /// Thrown when method failed due to invalid operation
+ /// Thrown when failed due to out of memory
+ /// Thrown when application does not have proper privileges
[SuppressMessage("Microsoft.Design", "CA1054:UriParametersShouldNotBeStrings")]
- public void RemoveDBChangedDelegate(string viewUri, CalendarDBChanged callback)
+ public void RemoveDBChangedDelegate(string viewUri, EventHandler DBChanged)
{
Log.Debug(Globals.LogTag, "RemoveDBChangedDelegate");
- int error = Interop.Database.RemoveChangedCallback(viewUri, _delegateMap[viewUri], IntPtr.Zero);
- if (CalendarError.None != (CalendarError)error)
+ EventHandler handler = null;
+ if (!_eventHandlerMap.TryGetValue(viewUri, out handler))
+ _eventHandlerMap.Add(viewUri, null);
+ else
+ _eventHandlerMap[viewUri] = handler - DBChanged;
+
+ if (_eventHandlerMap[viewUri] == null)
{
- Log.Error(Globals.LogTag, "RemoveDBChangedDelegate Failed with error " + error);
- throw CalendarErrorFactory.GetException(error);
- }
- _callbackMap[viewUri] -= callback;
- _delegateMap.Remove(viewUri);
+ int error = Interop.Database.RemoveChangedCallback(viewUri, _callbackMap[viewUri], IntPtr.Zero);
+ if (CalendarError.None != (CalendarError)error)
+ {
+ Log.Error(Globals.LogTag, "RemoveDBChangedDelegate Failed with error " + error);
+ throw CalendarErrorFactory.GetException(error);
+ }
+ _callbackMap.Remove(viewUri);
+ }
}
///
/// Link a record to another record.
///
+ /// 4
/// The base record ID
/// The record ID to link to
/// http://tizen.org/privilege/calendar.write
+ /// http://tizen.org/feature/calendar
+ /// Thrown when feature is not supported
/// Thrown when method failed due to invalid operation
- /// Thrown when an invoked method is not supported
/// Thrown when one of the arguments provided to a method is not valid
/// Thrown when failed due to out of memory
/// Thrown when application does not have proper privileges
@@ -560,10 +611,12 @@ namespace Tizen.Pims.Calendar
///
/// Unlink a record from base record.
///
+ /// 4
/// The record ID to unlink
/// http://tizen.org/privilege/calendar.write
+ /// http://tizen.org/feature/calendar
+ /// Thrown when feature is not supported
/// Thrown when method failed due to invalid operation
- /// Thrown when an invoked method is not supported
/// Thrown when one of the arguments provided to a method is not valid
/// Thrown when failed due to out of memory
/// Thrown when application does not have proper privileges