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.
18 using System.Collections.Generic;
19 using System.Threading.Tasks;
21 namespace Tizen.Pims.Calendar
24 /// A class for parsing and composing vCalendar.
27 /// It's based on the vCalendar v2.0 specification
29 public class CalendarVcalendar
31 internal CalendarVcalendar()
35 public delegate bool ParseDelegate(CalendarRecord record);
38 /// Retrieves a vcalendar stream from a calendar list.
40 /// <param name="list">The calendar list</param>
42 /// The composed stream.
44 /// <exception cref="ArgumentException">Thrown when one of the arguments provided to a method is not valid</exception>
45 /// <exception cref="OutOfMemoryException">Thrown when failed due to out of memory</exception>
46 public static string Compose(CalendarList list)
49 int error = Interop.Calendar.Vcalendar.Compose(list._listHandle, out stream);
50 if (CalendarError.None != (CalendarError)error)
52 Log.Error(Globals.LogTag, "MakeVcalendar Failed with error " + error);
53 throw CalendarErrorFactory.GetException(error);
59 /// Retrieves all calendars from a vcalendar stream.
61 /// <param name="stream">The vcalendar stream</param>
65 /// <exception cref="ArgumentException">Thrown when one of the arguments provided to a method is not valid</exception>
66 /// <exception cref="OutOfMemoryException">Thrown when failed due to out of memory</exception>
67 public static CalendarList Parse(string stream)
71 error = Interop.Calendar.Vcalendar.Parse(stream, out _listHandle);
72 if (CalendarError.None != (CalendarError)error)
74 Log.Error(Globals.LogTag, "Parse Vcalendar Failed [" + error + "]");
75 throw CalendarErrorFactory.GetException(error);
77 return new CalendarList(_listHandle);
81 /// Parse vcalendar file with foreach
83 /// <param name="path">The file path of the vCalendar stream file</param>
84 /// <param name="callback">he callback function to invoke</param>
85 /// <exception cref="InvalidOperationException">Thrown when method failed due to invalid operation</exception>
86 /// <exception cref="ArgumentException">Thrown when one of the arguments provided to a method is not valid</exception>
87 /// <exception cref="OutOfMemoryException">Thrown when failed due to out of memory</exception>
88 public static void ParseForEach(string path, ParseDelegate callback)
92 Interop.Calendar.Vcalendar.ParseCallback cb = (IntPtr handle, IntPtr data) =>
94 return callback(new CalendarRecord(handle, true));
97 error = Interop.Calendar.Vcalendar.ParseForEach(path, cb, IntPtr.Zero);
98 if (CalendarError.None != (CalendarError)error)
100 Log.Error(Globals.LogTag, "Parse foreach Vcalendar Failed [" + error + "]");
101 throw CalendarErrorFactory.GetException(error);