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=2cbb6bf2bc55b99dc39d742f8afa6aee0ecc2e64;hpb=87e72a859c56cb8732ccd14046cb509759ca9d2f;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 2cbb6bf..c088bd5 100644 --- a/src/Tizen.Pims.Calendar/Tizen.Pims.Calendar/CalendarDatabase.cs +++ b/src/Tizen.Pims.Calendar/Tizen.Pims.Calendar/CalendarDatabase.cs @@ -17,15 +17,7 @@ using System; using System.Collections.Generic; using System.Runtime.InteropServices; - -/// -/// The Calendar Service API provides functions, enumerations used in the entire Content Service. -/// -/// -/// The Calendar Service API provides functions and ienumerations used in the entire Content Service. -/// The Information about calendar items i.e. book, event, todo, alarm, attendee and extended are managed in the database -/// and operations that involve database requires an active connection with the calendar service. -/// +using System.Diagnostics.CodeAnalysis; namespace Tizen.Pims.Calendar { @@ -33,40 +25,33 @@ namespace Tizen.Pims.Calendar /// CalendarDatabase provides methods to manage calendar information from/to the database. /// /// - /// This class allows usre 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 { - /// - /// Delegete 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 CalendarDBChangedDelegate(string uri); - private Object thisLock = new Object(); - private Dictionary _callbackMap = new Dictionary(); - private Dictionary _delegateMap = new Dictionary(); - private Interop.Calendar.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 { get { int version = -1; - int error = Interop.Calendar.Database.GetCurrentVersion(out version); + int error = Interop.Database.GetCurrentVersion(out version); if (CalendarError.None != (CalendarError)error) { Log.Error(Globals.LogTag, "Version Failed with error " + error); @@ -78,17 +63,20 @@ 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 /// Thrown when failed due to out of memory /// Thrown when application does not have proper privileges + /// The last successful changed calendar database version on the current connection. + [SuppressMessage("Microsoft.Performance", "CA1822:MarkMembersAsStatic")] public int LastChangeVersion { get { int version = -1; - int error = Interop.Calendar.Database.GetLastChangeVersion(out version); + int error = Interop.Database.GetLastChangeVersion(out version); if (CalendarError.None != (CalendarError)error) { Log.Error(Globals.LogTag, "LastChangeVersion Failed with error " + error); @@ -100,18 +88,21 @@ 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 + [SuppressMessage("Microsoft.Performance", "CA1822:MarkMembersAsStatic")] public int Insert(CalendarRecord record) { int id = -1; - int error = Interop.Calendar.Database.Insert(record._recordHandle, out id); + int error = Interop.Database.Insert(record._recordHandle, out id); if (CalendarError.None != (CalendarError)error) { Log.Error(Globals.LogTag, "Insert Failed with error " + error); @@ -123,21 +114,25 @@ 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 + [SuppressMessage("Microsoft.Performance", "CA1822:MarkMembersAsStatic")] + [SuppressMessage("Microsoft.Design", "CA1054:UriParametersShouldNotBeStrings")] public CalendarRecord Get(string viewUri, int recordId) { IntPtr handle; - int error = Interop.Calendar.Database.Get(viewUri, recordId, out handle); + int error = Interop.Database.Get(viewUri, recordId, out handle); if (CalendarError.None != (CalendarError)error) { if (CalendarError.DBNotFound == (CalendarError)error) @@ -154,16 +149,19 @@ 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 + [SuppressMessage("Microsoft.Performance", "CA1822:MarkMembersAsStatic")] public void Update(CalendarRecord record) { - int error = Interop.Calendar.Database.Update(record._recordHandle); + int error = Interop.Database.Update(record._recordHandle); if (CalendarError.None != (CalendarError)error) { Log.Error(Globals.LogTag, "Update Failed with error " + error); @@ -174,17 +172,21 @@ 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 + [SuppressMessage("Microsoft.Performance", "CA1822:MarkMembersAsStatic")] + [SuppressMessage("Microsoft.Design", "CA1054:UriParametersShouldNotBeStrings")] public void Delete(string viewUri, int recordId) { - int error = Interop.Calendar.Database.Delete(viewUri, recordId); + int error = Interop.Database.Delete(viewUri, recordId); if (CalendarError.None != (CalendarError)error) { Log.Error(Globals.LogTag, "Delete Failed with error " + error); @@ -195,17 +197,20 @@ 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 + [SuppressMessage("Microsoft.Performance", "CA1822:MarkMembersAsStatic")] public void Replace(CalendarRecord record, int id) { - int error = Interop.Calendar.Database.Replace(record._recordHandle, id); + int error = Interop.Database.Replace(record._recordHandle, id); if (CalendarError.None != (CalendarError)error) { Log.Error(Globals.LogTag, "Replace Failed with error " + error); @@ -216,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) @@ -223,15 +229,18 @@ 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 + [SuppressMessage("Microsoft.Performance", "CA1822:MarkMembersAsStatic")] + [SuppressMessage("Microsoft.Design", "CA1054:UriParametersShouldNotBeStrings")] public CalendarList GetAll(string viewUri, int offset, int limit) { IntPtr handle; - int error = Interop.Calendar.Database.GetAllRecords(viewUri, offset, limit, out handle); + int error = Interop.Database.GetAllRecords(viewUri, offset, limit, out handle); if (CalendarError.None != (CalendarError)error) { Log.Error(Globals.LogTag, "GetAll Failed with error " + error); @@ -243,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) @@ -250,15 +260,16 @@ 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")] public CalendarList GetRecordsWithQuery(CalendarQuery query, int offset, int limit) { IntPtr handle; - int error = Interop.Calendar.Database.GetRecords(query._queryHandle, offset, limit, out handle); + int error = Interop.Database.GetRecords(query._queryHandle, offset, limit, out handle); if (CalendarError.None != (CalendarError)error) { Log.Error(Globals.LogTag, "GetAllWithQuery Failed with error " + error); @@ -270,21 +281,24 @@ 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 + [SuppressMessage("Microsoft.Performance", "CA1822:MarkMembersAsStatic")] public int[] Insert(CalendarList list) { IntPtr ids; int count; - int error = Interop.Calendar.Database.InsertRecords(list._listHandle, out ids, out count); + int error = Interop.Database.InsertRecords(list._listHandle, out ids, out count); if (CalendarError.None != (CalendarError)error) { Log.Error(Globals.LogTag, "Insert Failed with error " + error); @@ -299,16 +313,19 @@ 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 + [SuppressMessage("Microsoft.Performance", "CA1822:MarkMembersAsStatic")] public void Update(CalendarList list) { - int error = Interop.Calendar.Database.UpdateRecords(list._listHandle); + int error = Interop.Database.UpdateRecords(list._listHandle); if (CalendarError.None != (CalendarError)error) { Log.Error(Globals.LogTag, "Update Failed with error " + error); @@ -319,17 +336,21 @@ 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 + [SuppressMessage("Microsoft.Performance", "CA1822:MarkMembersAsStatic")] + [SuppressMessage("Microsoft.Design", "CA1054:UriParametersShouldNotBeStrings")] public void Delete(string viewUri, int[] idArray) { - int error = Interop.Calendar.Database.DeleteRecords(viewUri, idArray, idArray.Length); + int error = Interop.Database.DeleteRecords(viewUri, idArray, idArray.Length); if (CalendarError.None != (CalendarError)error) { Log.Error(Globals.LogTag, "Delete Failed with error " + error); @@ -340,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) @@ -387,17 +409,20 @@ 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 + [SuppressMessage("Microsoft.Performance", "CA1822:MarkMembersAsStatic")] public void Replace(CalendarList list, int[] idArray) { - int error = Interop.Calendar.Database.ReplaceRecords(list._listHandle, idArray, idArray.Length); + int error = Interop.Database.ReplaceRecords(list._listHandle, idArray, idArray.Length); if (CalendarError.None != (CalendarError)error) { Log.Error(Globals.LogTag, "Replace Failed with error " + error); @@ -408,23 +433,27 @@ 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 - /// + /// The current calendar database version /// /// 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 + [SuppressMessage("Microsoft.Performance", "CA1822:MarkMembersAsStatic")] + [SuppressMessage("Microsoft.Design", "CA1054:UriParametersShouldNotBeStrings")] public CalendarList GetChangesByVersion(string viewUri, int BookId, int calendarDBVersion, out int currentDBVersion) { IntPtr recordList; - int error = Interop.Calendar.Database.GetChangesByVersion(viewUri, BookId, calendarDBVersion, out recordList, out currentDBVersion); + int error = Interop.Database.GetChangesByVersion(viewUri, BookId, calendarDBVersion, out recordList, out currentDBVersion); if (CalendarError.None != (CalendarError)error) { Log.Error(Globals.LogTag, "GetChangesByVersion Failed with error " + error); @@ -436,15 +465,18 @@ namespace Tizen.Pims.Calendar /// /// Gets the record count of a specific view. /// + /// 4 /// The view URI to get records from /// /// The count of records /// /// http://tizen.org/privilege/calendar.read + [SuppressMessage("Microsoft.Design", "CA1822:MarkMembersAsStatic")] + [SuppressMessage("Microsoft.Design", "CA1054:UriParametersShouldNotBeStrings")] public int GetCount(string viewUri) { int count = -1; - int error = Interop.Calendar.Database.GetCount(viewUri, out count); + int error = Interop.Database.GetCount(viewUri, out count); if (CalendarError.None != (CalendarError)error) { Log.Error(Globals.LogTag, "GetCount Failed with error " + error); @@ -456,15 +488,17 @@ namespace Tizen.Pims.Calendar /// /// Gets the record count with a query. /// + /// 4 /// The query used for filtering the results /// /// The count of records /// /// http://tizen.org/privilege/calendar.read + [SuppressMessage("Microsoft.Design", "CA1822:MarkMembersAsStatic")] public int GetCount(CalendarQuery query) { int count = -1; - int error = Interop.Calendar.Database.GetCountWithQuery(query._queryHandle, out count); + int error = Interop.Database.GetCountWithQuery(query._queryHandle, out count); if (CalendarError.None != (CalendarError)error) { Log.Error(Globals.LogTag, "GetCount Failed with error " + error); @@ -475,63 +509,98 @@ 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 - public void AddDBChangedDelegate(string viewUri, CalendarDBChangedDelegate callback) + /// 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, EventHandler DBChanged) { Log.Debug(Globals.LogTag, "AddDBChangedDelegate"); - _dbChangedDelegate = (string uri, IntPtr userData) => - { - _callbackMap[uri](uri); - }; - int error = Interop.Calendar.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; } /// - /// Unregisters a callback function. + /// 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 - public void RemoveDBChangedDelegate(string viewUri, CalendarDBChangedDelegate callback) + /// 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, EventHandler DBChanged) { Log.Debug(Globals.LogTag, "RemoveDBChangedDelegate"); - int error = Interop.Calendar.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.Remove(viewUri); - _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 + [SuppressMessage("Microsoft.Design", "CA1822:MarkMembersAsStatic")] public void LinkRecord(int baseId, int recordId) { Log.Debug(Globals.LogTag, "LinkRecord"); - int error = Interop.Calendar.Database.LinkRecord(baseId, recordId); + int error = Interop.Database.LinkRecord(baseId, recordId); if (CalendarError.None != (CalendarError)error) { Log.Error(Globals.LogTag, "LinkRecor Failed with error " + error); @@ -542,17 +611,20 @@ 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 + [SuppressMessage("Microsoft.Performance", "CA1822:MarkMembersAsStatic")] public void UnlinkRecord(int recordId) { Log.Debug(Globals.LogTag, "UnlinkRecord"); - int error = Interop.Calendar.Database.UnlinkRecord(recordId); + int error = Interop.Database.UnlinkRecord(recordId); if (CalendarError.None != (CalendarError)error) { Log.Error(Globals.LogTag, "UnlinkRecor Failed with error " + error);