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;
19 using System.Collections.Generic;
21 namespace Tizen.Pims.Calendar
24 /// A list of records with the same type.
26 public class CalendarList:IDisposable
28 private Int64 _memoryPressure = 20;
29 internal int _count = -1;
30 internal IntPtr _listHandle;
32 internal CalendarList(IntPtr handle)
36 _memoryPressure += this.Count * CalendarViews.AverageSizeOfRecord;
37 GC.AddMemoryPressure(_memoryPressure);
41 /// Creates a calendar list.
43 /// <exception cref="NotSupportedException">Thrown when an invoked method is not supported</exception>
44 /// <exception cref="OutOfMemoryException">Thrown when failed due to out of memory</exception>
47 int error = Interop.Calendar.List.Create(out _listHandle);
48 if (CalendarError.None != (CalendarError)error)
50 Log.Error(Globals.LogTag, "CalendarList Failed with error " + error);
51 throw CalendarErrorFactory.GetException(error);
53 GC.AddMemoryPressure(_memoryPressure);
62 /// The count of the calendar entity.
71 int error = Interop.Calendar.List.GetCount(_listHandle, out count);
72 if (CalendarError.None != (CalendarError)error)
74 Log.Error(Globals.LogTag, "GetCount Failed with error " + error);
82 #region IDisposable Support
83 private bool disposedValue = false; // To detect redundant calls
85 protected virtual void Dispose(bool disposing)
89 Log.Debug(Globals.LogTag, "Dispose :" + disposing);
91 int error = Interop.Calendar.List.Destroy(_listHandle, true);
92 if (CalendarError.None != (CalendarError)error)
94 Log.Error(Globals.LogTag, "Destroy Failed with error " + error);
95 throw CalendarErrorFactory.GetException(error);
98 GC.RemoveMemoryPressure(_memoryPressure);
103 /// Releases all resources used by the CalendarList.
104 /// It should be called after finished using of the object.
106 public void Dispose()
113 /// Adds a record to the calendar list.
115 /// <param name="record">The record to be added</param>
116 /// <exception cref="NotSupportedException">Thrown when an invoked method is not supported</exception>
117 /// <exception cref="ArgumentException">Thrown when one of the arguments provided to a method is not valid</exception>
118 public void AddRecord(CalendarRecord record)
120 int error = Interop.Calendar.List.Add(_listHandle, record._recordHandle);
121 if (CalendarError.None != (CalendarError)error)
123 Log.Error(Globals.LogTag, "AddRecord Failed with error " + error);
124 throw CalendarErrorFactory.GetException(error);
126 record._disposedValue = true;
128 _memoryPressure += CalendarViews.AverageSizeOfRecord;
132 /// Removes a record from the calendar list.
134 /// <param name="record">The record to be removed</param>
135 /// <exception cref="NotSupportedException">Thrown when an invoked method is not supported</exception>
136 /// <exception cref="ArgumentException">Thrown when one of the arguments provided to a method is not valid</exception>
137 public void RemoveRecord(CalendarRecord record)
139 int error = Interop.Calendar.List.Remove(_listHandle, record._recordHandle);
140 if (CalendarError.None != (CalendarError)error)
142 Log.Error(Globals.LogTag, "RemoveRecord Failed with error " + error);
143 throw CalendarErrorFactory.GetException(error);
145 record._disposedValue = false;
147 _memoryPressure -= CalendarViews.AverageSizeOfRecord;
151 /// Retrieves a record from the calendar list.
156 public CalendarRecord GetCurrentRecord()
159 int error = Interop.Calendar.List.GetCurrentRecordP(_listHandle, out handle);
160 if (CalendarError.None != (CalendarError)error)
162 Log.Error(Globals.LogTag, "GetCurrentRecord Failed with error " + error);
163 throw CalendarErrorFactory.GetException(error);
165 return new CalendarRecord(handle, true);
169 /// Moves a calendar list to the previous position.
172 /// if cursor is moved to the end, it returns false.
174 public bool MovePrevious()
176 int error = Interop.Calendar.List.Prev(_listHandle);
177 if (CalendarError.None == (CalendarError)error)
181 else if (this.Count > 0 && CalendarError.NoData == (CalendarError)error)
183 Log.Debug(Globals.LogTag, "Nodata MovePrevious " + error);
188 Log.Error(Globals.LogTag, "MovePrevious Failed with error " + error);
189 throw CalendarErrorFactory.GetException(error);
194 /// Moves a calendar list to the next position.
197 /// if cursor is moved to the end, it returns false.
199 public bool MoveNext()
201 int error = Interop.Calendar.List.Next(_listHandle);
202 if (CalendarError.None == (CalendarError)error)
206 else if (this.Count > 0 && CalendarError.NoData == (CalendarError)error)
208 Log.Debug(Globals.LogTag, "Nodata MoveNext" + error);
213 Log.Error(Globals.LogTag, "MoveNext Failed with error " + error);
214 throw CalendarErrorFactory.GetException(error);
219 /// Moves a calendar list to the first position.
221 public void MoveFirst()
223 int error = Interop.Calendar.List.First(_listHandle);
224 if (CalendarError.None != (CalendarError)error)
226 Log.Error(Globals.LogTag, "MoveFirst Failed with error " + error);
227 throw CalendarErrorFactory.GetException(error);
232 /// Moves a calendar list to the last position.
234 public void MoveLast()
236 int error = Interop.Calendar.List.Last(_listHandle);
237 if (CalendarError.None != (CalendarError)error)
239 Log.Error(Globals.LogTag, "MoveLast Failed with error " + error);
240 throw CalendarErrorFactory.GetException(error);