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 /// A list of records with the same type.
24 /// <since_tizen> 4 </since_tizen>
25 public class CalendarList:IDisposable
27 private Int64 _memoryPressure = 20;
28 internal int _count = -1;
29 internal IntPtr _listHandle;
31 internal CalendarList(IntPtr handle)
35 int error = Interop.List.First(_listHandle);
36 if (CalendarError.None != (CalendarError)error)
38 Log.Error(Globals.LogTag, "MoveFirst Failed with error " + error);
39 throw CalendarErrorFactory.GetException(error);
42 _memoryPressure += this.Count * CalendarViews.Record.AverageSize;
43 GC.AddMemoryPressure(_memoryPressure);
47 /// Creates a calendar list.
49 /// <since_tizen> 4 </since_tizen>
50 /// <feature>http://tizen.org/feature/calendar</feature>
51 /// <exception cref="NotSupportedException">Thrown when feature is not supported</exception>
52 /// <exception cref="OutOfMemoryException">Thrown when failed due to out of memory</exception>
55 int error = Interop.List.Create(out _listHandle);
56 if (CalendarError.None != (CalendarError)error)
58 Log.Error(Globals.LogTag, "CalendarList Failed with error " + error);
59 throw CalendarErrorFactory.GetException(error);
61 GC.AddMemoryPressure(_memoryPressure);
65 /// The count of the calendar entity.
67 /// <since_tizen> 4 </since_tizen>
68 /// <value>The count of calendar entity.</value>
76 int error = Interop.List.GetCount(_listHandle, out count);
77 if (CalendarError.None != (CalendarError)error)
79 Log.Error(Globals.LogTag, "GetCount Failed with error " + error);
88 /// Destroy CalendarList resource.
95 #region IDisposable Support
96 private bool disposedValue = false; // To detect redundant calls
99 /// Disposes of the resources (other than memory) used by the CalendarList.
101 /// <param name="disposing">true to release both managed and unmanaged resources; false to release only unmanaged resources.</param>
102 protected virtual void Dispose(bool disposing)
106 Log.Debug(Globals.LogTag, "Dispose :" + disposing);
108 int error = Interop.List.Destroy(_listHandle, true);
109 if (CalendarError.None != (CalendarError)error)
111 Log.Error(Globals.LogTag, "Destroy Failed with error " + error);
113 disposedValue = true;
114 GC.RemoveMemoryPressure(_memoryPressure);
119 /// Releases all resources used by the CalendarList.
120 /// It should be called after having finished using of the object.
122 public void Dispose()
125 GC.SuppressFinalize(this);
130 /// Adds a record to the calendar list.
132 /// <since_tizen> 4 </since_tizen>
133 /// <param name="record">The record to be added</param>
134 /// <feature>http://tizen.org/feature/calendar</feature>
135 /// <exception cref="NotSupportedException">Thrown when feature is not supported</exception>
136 public void AddRecord(CalendarRecord record)
138 int error = Interop.List.Add(_listHandle, record._recordHandle);
139 if (CalendarError.None != (CalendarError)error)
141 Log.Error(Globals.LogTag, "AddRecord Failed with error " + error);
142 throw CalendarErrorFactory.GetException(error);
144 record._disposedValue = true;
146 _memoryPressure += CalendarViews.Record.AverageSize;
150 /// Removes a record from the calendar list.
152 /// <since_tizen> 4 </since_tizen>
153 /// <param name="record">The record to be removed</param>
154 /// <feature>http://tizen.org/feature/calendar</feature>
155 /// <exception cref="NotSupportedException">Thrown when feature is not supported</exception>
156 public void RemoveRecord(CalendarRecord record)
158 int error = Interop.List.Remove(_listHandle, record._recordHandle);
159 if (CalendarError.None != (CalendarError)error)
161 Log.Error(Globals.LogTag, "RemoveRecord Failed with error " + error);
162 throw CalendarErrorFactory.GetException(error);
164 record._disposedValue = false;
166 _memoryPressure -= CalendarViews.Record.AverageSize;
170 /// Retrieves a record from the calendar list.
172 /// <since_tizen> 4 </since_tizen>
176 /// <feature>http://tizen.org/feature/calendar</feature>
177 /// <exception cref="NotSupportedException">Thrown when feature is not supported</exception>
178 public CalendarRecord GetCurrentRecord()
181 int error = Interop.List.GetCurrentRecordP(_listHandle, out handle);
182 if (CalendarError.None != (CalendarError)error)
184 Log.Error(Globals.LogTag, "GetCurrentRecord Failed with error " + error);
185 throw CalendarErrorFactory.GetException(error);
187 return new CalendarRecord(handle, true);
191 /// Moves a calendar list to the previous position.
193 /// <since_tizen> 4 </since_tizen>
195 /// if cursor is moved to the end, it returns false.
197 /// <feature>http://tizen.org/feature/calendar</feature>
198 /// <exception cref="NotSupportedException">Thrown when feature is not supported</exception>
199 public bool MovePrevious()
201 int error = Interop.List.Prev(_listHandle);
202 if (CalendarError.None == (CalendarError)error)
206 else if (this.Count > 0 && CalendarError.NoData == (CalendarError)error)
208 Log.Debug(Globals.LogTag, "Nodata MovePrevious " + error);
213 Log.Error(Globals.LogTag, "MovePrevious Failed with error " + error);
214 throw CalendarErrorFactory.GetException(error);
219 /// Moves a calendar list to the next position.
221 /// <since_tizen> 4 </since_tizen>
223 /// if cursor is moved to the end, it returns false.
225 /// <feature>http://tizen.org/feature/calendar</feature>
226 /// <exception cref="NotSupportedException">Thrown when feature is not supported</exception>
227 public bool MoveNext()
229 int error = Interop.List.Next(_listHandle);
230 if (CalendarError.None == (CalendarError)error)
234 else if (this.Count > 0 && CalendarError.NoData == (CalendarError)error)
236 Log.Debug(Globals.LogTag, "Nodata MoveNext" + error);
241 Log.Error(Globals.LogTag, "MoveNext Failed with error " + error);
242 throw CalendarErrorFactory.GetException(error);
247 /// Moves a calendar list to the first position.
249 /// <since_tizen> 4 </since_tizen>
250 /// <feature>http://tizen.org/feature/calendar</feature>
251 /// <exception cref="NotSupportedException">Thrown when feature is not supported</exception>
252 public void MoveFirst()
254 int error = Interop.List.First(_listHandle);
255 if (CalendarError.None != (CalendarError)error)
257 Log.Error(Globals.LogTag, "MoveFirst Failed with error " + error);
258 throw CalendarErrorFactory.GetException(error);
263 /// Moves a calendar list to the last position.
265 /// <since_tizen> 4 </since_tizen>
266 /// <feature>http://tizen.org/feature/calendar</feature>
267 /// <exception cref="NotSupportedException">Thrown when feature is not supported</exception>
268 public void MoveLast()
270 int error = Interop.List.Last(_listHandle);
271 if (CalendarError.None != (CalendarError)error)
273 Log.Error(Globals.LogTag, "MoveLast Failed with error " + error);
274 throw CalendarErrorFactory.GetException(error);