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 protected virtual void Dispose(bool disposing)
274 Log.Debug(Globals.LogTag, "Dispose :" + disposing);
276 int error = Interop.Filter.Destroy(_filterHandle);
277 if (CalendarError.None != (CalendarError)error)
279 Log.Error(Globals.LogTag, "Destroy Failed with error " + error);
280 throw CalendarErrorFactory.GetException(error);
282 disposedValue = true;
287 /// Releases all resources used by the CalendarFilter.
288 /// It should be called after having finished using of the object.
290 public void Dispose()
293 GC.SuppressFinalize(this);
298 /// Adds a condition for the string type.
300 /// <param name="logicalOperator">The operator type</param>
301 /// <param name="propertyId">The property ID to add a condition</param>
302 /// <param name="matchType">The match flag</param>
303 /// <param name="matchValue">The match value</param>
304 /// <exception cref="NotSupportedException">Thrown when an invoked method is not supported</exception>
305 /// <exception cref="ArgumentException">Thrown when one of the arguments provided to a method is not valid</exception>
306 public void AddCondition(LogicalOperator logicalOperator, uint propertyId, StringMatchType matchType, string matchValue)
308 int error = Interop.Filter.AddOperator(_filterHandle, logicalOperator);
309 if (CalendarError.None != (CalendarError)error)
311 Log.Error(Globals.LogTag, "AddCondition Failed with error " + error);
312 throw CalendarErrorFactory.GetException(error);
315 error = Interop.Filter.AddString(_filterHandle, propertyId, matchType, matchValue);
316 if (CalendarError.None != (CalendarError)error)
318 Log.Error(Globals.LogTag, "AddCondition Failed with error " + error);
319 throw CalendarErrorFactory.GetException(error);
324 /// Adds a condition for the integer type.
326 /// <param name="logicalOperator">The operator type</param>
327 /// <param name="propertyId">The property ID to add a condition</param>
328 /// <param name="matchType">The match flag</param>
329 /// <param name="matchValue">The match value</param>
330 /// <exception cref="NotSupportedException">Thrown when an invoked method is not supported</exception>
331 /// <exception cref="ArgumentException">Thrown when one of the arguments provided to a method is not valid</exception>
332 public void AddCondition(LogicalOperator logicalOperator, uint propertyId, IntegerMatchType matchType, int matchValue)
334 int error = Interop.Filter.AddOperator(_filterHandle, logicalOperator);
335 if (CalendarError.None != (CalendarError)error)
337 Log.Error(Globals.LogTag, "AddCondition Failed with error " + error);
338 throw CalendarErrorFactory.GetException(error);
341 error = Interop.Filter.AddInteger(_filterHandle, propertyId, matchType, matchValue);
342 if (CalendarError.None != (CalendarError)error)
344 Log.Error(Globals.LogTag, "AddCondition Failed with error " + error);
345 throw CalendarErrorFactory.GetException(error);
350 /// Adds a condition for the long type.
352 /// <param name="logicalOperator">The operator type</param>
353 /// <param name="propertyId">The property ID to add a condition</param>
354 /// <param name="matchType">The match flag</param>
355 /// <param name="matchValue">The match value</param>
356 /// <exception cref="NotSupportedException">Thrown when an invoked method is not supported</exception>
357 /// <exception cref="ArgumentException">Thrown when one of the arguments provided to a method is not valid</exception>
358 public void AddCondition(LogicalOperator logicalOperator, uint propertyId, IntegerMatchType matchType, long matchValue)
360 int error = Interop.Filter.AddOperator(_filterHandle, logicalOperator);
361 if (CalendarError.None != (CalendarError)error)
363 Log.Error(Globals.LogTag, "AddCondition Failed with error " + error);
364 throw CalendarErrorFactory.GetException(error);
367 error = Interop.Filter.AddLong(_filterHandle, propertyId, matchType, matchValue);
368 if (CalendarError.None != (CalendarError)error)
370 Log.Error(Globals.LogTag, "AddCondition Failed with error " + error);
371 throw CalendarErrorFactory.GetException(error);
376 /// Adds a condition for the double type.
378 /// <param name="logicalOperator">The operator type</param>
379 /// <param name="propertyId">The property ID to add a condition</param>
380 /// <param name="matchType">The match flag</param>
381 /// <param name="matchValue">The match value</param>
382 /// <exception cref="NotSupportedException">Thrown when an invoked method is not supported</exception>
383 /// <exception cref="ArgumentException">Thrown when one of the arguments provided to a method is not valid</exception>
384 public void AddCondition(LogicalOperator logicalOperator, uint propertyId, IntegerMatchType matchType, double matchValue)
386 int error = Interop.Filter.AddOperator(_filterHandle, logicalOperator);
387 if (CalendarError.None != (CalendarError)error)
389 Log.Error(Globals.LogTag, "AddCondition Failed with error " + error);
390 throw CalendarErrorFactory.GetException(error);
393 error = Interop.Filter.AddDouble(_filterHandle, propertyId, matchType, matchValue);
394 if (CalendarError.None != (CalendarError)error)
396 Log.Error(Globals.LogTag, "AddCondition Failed with error " + error);
397 throw CalendarErrorFactory.GetException(error);
402 /// Adds a condition for the CalendarTime type.
404 /// <param name="logicalOperator">The operator type</param>
405 /// <param name="propertyId">The property ID to add a condition</param>
406 /// <param name="matchType">The match flag</param>
407 /// <param name="matchValue">The match value</param>
408 /// <exception cref="NotSupportedException">Thrown when an invoked method is not supported</exception>
409 /// <exception cref="ArgumentException">Thrown when one of the arguments provided to a method is not valid</exception>
410 public void AddCondition(LogicalOperator logicalOperator, uint propertyId, IntegerMatchType matchType, CalendarTime matchValue)
412 int error = Interop.Filter.AddOperator(_filterHandle, logicalOperator);
413 if (CalendarError.None != (CalendarError)error)
415 Log.Error(Globals.LogTag, "AddCondition Failed with error " + error);
416 throw CalendarErrorFactory.GetException(error);
419 Interop.Record.DateTime time = CalendarRecord.ConvertCalendarTimeToStruct(matchValue);
420 error = Interop.Filter.AddCalendarTime(_filterHandle, propertyId, matchType, time);
421 if (CalendarError.None != (CalendarError)error)
423 Log.Error(Globals.LogTag, "AddCondition Failed with error " + error);
424 throw CalendarErrorFactory.GetException(error);
429 /// Adds a child filter to a parent filter.
431 /// <param name="logicalOperator">The operator type</param>
432 /// <param name="filter">The child filter</param>
433 /// <exception cref="NotSupportedException">Thrown when an invoked method is not supported</exception>
434 /// <exception cref="ArgumentException">Thrown when one of the arguments provided to a method is not valid</exception>
435 public void AddFilter(LogicalOperator logicalOperator, CalendarFilter filter)
437 int error = Interop.Filter.AddOperator(_filterHandle, logicalOperator);
438 if (CalendarError.None != (CalendarError)error)
440 Log.Error(Globals.LogTag, "AddCondition Failed with error " + error);
441 throw CalendarErrorFactory.GetException(error);
444 error = Interop.Filter.AddFilter(_filterHandle, filter._filterHandle);
445 if (CalendarError.None != (CalendarError)error)
447 Log.Error(Globals.LogTag, "AddFilter Failed with error " + error);
448 throw CalendarErrorFactory.GetException(error);