/* * Copyright (c) 2016 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 query is used to retrieve data which satisfies given criteria. /// /// 4 /// /// A query is used to retrieve calendar data which satisfies a given criteria, /// such as an integer property being greater than a given value, /// or a string property containing a given substring. /// A query needs a filter which can set the conditions for the search. /// public class CalendarQuery:IDisposable { internal IntPtr _queryHandle; /// /// Creates a query. /// /// 4 /// http://tizen.org/feature/calendar /// The view URI of a query /// Thrown when 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 CalendarQuery(string viewUri) { int error = Interop.Query.Create(viewUri, out _queryHandle); if (CalendarError.None != (CalendarError)error) { Log.Error(Globals.LogTag, "CalendarQuery Failed with error " + error); throw CalendarErrorFactory.GetException(error); } } internal CalendarQuery(IntPtr handle) { _queryHandle = handle; } /// /// Destructor /// ~CalendarQuery() { Dispose(false); } #region IDisposable Support private bool disposedValue = false; /// /// Disposes of the resources (other than memory) used by the CalendarQuery. /// /// true to release both managed and unmanaged resources; false to release only unmanaged resources. protected virtual void Dispose(bool disposing) { if (!disposedValue) { Log.Debug(Globals.LogTag, "Dispose :" + disposing); int error = Interop.Query.Destroy(_queryHandle); if (CalendarError.None != (CalendarError)error) { Log.Error(Globals.LogTag, "CalendarQueryDestroy Failed with error " + error); throw CalendarErrorFactory.GetException(error); } disposedValue = true; } } /// /// Releases all resources used by the CalendarQuery. /// It should be called after having finished using of the object. /// public void Dispose() { Dispose(true); GC.SuppressFinalize(this); } #endregion /// /// Adds property IDs for projection. /// /// 4 /// The property ID array /// http://tizen.org/feature/calendar /// Thrown when feature is not supported /// Thrown when one of the arguments provided to a method is not valid public void SetProjection(uint[] propertyIdArray) { int error = Interop.Query.SetProjection(_queryHandle, propertyIdArray, propertyIdArray.Length); if (CalendarError.None != (CalendarError)error) { Log.Error(Globals.LogTag, "SetProjection Failed with error " + error); throw CalendarErrorFactory.GetException(error); } } /// /// Sets the "distinct" option for projection. /// /// 4 /// If true it is set, otherwise if false it is unset /// http://tizen.org/feature/calendar /// Thrown when feature is not supported /// Thrown when one of the arguments provided to a method is not valid public void SetDistinct(bool set) { int error = Interop.Query.SetDistinct(_queryHandle, set); if (CalendarError.None != (CalendarError)error) { Log.Error(Globals.LogTag, "SetDistinct Failed with error " + error); throw CalendarErrorFactory.GetException(error); } } /// /// Sets the filter for a query. /// /// 4 /// The filter /// http://tizen.org/feature/calendar /// Thrown when feature is not supported /// Thrown when one of the arguments provided to a method is not valid public void SetFilter(CalendarFilter filter) { int error = Interop.Query.SetFilter(_queryHandle, filter._filterHandle); if (CalendarError.None != (CalendarError)error) { Log.Error(Globals.LogTag, "SetFilter Failed with error " + error); throw CalendarErrorFactory.GetException(error); } } /// /// Sets the sort mode for a query. /// /// 4 /// The property ID to sort /// If true it sorts in the ascending order, otherwise if false it sorts in the descending order /// http://tizen.org/feature/calendar /// Thrown when feature is not supported /// Thrown when one of the arguments provided to a method is not valid public void SetSort(uint propertyId, bool isAscending) { int error = Interop.Query.SetSort(_queryHandle, propertyId, isAscending); if (CalendarError.None != (CalendarError)error) { Log.Error(Globals.LogTag, "SetSort Failed with error " + error); throw CalendarErrorFactory.GetException(error); } } } }