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 Log.Error(Globals.LogTag, "CalendarFilter Failed with error " + error);
57 throw CalendarErrorFactory.GetException(error);
62 /// Creates a filter with a condition for an integer type.
64 /// <since_tizen> 4 </since_tizen>
65 /// <feature>http://tizen.org/privilege/calendar</feature>
66 /// <param name="viewUri">The view URI of a filter</param>
67 /// <param name="propertyId">The property ID to add a condition</param>
68 /// <param name="matchType">The match flag</param>
69 /// <param name="matchValue">The match value</param>
70 /// <exception cref="NotSupportedException">Thrown when feature is not supported</exception>
71 /// <exception cref="ArgumentException">Thrown when one of the arguments provided to a method is not valid</exception>
72 /// <exception cref="OutOfMemoryException">Thrown when failed due to out of memory</exception>
73 [SuppressMessage("Microsoft.Design", "CA1054:UriParametersShouldNotBeStrings")]
74 public CalendarFilter(string viewUri, uint propertyId, IntegerMatchType matchType, int matchValue)
77 error = Interop.Filter.Create(viewUri, out _filterHandle);
78 if (CalendarError.None != (CalendarError)error)
80 Log.Error(Globals.LogTag, "CalendarFilter Failed with error " + error);
81 throw CalendarErrorFactory.GetException(error);
84 error = Interop.Filter.AddInteger(_filterHandle, propertyId, matchType, matchValue);
85 if (CalendarError.None != (CalendarError)error)
87 Log.Error(Globals.LogTag, "CalendarFilter Failed with error " + error);
88 throw CalendarErrorFactory.GetException(error);
93 /// Creates a filter with a condition for long type.
95 /// <since_tizen> 4 </since_tizen>
96 /// <feature>http://tizen.org/privilege/calendar</feature>
97 /// <param name="viewUri">The view URI of a filter</param>
98 /// <param name="propertyId">The property ID to add a condition</param>
99 /// <param name="matchType">The match flag</param>
100 /// <param name="matchValue">The match value</param>
101 /// <exception cref="NotSupportedException">Thrown when feature is not supported</exception>
102 /// <exception cref="ArgumentException">Thrown when one of the arguments provided to a method is not valid</exception>
103 /// <exception cref="OutOfMemoryException">Thrown when failed due to out of memory</exception>
104 [SuppressMessage("Microsoft.Design", "CA1054:UriParametersShouldNotBeStrings")]
105 public CalendarFilter(string viewUri, uint propertyId, IntegerMatchType matchType, long matchValue)
108 error = Interop.Filter.Create(viewUri, out _filterHandle);
109 if (CalendarError.None != (CalendarError)error)
111 Log.Error(Globals.LogTag, "CalendarFilter Failed with error " + error);
112 throw CalendarErrorFactory.GetException(error);
115 error = Interop.Filter.AddLong(_filterHandle, propertyId, matchType, matchValue);
116 if (CalendarError.None != (CalendarError)error)
118 Log.Error(Globals.LogTag, "CalendarFilter Failed with error " + error);
119 throw CalendarErrorFactory.GetException(error);
124 /// Creates a filter with a condition for double type.
126 /// <since_tizen> 4 </since_tizen>
127 /// <feature>http://tizen.org/privilege/calendar</feature>
128 /// <param name="viewUri">The view URI of a filter</param>
129 /// <param name="propertyId">The property ID to add a condition</param>
130 /// <param name="matchType">The match flag</param>
131 /// <param name="matchValue">The match value</param>
132 /// <exception cref="NotSupportedException">Thrown when feature is not supported</exception>
133 /// <exception cref="ArgumentException">Thrown when one of the arguments provided to a method is not valid</exception>
134 /// <exception cref="OutOfMemoryException">Thrown when failed due to out of memory</exception>
135 [SuppressMessage("Microsoft.Design", "CA1054:UriParametersShouldNotBeStrings")]
136 public CalendarFilter(string viewUri, uint propertyId, IntegerMatchType matchType, double matchValue)
139 error = Interop.Filter.Create(viewUri, out _filterHandle);
140 if (CalendarError.None != (CalendarError)error)
142 Log.Error(Globals.LogTag, "CalendarFilter Failed with error " + error);
143 throw CalendarErrorFactory.GetException(error);
146 error = Interop.Filter.AddDouble(_filterHandle, propertyId, matchType, matchValue);
147 if (CalendarError.None != (CalendarError)error)
149 Log.Error(Globals.LogTag, "CalendarFilter Failed with error " + error);
150 throw CalendarErrorFactory.GetException(error);
155 /// Creates a filter with a condition for CalendarTime type.
157 /// <since_tizen> 4 </since_tizen>
158 /// <feature>http://tizen.org/privilege/calendar</feature>
159 /// <param name="viewUri">The view URI of a filter</param>
160 /// <param name="propertyId">The property ID to add a condition</param>
161 /// <param name="matchType">The match flag</param>
162 /// <param name="matchValue">The match value</param>
163 /// <exception cref="NotSupportedException">Thrown when feature is not supported</exception>
164 /// <exception cref="ArgumentException">Thrown when one of the arguments provided to a method is not valid</exception>
165 /// <exception cref="OutOfMemoryException">Thrown when failed due to out of memory</exception>
166 [SuppressMessage("Microsoft.Design", "CA1054:UriParametersShouldNotBeStrings")]
167 public CalendarFilter(string viewUri, uint propertyId, IntegerMatchType matchType, CalendarTime matchValue)
170 error = Interop.Filter.Create(viewUri, out _filterHandle);
171 if (CalendarError.None != (CalendarError)error)
173 Log.Error(Globals.LogTag, "CalendarFilter Failed with error " + error);
174 throw CalendarErrorFactory.GetException(error);
177 Interop.Record.DateTime time = CalendarRecord.ConvertCalendarTimeToStruct(matchValue);
178 error = Interop.Filter.AddCalendarTime(_filterHandle, propertyId, matchType, time);
179 if (CalendarError.None != (CalendarError)error)
181 Log.Error(Globals.LogTag, "CalendarFilter Failed with error " + error);
182 throw CalendarErrorFactory.GetException(error);
195 /// Enumeration for the filter match type of a string.
197 public enum StringMatchType
200 /// Full string, case-sensitive
204 /// Full string, case-insensitive
208 /// Sub string, case-insensitive
212 /// Start with, case-insensitive
216 /// End with, case-insensitive
226 /// Enumeration for the filter match type of an integer.
228 public enum IntegerMatchType
251 /// <>, this flag can yield poor performance
261 /// Enumeration for a filter operator.
263 public enum LogicalOperator
275 #region IDisposable Support
276 private bool disposedValue = false; // To detect redundant calls
281 /// <param name="disposing">true to release both managed and unmanaged resources; false to release only unmanaged resources.</param>
282 protected virtual void Dispose(bool disposing)
286 Log.Debug(Globals.LogTag, "Dispose :" + disposing);
288 int error = Interop.Filter.Destroy(_filterHandle);
289 if (CalendarError.None != (CalendarError)error)
291 Log.Error(Globals.LogTag, "Destroy Failed with error " + error);
292 throw CalendarErrorFactory.GetException(error);
294 disposedValue = true;
299 /// Releases all resources used by the CalendarFilter.
300 /// It should be called after having finished using of the object.
302 public void Dispose()
305 GC.SuppressFinalize(this);
310 /// Adds a condition for the string type.
312 /// <since_tizen> 4 </since_tizen>
313 /// <feature>http://tizen.org/privilege/calendar</feature>
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 value</param>
318 /// <exception cref="NotSupportedException">Thrown when feature 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, StringMatchType matchType, string matchValue)
322 int error = Interop.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.Filter.AddString(_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 integer type.
340 /// <since_tizen> 4 </since_tizen>
341 /// <feature>http://tizen.org/privilege/calendar</feature>
342 /// <param name="logicalOperator">The operator type</param>
343 /// <param name="propertyId">The property ID to add a condition</param>
344 /// <param name="matchType">The match flag</param>
345 /// <param name="matchValue">The match value</param>
346 /// <exception cref="NotSupportedException">Thrown when feature is not supported</exception>
347 /// <exception cref="ArgumentException">Thrown when one of the arguments provided to a method is not valid</exception>
348 public void AddCondition(LogicalOperator logicalOperator, uint propertyId, IntegerMatchType matchType, int matchValue)
350 int error = Interop.Filter.AddOperator(_filterHandle, logicalOperator);
351 if (CalendarError.None != (CalendarError)error)
353 Log.Error(Globals.LogTag, "AddCondition Failed with error " + error);
354 throw CalendarErrorFactory.GetException(error);
357 error = Interop.Filter.AddInteger(_filterHandle, propertyId, matchType, matchValue);
358 if (CalendarError.None != (CalendarError)error)
360 Log.Error(Globals.LogTag, "AddCondition Failed with error " + error);
361 throw CalendarErrorFactory.GetException(error);
366 /// Adds a condition for the long type.
368 /// <since_tizen> 4 </since_tizen>
369 /// <feature>http://tizen.org/privilege/calendar</feature>
370 /// <param name="logicalOperator">The operator type</param>
371 /// <param name="propertyId">The property ID to add a condition</param>
372 /// <param name="matchType">The match flag</param>
373 /// <param name="matchValue">The match value</param>
374 /// <exception cref="NotSupportedException">Thrown when feature is not supported</exception>
375 /// <exception cref="ArgumentException">Thrown when one of the arguments provided to a method is not valid</exception>
376 public void AddCondition(LogicalOperator logicalOperator, uint propertyId, IntegerMatchType matchType, long matchValue)
378 int error = Interop.Filter.AddOperator(_filterHandle, logicalOperator);
379 if (CalendarError.None != (CalendarError)error)
381 Log.Error(Globals.LogTag, "AddCondition Failed with error " + error);
382 throw CalendarErrorFactory.GetException(error);
385 error = Interop.Filter.AddLong(_filterHandle, propertyId, matchType, matchValue);
386 if (CalendarError.None != (CalendarError)error)
388 Log.Error(Globals.LogTag, "AddCondition Failed with error " + error);
389 throw CalendarErrorFactory.GetException(error);
394 /// Adds a condition for the double type.
396 /// <since_tizen> 4 </since_tizen>
397 /// <feature>http://tizen.org/privilege/calendar</feature>
398 /// <param name="logicalOperator">The operator type</param>
399 /// <param name="propertyId">The property ID to add a condition</param>
400 /// <param name="matchType">The match flag</param>
401 /// <param name="matchValue">The match value</param>
402 /// <exception cref="NotSupportedException">Thrown when feature is not supported</exception>
403 /// <exception cref="ArgumentException">Thrown when one of the arguments provided to a method is not valid</exception>
404 public void AddCondition(LogicalOperator logicalOperator, uint propertyId, IntegerMatchType matchType, double matchValue)
406 int error = Interop.Filter.AddOperator(_filterHandle, logicalOperator);
407 if (CalendarError.None != (CalendarError)error)
409 Log.Error(Globals.LogTag, "AddCondition Failed with error " + error);
410 throw CalendarErrorFactory.GetException(error);
413 error = Interop.Filter.AddDouble(_filterHandle, propertyId, matchType, matchValue);
414 if (CalendarError.None != (CalendarError)error)
416 Log.Error(Globals.LogTag, "AddCondition Failed with error " + error);
417 throw CalendarErrorFactory.GetException(error);
422 /// Adds a condition for the CalendarTime type.
424 /// <since_tizen> 4 </since_tizen>
425 /// <feature>http://tizen.org/privilege/calendar</feature>
426 /// <param name="logicalOperator">The operator type</param>
427 /// <param name="propertyId">The property ID to add a condition</param>
428 /// <param name="matchType">The match flag</param>
429 /// <param name="matchValue">The match value</param>
430 /// <exception cref="NotSupportedException">Thrown when feature is not supported</exception>
431 /// <exception cref="ArgumentException">Thrown when one of the arguments provided to a method is not valid</exception>
432 public void AddCondition(LogicalOperator logicalOperator, uint propertyId, IntegerMatchType matchType, CalendarTime matchValue)
434 int error = Interop.Filter.AddOperator(_filterHandle, logicalOperator);
435 if (CalendarError.None != (CalendarError)error)
437 Log.Error(Globals.LogTag, "AddCondition Failed with error " + error);
438 throw CalendarErrorFactory.GetException(error);
441 Interop.Record.DateTime time = CalendarRecord.ConvertCalendarTimeToStruct(matchValue);
442 error = Interop.Filter.AddCalendarTime(_filterHandle, propertyId, matchType, time);
443 if (CalendarError.None != (CalendarError)error)
445 Log.Error(Globals.LogTag, "AddCondition Failed with error " + error);
446 throw CalendarErrorFactory.GetException(error);
451 /// Adds a child filter to a parent filter.
453 /// <since_tizen> 4 </since_tizen>
454 /// <feature>http://tizen.org/privilege/calendar</feature>
455 /// <param name="logicalOperator">The operator type</param>
456 /// <param name="filter">The child filter</param>
457 /// <exception cref="NotSupportedException">Thrown when feature is not supported</exception>
458 /// <exception cref="ArgumentException">Thrown when one of the arguments provided to a method is not valid</exception>
459 public void AddFilter(LogicalOperator logicalOperator, CalendarFilter filter)
461 int error = Interop.Filter.AddOperator(_filterHandle, logicalOperator);
462 if (CalendarError.None != (CalendarError)error)
464 Log.Error(Globals.LogTag, "AddCondition Failed with error " + error);
465 throw CalendarErrorFactory.GetException(error);
468 error = Interop.Filter.AddFilter(_filterHandle, filter._filterHandle);
469 if (CalendarError.None != (CalendarError)error)
471 Log.Error(Globals.LogTag, "AddFilter Failed with error " + error);
472 throw CalendarErrorFactory.GetException(error);