[Maps] Modify diposing routines
[platform/core/csapi/tizenfx.git] / src / Tizen.Maps / Tizen.Maps / SearchPreference.cs
1 /*
2  * Copyright (c) 2016 Samsung Electronics Co., Ltd All Rights Reserved
3  *
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
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
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.
15  */
16
17 using System;
18 using System.Collections.Generic;
19
20 namespace Tizen.Maps
21 {
22     /// <summary>
23     /// Preferences for route search requests.
24     /// </summary>
25     /// <since_tizen> 3 </since_tizen>
26     public class SearchPreference : IGeocodePreference, IPlaceSearchPreference, IRouteSearchPreference, IDisposable
27     {
28         internal Interop.PreferenceHandle handle;
29         private IDictionary<string, string> _properties = new Dictionary<string, string>();
30
31         /// <summary>
32         /// Constructor for a new search preference.
33         /// </summary>
34         /// <since_tizen> 3 </since_tizen>
35         public SearchPreference()
36         {
37             handle = new Interop.PreferenceHandle();
38         }
39
40         /// <summary>
41         /// Constructor for a new search preference.
42         /// </summary>
43         internal SearchPreference(Interop.PreferenceHandle nativeHandle)
44         {
45             handle = nativeHandle;
46         }
47
48         /// <summary>
49         /// Destroy the SearchPreference object.
50         /// </summary>
51         ~SearchPreference()
52         {
53             Dispose(false);
54         }
55
56         /// <summary>
57         /// Gets or sets a preferred language.
58         /// </summary>
59         /// <since_tizen> 3 </since_tizen>
60         /// <remarks>Language should be specified as an ISO 3166 alpha-2 two letter country-code
61         /// followed by ISO 639-1 for the two-letter language code.<br/>e.g. "ko-KR", "en-US".</remarks>
62         public string Language
63         {
64             get
65             {
66                 return handle.Language;
67             }
68             set
69             {
70                 Log.Info(string.Format("Language is changed from {0} to {1}", handle.Language, value));
71                 handle.Language = value;
72             }
73         }
74
75         /// <summary>
76         /// Gets or sets the maximum result count for each service request.
77         /// </summary>
78         /// <since_tizen> 3 </since_tizen>
79         /// <remarks>Setting negative value will not have any effect on MaxResults value.</remarks>
80         public int MaxResults
81         {
82             get
83             {
84                 return handle.MaxResult;
85             }
86             set
87             {
88                 Log.Info(string.Format("MaxResult is changed from {0} to {1}", handle.MaxResult, value));
89                 handle.MaxResult = value;
90             }
91         }
92
93         /// <summary>
94         /// Gets or sets the distance unit.
95         /// </summary>
96         /// <since_tizen> 3 </since_tizen>
97         public DistanceUnit Unit
98         {
99             get
100             {
101                 return (DistanceUnit)handle.Unit;
102             }
103             set
104             {
105                 Log.Info(string.Format("Unit is changed from {0} to {1}", handle.Unit, value));
106                 handle.Unit = (Interop.DistanceUnit)value;
107             }
108         }
109
110         /// <summary>
111         /// Gets or sets the preferred country.
112         /// </summary>
113         /// <since_tizen> 3 </since_tizen>
114         public string CountryCode
115         {
116             get
117             {
118                 return handle.CountryCode;
119             }
120             set
121             {
122                 Log.Info(string.Format("CountryCode is changed from {0} to {1}", handle.CountryCode, value));
123                 handle.CountryCode = value;
124             }
125         }
126
127         /// <summary>
128         /// Gets or sets the search properties as a key value pair.
129         /// </summary>
130         /// <since_tizen> 3 </since_tizen>
131         public IReadOnlyDictionary<string, string> Properties
132         {
133             get
134             {
135                 Action<string, string> action = (key, value) =>
136                 {
137                     _properties[key] = value;
138                 };
139
140                 handle.ForeachProperty(action);
141                 return (IReadOnlyDictionary<string, string>)_properties;
142             }
143             set
144             {
145                 foreach (var prop in value)
146                 {
147                     _properties[prop.Key] = prop.Value;
148                     handle.SetProperty(prop.Key, prop.Value);
149                     Log.Info(string.Format("Properties is changed to [{0}, {1}]", prop.Key, prop.Value));
150                 }
151             }
152         }
153
154         /// <summary>
155         /// Gets or sets the route optimization.
156         /// </summary>
157         /// <since_tizen> 3 </since_tizen>
158         public RouteOptimization Optimization
159         {
160             get
161             {
162                 return (RouteOptimization)handle.Optimization;
163             }
164             set
165             {
166                 Log.Info(string.Format("Optimization is changed from {0} to {1}", handle.Optimization, value));
167                 handle.Optimization = (Interop.RouteOptimization)value;
168             }
169         }
170
171         /// <summary>
172         /// Gets or sets the route transport mode.
173         /// </summary>
174         /// <since_tizen> 3 </since_tizen>
175         public TransportMode Mode
176         {
177             get
178             {
179                 return (TransportMode)handle.TransportMode;
180             }
181             set
182             {
183                 Log.Info(string.Format("TransportMode is changed from {0} to {1}", handle.TransportMode, value));
184                 handle.TransportMode = (Interop.RouteTransportMode)value;
185             }
186         }
187
188         /// <summary>
189         /// Gets or sets the route feature weight.
190         /// </summary>
191         /// <since_tizen> 3 </since_tizen>
192         public RouteFeatureWeight RouteFeatureWeight
193         {
194             get
195             {
196                 return (RouteFeatureWeight)handle.FeatureWeight;
197             }
198             set
199             {
200                 Log.Info(string.Format("RouteFeatureWeight is changed from {0} to {1}", handle.FeatureWeight, value));
201                 handle.FeatureWeight = (Interop.RouteFeatureWeight)value;
202             }
203         }
204
205         /// <summary>
206         /// Gets or sets the route feature.
207         /// </summary>
208         /// <since_tizen> 3 </since_tizen>
209         public RouteFeature RouteFeature
210         {
211             get
212             {
213                 return (RouteFeature)handle.Feature;
214             }
215             set
216             {
217                 Log.Info(string.Format("RouteFeature is changed from {0} to {1}", handle.Feature, value));
218                 handle.Feature = (Interop.RouteRequestFeature)value;
219             }
220         }
221
222         /// <summary>
223         /// Gets or sets if the searching for alternative routes is enabled.
224         /// </summary>
225         /// <since_tizen> 3 </since_tizen>
226         public bool SearchAlternativeRoutes
227         {
228             get
229             {
230                 return handle.AlternativesEnabled;
231             }
232             set
233             {
234                 Log.Info(string.Format("SearchAlternativeRoutes is {0}", (value ? "enabled" : "disabled")));
235                 handle.AlternativesEnabled = value;
236             }
237         }
238
239         #region IDisposable Support
240         private bool _disposedValue = false;
241
242         /// <summary>
243         /// Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.
244         /// </summary>
245         /// <param name="disposing">If true, managed and unmanaged resources can be disposed, otherwise only unmanaged resources can be disposed.</param>
246         /// <since_tizen> 3 </since_tizen>
247         protected virtual void Dispose(bool disposing)
248         {
249             if (!_disposedValue)
250             {
251                 handle?.Dispose();
252                 _disposedValue = true;
253             }
254         }
255
256         /// <summary>
257         /// Releases all the resources used by this object.
258         /// </summary>
259         /// <since_tizen> 3 </since_tizen>
260         public void Dispose()
261         {
262             Dispose(true);
263             GC.SuppressFinalize(this);
264         }
265         #endregion
266     }
267 }