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.Generic;
20 namespace Tizen.Pims.Calendar
23 /// A filter includes the conditions for the search.
25 public class CalendarFilter:IDisposable
27 internal IntPtr _filterHandle;
30 /// Creates a filter with a condition for a string type.
32 /// <param name="viewUri">The view URI of a filter</param>
33 /// <param name="propertyId">The property ID to add a condition</param>
34 /// <param name="matchType">The match flag</param>
35 /// <param name="matchValue">The match value</param>
36 /// <exception cref="NotSupportedException">Thrown when an invoked method is not supported</exception>
37 /// <exception cref="ArgumentException">Thrown when one of the arguments provided to a method is not valid</exception>
38 /// <exception cref="OutOfMemoryException">Thrown when failed due to out of memory</exception>
39 public CalendarFilter(string viewUri, uint propertyId, StringMatchType matchType, string matchValue)
42 error = Interop.Calendar.Filter.Create(viewUri, out _filterHandle);
43 if (CalendarError.None != (CalendarError)error)
45 Log.Error(Globals.LogTag, "CalendarFilter Failed with error " + error);
46 throw CalendarErrorFactory.GetException(error);
49 error = Interop.Calendar.Filter.AddString(_filterHandle, propertyId, matchType, matchValue);
50 if (CalendarError.None != (CalendarError)error)
52 Log.Error(Globals.LogTag, "CalendarFilter Failed with error " + error);
53 throw CalendarErrorFactory.GetException(error);
58 /// Creates a filter with a condition for an integer type.
60 /// <param name="viewUri">The view URI of a filter</param>
61 /// <param name="propertyId">The property ID to add a condition</param>
62 /// <param name="matchType">The match flag</param>
63 /// <param name="matchValue">The match value</param>
64 /// <exception cref="NotSupportedException">Thrown when an invoked method is not supported</exception>
65 /// <exception cref="ArgumentException">Thrown when one of the arguments provided to a method is not valid</exception>
66 /// <exception cref="OutOfMemoryException">Thrown when failed due to out of memory</exception>
67 public CalendarFilter(string viewUri, uint propertyId, IntegerMatchType matchType, int matchValue)
70 error = Interop.Calendar.Filter.Create(viewUri, out _filterHandle);
71 if (CalendarError.None != (CalendarError)error)
73 Log.Error(Globals.LogTag, "CalendarFilter Failed with error " + error);
74 throw CalendarErrorFactory.GetException(error);
77 error = Interop.Calendar.Filter.AddInteger(_filterHandle, propertyId, matchType, matchValue);
78 if (CalendarError.None != (CalendarError)error)
80 Log.Error(Globals.LogTag, "CalendarFilter Failed with error " + error);
81 throw CalendarErrorFactory.GetException(error);
86 /// Creates a filter with a condition for long type.
88 /// <param name="viewUri">The view URI of a filter</param>
89 /// <param name="propertyId">The property ID to add a condition</param>
90 /// <param name="matchType">The match flag</param>
91 /// <param name="matchValue">The match value</param>
92 /// <exception cref="NotSupportedException">Thrown when an invoked method is not supported</exception>
93 /// <exception cref="ArgumentException">Thrown when one of the arguments provided to a method is not valid</exception>
94 /// <exception cref="OutOfMemoryException">Thrown when failed due to out of memory</exception>
95 public CalendarFilter(string viewUri, uint propertyId, IntegerMatchType matchType, long matchValue)
98 error = Interop.Calendar.Filter.Create(viewUri, out _filterHandle);
99 if (CalendarError.None != (CalendarError)error)
101 Log.Error(Globals.LogTag, "CalendarFilter Failed with error " + error);
102 throw CalendarErrorFactory.GetException(error);
105 error = Interop.Calendar.Filter.AddLong(_filterHandle, propertyId, matchType, matchValue);
106 if (CalendarError.None != (CalendarError)error)
108 Log.Error(Globals.LogTag, "CalendarFilter Failed with error " + error);
109 throw CalendarErrorFactory.GetException(error);
114 /// Creates a filter with a condition for double type.
116 /// <param name="viewUri">The view URI of a filter</param>
117 /// <param name="propertyId">The property ID to add a condition</param>
118 /// <param name="matchType">The match flag</param>
119 /// <param name="matchValue">The match value</param>
120 /// <exception cref="NotSupportedException">Thrown when an invoked method is not supported</exception>
121 /// <exception cref="ArgumentException">Thrown when one of the arguments provided to a method is not valid</exception>
122 /// <exception cref="OutOfMemoryException">Thrown when failed due to out of memory</exception>
123 public CalendarFilter(string viewUri, uint propertyId, IntegerMatchType matchType, double matchValue)
126 error = Interop.Calendar.Filter.Create(viewUri, out _filterHandle);
127 if (CalendarError.None != (CalendarError)error)
129 Log.Error(Globals.LogTag, "CalendarFilter Failed with error " + error);
130 throw CalendarErrorFactory.GetException(error);
133 error = Interop.Calendar.Filter.AddDouble(_filterHandle, propertyId, matchType, matchValue);
134 if (CalendarError.None != (CalendarError)error)
136 Log.Error(Globals.LogTag, "CalendarFilter Failed with error " + error);
137 throw CalendarErrorFactory.GetException(error);
142 /// Creates a filter with a condition for CalendarTime type.
144 /// <param name="viewUri">The view URI of a filter</param>
145 /// <param name="propertyId">The property ID to add a condition</param>
146 /// <param name="matchType">The match flag</param>
147 /// <param name="matchValue">The match value</param>
148 /// <exception cref="NotSupportedException">Thrown when an invoked method is not supported</exception>
149 /// <exception cref="ArgumentException">Thrown when one of the arguments provided to a method is not valid</exception>
150 /// <exception cref="OutOfMemoryException">Thrown when failed due to out of memory</exception>
151 public CalendarFilter(string viewUri, uint propertyId, IntegerMatchType matchType, CalendarTime matchValue)
154 error = Interop.Calendar.Filter.Create(viewUri, out _filterHandle);
155 if (CalendarError.None != (CalendarError)error)
157 Log.Error(Globals.LogTag, "CalendarFilter Failed with error " + error);
158 throw CalendarErrorFactory.GetException(error);
161 Interop.Calendar.Record.DateTime time = CalendarRecord.ConvertCalendarTimeToStruct(matchValue);
162 error = Interop.Calendar.Filter.AddCalendarTime(_filterHandle, propertyId, matchType, time);
163 if (CalendarError.None != (CalendarError)error)
165 Log.Error(Globals.LogTag, "CalendarFilter Failed with error " + error);
166 throw CalendarErrorFactory.GetException(error);
176 /// Enumeration for the filter match type of a string.
178 public enum StringMatchType
181 /// Full string, case-sensitive
185 /// Full string, case-insensitive
189 /// Sub string, case-insensitive
193 /// Start with, case-insensitive
197 /// End with, case-insensitive
207 /// Enumeration for the filter match type of an integer.
209 public enum IntegerMatchType
232 /// <>, this flag can yield poor performance
242 /// Enumeration for a filter operator.
244 public enum LogicalOperator
256 #region IDisposable Support
257 private bool disposedValue = false; // To detect redundant calls
259 protected virtual void Dispose(bool disposing)
263 Log.Debug(Globals.LogTag, "Dispose :" + disposing);
265 int error = Interop.Calendar.Filter.Destroy(_filterHandle);
266 if (CalendarError.None != (CalendarError)error)
268 Log.Error(Globals.LogTag, "Destroy Failed with error " + error);
269 throw CalendarErrorFactory.GetException(error);
271 disposedValue = true;
276 /// Releases all resources used by the CalendarFilter.
277 /// It should be called after finished using of the object.
279 public void Dispose()
286 /// Adds a condition for the string type.
288 /// <param name="logicalOperator">The operator type</param>
289 /// <param name="propertyId">The property ID to add a condition</param>
290 /// <param name="matchType">The match flag</param>
291 /// <param name="matchValue">The match valu</param>
292 /// <exception cref="NotSupportedException">Thrown when an invoked method is not supported</exception>
293 /// <exception cref="ArgumentException">Thrown when one of the arguments provided to a method is not valid</exception>
294 public void AddCondition(LogicalOperator logicalOperator, uint propertyId, StringMatchType matchType, string matchValue)
296 int error = Interop.Calendar.Filter.AddOperator(_filterHandle, logicalOperator);
297 if (CalendarError.None != (CalendarError)error)
299 Log.Error(Globals.LogTag, "AddCondition Failed with error " + error);
300 throw CalendarErrorFactory.GetException(error);
303 error = Interop.Calendar.Filter.AddString(_filterHandle, propertyId, matchType, matchValue);
304 if (CalendarError.None != (CalendarError)error)
306 Log.Error(Globals.LogTag, "AddCondition Failed with error " + error);
307 throw CalendarErrorFactory.GetException(error);
312 /// Adds a condition for the integer type.
314 /// <param name="logicalOperator">The operator type</param>
315 /// <param name="propertyId">The property ID to add a condition</param>
316 /// <param name="matchType">The match flag</param>
317 /// <param name="matchValue">The match valu</param>
318 /// <exception cref="NotSupportedException">Thrown when an invoked method is not supported</exception>
319 /// <exception cref="ArgumentException">Thrown when one of the arguments provided to a method is not valid</exception>
320 public void AddCondition(LogicalOperator logicalOperator, uint propertyId, IntegerMatchType matchType, int matchValue)
322 int error = Interop.Calendar.Filter.AddOperator(_filterHandle, logicalOperator);
323 if (CalendarError.None != (CalendarError)error)
325 Log.Error(Globals.LogTag, "AddCondition Failed with error " + error);
326 throw CalendarErrorFactory.GetException(error);
329 error = Interop.Calendar.Filter.AddInteger(_filterHandle, propertyId, matchType, matchValue);
330 if (CalendarError.None != (CalendarError)error)
332 Log.Error(Globals.LogTag, "AddCondition Failed with error " + error);
333 throw CalendarErrorFactory.GetException(error);
338 /// Adds a condition for the long type.
340 /// <param name="logicalOperator">The operator type</param>
341 /// <param name="propertyId">The property ID to add a condition</param>
342 /// <param name="matchType">The match flag</param>
343 /// <param name="matchValue">The match valu</param>
344 /// <exception cref="NotSupportedException">Thrown when an invoked method is not supported</exception>
345 /// <exception cref="ArgumentException">Thrown when one of the arguments provided to a method is not valid</exception>
346 public void AddCondition(LogicalOperator logicalOperator, uint propertyId, IntegerMatchType matchType, long matchValue)
348 int error = Interop.Calendar.Filter.AddOperator(_filterHandle, logicalOperator);
349 if (CalendarError.None != (CalendarError)error)
351 Log.Error(Globals.LogTag, "AddCondition Failed with error " + error);
352 throw CalendarErrorFactory.GetException(error);
355 error = Interop.Calendar.Filter.AddLong(_filterHandle, propertyId, matchType, matchValue);
356 if (CalendarError.None != (CalendarError)error)
358 Log.Error(Globals.LogTag, "AddCondition Failed with error " + error);
359 throw CalendarErrorFactory.GetException(error);
364 /// Adds a condition for the double type.
366 /// <param name="logicalOperator">The operator type</param>
367 /// <param name="propertyId">The property ID to add a condition</param>
368 /// <param name="matchType">The match flag</param>
369 /// <param name="matchValue">The match valu</param>
370 /// <exception cref="NotSupportedException">Thrown when an invoked method is not supported</exception>
371 /// <exception cref="ArgumentException">Thrown when one of the arguments provided to a method is not valid</exception>
372 public void AddCondition(LogicalOperator logicalOperator, uint propertyId, IntegerMatchType matchType, double matchValue)
374 int error = Interop.Calendar.Filter.AddOperator(_filterHandle, logicalOperator);
375 if (CalendarError.None != (CalendarError)error)
377 Log.Error(Globals.LogTag, "AddCondition Failed with error " + error);
378 throw CalendarErrorFactory.GetException(error);
381 error = Interop.Calendar.Filter.AddDouble(_filterHandle, propertyId, matchType, matchValue);
382 if (CalendarError.None != (CalendarError)error)
384 Log.Error(Globals.LogTag, "AddCondition Failed with error " + error);
385 throw CalendarErrorFactory.GetException(error);
390 /// Adds a condition for the CalendarTime type.
392 /// <param name="logicalOperator">The operator type</param>
393 /// <param name="propertyId">The property ID to add a condition</param>
394 /// <param name="matchType">The match flag</param>
395 /// <param name="matchValue">The match valu</param>
396 /// <exception cref="NotSupportedException">Thrown when an invoked method is not supported</exception>
397 /// <exception cref="ArgumentException">Thrown when one of the arguments provided to a method is not valid</exception>
398 public void AddCondition(LogicalOperator logicalOperator, uint propertyId, IntegerMatchType matchType, CalendarTime matchValue)
400 int error = Interop.Calendar.Filter.AddOperator(_filterHandle, logicalOperator);
401 if (CalendarError.None != (CalendarError)error)
403 Log.Error(Globals.LogTag, "AddCondition Failed with error " + error);
404 throw CalendarErrorFactory.GetException(error);
407 Interop.Calendar.Record.DateTime time = CalendarRecord.ConvertCalendarTimeToStruct(matchValue);
408 error = Interop.Calendar.Filter.AddCalendarTime(_filterHandle, propertyId, matchType, time);
409 if (CalendarError.None != (CalendarError)error)
411 Log.Error(Globals.LogTag, "AddCondition Failed with error " + error);
412 throw CalendarErrorFactory.GetException(error);
417 /// Adds a child filter to a parent filter.
419 /// <param name="logicalOperator">The operator type</param>
420 /// <param name="filter">The child filter</param>
421 /// <exception cref="NotSupportedException">Thrown when an invoked method is not supported</exception>
422 /// <exception cref="ArgumentException">Thrown when one of the arguments provided to a method is not valid</exception>
423 public void AddFilter(LogicalOperator logicalOperator, CalendarFilter filter)
425 int error = Interop.Calendar.Filter.AddOperator(_filterHandle, logicalOperator);
426 if (CalendarError.None != (CalendarError)error)
428 Log.Error(Globals.LogTag, "AddCondition Failed with error " + error);
429 throw CalendarErrorFactory.GetException(error);
432 error = Interop.Calendar.Filter.AddFilter(_filterHandle, filter._filterHandle);
433 if (CalendarError.None != (CalendarError)error)
435 Log.Error(Globals.LogTag, "AddFilter Failed with error " + error);
436 throw CalendarErrorFactory.GetException(error);