/*
* Copyright (c) 2018 Samsung Electronics Co., Ltd All Rights Reserved
*
* Licensed under the Apache License, Version 2.0 (the License);
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an AS IS BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
using System;
using System.Diagnostics.CodeAnalysis;
namespace Tizen.Pims.Calendar
{
///
/// A filter includes the conditions for the search.
///
/// 4
public class CalendarFilter:IDisposable
{
internal IntPtr _filterHandle;
///
/// Creates a filter with a condition for a string type.
///
/// 4
/// http://tizen.org/feature/calendar
/// The view URI of a filter.
/// The property ID to add a condition.
/// The match flag.
/// The match value.
/// Thrown when the feature is not supported.
/// Thrown when one of the arguments provided to a method is not valid.
/// Thrown when failed due to out of memory.
[SuppressMessage("Microsoft.Design", "CA1054:UriParametersShouldNotBeStrings")]
public CalendarFilter(string viewUri, uint propertyId, StringMatchType matchType, string matchValue)
{
int error = 0;
error = Interop.Filter.Create(viewUri, out _filterHandle);
if (CalendarError.None != (CalendarError)error)
{
Log.Error(Globals.LogTag, "CalendarFilter Failed with error " + error);
throw CalendarErrorFactory.GetException(error);
}
error = Interop.Filter.AddString(_filterHandle, propertyId, matchType, matchValue);
if (CalendarError.None != (CalendarError)error)
{
Interop.Filter.Destroy(_filterHandle);
Log.Error(Globals.LogTag, "CalendarFilter Failed with error " + error);
throw CalendarErrorFactory.GetException(error);
}
}
///
/// Creates a filter with a condition for an integer type.
///
/// 4
/// http://tizen.org/feature/calendar
/// The view URI of a filter.
/// The property ID to add a condition.
/// The match flag.
/// The match value.
/// Thrown when the feature is not supported.
/// Thrown when one of the arguments provided to a method is not valid.
/// Thrown when failed due to out of memory.
[SuppressMessage("Microsoft.Design", "CA1054:UriParametersShouldNotBeStrings")]
public CalendarFilter(string viewUri, uint propertyId, IntegerMatchType matchType, int matchValue)
{
int error = 0;
error = Interop.Filter.Create(viewUri, out _filterHandle);
if (CalendarError.None != (CalendarError)error)
{
Log.Error(Globals.LogTag, "CalendarFilter Failed with error " + error);
throw CalendarErrorFactory.GetException(error);
}
error = Interop.Filter.AddInteger(_filterHandle, propertyId, matchType, matchValue);
if (CalendarError.None != (CalendarError)error)
{
Interop.Filter.Destroy(_filterHandle);
Log.Error(Globals.LogTag, "CalendarFilter Failed with error " + error);
throw CalendarErrorFactory.GetException(error);
}
}
///
/// Creates a filter with a condition for a long type.
///
/// 4
/// http://tizen.org/feature/calendar
/// The view URI of a filter.
/// The property ID to add a condition.
/// The match flag.
/// The match value.
/// Thrown when the feature is not supported.
/// Thrown when one of the arguments provided to a method is not valid.
/// Thrown when failed due to out of memory.
[SuppressMessage("Microsoft.Design", "CA1054:UriParametersShouldNotBeStrings")]
public CalendarFilter(string viewUri, uint propertyId, IntegerMatchType matchType, long matchValue)
{
int error = 0;
error = Interop.Filter.Create(viewUri, out _filterHandle);
if (CalendarError.None != (CalendarError)error)
{
Log.Error(Globals.LogTag, "CalendarFilter Failed with error " + error);
throw CalendarErrorFactory.GetException(error);
}
error = Interop.Filter.AddLong(_filterHandle, propertyId, matchType, matchValue);
if (CalendarError.None != (CalendarError)error)
{
Interop.Filter.Destroy(_filterHandle);
Log.Error(Globals.LogTag, "CalendarFilter Failed with error " + error);
throw CalendarErrorFactory.GetException(error);
}
}
///
/// Creates a filter with a condition for a double type.
///
/// 4
/// http://tizen.org/feature/calendar
/// The view URI of a filter.
/// The property ID to add a condition.
/// The match flag.
/// The match value.
/// Thrown when the feature is not supported.
/// Thrown when one of the arguments provided to a method is not valid.
/// Thrown when failed due to out of memory.
[SuppressMessage("Microsoft.Design", "CA1054:UriParametersShouldNotBeStrings")]
public CalendarFilter(string viewUri, uint propertyId, IntegerMatchType matchType, double matchValue)
{
int error = 0;
error = Interop.Filter.Create(viewUri, out _filterHandle);
if (CalendarError.None != (CalendarError)error)
{
Log.Error(Globals.LogTag, "CalendarFilter Failed with error " + error);
throw CalendarErrorFactory.GetException(error);
}
error = Interop.Filter.AddDouble(_filterHandle, propertyId, matchType, matchValue);
if (CalendarError.None != (CalendarError)error)
{
Interop.Filter.Destroy(_filterHandle);
Log.Error(Globals.LogTag, "CalendarFilter Failed with error " + error);
throw CalendarErrorFactory.GetException(error);
}
}
///
/// Creates a filter with a condition for the CalendarTime type.
///
/// 4
/// http://tizen.org/feature/calendar
/// The view URI of a filter.
/// The property ID to add a condition.
/// The match flag.
/// The match value.
/// Thrown when the feature is not supported.
/// Thrown when one of the arguments provided to a method is not valid.
/// Thrown when failed due to out of memory.
[SuppressMessage("Microsoft.Design", "CA1054:UriParametersShouldNotBeStrings")]
public CalendarFilter(string viewUri, uint propertyId, IntegerMatchType matchType, CalendarTime matchValue)
{
int error = 0;
error = Interop.Filter.Create(viewUri, out _filterHandle);
if (CalendarError.None != (CalendarError)error)
{
Log.Error(Globals.LogTag, "CalendarFilter Failed with error " + error);
throw CalendarErrorFactory.GetException(error);
}
IntPtr time = CalendarRecord.ConvertCalendarTimeToStruct(matchValue);
error = Interop.Filter.AddCalendarTime(_filterHandle, propertyId, matchType, time);
if (CalendarError.None != (CalendarError)error)
{
Interop.Filter.Destroy(_filterHandle);
Log.Error(Globals.LogTag, "CalendarFilter Failed with error " + error);
throw CalendarErrorFactory.GetException(error);
}
}
///
/// Destroys the filter.
///
~CalendarFilter()
{
Dispose(false);
}
///
/// Enumeration for the filter match type of a string.
///
/// 4
public enum StringMatchType
{
///
/// Full string, case-sensitive.
///
Exactly,
///
/// Full string, case-insensitive.
///
FullString,
///
/// Sub-string, case-insensitive.
///
Contains,
///
/// Starts with, case-insensitive.
///
StartsWith,
///
/// Ends with, case-insensitive.
///
EndsWith,
///
/// IS NOT NULL.
///
Exists,
}
///
/// Enumeration for the filter match type of an integer.
///
/// 4
public enum IntegerMatchType
{
///
/// '='
///
Equal,
///
/// '>'
///
GreaterThan,
///
/// '>='
///
GreaterThanOrEqual,
///
/// <
///
LessThan,
///
/// <=
///
LessThanOrEqual,
///
/// <>, this flag can yield poor performance.
///
NotEqual,
///
/// IS NULL.
///
None,
}
///
/// Enumeration for a filter operator.
///
/// 4
public enum LogicalOperator
{
///
/// And.
///
And,
///
/// Or.
///
Or,
}
#region IDisposable Support
private bool disposedValue = false; // To detect redundant calls
///
/// Dispose.
///
/// true to release both managed and unmanaged resources, false to release only unmanaged resources.
/// 4
protected virtual void Dispose(bool disposing)
{
if (!disposedValue)
{
Log.Debug(Globals.LogTag, "Dispose :" + disposing);
int error = Interop.Filter.Destroy(_filterHandle);
if (CalendarError.None != (CalendarError)error)
{
Log.Error(Globals.LogTag, "Destroy Failed with error " + error);
}
disposedValue = true;
}
}
///
/// Releases all the resources used by the CalendarFilter.
/// It should be called after having finished using the object.
///
/// 4
public void Dispose()
{
Dispose(true);
GC.SuppressFinalize(this);
}
#endregion
///
/// Adds a condition for the string type.
///
/// 4
/// http://tizen.org/feature/calendar
/// The operator type.
/// The property ID to add a condition.
/// The match flag.
/// The match value.
/// Thrown when the feature is not supported.
/// Thrown when one of the arguments provided to a method is not valid.
public void AddCondition(LogicalOperator logicalOperator, uint propertyId, StringMatchType matchType, string matchValue)
{
int error = Interop.Filter.AddOperator(_filterHandle, logicalOperator);
if (CalendarError.None != (CalendarError)error)
{
Log.Error(Globals.LogTag, "AddCondition Failed with error " + error);
throw CalendarErrorFactory.GetException(error);
}
error = Interop.Filter.AddString(_filterHandle, propertyId, matchType, matchValue);
if (CalendarError.None != (CalendarError)error)
{
Log.Error(Globals.LogTag, "AddCondition Failed with error " + error);
throw CalendarErrorFactory.GetException(error);
}
}
///
/// Adds a condition for the integer type.
///
/// 4
/// http://tizen.org/feature/calendar
/// The operator type.
/// The property ID to add a condition.
/// The match flag.
/// The match value.
/// Thrown when the feature is not supported.
/// Thrown when one of the arguments provided to a method is not valid.
public void AddCondition(LogicalOperator logicalOperator, uint propertyId, IntegerMatchType matchType, int matchValue)
{
int error = Interop.Filter.AddOperator(_filterHandle, logicalOperator);
if (CalendarError.None != (CalendarError)error)
{
Log.Error(Globals.LogTag, "AddCondition Failed with error " + error);
throw CalendarErrorFactory.GetException(error);
}
error = Interop.Filter.AddInteger(_filterHandle, propertyId, matchType, matchValue);
if (CalendarError.None != (CalendarError)error)
{
Log.Error(Globals.LogTag, "AddCondition Failed with error " + error);
throw CalendarErrorFactory.GetException(error);
}
}
///
/// Adds a condition for the long type.
///
/// 4
/// http://tizen.org/feature/calendar
/// The operator type.
/// The property ID to add a condition.
/// The match flag.
/// The match value.
/// Thrown when the feature is not supported.
/// Thrown when one of the arguments provided to a method is not valid.
public void AddCondition(LogicalOperator logicalOperator, uint propertyId, IntegerMatchType matchType, long matchValue)
{
int error = Interop.Filter.AddOperator(_filterHandle, logicalOperator);
if (CalendarError.None != (CalendarError)error)
{
Log.Error(Globals.LogTag, "AddCondition Failed with error " + error);
throw CalendarErrorFactory.GetException(error);
}
error = Interop.Filter.AddLong(_filterHandle, propertyId, matchType, matchValue);
if (CalendarError.None != (CalendarError)error)
{
Log.Error(Globals.LogTag, "AddCondition Failed with error " + error);
throw CalendarErrorFactory.GetException(error);
}
}
///
/// Adds a condition for the double type.
///
/// 4
/// http://tizen.org/feature/calendar
/// The operator type.
/// The property ID to add a condition.
/// The match flag.
/// The match value.
/// Thrown when the feature is not supported.
/// Thrown when one of the arguments provided to a method is not valid.
public void AddCondition(LogicalOperator logicalOperator, uint propertyId, IntegerMatchType matchType, double matchValue)
{
int error = Interop.Filter.AddOperator(_filterHandle, logicalOperator);
if (CalendarError.None != (CalendarError)error)
{
Log.Error(Globals.LogTag, "AddCondition Failed with error " + error);
throw CalendarErrorFactory.GetException(error);
}
error = Interop.Filter.AddDouble(_filterHandle, propertyId, matchType, matchValue);
if (CalendarError.None != (CalendarError)error)
{
Log.Error(Globals.LogTag, "AddCondition Failed with error " + error);
throw CalendarErrorFactory.GetException(error);
}
}
///
/// Adds a condition for the CalendarTime type.
///
/// 4
/// http://tizen.org/feature/calendar
/// The operator type.
/// The property ID to add a condition.
/// The match flag.
/// The match value.
/// Thrown when the feature is not supported.
/// Thrown when one of the arguments provided to a method is not valid.
public void AddCondition(LogicalOperator logicalOperator, uint propertyId, IntegerMatchType matchType, CalendarTime matchValue)
{
int error = Interop.Filter.AddOperator(_filterHandle, logicalOperator);
if (CalendarError.None != (CalendarError)error)
{
Log.Error(Globals.LogTag, "AddCondition Failed with error " + error);
throw CalendarErrorFactory.GetException(error);
}
IntPtr time = CalendarRecord.ConvertCalendarTimeToStruct(matchValue);
error = Interop.Filter.AddCalendarTime(_filterHandle, propertyId, matchType, time);
if (CalendarError.None != (CalendarError)error)
{
Log.Error(Globals.LogTag, "AddCondition Failed with error " + error);
throw CalendarErrorFactory.GetException(error);
}
}
///
/// Adds a child filter to a parent filter.
///
/// 4
/// http://tizen.org/feature/calendar
/// The operator type.
/// The child filter.
/// Thrown when the feature is not supported.
/// Thrown when one of the arguments provided to a method is not valid.
public void AddFilter(LogicalOperator logicalOperator, CalendarFilter filter)
{
int error = Interop.Filter.AddOperator(_filterHandle, logicalOperator);
if (CalendarError.None != (CalendarError)error)
{
Log.Error(Globals.LogTag, "AddCondition Failed with error " + error);
throw CalendarErrorFactory.GetException(error);
}
error = Interop.Filter.AddFilter(_filterHandle, filter._filterHandle);
if (CalendarError.None != (CalendarError)error)
{
Log.Error(Globals.LogTag, "AddFilter Failed with error " + error);
throw CalendarErrorFactory.GetException(error);
}
}
}
}