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 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 [SuppressMessage("Microsoft.Design", "CA1054:UriParametersShouldNotBeStrings")]
40 public CalendarFilter(string viewUri, uint propertyId, StringMatchType matchType, string matchValue)
43 error = Interop.Filter.Create(viewUri, out _filterHandle);
44 if (CalendarError.None != (CalendarError)error)
46 Log.Error(Globals.LogTag, "CalendarFilter Failed with error " + error);
47 throw CalendarErrorFactory.GetException(error);
50 error = Interop.Filter.AddString(_filterHandle, propertyId, matchType, matchValue);
51 if (CalendarError.None != (CalendarError)error)
53 Log.Error(Globals.LogTag, "CalendarFilter Failed with error " + error);
54 throw CalendarErrorFactory.GetException(error);
59 /// Creates a filter with a condition for an integer type.
61 /// <param name="viewUri">The view URI of a filter</param>
62 /// <param name="propertyId">The property ID to add a condition</param>
63 /// <param name="matchType">The match flag</param>
64 /// <param name="matchValue">The match value</param>
65 /// <exception cref="NotSupportedException">Thrown when an invoked method is not supported</exception>
66 /// <exception cref="ArgumentException">Thrown when one of the arguments provided to a method is not valid</exception>
67 /// <exception cref="OutOfMemoryException">Thrown when failed due to out of memory</exception>
68 [SuppressMessage("Microsoft.Design", "CA1054:UriParametersShouldNotBeStrings")]
69 public CalendarFilter(string viewUri, uint propertyId, IntegerMatchType matchType, int matchValue)
72 error = Interop.Filter.Create(viewUri, out _filterHandle);
73 if (CalendarError.None != (CalendarError)error)
75 Log.Error(Globals.LogTag, "CalendarFilter Failed with error " + error);
76 throw CalendarErrorFactory.GetException(error);
79 error = Interop.Filter.AddInteger(_filterHandle, propertyId, matchType, matchValue);
80 if (CalendarError.None != (CalendarError)error)
82 Log.Error(Globals.LogTag, "CalendarFilter Failed with error " + error);
83 throw CalendarErrorFactory.GetException(error);
88 /// Creates a filter with a condition for long type.
90 /// <param name="viewUri">The view URI of a filter</param>
91 /// <param name="propertyId">The property ID to add a condition</param>
92 /// <param name="matchType">The match flag</param>
93 /// <param name="matchValue">The match value</param>
94 /// <exception cref="NotSupportedException">Thrown when an invoked method is not supported</exception>
95 /// <exception cref="ArgumentException">Thrown when one of the arguments provided to a method is not valid</exception>
96 /// <exception cref="OutOfMemoryException">Thrown when failed due to out of memory</exception>
97 [SuppressMessage("Microsoft.Design", "CA1054:UriParametersShouldNotBeStrings")]
98 public CalendarFilter(string viewUri, uint propertyId, IntegerMatchType matchType, long matchValue)
101 error = Interop.Filter.Create(viewUri, out _filterHandle);
102 if (CalendarError.None != (CalendarError)error)
104 Log.Error(Globals.LogTag, "CalendarFilter Failed with error " + error);
105 throw CalendarErrorFactory.GetException(error);
108 error = Interop.Filter.AddLong(_filterHandle, propertyId, matchType, matchValue);
109 if (CalendarError.None != (CalendarError)error)
111 Log.Error(Globals.LogTag, "CalendarFilter Failed with error " + error);
112 throw CalendarErrorFactory.GetException(error);
117 /// Creates a filter with a condition for double type.
119 /// <param name="viewUri">The view URI of a filter</param>
120 /// <param name="propertyId">The property ID to add a condition</param>
121 /// <param name="matchType">The match flag</param>
122 /// <param name="matchValue">The match value</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 /// <exception cref="OutOfMemoryException">Thrown when failed due to out of memory</exception>
126 [SuppressMessage("Microsoft.Design", "CA1054:UriParametersShouldNotBeStrings")]
127 public CalendarFilter(string viewUri, uint propertyId, IntegerMatchType matchType, double matchValue)
130 error = Interop.Filter.Create(viewUri, out _filterHandle);
131 if (CalendarError.None != (CalendarError)error)
133 Log.Error(Globals.LogTag, "CalendarFilter Failed with error " + error);
134 throw CalendarErrorFactory.GetException(error);
137 error = Interop.Filter.AddDouble(_filterHandle, propertyId, matchType, matchValue);
138 if (CalendarError.None != (CalendarError)error)
140 Log.Error(Globals.LogTag, "CalendarFilter Failed with error " + error);
141 throw CalendarErrorFactory.GetException(error);
146 /// Creates a filter with a condition for CalendarTime type.
148 /// <param name="viewUri">The view URI of a filter</param>
149 /// <param name="propertyId">The property ID to add a condition</param>
150 /// <param name="matchType">The match flag</param>
151 /// <param name="matchValue">The match value</param>
152 /// <exception cref="NotSupportedException">Thrown when an invoked method is not supported</exception>
153 /// <exception cref="ArgumentException">Thrown when one of the arguments provided to a method is not valid</exception>
154 /// <exception cref="OutOfMemoryException">Thrown when failed due to out of memory</exception>
155 [SuppressMessage("Microsoft.Design", "CA1054:UriParametersShouldNotBeStrings")]
156 public CalendarFilter(string viewUri, uint propertyId, IntegerMatchType matchType, CalendarTime matchValue)
159 error = Interop.Filter.Create(viewUri, out _filterHandle);
160 if (CalendarError.None != (CalendarError)error)
162 Log.Error(Globals.LogTag, "CalendarFilter Failed with error " + error);
163 throw CalendarErrorFactory.GetException(error);
166 Interop.Record.DateTime time = CalendarRecord.ConvertCalendarTimeToStruct(matchValue);
167 error = Interop.Filter.AddCalendarTime(_filterHandle, propertyId, matchType, time);
168 if (CalendarError.None != (CalendarError)error)
170 Log.Error(Globals.LogTag, "CalendarFilter Failed with error " + error);
171 throw CalendarErrorFactory.GetException(error);
184 /// Enumeration for the filter match type of a string.
186 public enum StringMatchType
189 /// Full string, case-sensitive
193 /// Full string, case-insensitive
197 /// Sub string, case-insensitive
201 /// Start with, case-insensitive
205 /// End with, case-insensitive
215 /// Enumeration for the filter match type of an integer.
217 public enum IntegerMatchType
240 /// <>, this flag can yield poor performance
250 /// Enumeration for a filter operator.
252 public enum LogicalOperator
264 #region IDisposable Support
265 private bool disposedValue = false; // To detect redundant calls
270 /// <param name="disposing">true to release both managed and unmanaged resources; false to release only unmanaged resources.</param>
271 protected virtual void Dispose(bool disposing)
275 Log.Debug(Globals.LogTag, "Dispose :" + disposing);
277 int error = Interop.Filter.Destroy(_filterHandle);
278 if (CalendarError.None != (CalendarError)error)
280 Log.Error(Globals.LogTag, "Destroy Failed with error " + error);
281 throw CalendarErrorFactory.GetException(error);
283 disposedValue = true;
288 /// Releases all resources used by the CalendarFilter.
289 /// It should be called after having finished using of the object.
291 public void Dispose()
294 GC.SuppressFinalize(this);
299 /// Adds a condition for the string type.
301 /// <param name="logicalOperator">The operator type</param>
302 /// <param name="propertyId">The property ID to add a condition</param>
303 /// <param name="matchType">The match flag</param>
304 /// <param name="matchValue">The match value</param>
305 /// <exception cref="NotSupportedException">Thrown when an invoked method is not supported</exception>
306 /// <exception cref="ArgumentException">Thrown when one of the arguments provided to a method is not valid</exception>
307 public void AddCondition(LogicalOperator logicalOperator, uint propertyId, StringMatchType matchType, string matchValue)
309 int error = Interop.Filter.AddOperator(_filterHandle, logicalOperator);
310 if (CalendarError.None != (CalendarError)error)
312 Log.Error(Globals.LogTag, "AddCondition Failed with error " + error);
313 throw CalendarErrorFactory.GetException(error);
316 error = Interop.Filter.AddString(_filterHandle, propertyId, matchType, matchValue);
317 if (CalendarError.None != (CalendarError)error)
319 Log.Error(Globals.LogTag, "AddCondition Failed with error " + error);
320 throw CalendarErrorFactory.GetException(error);
325 /// Adds a condition for the integer type.
327 /// <param name="logicalOperator">The operator type</param>
328 /// <param name="propertyId">The property ID to add a condition</param>
329 /// <param name="matchType">The match flag</param>
330 /// <param name="matchValue">The match value</param>
331 /// <exception cref="NotSupportedException">Thrown when an invoked method is not supported</exception>
332 /// <exception cref="ArgumentException">Thrown when one of the arguments provided to a method is not valid</exception>
333 public void AddCondition(LogicalOperator logicalOperator, uint propertyId, IntegerMatchType matchType, int matchValue)
335 int error = Interop.Filter.AddOperator(_filterHandle, logicalOperator);
336 if (CalendarError.None != (CalendarError)error)
338 Log.Error(Globals.LogTag, "AddCondition Failed with error " + error);
339 throw CalendarErrorFactory.GetException(error);
342 error = Interop.Filter.AddInteger(_filterHandle, propertyId, matchType, matchValue);
343 if (CalendarError.None != (CalendarError)error)
345 Log.Error(Globals.LogTag, "AddCondition Failed with error " + error);
346 throw CalendarErrorFactory.GetException(error);
351 /// Adds a condition for the long type.
353 /// <param name="logicalOperator">The operator type</param>
354 /// <param name="propertyId">The property ID to add a condition</param>
355 /// <param name="matchType">The match flag</param>
356 /// <param name="matchValue">The match value</param>
357 /// <exception cref="NotSupportedException">Thrown when an invoked method is not supported</exception>
358 /// <exception cref="ArgumentException">Thrown when one of the arguments provided to a method is not valid</exception>
359 public void AddCondition(LogicalOperator logicalOperator, uint propertyId, IntegerMatchType matchType, long matchValue)
361 int error = Interop.Filter.AddOperator(_filterHandle, logicalOperator);
362 if (CalendarError.None != (CalendarError)error)
364 Log.Error(Globals.LogTag, "AddCondition Failed with error " + error);
365 throw CalendarErrorFactory.GetException(error);
368 error = Interop.Filter.AddLong(_filterHandle, propertyId, matchType, matchValue);
369 if (CalendarError.None != (CalendarError)error)
371 Log.Error(Globals.LogTag, "AddCondition Failed with error " + error);
372 throw CalendarErrorFactory.GetException(error);
377 /// Adds a condition for the double type.
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 an invoked method 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, double 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.AddDouble(_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 CalendarTime type.
405 /// <param name="logicalOperator">The operator type</param>
406 /// <param name="propertyId">The property ID to add a condition</param>
407 /// <param name="matchType">The match flag</param>
408 /// <param name="matchValue">The match value</param>
409 /// <exception cref="NotSupportedException">Thrown when an invoked method is not supported</exception>
410 /// <exception cref="ArgumentException">Thrown when one of the arguments provided to a method is not valid</exception>
411 public void AddCondition(LogicalOperator logicalOperator, uint propertyId, IntegerMatchType matchType, CalendarTime matchValue)
413 int error = Interop.Filter.AddOperator(_filterHandle, logicalOperator);
414 if (CalendarError.None != (CalendarError)error)
416 Log.Error(Globals.LogTag, "AddCondition Failed with error " + error);
417 throw CalendarErrorFactory.GetException(error);
420 Interop.Record.DateTime time = CalendarRecord.ConvertCalendarTimeToStruct(matchValue);
421 error = Interop.Filter.AddCalendarTime(_filterHandle, propertyId, matchType, time);
422 if (CalendarError.None != (CalendarError)error)
424 Log.Error(Globals.LogTag, "AddCondition Failed with error " + error);
425 throw CalendarErrorFactory.GetException(error);
430 /// Adds a child filter to a parent filter.
432 /// <param name="logicalOperator">The operator type</param>
433 /// <param name="filter">The child filter</param>
434 /// <exception cref="NotSupportedException">Thrown when an invoked method 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 AddFilter(LogicalOperator logicalOperator, CalendarFilter filter)
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 error = Interop.Filter.AddFilter(_filterHandle, filter._filterHandle);
446 if (CalendarError.None != (CalendarError)error)
448 Log.Error(Globals.LogTag, "AddFilter Failed with error " + error);
449 throw CalendarErrorFactory.GetException(error);