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.Calendar
22 /// Parsing vcalendar file callback function.
24 /// <param name="record">The record</param>
25 /// <returns>true to continue with the next iteration of the loop, otherwise false to break out of the loop</returns>
26 /// <since_tizen> 4 </since_tizen>
27 public delegate bool ParseCallback(CalendarRecord record);
30 /// A class for parsing and composing vCalendar.
33 /// It's based on the vCalendar v2.0 specification
35 /// <since_tizen> 4 </since_tizen>
36 public static class CalendarVcalendar
39 /// Retrieves a vcalendar stream from a calendar list.
41 /// <param name="list">The calendar list</param>
43 /// The composed stream.
45 /// <exception cref="ArgumentException">Thrown when one of the arguments provided to a method is not valid</exception>
46 /// <exception cref="OutOfMemoryException">Thrown when failed due to out of memory</exception>
47 /// <since_tizen> 4 </since_tizen>
48 public static string Compose(CalendarList list)
51 int error = Interop.Vcalendar.Compose(list._listHandle, out stream);
52 if (CalendarError.None != (CalendarError)error)
54 Log.Error(Globals.LogTag, "MakeVcalendar Failed with error " + error);
55 throw CalendarErrorFactory.GetException(error);
61 /// Retrieves all calendars from a vcalendar stream.
63 /// <param name="stream">The vcalendar stream</param>
67 /// <exception cref="ArgumentException">Thrown when one of the arguments provided to a method is not valid</exception>
68 /// <exception cref="OutOfMemoryException">Thrown when failed due to out of memory</exception>
69 /// <since_tizen> 4 </since_tizen>
70 public static CalendarList Parse(string stream)
74 error = Interop.Vcalendar.Parse(stream, out _listHandle);
75 if (CalendarError.None != (CalendarError)error)
77 Log.Error(Globals.LogTag, "Parse Vcalendar Failed [" + error + "]");
78 throw CalendarErrorFactory.GetException(error);
80 return new CalendarList(_listHandle);
84 /// Parse vcalendar file with ForEach
86 /// <param name="path">The file path of the vCalendar stream file</param>
87 /// <param name="callback">he callback function to invoke</param>
88 /// <exception cref="InvalidOperationException">Thrown when method failed due to invalid operation</exception>
89 /// <exception cref="ArgumentException">Thrown when one of the arguments provided to a method is not valid</exception>
90 /// <exception cref="OutOfMemoryException">Thrown when failed due to out of memory</exception>
91 /// <since_tizen> 4 </since_tizen>
92 public static void ParseForEach(string path, ParseCallback callback)
96 Interop.Vcalendar.ParseCallback cb = (IntPtr handle, IntPtr data) =>
98 return callback(new CalendarRecord(handle, true));
101 error = Interop.Vcalendar.ParseForEach(path, cb, IntPtr.Zero);
102 if (CalendarError.None != (CalendarError)error)
104 Log.Error(Globals.LogTag, "Parse ForEach Vcalendar Failed [" + error + "]");
105 throw CalendarErrorFactory.GetException(error);