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 /// <since_tizen> 4 </since_tizen>
103 protected virtual void Dispose(bool disposing)
107 Log.Debug(Globals.LogTag, "Dispose :" + disposing);
109 int error = Interop.List.Destroy(_listHandle, true);
110 if (CalendarError.None != (CalendarError)error)
112 Log.Error(Globals.LogTag, "Destroy Failed with error " + error);
114 disposedValue = true;
115 GC.RemoveMemoryPressure(_memoryPressure);
120 /// Releases all resources used by the CalendarList.
121 /// It should be called after having finished using of the object.
123 /// <since_tizen> 4 </since_tizen>
124 public void Dispose()
127 GC.SuppressFinalize(this);
132 /// Adds a record to the calendar list.
134 /// <since_tizen> 4 </since_tizen>
135 /// <param name="record">The record to be added</param>
136 /// <feature>http://tizen.org/feature/calendar</feature>
137 /// <exception cref="NotSupportedException">Thrown when feature is not supported</exception>
138 public void AddRecord(CalendarRecord record)
140 int error = Interop.List.Add(_listHandle, record._recordHandle);
141 if (CalendarError.None != (CalendarError)error)
143 Log.Error(Globals.LogTag, "AddRecord Failed with error " + error);
144 throw CalendarErrorFactory.GetException(error);
146 record._disposedValue = true;
148 _memoryPressure += CalendarViews.Record.AverageSize;
152 /// Removes a record from the calendar list.
154 /// <since_tizen> 4 </since_tizen>
155 /// <param name="record">The record to be removed</param>
156 /// <feature>http://tizen.org/feature/calendar</feature>
157 /// <exception cref="NotSupportedException">Thrown when feature is not supported</exception>
158 public void RemoveRecord(CalendarRecord record)
160 int error = Interop.List.Remove(_listHandle, record._recordHandle);
161 if (CalendarError.None != (CalendarError)error)
163 Log.Error(Globals.LogTag, "RemoveRecord Failed with error " + error);
164 throw CalendarErrorFactory.GetException(error);
166 record._disposedValue = false;
168 _memoryPressure -= CalendarViews.Record.AverageSize;
172 /// Retrieves a record from the calendar list.
174 /// <since_tizen> 4 </since_tizen>
178 /// <feature>http://tizen.org/feature/calendar</feature>
179 /// <exception cref="NotSupportedException">Thrown when feature is not supported</exception>
180 public CalendarRecord GetCurrentRecord()
183 int error = Interop.List.GetCurrentRecordP(_listHandle, out handle);
184 if (CalendarError.None != (CalendarError)error)
186 Log.Error(Globals.LogTag, "GetCurrentRecord Failed with error " + error);
187 throw CalendarErrorFactory.GetException(error);
189 return new CalendarRecord(handle, true);
193 /// Moves a calendar list to the previous position.
195 /// <since_tizen> 4 </since_tizen>
197 /// if cursor is moved to the end, it returns false.
199 /// <feature>http://tizen.org/feature/calendar</feature>
200 /// <exception cref="NotSupportedException">Thrown when feature is not supported</exception>
201 public bool MovePrevious()
203 int error = Interop.List.Prev(_listHandle);
204 if (CalendarError.None == (CalendarError)error)
208 else if (this.Count > 0 && CalendarError.NoData == (CalendarError)error)
210 Log.Debug(Globals.LogTag, "Nodata MovePrevious " + error);
215 Log.Error(Globals.LogTag, "MovePrevious Failed with error " + error);
216 throw CalendarErrorFactory.GetException(error);
221 /// Moves a calendar list to the next position.
223 /// <since_tizen> 4 </since_tizen>
225 /// if cursor is moved to the end, it returns false.
227 /// <feature>http://tizen.org/feature/calendar</feature>
228 /// <exception cref="NotSupportedException">Thrown when feature is not supported</exception>
229 public bool MoveNext()
231 int error = Interop.List.Next(_listHandle);
232 if (CalendarError.None == (CalendarError)error)
236 else if (this.Count > 0 && CalendarError.NoData == (CalendarError)error)
238 Log.Debug(Globals.LogTag, "Nodata MoveNext" + error);
243 Log.Error(Globals.LogTag, "MoveNext Failed with error " + error);
244 throw CalendarErrorFactory.GetException(error);
249 /// Moves a calendar list to the first position.
251 /// <since_tizen> 4 </since_tizen>
252 /// <feature>http://tizen.org/feature/calendar</feature>
253 /// <exception cref="NotSupportedException">Thrown when feature is not supported</exception>
254 public void MoveFirst()
256 int error = Interop.List.First(_listHandle);
257 if (CalendarError.None != (CalendarError)error)
259 Log.Error(Globals.LogTag, "MoveFirst Failed with error " + error);
260 throw CalendarErrorFactory.GetException(error);
265 /// Moves a calendar list to the last position.
267 /// <since_tizen> 4 </since_tizen>
268 /// <feature>http://tizen.org/feature/calendar</feature>
269 /// <exception cref="NotSupportedException">Thrown when feature is not supported</exception>
270 public void MoveLast()
272 int error = Interop.List.Last(_listHandle);
273 if (CalendarError.None != (CalendarError)error)
275 Log.Error(Globals.LogTag, "MoveLast Failed with error " + error);
276 throw CalendarErrorFactory.GetException(error);