Beispiel #1
0
        /// <summary>
        /// Retrieves the vCard stream from a contacts record.
        /// </summary>
        /// <param name="record">The contacts record</param>
        /// <returns>
        /// The vCard stream.
        /// </returns>
        /// <privilege>http://tizen.org/privilege/contact.read</privilege>
        /// <feature>http://tizen.org/feature/contact</feature>
        /// <exception cref="ArgumentException">Thrown when one of the arguments provided to a method is not valid</exception>
        /// <exception cref="OutOfMemoryException">Thrown when failed due to out of memory</exception>
        /// <exception cref="NotSupportedException">Thrown when feature is not supported</exception>
        /// <since_tizen> 4 </since_tizen>
        public static string Compose(ContactsRecord record)
        {
            int    error  = 0;
            string stream = null;

            if (record.Uri.Equals(Person.Uri))
            {
                error = Interop.Vcard.ContactsVcardMakeFromPerson(record._recordHandle, out stream);
            }
            else if (record.Uri.Equals(Contact.Uri))
            {
                error = Interop.Vcard.ContactsVcardMakeFromContact(record._recordHandle, out stream);
            }
            else if (record.Uri.Equals(MyProfile.Uri))
            {
                error = Interop.Vcard.ContactsVcardMakeFromMyProfile(record._recordHandle, out stream);
            }
            else
            {
                throw new ArgumentException("Invalid Parameters Provided");
            }

            if ((int)ContactsError.None != error)
            {
                Log.Error(Globals.LogTag, "Compose Failed with error " + error);
                throw ContactsErrorFactory.CheckAndCreateException(error);
            }

            return(stream);
        }
Beispiel #2
0
        public void AddDBChangedEventHandler(string viewUri, EventHandler <DBChangedEventArgs> 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 <DBChangedEventArgs> handler = null;

            if (!_eventHandlerMap.TryGetValue(viewUri, out handler))
            {
                _eventHandlerMap.Add(viewUri, null);
            }

            _eventHandlerMap[viewUri] = handler + DBChanged;
        }
Beispiel #3
0
 /// <summary>
 /// Sets a value of the property to a record.
 /// </summary>
 /// <feature>http://tizen.org/feature/contact</feature>
 /// <exception cref="NotSupportedException">Thrown when the feature is not supported.</exception>
 /// <param name="propertyId">The property ID.</param>
 /// <param name="value">The value to set.</param>
 /// <exception cref="ArgumentException">Thrown when one of the arguments provided to a method is not valid.</exception>
 /// <since_tizen> 4 </since_tizen>
 public void Set <T>(uint propertyId, T value)
 {
     if (typeof(T) == typeof(string))
     {
         string val   = Convert.ToString(value);
         int    error = Interop.Record.SetStr(_recordHandle, propertyId, val);
         if ((int)ContactsError.None != error)
         {
             Log.Error(Globals.LogTag, "Set String Failed with error " + error);
             throw ContactsErrorFactory.CheckAndCreateException(error);
         }
     }
     else if (typeof(T) == typeof(int))
     {
         int val   = Convert.ToInt32(value);
         int error = Interop.Record.SetInt(_recordHandle, propertyId, val);
         if ((int)ContactsError.None != error)
         {
             Log.Error(Globals.LogTag, "Set Int Failed with error " + error);
             throw ContactsErrorFactory.CheckAndCreateException(error);
         }
     }
     else if (typeof(T) == typeof(bool))
     {
         bool val   = Convert.ToBoolean(value);
         int  error = Interop.Record.SetBool(_recordHandle, propertyId, val);
         if ((int)ContactsError.None != error)
         {
             Log.Error(Globals.LogTag, "Set Bool Failed with error " + error);
             throw ContactsErrorFactory.CheckAndCreateException(error);
         }
     }
     else if (typeof(T) == typeof(long))
     {
         long val   = Convert.ToInt64(value);
         int  error = Interop.Record.SetLli(_recordHandle, propertyId, val);
         if ((int)ContactsError.None != error)
         {
             Log.Error(Globals.LogTag, "Set Long Failed with error " + error);
             throw ContactsErrorFactory.CheckAndCreateException(error);
         }
     }
     else if (typeof(T) == typeof(double))
     {
         double val   = Convert.ToDouble(value);
         int    error = Interop.Record.SetDouble(_recordHandle, propertyId, val);
         if ((int)ContactsError.None != error)
         {
             Log.Error(Globals.LogTag, "Get Long Failed with error " + error);
             throw ContactsErrorFactory.CheckAndCreateException(error);
         }
     }
     else
     {
         Log.Error(Globals.LogTag, "Not Supported Data Type");
         throw ContactsErrorFactory.CheckAndCreateException((int)ContactsError.NotSupported);
     }
 }
