2 * Copyright (c) 2016 Samsung Electronics Co., Ltd All Rights Reserved
4 * Licensed under the Apache License, Version 2.0 (the License);
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an AS IS BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
19 namespace Tizen.Pims.Contacts
24 /// Delegates for getting a record parsed from a vCard file.
26 /// <param name="record">The contacts record.</param>
27 /// <returns>true to continue with the next iteration of the loop, otherwise false to break out of the loop.</returns>
28 /// <since_tizen> 4 </since_tizen>
29 public delegate bool ParseCallback(ContactsRecord record);
32 /// A class for parsing and making the vCards.
35 /// It's based on the vCard v3.0 specification.
37 /// <since_tizen> 4 </since_tizen>
38 public static class ContactsVcard
41 /// Retrieves the vCard stream from a contacts record.
43 /// <param name="record">The contacts record.</param>
47 /// <privilege>http://tizen.org/privilege/contact.read</privilege>
48 /// <feature>http://tizen.org/feature/contact</feature>
49 /// <exception cref="ArgumentException">Thrown when one of the arguments provided to a method is not valid.</exception>
50 /// <exception cref="OutOfMemoryException">Thrown when failed due to out of memory.</exception>
51 /// <exception cref="NotSupportedException">Thrown when the feature is not supported.</exception>
52 /// <since_tizen> 4 </since_tizen>
53 public static string Compose(ContactsRecord record)
58 if (record.Uri.Equals(Person.Uri))
60 error = Interop.Vcard.ContactsVcardMakeFromPerson(record._recordHandle, out stream);
62 else if (record.Uri.Equals(Contact.Uri))
64 error = Interop.Vcard.ContactsVcardMakeFromContact(record._recordHandle, out stream);
66 else if (record.Uri.Equals(MyProfile.Uri))
68 error = Interop.Vcard.ContactsVcardMakeFromMyProfile(record._recordHandle, out stream);
72 throw new ArgumentException("Invalid Parameters Provided");
75 if ((int)ContactsError.None != error)
77 Log.Error(Globals.LogTag, "Compose Failed with error " + error);
78 throw ContactsErrorFactory.CheckAndCreateException(error);
85 /// Retrieves all the contacts with a contacts list from a vCard stream.
87 /// <param name="stream">The vCard stream.</param>
89 /// The contacts list.
91 /// <feature>http://tizen.org/feature/contact</feature>
92 /// <exception cref="ArgumentException">Thrown when one of the arguments provided to a method is not valid.</exception>
93 /// <exception cref="OutOfMemoryException">Thrown when failed due to out of memory.</exception>
94 /// <exception cref="NotSupportedException">Thrown when the feature is not supported.</exception>
95 /// <since_tizen> 4 </since_tizen>
96 public static ContactsList Parse(string stream)
100 int error = Interop.Vcard.ContactsVcardParseToContacts(stream, out listHandle);
101 if ((int)ContactsError.None != error)
103 Log.Error(Globals.LogTag, "Parse Failed with error " + error);
104 throw ContactsErrorFactory.CheckAndCreateException(error);
107 return new ContactsList(listHandle);
111 /// Retrieves all the contacts with a record from a vCard file.
113 /// <param name="path">The file path of a vCard stream file.</param>
114 /// <param name="callback">The callback function to invoke.</param>
115 /// <feature>http://tizen.org/feature/contact</feature>
116 /// <exception cref="InvalidOperationException">Thrown when the method failed due to an invalid operation.</exception>
117 /// <exception cref="ArgumentException">Thrown when one of the arguments provided to a method is not valid.</exception>
118 /// <exception cref="OutOfMemoryException">Thrown when failed due to out of memory.</exception>
119 /// <exception cref="NotSupportedException">Thrown when the feature is not supported.</exception>
120 /// <since_tizen> 4 </since_tizen>
121 public static void ParseForEach(string path, ParseCallback callback)
123 Interop.Vcard.ContactsVcardParseCallback cb = (IntPtr handle, IntPtr data) =>
125 return callback(new ContactsRecord(handle, true));
128 int error = Interop.Vcard.ContactsVcardParseToContactForeach(path, cb, IntPtr.Zero);
129 if ((int)ContactsError.None != error)
131 Log.Error(Globals.LogTag, "ParseForEach Failed with error " + error);
132 throw ContactsErrorFactory.CheckAndCreateException(error);