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.
25 /// <since_tizen> 4 </since_tizen>
27 /// A query is used to retrieve calendar data which satisfies a given criteria,
28 /// such as an integer property being greater than a given value,
29 /// or a string property containing a given substring.
30 /// A query needs a filter which can set the conditions for the search.
32 public class CalendarQuery:IDisposable
34 internal IntPtr _queryHandle;
39 /// <since_tizen> 4 </since_tizen>
40 /// <feature>http://tizen.org/feature/calendar</feature>
41 /// <param name="viewUri">The view URI of a query</param>
42 /// <exception cref="NotSupportedException">Thrown when feature is not supported</exception>
43 /// <exception cref="ArgumentException">Thrown when one of the arguments provided to a method is not valid</exception>
44 /// <exception cref="OutOfMemoryException">Thrown when failed due to out of memory</exception>
45 [SuppressMessage("Microsoft.Design", "CA1054:UriParametersShouldNotBeStrings")]
46 public CalendarQuery(string viewUri)
48 int error = Interop.Query.Create(viewUri, out _queryHandle);
49 if (CalendarError.None != (CalendarError)error)
51 Log.Error(Globals.LogTag, "CalendarQuery Failed with error " + error);
52 throw CalendarErrorFactory.GetException(error);
56 internal CalendarQuery(IntPtr handle)
58 _queryHandle = handle;
69 #region IDisposable Support
70 private bool disposedValue = false;
73 /// Disposes of the resources (other than memory) used by the CalendarQuery.
75 /// <param name="disposing">true to release both managed and unmanaged resources; false to release only unmanaged resources.</param>
76 protected virtual void Dispose(bool disposing)
80 Log.Debug(Globals.LogTag, "Dispose :" + disposing);
82 int error = Interop.Query.Destroy(_queryHandle);
83 if (CalendarError.None != (CalendarError)error)
85 Log.Error(Globals.LogTag, "CalendarQueryDestroy Failed with error " + error);
92 /// Releases all resources used by the CalendarQuery.
93 /// It should be called after having finished using of the object.
98 GC.SuppressFinalize(this);
103 /// Adds property IDs for projection.
105 /// <since_tizen> 4 </since_tizen>
106 /// <param name="propertyIdArray">The property ID array </param>
107 /// <feature>http://tizen.org/feature/calendar</feature>
108 /// <exception cref="NotSupportedException">Thrown when feature is not supported</exception>
109 /// <exception cref="ArgumentException">Thrown when one of the arguments provided to a method is not valid</exception>
110 public void SetProjection(uint[] propertyIdArray)
112 if (propertyIdArray == null)
114 throw new ArgumentException("Invalid Parameters Provided");
117 int error = Interop.Query.SetProjection(_queryHandle, propertyIdArray, propertyIdArray.Length);
118 if (CalendarError.None != (CalendarError)error)
120 Log.Error(Globals.LogTag, "SetProjection Failed with error " + error);
121 throw CalendarErrorFactory.GetException(error);
126 /// Sets the "distinct" option for projection.
128 /// <since_tizen> 4 </since_tizen>
129 /// <param name="set">If true it is set, otherwise if false it is unset</param>
130 /// <feature>http://tizen.org/feature/calendar</feature>
131 /// <exception cref="NotSupportedException">Thrown when feature is not supported</exception>
132 /// <exception cref="ArgumentException">Thrown when one of the arguments provided to a method is not valid</exception>
133 public void SetDistinct(bool set)
135 int error = Interop.Query.SetDistinct(_queryHandle, set);
136 if (CalendarError.None != (CalendarError)error)
138 Log.Error(Globals.LogTag, "SetDistinct Failed with error " + error);
139 throw CalendarErrorFactory.GetException(error);
144 /// Sets the filter for a query.
146 /// <since_tizen> 4 </since_tizen>
147 /// <param name="filter">The filter</param>
148 /// <feature>http://tizen.org/feature/calendar</feature>
149 /// <exception cref="NotSupportedException">Thrown when feature is not supported</exception>
150 /// <exception cref="ArgumentException">Thrown when one of the arguments provided to a method is not valid</exception>
151 public void SetFilter(CalendarFilter filter)
153 int error = Interop.Query.SetFilter(_queryHandle, filter._filterHandle);
154 if (CalendarError.None != (CalendarError)error)
156 Log.Error(Globals.LogTag, "SetFilter Failed with error " + error);
157 throw CalendarErrorFactory.GetException(error);
162 /// Sets the sort mode for a query.
164 /// <since_tizen> 4 </since_tizen>
165 /// <param name="propertyId">The property ID to sort</param>
166 /// <param name="isAscending">If true it sorts in the ascending order, otherwise if false it sorts in the descending order</param>
167 /// <feature>http://tizen.org/feature/calendar</feature>
168 /// <exception cref="NotSupportedException">Thrown when feature is not supported</exception>
169 /// <exception cref="ArgumentException">Thrown when one of the arguments provided to a method is not valid</exception>
170 public void SetSort(uint propertyId, bool isAscending)
172 int error = Interop.Query.SetSort(_queryHandle, propertyId, isAscending);
173 if (CalendarError.None != (CalendarError)error)
175 Log.Error(Globals.LogTag, "SetSort Failed with error " + error);
176 throw CalendarErrorFactory.GetException(error);