Beispiel #4
0
        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);
            }
        }
Beispiel #5
0
        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);
            }
        }
Beispiel #6
0
        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);
            }
        }
Beispiel #7
0
        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);
            }
        }
Beispiel #8
0
        /// <summary>
        /// Sets the "distinct" option for projection.
        /// </summary>
        /// <param name="set">If true it is set, otherwise if false it is unset.</param>
        /// <feature>http://tizen.org/feature/contact</feature>
        /// <exception cref="NotSupportedException">Thrown when the feature is not supported.</exception>
        /// <since_tizen> 4 </since_tizen>
        public void SetDistinct(bool set)
        {
            int error = Interop.Query.ContactsQuerySetDistinct(_queryHandle, set);

            if ((int)ContactsError.None != error)
            {
                Log.Error(Globals.LogTag, "SetDistinct Failed with error " + error);
                throw ContactsErrorFactory.CheckAndCreateException(error);
            }
        }
Beispiel #9
0
        /// <summary>
        /// Sets the filter for a query.
        /// </summary>
        /// <param name="filter">The filter.</param>
        /// <feature>http://tizen.org/feature/contact</feature>
        /// <exception cref="NotSupportedException">Thrown when the feature is not supported.</exception>
        /// <exception cref="ArgumentException">Thrown when one of the arguments provided to a method is not valid.</exception>
        /// <since_tizen> 4 </since_tizen>
        public void SetFilter(ContactsFilter filter)
        {
            int error = Interop.Query.ContactsQuerySetFilter(_queryHandle, filter._filterHandle);

            if ((int)ContactsError.None != error)
            {
                Log.Error(Globals.LogTag, "SetFilter Failed with error " + error);
                throw ContactsErrorFactory.CheckAndCreateException(error);
            }
        }
Beispiel #10
0
        /// <summary>
        /// Sets the sort mode for a query.
        /// </summary>
        /// <param name="propertyId">The property ID to sort.</param>
        /// <param name="isAscending">If true it sorts in ascending order, otherwise if false it sorts in descending order.</param>
        /// <feature>http://tizen.org/feature/contact</feature>
        /// <exception cref="NotSupportedException">Thrown when the feature is not supported.</exception>
        /// <exception cref="ArgumentException">Thrown when one of the arguments provided to a method is not valid.</exception>
        /// <since_tizen> 4 </since_tizen>
        public void SetSort(uint propertyId, bool isAscending)
        {
            int error = Interop.Query.ContactsQuerySetSort(_queryHandle, propertyId, isAscending);

            if ((int)ContactsError.None != error)
            {
                Log.Error(Globals.LogTag, "SetSort Failed with error " + error);
                throw ContactsErrorFactory.CheckAndCreateException(error);
            }
        }
Beispiel #11
0
        public ContactsQuery(string viewUri)
        {
            int error = Interop.Query.ContactsQueryCreate(viewUri, out _queryHandle);

            if ((int)ContactsError.None != error)
            {
                Log.Error(Globals.LogTag, "ContactsQuery Failed with error " + error);
                throw ContactsErrorFactory.CheckAndCreateException(error);
            }
        }
Beispiel #12
0
        /// <summary>
        /// Moves a contacts list to the last position.
        /// </summary>
        /// <feature>http://tizen.org/feature/contact</feature>
        /// <exception cref="NotSupportedException">Thrown when the feature is not supported.</exception>
        /// <since_tizen> 4 </since_tizen>
        public void MoveLast()
        {
            int error = Interop.List.ContactsListLast(_listHandle);

            if ((int)ContactsError.None != error)
            {
                Log.Error(Globals.LogTag, "MoveFirst Failed with error " + error);
                throw ContactsErrorFactory.CheckAndCreateException(error);
            }
        }
