/* * Copyright (c) 2016 Samsung Electronics Co., Ltd All Rights Reserved * * Licensed under the Apache License, Version 2.0 (the License); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an AS IS BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ using System; using System.Collections.Generic; using System.Diagnostics.CodeAnalysis; using System.Runtime.InteropServices; namespace Tizen.Pims.Contacts { /// /// ContactsDatabase provides methods to manage contacts information from/to the database. /// /// /// This class allows user to access/create/update db operations for contacts information. /// /// 4 public class ContactsDatabase { private Object thisLock = new Object(); private Interop.Database.ContactsDBStatusChangedCallback _contactsDBStatusChangedCallback; private EventHandler _dbStatusChanged; private Dictionary> _eventHandlerMap = new Dictionary>(); private Dictionary _callbackMap = new Dictionary(); internal ContactsDatabase() { /*To be created in ContactsManager only.*/ } /// /// Enumeration for contacts database status. /// /// 4 public enum DBStatus { /// /// Normal /// Normal, /// /// Changing collation. /// ChangingCollation } /// /// Enumeration for Contacts search range. /// /// 4 [Flags] public enum SearchRanges { /// /// None /// None = 0, /// /// Search record from name /// Name = 0x00000001, /// /// Search record from number /// Number = 0x00000002, /// /// Search record from data /// Data = 0x00000004, /// /// Search record from email. Now, support only PersonEmail view /// Email = 0x00000008, } /// /// Occurs when contacts database status is changed. /// /// 4 public event EventHandler DBStatusChanged { add { lock (thisLock) { if (_contactsDBStatusChangedCallback == null) { _contactsDBStatusChangedCallback = (DBStatus status, IntPtr userData) => { DBStatusChangedEventArgs args = new DBStatusChangedEventArgs(status); _dbStatusChanged?.Invoke(this, args); }; } if (_dbStatusChanged == null) { int error = Interop.Database.AddStatusChangedCb(_contactsDBStatusChangedCallback, IntPtr.Zero); if ((int)ContactsError.None != error) { Log.Error(Globals.LogTag, "Add StatusChanged Failed with error " + error); } } _dbStatusChanged += value; } } remove { lock (thisLock) { _dbStatusChanged -= value; if (_dbStatusChanged == null) { int error = Interop.Database.RemoveStatusChangedCb(_contactsDBStatusChangedCallback, IntPtr.Zero); if ((int)ContactsError.None != error) { Log.Error(Globals.LogTag, "Remove StatusChanged Failed with error " + error); } } } } } /// /// The current contacts database version. /// /// The current contacts database version. /// 4 [SuppressMessage("Microsoft.Performance", "CA1822:MarkMembersAsStatic")] public int Version { get { int version = -1; int error = Interop.Database.GetVersion(out version); if ((int)ContactsError.None != error) { Log.Error(Globals.LogTag, "Version Failed with error " + error); } return version; } } /// /// The last successful changed contacts database version on the current connection. /// /// The last successful changed contacts database version on the current connection. /// 4 [SuppressMessage("Microsoft.Performance", "CA1822:MarkMembersAsStatic")] public int LastChangeVersion { get { int version = -1; int error = Interop.Database.GetLastChangeVersion(out version); if ((int)ContactsError.None != error) { Log.Error(Globals.LogTag, "LastChangeVersion Failed with error " + error); } return version; } } /// /// The contacts database status. /// /// The contacts database status. /// 4 [SuppressMessage("Microsoft.Performance", "CA1822:MarkMembersAsStatic")] public DBStatus Status { get { DBStatus status = DBStatus.Normal; int error = Interop.Database.GetStatus(out status); if ((int)ContactsError.None != error) { Log.Error(Globals.LogTag, "GetStatus Failed with error " + error); } return status; } } /// /// Inserts a record into the contacts database. /// /// The record to insert /// The ID of inserted record /// http://tizen.org/privilege/contact.write /// http://tizen.org/privilege/callhistory.write /// http://tizen.org/feature/contact /// Thrown when method failed due to invalid operation /// Thrown when feature 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 /// 4 [SuppressMessage("Microsoft.Performance", "CA1822:MarkMembersAsStatic")] public int Insert(ContactsRecord record) { int id = -1; int error = Interop.Database.Insert(record._recordHandle, out id); if ((int)ContactsError.None != error) { Log.Error(Globals.LogTag, "Insert Failed with error " + error); throw ContactsErrorFactory.CheckAndCreateException(error); } return id; } /// /// Inserts multiple records into the contacts database as a batch operation. /// /// The record list /// The inserted record ID array /// http://tizen.org/privilege/contact.write /// http://tizen.org/privilege/callhistory.write /// http://tizen.org/feature/contact /// Thrown when method failed due to invalid operation /// Thrown when feature 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 /// 4 [SuppressMessage("Microsoft.Performance", "CA1822:MarkMembersAsStatic")] public int[] Insert(ContactsList list) { IntPtr ids; int count; int error = Interop.Database.InsertRecords(list._listHandle, out ids, out count); if ((int)ContactsError.None != error) { Log.Error(Globals.LogTag, "Insert Failed with error " + error); throw ContactsErrorFactory.CheckAndCreateException(error); } int[] idArr = new int[count]; Marshal.Copy(ids, idArr, 0, count); return idArr; } /// /// Gets a record from the contacts database. /// /// The view URI of a record /// The record ID /// The record associated with the record ID /// http://tizen.org/privilege/contact.read /// http://tizen.org/privilege/callhistory.read /// http://tizen.org/feature/contact /// Thrown when method failed due to invalid operation /// Thrown when feature 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 /// 4 [SuppressMessage("Microsoft.Performance", "CA1822:MarkMembersAsStatic")] [SuppressMessage("Microsoft.Design", "CA1054:UriParametersShouldNotBeStrings")] public ContactsRecord Get(string viewUri, int recordId) { IntPtr handle; int error = Interop.Database.Get(viewUri, recordId, out handle); if ((int)ContactsError.None != error) { Log.Error(Globals.LogTag, "Get Failed with error " + error); throw ContactsErrorFactory.CheckAndCreateException(error); } return new ContactsRecord(handle); } /// /// Updates a record in the contacts database. /// /// The record to update /// http://tizen.org/privilege/contact.write /// http://tizen.org/privilege/callhistory.write /// http://tizen.org/feature/contact /// Thrown when method failed due to invalid operation /// Thrown when feature 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 /// 4 [SuppressMessage("Microsoft.Performance", "CA1822:MarkMembersAsStatic")] public void Update(ContactsRecord record) { int error = Interop.Database.Update(record._recordHandle); if ((int)ContactsError.None != error) { Log.Error(Globals.LogTag, "Update Failed with error " + error); throw ContactsErrorFactory.CheckAndCreateException(error); } } /// /// Updates multiple records in the contacts database as a batch operation. /// /// The record list /// http://tizen.org/privilege/contact.write /// http://tizen.org/privilege/callhistory.write /// http://tizen.org/feature/contact /// Thrown when method failed due to invalid operation /// Thrown when feature 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 /// 4 [SuppressMessage("Microsoft.Performance", "CA1822:MarkMembersAsStatic")] public void Update(ContactsList list) { int error = Interop.Database.UpdateRecords(list._listHandle); if ((int)ContactsError.None != error) { Log.Error(Globals.LogTag, "Update Failed with error " + error); throw ContactsErrorFactory.CheckAndCreateException(error); } } /// /// Deletes a record from the contacts database with related child records. /// /// The view URI of a record /// The record ID to delete /// http://tizen.org/privilege/contact.write /// http://tizen.org/privilege/callhistory.write /// http://tizen.org/feature/contact /// Thrown when method failed due to invalid operation /// Thrown when feature 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 /// 4 [SuppressMessage("Microsoft.Performance", "CA1822:MarkMembersAsStatic")] [SuppressMessage("Microsoft.Design", "CA1054:UriParametersShouldNotBeStrings")] public void Delete(string viewUri, int recordId) { int error = Interop.Database.Delete(viewUri, recordId); if ((int)ContactsError.None != error) { Log.Error(Globals.LogTag, "Delete Failed with error " + error); throw ContactsErrorFactory.CheckAndCreateException(error); } } /// /// Deletes multiple records with related child records from the contacts database as a batch operation. /// /// The view URI of the records to delete /// The record IDs to delete /// http://tizen.org/privilege/contact.write /// http://tizen.org/privilege/callhistory.write /// http://tizen.org/feature/contact /// Thrown when method failed due to invalid operation /// Thrown when feature 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 /// 4 [SuppressMessage("Microsoft.Performance", "CA1822:MarkMembersAsStatic")] [SuppressMessage("Microsoft.Design", "CA1054:UriParametersShouldNotBeStrings")] public void Delete(string viewUri, int[] idArray) { int error = Interop.Database.DeleteRecords(viewUri, idArray, idArray.Length); if ((int)ContactsError.None != error) { Log.Error(Globals.LogTag, "Delete Failed with error " + error); throw ContactsErrorFactory.CheckAndCreateException(error); } } /// /// Replaces a record in the contacts database. /// /// The record to replace /// the record ID to be replaced /// http://tizen.org/privilege/contact.write /// http://tizen.org/privilege/callhistory.write /// http://tizen.org/feature/contact /// Thrown when method failed due to invalid operation /// Thrown when feature 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 /// 4 [SuppressMessage("Microsoft.Performance", "CA1822:MarkMembersAsStatic")] public void Replace(ContactsRecord record, int recordId) { int error = Interop.Database.Replace(record._recordHandle, recordId); if ((int)ContactsError.None != error) { Log.Error(Globals.LogTag, "Replace Failed with error " + error); throw ContactsErrorFactory.CheckAndCreateException(error); } } /// /// Replaces multiple records in the contacts database as a batch operation. /// /// The record list to replace /// The record IDs to be replaced /// http://tizen.org/privilege/contact.write /// http://tizen.org/privilege/callhistory.write /// http://tizen.org/feature/contact /// Thrown when method failed due to invalid operation /// Thrown when feature 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 /// 4 [SuppressMessage("Microsoft.Performance", "CA1822:MarkMembersAsStatic")] public void Replace(ContactsList list, int[] idArray) { int error = Interop.Database.ReplaceRecords(list._listHandle, idArray, idArray.Length); if ((int)ContactsError.None != error) { Log.Error(Globals.LogTag, "Replace Failed with error " + error); throw ContactsErrorFactory.CheckAndCreateException(error); } } /// /// Retrieves all records as a list. /// /// The view URI to get records /// The index from which results /// The number to limit results(value 0 is used for all records) /// /// The record list /// /// http://tizen.org/privilege/contact.read /// http://tizen.org/privilege/callhistory.read /// http://tizen.org/feature/contact /// Thrown when method failed due to invalid operation /// Thrown when feature 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 /// 4 [SuppressMessage("Microsoft.Performance", "CA1822:MarkMembersAsStatic")] [SuppressMessage("Microsoft.Design", "CA1054:UriParametersShouldNotBeStrings")] public ContactsList GetAll(string viewUri, int offset, int limit) { IntPtr handle; int error = Interop.Database.GetRecords(viewUri, offset, limit, out handle); if ((int)ContactsError.None != error) { Log.Error(Globals.LogTag, "GetAll Failed with error " + error); throw ContactsErrorFactory.CheckAndCreateException(error); } return new ContactsList(handle); } /// /// Retrieves records using a query. /// /// The query to filter the results /// The index from which to get results /// The number to limit results(value 0 is used for get all records) /// /// The record list /// /// http://tizen.org/privilege/contact.read /// http://tizen.org/privilege/callhistory.read /// http://tizen.org/feature/contact /// Thrown when method failed due to invalid operation /// Thrown when feature 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 /// 4 [SuppressMessage("Microsoft.Performance", "CA1822:MarkMembersAsStatic")] public ContactsList GetRecordsWithQuery(ContactsQuery query, int offset, int limit) { IntPtr handle; int error = Interop.Database.GetRecords(query._queryHandle, offset, limit, out handle); if ((int)ContactsError.None != error) { Log.Error(Globals.LogTag, "GetAllWithQuery Failed with error " + error); throw ContactsErrorFactory.CheckAndCreateException(error); } return new ContactsList(handle); } /// /// Retrieves records changes since the given database version. /// /// The view URI to get records /// The address book ID to filter /// The contacts database version /// The current contacts database version /// /// The record list /// /// http://tizen.org/privilege/contact.read /// http://tizen.org/feature/contact /// Thrown when method failed due to invalid operation /// Thrown when feature 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 /// 4 [SuppressMessage("Microsoft.Performance", "CA1822:MarkMembersAsStatic")] [SuppressMessage("Microsoft.Design", "CA1054:UriParametersShouldNotBeStrings")] public ContactsList GetChangesByVersion(string viewUri, int addressBookId, int contactsDBVersion, out int currentDBVersion) { IntPtr recordList; int error = Interop.Database.GetChangesByVersion(viewUri, addressBookId, contactsDBVersion, out recordList,out currentDBVersion); if ((int)ContactsError.None != error) { Log.Error(Globals.LogTag, "GetChangesByVersion Failed with error " + error); throw ContactsErrorFactory.CheckAndCreateException(error); } return new ContactsList(recordList); } /// /// Finds records based on a given keyword. /// /// /// This API works only for the Views below. /// Person, PersonContact, PersonGroupRelation, PersonGroupAssigned and PersonGroupNotAssigned. /// /// The view URI to find records /// The keyword /// The index from which to get results /// The number to limit results(value 0 is used for get all records) /// The record list /// http://tizen.org/privilege/contact.read /// http://tizen.org/feature/contact /// Thrown when method failed due to invalid operation /// Thrown when feature 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 /// 4 [SuppressMessage("Microsoft.Performance", "CA1822:MarkMembersAsStatic")] [SuppressMessage("Microsoft.Design", "CA1054:UriParametersShouldNotBeStrings")] public ContactsList Search(string viewUri, string keyword, int offset, int limit) { IntPtr recordList; int error = Interop.Database.Search(viewUri, keyword, offset, limit, out recordList); if ((int)ContactsError.None != error) { Log.Error(Globals.LogTag, "Search Failed with error " + error); throw ContactsErrorFactory.CheckAndCreateException(error); } return new ContactsList(recordList); } /// /// Finds records based on given query and keyword. /// /// /// This API works only for the Views below. /// Person, PersonContact, PersonGroupRelation, PersonGroupAssigned and PersonGroupNotAssigned. /// /// The query to filter /// The keyword /// The index from which to get results /// The number to limit results(value 0 used for get all records) /// The record list /// http://tizen.org/privilege/contact.read /// http://tizen.org/feature/contact /// Thrown when method failed due to invalid operation /// Thrown when feature 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 /// 4 [SuppressMessage("Microsoft.Performance", "CA1822:MarkMembersAsStatic")] public ContactsList Search(ContactsQuery query, string keyword, int offset, int limit) { IntPtr recordList; int error = Interop.Database.Search(query._queryHandle, keyword, offset, limit, out recordList); if ((int)ContactsError.None != error) { Log.Error(Globals.LogTag, "Search Failed with error " + error); throw ContactsErrorFactory.CheckAndCreateException(error); } return new ContactsList(recordList); } /// /// Finds records based on a keyword and range. /// /// /// This API works only for the Views below. /// Person, PersonContact, PersonGroupRelation, PersonGroupAssigned, PersonGroupNotAssigned, PersonNumber and PersonEmail /// /// The view URI /// The keyword /// The index from which to get results /// The number to limit results(value 0 is used for get all records) /// The search range, it should be a element of SearchRange or bitwise OR operation of them /// The record list /// http://tizen.org/privilege/contact.read /// http://tizen.org/feature/contact /// Thrown when method failed due to invalid operation /// Thrown when feature 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 /// 4 [SuppressMessage("Microsoft.Performance", "CA1822:MarkMembersAsStatic")] [SuppressMessage("Microsoft.Design", "CA1054:UriParametersShouldNotBeStrings")] public ContactsList Search(string viewUri, string keyword, int offset, int limit, int range) { IntPtr recordList; int error = Interop.Database.Search(viewUri, keyword, offset, limit, range, out recordList); if ((int)ContactsError.None != error) { Log.Error(Globals.LogTag, "Search Failed with error " + error); throw ContactsErrorFactory.CheckAndCreateException(error); } return new ContactsList(recordList); } /// /// Finds records based on a given keyword for snippet /// /// /// This API works only for the Views below. /// Person, PersonContact, PersonGroupRelation, PersonGroupAssigned and PersonGroupNotAssigned. /// Because start match and end match are needed to be composed with keyword, this API performance is lower than Search(string viewUri, string keyword, int offset, int limit). /// /// The view URI to find records /// The keyword /// The index from which to get results /// The number to limit results(value 0 used for get all records) /// The text which is inserted into the fragment before the keyword(If NULL, default is "[") /// The text which is inserted into the fragment after the keyword(If NULL, default is "]") /// The one side extra number of tokens near keyword(If negative value, full sentence is printed. e.g. if token number is 3 with 'abc' keyword, "my name is [abc]de and my home") /// The record list /// http://tizen.org/privilege/contact.read /// http://tizen.org/feature/contact /// Thrown when method failed due to invalid operation /// Thrown when feature 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 /// 4 [SuppressMessage("Microsoft.Performance", "CA1822:MarkMembersAsStatic")] [SuppressMessage("Microsoft.Design", "CA1054:UriParametersShouldNotBeStrings")] public ContactsList Search(string viewUri, string keyword, int offset, int limit, string startMatch, string endMatch, int tokenNumber) { IntPtr recordList; int error = Interop.Database.Search(viewUri, keyword, offset, limit, startMatch, endMatch, tokenNumber, out recordList); if ((int)ContactsError.None != error) { Log.Error(Globals.LogTag, "Search Failed with error " + error); throw ContactsErrorFactory.CheckAndCreateException(error); } return new ContactsList(recordList); } /// /// Finds records based on given query and keyword for snippet. /// /// /// This API works only for the Views below. /// Person, PersonContact, PersonGroupRelation, PersonGroupAssigned and PersonGroupNotAssigned. /// Because start match and end match are needed to be composed with keyword, this API performance is lower than Search(ContactsQuery query, string keyword, int offset, int limit). /// /// The query to filter /// The keyword /// The index from which to get results /// The number to limit results(value 0 used for get all records) /// The text which is inserted into the fragment before the keyword(If NULL, default is "[") /// The text which is inserted into the fragment after the keyword(If NULL, default is "]") /// The one side extra number of tokens near keyword(If negative value, full sentence is printed. e.g. if token number is 3 with 'abc' keyword, "my name is [abc]de and my home") /// The record list /// http://tizen.org/privilege/contact.read /// http://tizen.org/feature/contact /// Thrown when method failed due to invalid operation /// Thrown when feature 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 /// 4 [SuppressMessage("Microsoft.Performance", "CA1822:MarkMembersAsStatic")] public ContactsList Search(ContactsQuery query, string keyword, int offset, int limit, string startMatch, string endMatch, int tokenNumber) { IntPtr recordList; int error = Interop.Database.Search(query._queryHandle, keyword, offset, limit, startMatch, endMatch, tokenNumber, out recordList); if ((int)ContactsError.None != error) { Log.Error(Globals.LogTag, "Search Failed with error " + error); throw ContactsErrorFactory.CheckAndCreateException(error); } return new ContactsList(recordList); } /// /// Finds records based on a keyword and range for snippet. /// /// /// This API works only for the Views below. /// Person, PersonContact, PersonGroupRelation, PersonGroupAssigned, PersonGroupNotAssigned, PersonNumber and PersonEmail /// Because start match and end match are needed to be composed with keyword, this API performance is lower than Search(string viewUri, string keyword, int offset, int limit, int range). /// /// The view URI /// The keyword /// The index from which to get results /// The number to limit results(value 0 is used for get all records) /// The search range, it should be a element of SearchRange or bitwise OR operation of them /// The text which is inserted into the fragment before the keyword(If NULL, default is "[") /// The text which is inserted into the fragment after the keyword(If NULL, default is "]") /// The one side extra number of tokens near keyword(If negative value, full sentence is printed. e.g. if token number is 3 with 'abc' keyword, "my name is [abc]de and my home") /// The record list /// http://tizen.org/privilege/contact.read /// http://tizen.org/feature/contact /// Thrown when method failed due to invalid operation /// Thrown when feature 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 /// 4 [SuppressMessage("Microsoft.Performance", "CA1822:MarkMembersAsStatic")] [SuppressMessage("Microsoft.Design", "CA1054:UriParametersShouldNotBeStrings")] public ContactsList Search(string viewUri, string keyword, int offset, int limit, int range, string startMatch, string endMatch, int tokenNumber) { IntPtr recordList; int error = Interop.Database.Search(viewUri, keyword, offset, limit, range, startMatch, endMatch, tokenNumber, out recordList); if ((int)ContactsError.None != error) { Log.Error(Globals.LogTag, "Search Failed with error " + error); throw ContactsErrorFactory.CheckAndCreateException(error); } return new ContactsList(recordList); } /// /// Gets the number of records in a specific view /// /// The view URI /// The count of records /// 4 [SuppressMessage("Microsoft.Performance", "CA1822:MarkMembersAsStatic")] [SuppressMessage("Microsoft.Design", "CA1054:UriParametersShouldNotBeStrings")] public int GetCount(string viewUri) { int count = -1; int error = Interop.Database.GetCount(viewUri, out count); if ((int)ContactsError.None != error) { Log.Error(Globals.LogTag, "GetCount Failed with error " + error); throw ContactsErrorFactory.CheckAndCreateException(error); } return count; } /// /// Gets the number of records matching a query. /// /// The query used for filtering the results /// The count of records /// 4 [SuppressMessage("Microsoft.Performance", "CA1822:MarkMembersAsStatic")] public int GetCount(ContactsQuery query) { int count = -1; int error = Interop.Database.GetCount(query._queryHandle, out count); if ((int)ContactsError.None != error) { Log.Error(Globals.LogTag, "GetCount Failed with error " + error); throw ContactsErrorFactory.CheckAndCreateException(error); } return count; } /// /// Registers a EventHandler to be invoked when a record changes. /// /// The view URI of records whose changes are monitored /// The EventHandler to register /// http://tizen.org/privilege/contact.read /// http://tizen.org/privilege/callhistory.read /// http://tizen.org/feature/contact /// Thrown when method failed due to invalid operation /// Thrown when feature 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 /// 4 [SuppressMessage("Microsoft.Design", "CA1054:UriParametersShouldNotBeStrings")] public void AddDBChangedEventHandler(string viewUri, EventHandler DBChanged) { if (!_callbackMap.ContainsKey(viewUri)) { _callbackMap[viewUri] = (string uri, IntPtr userData) => { DBChangedEventArgs args = new DBChangedEventArgs(uri); _eventHandlerMap[uri]?.Invoke(this, args); }; int error = Interop.Database.AddChangedCb(viewUri, _callbackMap[viewUri], IntPtr.Zero); if ((int)ContactsError.None != error) { Log.Error(Globals.LogTag, "AddDBChangedEventHandler Failed with error " + error); throw ContactsErrorFactory.CheckAndCreateException(error); } } EventHandler handler = null; if (!_eventHandlerMap.TryGetValue(viewUri, out handler)) _eventHandlerMap.Add(viewUri, null); _eventHandlerMap[viewUri] = handler + DBChanged; } /// /// Deregisters a EventHandler. /// /// The view URI of records whose changes are monitored /// The EventHandler to deregister /// http://tizen.org/feature/contact /// Thrown when method failed due to invalid operation /// Thrown when feature is not supported /// Thrown when one of the arguments provided to a method is not valid /// Thrown when failed due to out of memory /// 4 [SuppressMessage("Microsoft.Design", "CA1054:UriParametersShouldNotBeStrings")] public void RemoveDBChangedEventHandler(string viewUri, EventHandler DBChanged) { EventHandler handler = null; if (!_eventHandlerMap.TryGetValue(viewUri, out handler)) _eventHandlerMap.Add(viewUri, null); else _eventHandlerMap[viewUri] = handler - DBChanged; if (_eventHandlerMap[viewUri] == null) { int error = Interop.Database.RemoveChangedCb(viewUri, _callbackMap[viewUri], IntPtr.Zero); if ((int)ContactsError.None != error) { Log.Error(Globals.LogTag, "RemoveDBChangedEventHandler Failed with error " + error); throw ContactsErrorFactory.CheckAndCreateException(error); } _callbackMap.Remove(viewUri); } } } }