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 _memoryPressure += this.Count * CalendarViews.Record.AverageSize;
36 GC.AddMemoryPressure(_memoryPressure);
40 /// Creates a calendar list.
42 /// <since_tizen> 4 </since_tizen>
43 /// <feature>http://tizen.org/feature/calendar</feature>
44 /// <exception cref="NotSupportedException">Thrown when feature is not supported</exception>
45 /// <exception cref="OutOfMemoryException">Thrown when failed due to out of memory</exception>
48 int error = Interop.List.Create(out _listHandle);
49 if (CalendarError.None != (CalendarError)error)
51 Log.Error(Globals.LogTag, "CalendarList Failed with error " + error);
52 throw CalendarErrorFactory.GetException(error);
54 GC.AddMemoryPressure(_memoryPressure);
58 /// The count of the calendar entity.
60 /// <since_tizen> 4 </since_tizen>
61 /// <value>The count of calendar entity.</value>
69 int error = Interop.List.GetCount(_listHandle, out count);
70 if (CalendarError.None != (CalendarError)error)
72 Log.Error(Globals.LogTag, "GetCount Failed with error " + error);
81 /// Destroy CalendarList resource.
88 #region IDisposable Support
89 private bool disposedValue = false; // To detect redundant calls
92 /// Disposes of the resources (other than memory) used by the CalendarList.
94 /// <param name="disposing">true to release both managed and unmanaged resources; false to release only unmanaged resources.</param>
95 protected virtual void Dispose(bool disposing)
99 Log.Debug(Globals.LogTag, "Dispose :" + disposing);
101 int error = Interop.List.Destroy(_listHandle, true);
102 if (CalendarError.None != (CalendarError)error)
104 Log.Error(Globals.LogTag, "Destroy Failed with error " + error);
106 disposedValue = true;
107 GC.RemoveMemoryPressure(_memoryPressure);
112 /// Releases all resources used by the CalendarList.
113 /// It should be called after having finished using of the object.
115 public void Dispose()
118 GC.SuppressFinalize(this);
123 /// Adds a record to the calendar list.
125 /// <since_tizen> 4 </since_tizen>
126 /// <param name="record">The record to be added</param>
127 /// <feature>http://tizen.org/feature/calendar</feature>
128 /// <exception cref="NotSupportedException">Thrown when feature is not supported</exception>
129 /// <exception cref="ArgumentException">Thrown when one of the arguments provided to a method is not valid</exception>
130 public void AddRecord(CalendarRecord record)
132 int error = Interop.List.Add(_listHandle, record._recordHandle);
133 if (CalendarError.None != (CalendarError)error)
135 Log.Error(Globals.LogTag, "AddRecord Failed with error " + error);
136 throw CalendarErrorFactory.GetException(error);
138 record._disposedValue = true;
140 _memoryPressure += CalendarViews.Record.AverageSize;
144 /// Removes a record from the calendar list.
146 /// <since_tizen> 4 </since_tizen>
147 /// <param name="record">The record to be removed</param>
148 /// <feature>http://tizen.org/feature/calendar</feature>
149 /// <exception cref="NotSupportedException">Thrown when feature is not supported</exception>
150 /// <exception cref="ArgumentException">Thrown when one of the arguments provided to a method is not valid</exception>
151 public void RemoveRecord(CalendarRecord record)
153 int error = Interop.List.Remove(_listHandle, record._recordHandle);
154 if (CalendarError.None != (CalendarError)error)
156 Log.Error(Globals.LogTag, "RemoveRecord Failed with error " + error);
157 throw CalendarErrorFactory.GetException(error);
159 record._disposedValue = false;
161 _memoryPressure -= CalendarViews.Record.AverageSize;
165 /// Retrieves a record from the calendar list.
167 /// <since_tizen> 4 </since_tizen>
171 /// <feature>http://tizen.org/feature/calendar</feature>
172 /// <exception cref="NotSupportedException">Thrown when feature is not supported</exception>
173 public CalendarRecord GetCurrentRecord()
176 int error = Interop.List.GetCurrentRecordP(_listHandle, out handle);
177 if (CalendarError.None != (CalendarError)error)
179 Log.Error(Globals.LogTag, "GetCurrentRecord Failed with error " + error);
180 throw CalendarErrorFactory.GetException(error);
182 return new CalendarRecord(handle, true);
186 /// Moves a calendar list to the previous position.
188 /// <since_tizen> 4 </since_tizen>
190 /// if cursor is moved to the end, it returns false.
192 /// <feature>http://tizen.org/feature/calendar</feature>
193 /// <exception cref="NotSupportedException">Thrown when feature is not supported</exception>
194 public bool MovePrevious()
196 int error = Interop.List.Prev(_listHandle);
197 if (CalendarError.None == (CalendarError)error)
201 else if (this.Count > 0 && CalendarError.NoData == (CalendarError)error)
203 Log.Debug(Globals.LogTag, "Nodata MovePrevious " + error);
208 Log.Error(Globals.LogTag, "MovePrevious Failed with error " + error);
209 throw CalendarErrorFactory.GetException(error);
214 /// Moves a calendar list to the next position.
216 /// <since_tizen> 4 </since_tizen>
218 /// if cursor is moved to the end, it returns false.
220 /// <feature>http://tizen.org/feature/calendar</feature>
221 /// <exception cref="NotSupportedException">Thrown when feature is not supported</exception>
222 public bool MoveNext()
224 int error = Interop.List.Next(_listHandle);
225 if (CalendarError.None == (CalendarError)error)
229 else if (this.Count > 0 && CalendarError.NoData == (CalendarError)error)
231 Log.Debug(Globals.LogTag, "Nodata MoveNext" + error);
236 Log.Error(Globals.LogTag, "MoveNext Failed with error " + error);
237 throw CalendarErrorFactory.GetException(error);
242 /// Moves a calendar list to the first position.
244 /// <since_tizen> 4 </since_tizen>
245 /// <feature>http://tizen.org/feature/calendar</feature>
246 /// <exception cref="NotSupportedException">Thrown when feature is not supported</exception>
247 public void MoveFirst()
249 int error = Interop.List.First(_listHandle);
250 if (CalendarError.None != (CalendarError)error)
252 Log.Error(Globals.LogTag, "MoveFirst Failed with error " + error);
253 throw CalendarErrorFactory.GetException(error);
258 /// Moves a calendar list to the last position.
260 /// <since_tizen> 4 </since_tizen>
261 /// <feature>http://tizen.org/feature/calendar</feature>
262 /// <exception cref="NotSupportedException">Thrown when feature is not supported</exception>
263 public void MoveLast()
265 int error = Interop.List.Last(_listHandle);
266 if (CalendarError.None != (CalendarError)error)
268 Log.Error(Globals.LogTag, "MoveLast Failed with error " + error);
269 throw CalendarErrorFactory.GetException(error);