Beispiel #13
0
        /// <summary>
        /// Removes a child record from the parent record.
        /// </summary>
        /// <param name="propertyId">The property ID.</param>
        /// <param name="childRecord">The child record to remove from the parent record.</param>
        /// <feature>http://tizen.org/feature/contact</feature>
        /// <exception cref="NotSupportedException">Thrown when feature is not supported.</exception>
        /// <exception cref="ArgumentException">Thrown when one of the arguments provided to a method is not valid.</exception>
        /// <since_tizen> 4 </since_tizen>
        public void RemoveChildRecord(uint propertyId, ContactsRecord childRecord)
        {
            int error = Interop.Record.RemoveChildRecord(_recordHandle, propertyId, childRecord._recordHandle);

            if ((int)ContactsError.None != error)
            {
                Log.Error(Globals.LogTag, "RemoveChildRecord Failed with error " + error);
                throw ContactsErrorFactory.CheckAndCreateException(error);
            }
            childRecord._disposedValue = false;
        }
Beispiel #14
0
        /// <summary>
        /// Creates a contacts record list.
        /// </summary>
        /// <feature>http://tizen.org/feature/contact</feature>
        /// <exception cref="NotSupportedException">Thrown when the feature is not supported.</exception>
        /// <exception cref="OutOfMemoryException">Thrown when failed due to out of memory.</exception>
        /// <since_tizen> 4 </since_tizen>
        public ContactsList()
        {
            int error = Interop.List.ContactsListCreate(out _listHandle);

            if ((int)ContactsError.None != error)
            {
                Log.Error(Globals.LogTag, "ContactsList Failed with error " + error);
                throw ContactsErrorFactory.CheckAndCreateException(error);
            }
            GC.AddMemoryPressure(_memoryPressure);
        }
Beispiel #15
0
        /// <summary>
        /// Creates a ContactsManager.
        /// </summary>
        /// <feature>http://tizen.org/feature/contact</feature>
        /// <exception cref="InvalidOperationException">Thrown when the method failed due to an invalid operation.</exception>
        /// <exception cref="NotSupportedException">Thrown when the feature is not supported.</exception>
        /// <since_tizen> 4 </since_tizen>
        public ContactsManager()
        {
            int error = Interop.Service.Connect();

            if ((int)ContactsError.None != error)
            {
                Log.Error(Globals.LogTag, "Connect Failed with error " + error);
                throw ContactsErrorFactory.CheckAndCreateException(error);
            }
            _db = new ContactsDatabase();
        }
Beispiel #16
0
        /// <summary>
        /// Gets the number of child records of a parent record.
        /// </summary>
        /// <param name="propertyId">The property ID.</param>
        /// <returns>The number of child records corresponding to the property ID.</returns>
        /// <feature>http://tizen.org/feature/contact</feature>
        /// <exception cref="NotSupportedException">Thrown when the feature is not supported.</exception>
        /// <exception cref="ArgumentException">Thrown when one of the arguments provided to a method is not valid.</exception>
        /// <since_tizen> 4 </since_tizen>
        public int GetChildRecordCount(uint propertyId)
        {
            int count = 0;
            int error = Interop.Record.GetChildRecordCount(_recordHandle, propertyId, out count);

            if ((int)ContactsError.None != error)
            {
                Log.Error(Globals.LogTag, "GetChildRecordCount Failed with error " + error);
                throw ContactsErrorFactory.CheckAndCreateException(error);
            }
            return(count);
        }
Beispiel #17
0
        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));
        }
Beispiel #18
0
        /// <summary>
        /// Removes a record from the contacts list.
        /// </summary>
        /// <param name="record">The record to remove.</param>
        /// <feature>http://tizen.org/feature/contact</feature>
        /// <exception cref="NotSupportedException">Thrown when the feature is not supported.</exception>
        /// <exception cref="ArgumentException">Thrown when one of the arguments provided to a method is not valid.</exception>
        /// <since_tizen> 4 </since_tizen>
        public void RemoveRecord(ContactsRecord record)
        {
            int error = Interop.List.ContactsListRemove(_listHandle, record._recordHandle);

            if ((int)ContactsError.None != error)
            {
                Log.Error(Globals.LogTag, "RemoveRecord Failed with error " + error);
                throw ContactsErrorFactory.CheckAndCreateException(error);
            }
            record._disposedValue = false;
            _memoryPressure      -= ContactsViews.Record.AverageSize;
        }
