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 query is used to retrieve data which satisfies given criteria.
26 /// A query is used to retrieve calendar data which satisfies a given criteria,
27 /// such as an integer property being greater than a given value,
28 /// or a string property containing a given substring.
29 /// A query needs a filter which can set the conditions for the search.
31 public class CalendarQuery:IDisposable
33 internal IntPtr _queryHandle;
38 /// <param name="viewUri">The view URI of a query</param>
39 /// <exception cref="NotSupportedException">Thrown when an invoked method 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 CalendarQuery(string viewUri)
45 int error = Interop.Query.Create(viewUri, out _queryHandle);
46 if (CalendarError.None != (CalendarError)error)
48 Log.Error(Globals.LogTag, "CalendarQuery Failed with error " + error);
49 throw CalendarErrorFactory.GetException(error);
53 internal CalendarQuery(IntPtr handle)
55 _queryHandle = handle;
66 #region IDisposable Support
67 private bool disposedValue = false;
70 /// Disposes of the resources (other than memory) used by the CalendarQuery.
72 /// <param name="disposing">true to release both managed and unmanaged resources; false to release only unmanaged resources.</param>
73 protected virtual void Dispose(bool disposing)
77 Log.Debug(Globals.LogTag, "Dispose :" + disposing);
79 int error = Interop.Query.Destroy(_queryHandle);
80 if (CalendarError.None != (CalendarError)error)
82 Log.Error(Globals.LogTag, "CalendarQueryDestroy Failed with error " + error);
83 throw CalendarErrorFactory.GetException(error);
90 /// Releases all resources used by the CalendarQuery.
91 /// It should be called after having finished using of the object.
96 GC.SuppressFinalize(this);
101 /// Adds property IDs for projection.
103 /// <param name="propertyIdArray">The property ID array </param>
104 /// <exception cref="ArgumentException">Thrown when one of the arguments provided to a method is not valid</exception>
105 public void SetProjection(uint[] propertyIdArray)
107 int error = Interop.Query.SetProjection(_queryHandle, propertyIdArray, propertyIdArray.Length);
108 if (CalendarError.None != (CalendarError)error)
110 Log.Error(Globals.LogTag, "SetProjection Failed with error " + error);
111 throw CalendarErrorFactory.GetException(error);
116 /// Sets the "distinct" option for projection.
118 /// <param name="set">If true it is set, otherwise if false it is unset</param>
119 /// <exception cref="ArgumentException">Thrown when one of the arguments provided to a method is not valid</exception>
120 public void SetDistinct(bool set)
122 int error = Interop.Query.SetDistinct(_queryHandle, set);
123 if (CalendarError.None != (CalendarError)error)
125 Log.Error(Globals.LogTag, "SetDistinct Failed with error " + error);
126 throw CalendarErrorFactory.GetException(error);
131 /// Sets the filter for a query.
133 /// <param name="filter">The filter</param>
134 /// <exception cref="ArgumentException">Thrown when one of the arguments provided to a method is not valid</exception>
135 public void SetFilter(CalendarFilter filter)
137 int error = Interop.Query.SetFilter(_queryHandle, filter._filterHandle);
138 if (CalendarError.None != (CalendarError)error)
140 Log.Error(Globals.LogTag, "SetFilter Failed with error " + error);
141 throw CalendarErrorFactory.GetException(error);
146 /// Sets the sort mode for a query.
148 /// <param name="propertyId">The property ID to sort</param>
149 /// <param name="isAscending">If true it sorts in the ascending order, otherwise if false it sorts in the descending order</param>
150 /// <exception cref="ArgumentException">Thrown when one of the arguments provided to a method is not valid</exception>
151 public void SetSort(uint propertyId, bool isAscending)
153 int error = Interop.Query.SetSort(_queryHandle, propertyId, isAscending);
154 if (CalendarError.None != (CalendarError)error)
156 Log.Error(Globals.LogTag, "SetSort Failed with error " + error);
157 throw CalendarErrorFactory.GetException(error);