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 public class CalendarList:IDisposable
26 private Int64 _memoryPressure = 20;
27 internal int _count = -1;
28 internal IntPtr _listHandle;
30 internal CalendarList(IntPtr handle)
34 _memoryPressure += this.Count * CalendarViews.Record.AverageSize;
35 GC.AddMemoryPressure(_memoryPressure);
39 /// Creates a calendar list.
41 /// <exception cref="NotSupportedException">Thrown when an invoked method is not supported</exception>
42 /// <exception cref="OutOfMemoryException">Thrown when failed due to out of memory</exception>
45 int error = Interop.List.Create(out _listHandle);
46 if (CalendarError.None != (CalendarError)error)
48 Log.Error(Globals.LogTag, "CalendarList Failed with error " + error);
49 throw CalendarErrorFactory.GetException(error);
51 GC.AddMemoryPressure(_memoryPressure);
55 /// The count of the calendar entity.
57 /// <value>The count of calendar entity.</value>
65 int error = Interop.List.GetCount(_listHandle, out count);
66 if (CalendarError.None != (CalendarError)error)
68 Log.Error(Globals.LogTag, "GetCount Failed with error " + error);
77 /// Destory CalendarList resource.
84 #region IDisposable Support
85 private bool disposedValue = false; // To detect redundant calls
88 /// Disposes of the resources (other than memory) used by the CalendarList.
90 /// <param name="disposing">true to release both managed and unmanaged resources; false to release only unmanaged resources.</param>
91 protected virtual void Dispose(bool disposing)
95 Log.Debug(Globals.LogTag, "Dispose :" + disposing);
97 int error = Interop.List.Destroy(_listHandle, true);
98 if (CalendarError.None != (CalendarError)error)
100 Log.Error(Globals.LogTag, "Destroy Failed with error " + error);
101 throw CalendarErrorFactory.GetException(error);
103 disposedValue = true;
104 GC.RemoveMemoryPressure(_memoryPressure);
109 /// Releases all resources used by the CalendarList.
110 /// It should be called after having finished using of the object.
112 public void Dispose()
115 GC.SuppressFinalize(this);
120 /// Adds a record to the calendar list.
122 /// <param name="record">The record to be added</param>
123 /// <exception cref="NotSupportedException">Thrown when an invoked method is not supported</exception>
124 /// <exception cref="ArgumentException">Thrown when one of the arguments provided to a method is not valid</exception>
125 public void AddRecord(CalendarRecord record)
127 int error = Interop.List.Add(_listHandle, record._recordHandle);
128 if (CalendarError.None != (CalendarError)error)
130 Log.Error(Globals.LogTag, "AddRecord Failed with error " + error);
131 throw CalendarErrorFactory.GetException(error);
133 record._disposedValue = true;
135 _memoryPressure += CalendarViews.Record.AverageSize;
139 /// Removes a record from the calendar list.
141 /// <param name="record">The record to be removed</param>
142 /// <exception cref="NotSupportedException">Thrown when an invoked method is not supported</exception>
143 /// <exception cref="ArgumentException">Thrown when one of the arguments provided to a method is not valid</exception>
144 public void RemoveRecord(CalendarRecord record)
146 int error = Interop.List.Remove(_listHandle, record._recordHandle);
147 if (CalendarError.None != (CalendarError)error)
149 Log.Error(Globals.LogTag, "RemoveRecord Failed with error " + error);
150 throw CalendarErrorFactory.GetException(error);
152 record._disposedValue = false;
154 _memoryPressure -= CalendarViews.Record.AverageSize;
158 /// Retrieves a record from the calendar list.
163 public CalendarRecord GetCurrentRecord()
166 int error = Interop.List.GetCurrentRecordP(_listHandle, out handle);
167 if (CalendarError.None != (CalendarError)error)
169 Log.Error(Globals.LogTag, "GetCurrentRecord Failed with error " + error);
170 throw CalendarErrorFactory.GetException(error);
172 return new CalendarRecord(handle, true);
176 /// Moves a calendar list to the previous position.
179 /// if cursor is moved to the end, it returns false.
181 public bool MovePrevious()
183 int error = Interop.List.Prev(_listHandle);
184 if (CalendarError.None == (CalendarError)error)
188 else if (this.Count > 0 && CalendarError.NoData == (CalendarError)error)
190 Log.Debug(Globals.LogTag, "Nodata MovePrevious " + error);
195 Log.Error(Globals.LogTag, "MovePrevious Failed with error " + error);
196 throw CalendarErrorFactory.GetException(error);
201 /// Moves a calendar list to the next position.
204 /// if cursor is moved to the end, it returns false.
206 public bool MoveNext()
208 int error = Interop.List.Next(_listHandle);
209 if (CalendarError.None == (CalendarError)error)
213 else if (this.Count > 0 && CalendarError.NoData == (CalendarError)error)
215 Log.Debug(Globals.LogTag, "Nodata MoveNext" + error);
220 Log.Error(Globals.LogTag, "MoveNext Failed with error " + error);
221 throw CalendarErrorFactory.GetException(error);
226 /// Moves a calendar list to the first position.
228 public void MoveFirst()
230 int error = Interop.List.First(_listHandle);
231 if (CalendarError.None != (CalendarError)error)
233 Log.Error(Globals.LogTag, "MoveFirst Failed with error " + error);
234 throw CalendarErrorFactory.GetException(error);
239 /// Moves a calendar list to the last position.
241 public void MoveLast()
243 int error = Interop.List.Last(_listHandle);
244 if (CalendarError.None != (CalendarError)error)
246 Log.Error(Globals.LogTag, "MoveLast Failed with error " + error);
247 throw CalendarErrorFactory.GetException(error);