Beispiel #19
0
        /// <summary>
        /// Retrieves a record from the contacts list.
        /// </summary>
        /// <returns>
        /// The contacts record.
        /// </returns>
        /// <feature>http://tizen.org/feature/contact</feature>
        /// <exception cref="NotSupportedException">Thrown when the feature is not supported.</exception>
        /// <since_tizen> 4 </since_tizen>
        public ContactsRecord GetCurrentRecord()
        {
            IntPtr handle;
            int    error = Interop.List.ContactsListGetCurrentRecordP(_listHandle, out handle);

            if ((int)ContactsError.None != error)
            {
                Log.Error(Globals.LogTag, "GetCurrentRecord Failed with error " + error);
                throw ContactsErrorFactory.CheckAndCreateException(error);
            }
            return(new ContactsRecord(handle, true));
        }
Beispiel #20
0
        public ContactsRecord(string viewUri)
        {
            int error = Interop.Record.Create(viewUri, out _recordHandle);

            if ((int)ContactsError.None != error)
            {
                Log.Error(Globals.LogTag, "ContactsRecord Failed with error " + error);
                throw ContactsErrorFactory.CheckAndCreateException(error);
            }
            _uri = viewUri;
            GC.AddMemoryPressure(_memoryPressure);
        }
Beispiel #21
0
        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));
        }
Beispiel #22
0
        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);
        }
Beispiel #23
0
        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));
        }
Beispiel #24
0
        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));
        }
Beispiel #25
0
        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);
        }
Beispiel #26
0
        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);
        }
Beispiel #27
0
        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));
        }
Beispiel #28
0
        /// <summary>
        /// Makes a clone of a record.
        /// </summary>
        /// <returns>A cloned record.</returns>
        /// <feature>http://tizen.org/feature/contact</feature>
        /// <exception cref="NotSupportedException">Thrown when the feature is not supported.</exception>
        /// <exception cref="OutOfMemoryException">Thrown when failed due to out of memory.</exception>
        /// <since_tizen> 4 </since_tizen>
        public ContactsRecord Clone()
        {
            IntPtr _clonedRecordHandle;
            int    error = Interop.Record.Clone(_recordHandle, out _clonedRecordHandle);

            if ((int)ContactsError.None != error)
            {
                Log.Error(Globals.LogTag, "Clone Failed with error " + error);
                throw ContactsErrorFactory.CheckAndCreateException(error);
            }
            return(new ContactsRecord(_clonedRecordHandle, (int)_id));
        }
Beispiel #29
0
        /// <summary>
        /// Gets a child record from the parent record.
        /// </summary>
        /// <param name="propertyId">The property ID.</param>
        /// <param name="index">The index of the child record.</param>
        /// <returns>The record </returns>
        /// <feature>http://tizen.org/feature/contact</feature>
        /// <exception cref="NotSupportedException">Thrown when the feature is not supported.</exception>
        /// <exception cref="ArgumentException">Thrown when one of the arguments provided to a method is not valid.</exception>
        /// <since_tizen> 4 </since_tizen>
        public ContactsRecord GetChildRecord(uint propertyId, int index)
        {
            IntPtr handle;

            int error = Interop.Record.GetChildRecordAtP(_recordHandle, propertyId, index, out handle);

            if ((int)ContactsError.None != error)
            {
                Log.Error(Globals.LogTag, "GetChildRecord Failed with error " + error);
                throw ContactsErrorFactory.CheckAndCreateException(error);
            }
            return(new ContactsRecord(handle, true));
        }
Beispiel #30
0
        /// <summary>
        /// Retrieves all contacts with a contacts list from a vCard stream
        /// </summary>
        /// <param name="stream">The vCard stream</param>
        /// <returns>
        /// The contacts list
        /// </returns>
        /// <feature>http://tizen.org/feature/contact</feature>
        /// <exception cref="ArgumentException">Thrown when one of the arguments provided to a method is not valid</exception>
        /// <exception cref="OutOfMemoryException">Thrown when failed due to out of memory</exception>
        /// <exception cref="NotSupportedException">Thrown when feature is not supported</exception>
        /// <since_tizen> 4 </since_tizen>
        public static ContactsList Parse(string stream)
        {
            IntPtr listHandle;

            int error = Interop.Vcard.ContactsVcardParseToContacts(stream, out listHandle);

            if ((int)ContactsError.None != error)
            {
                Log.Error(Globals.LogTag, "Parse Failed with error " + error);
                throw ContactsErrorFactory.CheckAndCreateException(error);
            }

            return(new ContactsList(listHandle));
        }