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.Diagnostics.CodeAnalysis;
20 namespace Tizen.Pims.Calendar
23 /// A filter includes the conditions for the search.
25 /// <since_tizen> 4 </since_tizen>
26 public class CalendarFilter:IDisposable
28 internal IntPtr _filterHandle;
31 /// Creates a filter with a condition for a string type.
33 /// <since_tizen> 4 </since_tizen>
34 /// <feature>http://tizen.org/privilege/calendar</feature>
35 /// <param name="viewUri">The view URI of a filter</param>
36 /// <param name="propertyId">The property ID to add a condition</param>
37 /// <param name="matchType">The match flag</param>
38 /// <param name="matchValue">The match value</param>
39 /// <exception cref="NotSupportedException">Thrown when feature is not supported</exception>
40 /// <exception cref="ArgumentException">Thrown when one of the arguments provided to a method is not valid</exception>
41 /// <exception cref="OutOfMemoryException">Thrown when failed due to out of memory</exception>
42 [SuppressMessage("Microsoft.Design", "CA1054:UriParametersShouldNotBeStrings")]
43 public CalendarFilter(string viewUri, uint propertyId, StringMatchType matchType, string matchValue)
46 error = Interop.Filter.Create(viewUri, out _filterHandle);
47 if (CalendarError.None != (CalendarError)error)
49 Log.Error(Globals.LogTag, "CalendarFilter Failed with error " + error);
50 throw CalendarErrorFactory.GetException(error);
53 error = Interop.Filter.AddString(_filterHandle, propertyId, matchType, matchValue);
54 if (CalendarError.None != (CalendarError)error)
56 Interop.Filter.Destroy(_filterHandle);
57 Log.Error(Globals.LogTag, "CalendarFilter Failed with error " + error);
58 throw CalendarErrorFactory.GetException(error);
63 /// Creates a filter with a condition for an integer type.
65 /// <since_tizen> 4 </since_tizen>
66 /// <feature>http://tizen.org/privilege/calendar</feature>
67 /// <param name="viewUri">The view URI of a filter</param>
68 /// <param name="propertyId">The property ID to add a condition</param>
69 /// <param name="matchType">The match flag</param>
70 /// <param name="matchValue">The match value</param>
71 /// <exception cref="NotSupportedException">Thrown when feature is not supported</exception>
72 /// <exception cref="ArgumentException">Thrown when one of the arguments provided to a method is not valid</exception>
73 /// <exception cref="OutOfMemoryException">Thrown when failed due to out of memory</exception>
74 [SuppressMessage("Microsoft.Design", "CA1054:UriParametersShouldNotBeStrings")]
75 public CalendarFilter(string viewUri, uint propertyId, IntegerMatchType matchType, int matchValue)
78 error = Interop.Filter.Create(viewUri, out _filterHandle);
79 if (CalendarError.None != (CalendarError)error)
81 Log.Error(Globals.LogTag, "CalendarFilter Failed with error " + error);
82 throw CalendarErrorFactory.GetException(error);
85 error = Interop.Filter.AddInteger(_filterHandle, propertyId, matchType, matchValue);
86 if (CalendarError.None != (CalendarError)error)
88 Interop.Filter.Destroy(_filterHandle);
89 Log.Error(Globals.LogTag, "CalendarFilter Failed with error " + error);
90 throw CalendarErrorFactory.GetException(error);
95 /// Creates a filter with a condition for long type.
97 /// <since_tizen> 4 </since_tizen>
98 /// <feature>http://tizen.org/privilege/calendar</feature>
99 /// <param name="viewUri">The view URI of a filter</param>
100 /// <param name="propertyId">The property ID to add a condition</param>
101 /// <param name="matchType">The match flag</param>
102 /// <param name="matchValue">The match value</param>
103 /// <exception cref="NotSupportedException">Thrown when feature is not supported</exception>
104 /// <exception cref="ArgumentException">Thrown when one of the arguments provided to a method is not valid</exception>
105 /// <exception cref="OutOfMemoryException">Thrown when failed due to out of memory</exception>
106 [SuppressMessage("Microsoft.Design", "CA1054:UriParametersShouldNotBeStrings")]
107 public CalendarFilter(string viewUri, uint propertyId, IntegerMatchType matchType, long matchValue)
110 error = Interop.Filter.Create(viewUri, out _filterHandle);
111 if (CalendarError.None != (CalendarError)error)
113 Log.Error(Globals.LogTag, "CalendarFilter Failed with error " + error);
114 throw CalendarErrorFactory.GetException(error);
117 error = Interop.Filter.AddLong(_filterHandle, propertyId, matchType, matchValue);
118 if (CalendarError.None != (CalendarError)error)
120 Interop.Filter.Destroy(_filterHandle);
121 Log.Error(Globals.LogTag, "CalendarFilter Failed with error " + error);
122 throw CalendarErrorFactory.GetException(error);
127 /// Creates a filter with a condition for double type.
129 /// <since_tizen> 4 </since_tizen>
130 /// <feature>http://tizen.org/privilege/calendar</feature>
131 /// <param name="viewUri">The view URI of a filter</param>
132 /// <param name="propertyId">The property ID to add a condition</param>
133 /// <param name="matchType">The match flag</param>
134 /// <param name="matchValue">The match value</param>
135 /// <exception cref="NotSupportedException">Thrown when feature is not supported</exception>
136 /// <exception cref="ArgumentException">Thrown when one of the arguments provided to a method is not valid</exception>
137 /// <exception cref="OutOfMemoryException">Thrown when failed due to out of memory</exception>
138 [SuppressMessage("Microsoft.Design", "CA1054:UriParametersShouldNotBeStrings")]
139 public CalendarFilter(string viewUri, uint propertyId, IntegerMatchType matchType, double matchValue)
142 error = Interop.Filter.Create(viewUri, out _filterHandle);
143 if (CalendarError.None != (CalendarError)error)
145 Log.Error(Globals.LogTag, "CalendarFilter Failed with error " + error);
146 throw CalendarErrorFactory.GetException(error);
149 error = Interop.Filter.AddDouble(_filterHandle, propertyId, matchType, matchValue);
150 if (CalendarError.None != (CalendarError)error)
152 Interop.Filter.Destroy(_filterHandle);
153 Log.Error(Globals.LogTag, "CalendarFilter Failed with error " + error);
154 throw CalendarErrorFactory.GetException(error);
159 /// Creates a filter with a condition for CalendarTime type.
161 /// <since_tizen> 4 </since_tizen>
162 /// <feature>http://tizen.org/privilege/calendar</feature>
163 /// <param name="viewUri">The view URI of a filter</param>
164 /// <param name="propertyId">The property ID to add a condition</param>
165 /// <param name="matchType">The match flag</param>
166 /// <param name="matchValue">The match value</param>
167 /// <exception cref="NotSupportedException">Thrown when feature is not supported</exception>
168 /// <exception cref="ArgumentException">Thrown when one of the arguments provided to a method is not valid</exception>
169 /// <exception cref="OutOfMemoryException">Thrown when failed due to out of memory</exception>
170 [SuppressMessage("Microsoft.Design", "CA1054:UriParametersShouldNotBeStrings")]
171 public CalendarFilter(string viewUri, uint propertyId, IntegerMatchType matchType, CalendarTime matchValue)
174 error = Interop.Filter.Create(viewUri, out _filterHandle);
175 if (CalendarError.None != (CalendarError)error)
177 Log.Error(Globals.LogTag, "CalendarFilter Failed with error " + error);
178 throw CalendarErrorFactory.GetException(error);
181 Interop.Record.DateTime time = CalendarRecord.ConvertCalendarTimeToStruct(matchValue);
182 error = Interop.Filter.AddCalendarTime(_filterHandle, propertyId, matchType, time);
183 if (CalendarError.None != (CalendarError)error)
185 Interop.Filter.Destroy(_filterHandle);
186 Log.Error(Globals.LogTag, "CalendarFilter Failed with error " + error);
187 throw CalendarErrorFactory.GetException(error);
200 /// Enumeration for the filter match type of a string.
202 public enum StringMatchType
205 /// Full string, case-sensitive
209 /// Full string, case-insensitive
213 /// Sub string, case-insensitive
217 /// Start with, case-insensitive
221 /// End with, case-insensitive
231 /// Enumeration for the filter match type of an integer.
233 public enum IntegerMatchType
256 /// <>, this flag can yield poor performance
266 /// Enumeration for a filter operator.
268 public enum LogicalOperator
280 #region IDisposable Support
281 private bool disposedValue = false; // To detect redundant calls
286 /// <param name="disposing">true to release both managed and unmanaged resources; false to release only unmanaged resources.</param>
287 protected virtual void Dispose(bool disposing)
291 Log.Debug(Globals.LogTag, "Dispose :" + disposing);
293 int error = Interop.Filter.Destroy(_filterHandle);
294 if (CalendarError.None != (CalendarError)error)
296 Log.Error(Globals.LogTag, "Destroy Failed with error " + error);
298 disposedValue = true;
303 /// Releases all resources used by the CalendarFilter.
304 /// It should be called after having finished using of the object.
306 public void Dispose()
309 GC.SuppressFinalize(this);
314 /// Adds a condition for the string type.
316 /// <since_tizen> 4 </since_tizen>
317 /// <feature>http://tizen.org/privilege/calendar</feature>
318 /// <param name="logicalOperator">The operator type</param>
319 /// <param name="propertyId">The property ID to add a condition</param>
320 /// <param name="matchType">The match flag</param>
321 /// <param name="matchValue">The match value</param>
322 /// <exception cref="NotSupportedException">Thrown when feature is not supported</exception>
323 /// <exception cref="ArgumentException">Thrown when one of the arguments provided to a method is not valid</exception>
324 public void AddCondition(LogicalOperator logicalOperator, uint propertyId, StringMatchType matchType, string matchValue)
326 int error = Interop.Filter.AddOperator(_filterHandle, logicalOperator);
327 if (CalendarError.None != (CalendarError)error)
329 Log.Error(Globals.LogTag, "AddCondition Failed with error " + error);
330 throw CalendarErrorFactory.GetException(error);
333 error = Interop.Filter.AddString(_filterHandle, propertyId, matchType, matchValue);
334 if (CalendarError.None != (CalendarError)error)
336 Log.Error(Globals.LogTag, "AddCondition Failed with error " + error);
337 throw CalendarErrorFactory.GetException(error);
342 /// Adds a condition for the integer type.
344 /// <since_tizen> 4 </since_tizen>
345 /// <feature>http://tizen.org/privilege/calendar</feature>
346 /// <param name="logicalOperator">The operator type</param>
347 /// <param name="propertyId">The property ID to add a condition</param>
348 /// <param name="matchType">The match flag</param>
349 /// <param name="matchValue">The match value</param>
350 /// <exception cref="NotSupportedException">Thrown when feature is not supported</exception>
351 /// <exception cref="ArgumentException">Thrown when one of the arguments provided to a method is not valid</exception>
352 public void AddCondition(LogicalOperator logicalOperator, uint propertyId, IntegerMatchType matchType, int matchValue)
354 int error = Interop.Filter.AddOperator(_filterHandle, logicalOperator);
355 if (CalendarError.None != (CalendarError)error)
357 Log.Error(Globals.LogTag, "AddCondition Failed with error " + error);
358 throw CalendarErrorFactory.GetException(error);
361 error = Interop.Filter.AddInteger(_filterHandle, propertyId, matchType, matchValue);
362 if (CalendarError.None != (CalendarError)error)
364 Log.Error(Globals.LogTag, "AddCondition Failed with error " + error);
365 throw CalendarErrorFactory.GetException(error);
370 /// Adds a condition for the long type.
372 /// <since_tizen> 4 </since_tizen>
373 /// <feature>http://tizen.org/privilege/calendar</feature>
374 /// <param name="logicalOperator">The operator type</param>
375 /// <param name="propertyId">The property ID to add a condition</param>
376 /// <param name="matchType">The match flag</param>
377 /// <param name="matchValue">The match value</param>
378 /// <exception cref="NotSupportedException">Thrown when feature is not supported</exception>
379 /// <exception cref="ArgumentException">Thrown when one of the arguments provided to a method is not valid</exception>
380 public void AddCondition(LogicalOperator logicalOperator, uint propertyId, IntegerMatchType matchType, long matchValue)
382 int error = Interop.Filter.AddOperator(_filterHandle, logicalOperator);
383 if (CalendarError.None != (CalendarError)error)
385 Log.Error(Globals.LogTag, "AddCondition Failed with error " + error);
386 throw CalendarErrorFactory.GetException(error);
389 error = Interop.Filter.AddLong(_filterHandle, propertyId, matchType, matchValue);
390 if (CalendarError.None != (CalendarError)error)
392 Log.Error(Globals.LogTag, "AddCondition Failed with error " + error);
393 throw CalendarErrorFactory.GetException(error);
398 /// Adds a condition for the double type.
400 /// <since_tizen> 4 </since_tizen>
401 /// <feature>http://tizen.org/privilege/calendar</feature>
402 /// <param name="logicalOperator">The operator type</param>
403 /// <param name="propertyId">The property ID to add a condition</param>
404 /// <param name="matchType">The match flag</param>
405 /// <param name="matchValue">The match value</param>
406 /// <exception cref="NotSupportedException">Thrown when feature is not supported</exception>
407 /// <exception cref="ArgumentException">Thrown when one of the arguments provided to a method is not valid</exception>
408 public void AddCondition(LogicalOperator logicalOperator, uint propertyId, IntegerMatchType matchType, double matchValue)
410 int error = Interop.Filter.AddOperator(_filterHandle, logicalOperator);
411 if (CalendarError.None != (CalendarError)error)
413 Log.Error(Globals.LogTag, "AddCondition Failed with error " + error);
414 throw CalendarErrorFactory.GetException(error);
417 error = Interop.Filter.AddDouble(_filterHandle, propertyId, matchType, matchValue);
418 if (CalendarError.None != (CalendarError)error)
420 Log.Error(Globals.LogTag, "AddCondition Failed with error " + error);
421 throw CalendarErrorFactory.GetException(error);
426 /// Adds a condition for the CalendarTime type.
428 /// <since_tizen> 4 </since_tizen>
429 /// <feature>http://tizen.org/privilege/calendar</feature>
430 /// <param name="logicalOperator">The operator type</param>
431 /// <param name="propertyId">The property ID to add a condition</param>
432 /// <param name="matchType">The match flag</param>
433 /// <param name="matchValue">The match value</param>
434 /// <exception cref="NotSupportedException">Thrown when feature is not supported</exception>
435 /// <exception cref="ArgumentException">Thrown when one of the arguments provided to a method is not valid</exception>
436 public void AddCondition(LogicalOperator logicalOperator, uint propertyId, IntegerMatchType matchType, CalendarTime matchValue)
438 int error = Interop.Filter.AddOperator(_filterHandle, logicalOperator);
439 if (CalendarError.None != (CalendarError)error)
441 Log.Error(Globals.LogTag, "AddCondition Failed with error " + error);
442 throw CalendarErrorFactory.GetException(error);
445 Interop.Record.DateTime time = CalendarRecord.ConvertCalendarTimeToStruct(matchValue);
446 error = Interop.Filter.AddCalendarTime(_filterHandle, propertyId, matchType, time);
447 if (CalendarError.None != (CalendarError)error)
449 Log.Error(Globals.LogTag, "AddCondition Failed with error " + error);
450 throw CalendarErrorFactory.GetException(error);
455 /// Adds a child filter to a parent filter.
457 /// <since_tizen> 4 </since_tizen>
458 /// <feature>http://tizen.org/privilege/calendar</feature>
459 /// <param name="logicalOperator">The operator type</param>
460 /// <param name="filter">The child filter</param>
461 /// <exception cref="NotSupportedException">Thrown when feature is not supported</exception>
462 /// <exception cref="ArgumentException">Thrown when one of the arguments provided to a method is not valid</exception>
463 public void AddFilter(LogicalOperator logicalOperator, CalendarFilter filter)
465 int error = Interop.Filter.AddOperator(_filterHandle, logicalOperator);
466 if (CalendarError.None != (CalendarError)error)
468 Log.Error(Globals.LogTag, "AddCondition Failed with error " + error);
469 throw CalendarErrorFactory.GetException(error);
472 error = Interop.Filter.AddFilter(_filterHandle, filter._filterHandle);
473 if (CalendarError.None != (CalendarError)error)
475 Log.Error(Globals.LogTag, "AddFilter Failed with error " + error);
476 throw CalendarErrorFactory.GetException(error);