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/feature/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 the 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/feature/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 the 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 a long type.
97 /// <since_tizen> 4 </since_tizen>
98 /// <feature>http://tizen.org/feature/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 the 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 a double type.
129 /// <since_tizen> 4 </since_tizen>
130 /// <feature>http://tizen.org/feature/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 the 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 the CalendarTime type.
161 /// <since_tizen> 4 </since_tizen>
162 /// <feature>http://tizen.org/feature/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 the 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);
192 /// Destroys the filter.
200 /// Enumeration for the filter match type of a string.
202 /// <since_tizen> 4 </since_tizen>
203 public enum StringMatchType
206 /// Full string, case-sensitive.
210 /// Full string, case-insensitive.
214 /// Sub-string, case-insensitive.
218 /// Starts with, case-insensitive.
222 /// Ends with, case-insensitive.
232 /// Enumeration for the filter match type of an integer.
234 /// <since_tizen> 4 </since_tizen>
235 public enum IntegerMatchType
258 /// <>, this flag can yield poor performance.
268 /// Enumeration for a filter operator.
270 /// <since_tizen> 4 </since_tizen>
271 public enum LogicalOperator
283 #region IDisposable Support
284 private bool disposedValue = false; // To detect redundant calls
289 /// <param name="disposing">true to release both managed and unmanaged resources, false to release only unmanaged resources.</param>
290 /// <since_tizen> 4 </since_tizen>
291 protected virtual void Dispose(bool disposing)
295 Log.Debug(Globals.LogTag, "Dispose :" + disposing);
297 int error = Interop.Filter.Destroy(_filterHandle);
298 if (CalendarError.None != (CalendarError)error)
300 Log.Error(Globals.LogTag, "Destroy Failed with error " + error);
302 disposedValue = true;
307 /// Releases all the resources used by the CalendarFilter.
308 /// It should be called after having finished using the object.
310 /// <since_tizen> 4 </since_tizen>
311 public void Dispose()
314 GC.SuppressFinalize(this);
319 /// Adds a condition for the string type.
321 /// <since_tizen> 4 </since_tizen>
322 /// <feature>http://tizen.org/feature/calendar</feature>
323 /// <param name="logicalOperator">The operator type.</param>
324 /// <param name="propertyId">The property ID to add a condition.</param>
325 /// <param name="matchType">The match flag.</param>
326 /// <param name="matchValue">The match value.</param>
327 /// <exception cref="NotSupportedException">Thrown when the feature is not supported.</exception>
328 /// <exception cref="ArgumentException">Thrown when one of the arguments provided to a method is not valid.</exception>
329 public void AddCondition(LogicalOperator logicalOperator, uint propertyId, StringMatchType matchType, string matchValue)
331 int error = Interop.Filter.AddOperator(_filterHandle, logicalOperator);
332 if (CalendarError.None != (CalendarError)error)
334 Log.Error(Globals.LogTag, "AddCondition Failed with error " + error);
335 throw CalendarErrorFactory.GetException(error);
338 error = Interop.Filter.AddString(_filterHandle, propertyId, matchType, matchValue);
339 if (CalendarError.None != (CalendarError)error)
341 Log.Error(Globals.LogTag, "AddCondition Failed with error " + error);
342 throw CalendarErrorFactory.GetException(error);
347 /// Adds a condition for the integer type.
349 /// <since_tizen> 4 </since_tizen>
350 /// <feature>http://tizen.org/feature/calendar</feature>
351 /// <param name="logicalOperator">The operator type.</param>
352 /// <param name="propertyId">The property ID to add a condition.</param>
353 /// <param name="matchType">The match flag.</param>
354 /// <param name="matchValue">The match value.</param>
355 /// <exception cref="NotSupportedException">Thrown when the feature is not supported.</exception>
356 /// <exception cref="ArgumentException">Thrown when one of the arguments provided to a method is not valid.</exception>
357 public void AddCondition(LogicalOperator logicalOperator, uint propertyId, IntegerMatchType matchType, int matchValue)
359 int error = Interop.Filter.AddOperator(_filterHandle, logicalOperator);
360 if (CalendarError.None != (CalendarError)error)
362 Log.Error(Globals.LogTag, "AddCondition Failed with error " + error);
363 throw CalendarErrorFactory.GetException(error);
366 error = Interop.Filter.AddInteger(_filterHandle, propertyId, matchType, matchValue);
367 if (CalendarError.None != (CalendarError)error)
369 Log.Error(Globals.LogTag, "AddCondition Failed with error " + error);
370 throw CalendarErrorFactory.GetException(error);
375 /// Adds a condition for the long type.
377 /// <since_tizen> 4 </since_tizen>
378 /// <feature>http://tizen.org/feature/calendar</feature>
379 /// <param name="logicalOperator">The operator type.</param>
380 /// <param name="propertyId">The property ID to add a condition.</param>
381 /// <param name="matchType">The match flag.</param>
382 /// <param name="matchValue">The match value.</param>
383 /// <exception cref="NotSupportedException">Thrown when the feature is not supported.</exception>
384 /// <exception cref="ArgumentException">Thrown when one of the arguments provided to a method is not valid.</exception>
385 public void AddCondition(LogicalOperator logicalOperator, uint propertyId, IntegerMatchType matchType, long matchValue)
387 int error = Interop.Filter.AddOperator(_filterHandle, logicalOperator);
388 if (CalendarError.None != (CalendarError)error)
390 Log.Error(Globals.LogTag, "AddCondition Failed with error " + error);
391 throw CalendarErrorFactory.GetException(error);
394 error = Interop.Filter.AddLong(_filterHandle, propertyId, matchType, matchValue);
395 if (CalendarError.None != (CalendarError)error)
397 Log.Error(Globals.LogTag, "AddCondition Failed with error " + error);
398 throw CalendarErrorFactory.GetException(error);
403 /// Adds a condition for the double type.
405 /// <since_tizen> 4 </since_tizen>
406 /// <feature>http://tizen.org/feature/calendar</feature>
407 /// <param name="logicalOperator">The operator type.</param>
408 /// <param name="propertyId">The property ID to add a condition.</param>
409 /// <param name="matchType">The match flag.</param>
410 /// <param name="matchValue">The match value.</param>
411 /// <exception cref="NotSupportedException">Thrown when the feature is not supported.</exception>
412 /// <exception cref="ArgumentException">Thrown when one of the arguments provided to a method is not valid.</exception>
413 public void AddCondition(LogicalOperator logicalOperator, uint propertyId, IntegerMatchType matchType, double matchValue)
415 int error = Interop.Filter.AddOperator(_filterHandle, logicalOperator);
416 if (CalendarError.None != (CalendarError)error)
418 Log.Error(Globals.LogTag, "AddCondition Failed with error " + error);
419 throw CalendarErrorFactory.GetException(error);
422 error = Interop.Filter.AddDouble(_filterHandle, propertyId, matchType, matchValue);
423 if (CalendarError.None != (CalendarError)error)
425 Log.Error(Globals.LogTag, "AddCondition Failed with error " + error);
426 throw CalendarErrorFactory.GetException(error);
431 /// Adds a condition for the CalendarTime type.
433 /// <since_tizen> 4 </since_tizen>
434 /// <feature>http://tizen.org/feature/calendar</feature>
435 /// <param name="logicalOperator">The operator type.</param>
436 /// <param name="propertyId">The property ID to add a condition.</param>
437 /// <param name="matchType">The match flag.</param>
438 /// <param name="matchValue">The match value.</param>
439 /// <exception cref="NotSupportedException">Thrown when the feature is not supported.</exception>
440 /// <exception cref="ArgumentException">Thrown when one of the arguments provided to a method is not valid.</exception>
441 public void AddCondition(LogicalOperator logicalOperator, uint propertyId, IntegerMatchType matchType, CalendarTime matchValue)
443 int error = Interop.Filter.AddOperator(_filterHandle, logicalOperator);
444 if (CalendarError.None != (CalendarError)error)
446 Log.Error(Globals.LogTag, "AddCondition Failed with error " + error);
447 throw CalendarErrorFactory.GetException(error);
450 Interop.Record.DateTime time = CalendarRecord.ConvertCalendarTimeToStruct(matchValue);
451 error = Interop.Filter.AddCalendarTime(_filterHandle, propertyId, matchType, time);
452 if (CalendarError.None != (CalendarError)error)
454 Log.Error(Globals.LogTag, "AddCondition Failed with error " + error);
455 throw CalendarErrorFactory.GetException(error);
460 /// Adds a child filter to a parent filter.
462 /// <since_tizen> 4 </since_tizen>
463 /// <feature>http://tizen.org/feature/calendar</feature>
464 /// <param name="logicalOperator">The operator type.</param>
465 /// <param name="filter">The child filter.</param>
466 /// <exception cref="NotSupportedException">Thrown when the feature is not supported.</exception>
467 /// <exception cref="ArgumentException">Thrown when one of the arguments provided to a method is not valid.</exception>
468 public void AddFilter(LogicalOperator logicalOperator, CalendarFilter filter)
470 int error = Interop.Filter.AddOperator(_filterHandle, logicalOperator);
471 if (CalendarError.None != (CalendarError)error)
473 Log.Error(Globals.LogTag, "AddCondition Failed with error " + error);
474 throw CalendarErrorFactory.GetException(error);
477 error = Interop.Filter.AddFilter(_filterHandle, filter._filterHandle);
478 if (CalendarError.None != (CalendarError)error)
480 Log.Error(Globals.LogTag, "AddFilter Failed with error " + error);
481 throw CalendarErrorFactory.GetException(error);