Fix Properties of SearchPreference didn't work
[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     public class SearchPreference : IGeocodePreference, IPlaceSearchPreference, IRouteSearchPreference, IDisposable
26     {
27         internal Interop.PreferenceHandle handle;
28         private IDictionary<string, string> _properties = new Dictionary<string, string>();
29
30         /// <summary>
31         /// Constructors a new search preference.
32         /// </summary>
33         public SearchPreference()
34         {
35             handle = new Interop.PreferenceHandle();
36         }
37
38         /// <summary>
39         /// Constructors a new search preference.
40         /// </summary>
41         internal SearchPreference(Interop.PreferenceHandle nativeHandle)
42         {
43             handle = nativeHandle;
44         }
45
46         /// <summary>
47         /// Gets or sets preferred language.
48         /// </summary>
49         /// <remarks>Language should be specified as an ISO 3166 alpha-2 two letter country-code
50         /// followed by ISO 639-1 for the two-letter language code.<br/>e.g. "ko-KR", "en-US".</remarks>
51         public string Language
52         {
53             get
54             {
55                 return handle.Language;
56             }
57             set
58             {
59                 Log.Info(string.Format("Language is changed from {0} to {1}", handle.Language, value));
60                 handle.Language = value;
61             }
62         }
63
64         /// <summary>
65         /// Gets or sets the maximum result count for each service request.
66         /// </summary>
67         /// <remarks>Setting negative value will not have any effect on MaxResults value</remarks>
68         public int MaxResults
69         {
70             get
71             {
72                 return handle.MaxResult;
73             }
74             set
75             {
76                 Log.Info(string.Format("MaxResult is changed from {0} to {1}", handle.MaxResult, value));
77                 handle.MaxResult = value;
78             }
79         }
80
81         /// <summary>
82         /// Gets or sets distance unit.
83         /// </summary>
84         public DistanceUnit Unit
85         {
86             get
87             {
88                 return (DistanceUnit)handle.Unit;
89             }
90             set
91             {
92                 Log.Info(string.Format("Unit is changed from {0} to {1}", handle.Unit, value));
93                 handle.Unit = (Interop.DistanceUnit)value;
94             }
95         }
96
97         /// <summary>
98         /// Gets or sets preferred country.
99         /// </summary>
100         public string CountryCode
101         {
102             get
103             {
104                 return handle.CountryCode;
105             }
106             set
107             {
108                 Log.Info(string.Format("CountryCode is changed from {0} to {1}", handle.CountryCode, value));
109                 handle.CountryCode = value;
110             }
111         }
112
113         /// <summary>
114         /// Gets or sets search properties as key value pair.
115         /// </summary>
116         public IReadOnlyDictionary<string, string> Properties
117         {
118             get
119             {
120                 Action<string, string> action = (key, value) =>
121                 {
122                     _properties[key] = value;
123                 };
124
125                 handle.ForeachProperty(action);
126                 return (IReadOnlyDictionary<string, string>)_properties;
127             }
128             set
129             {
130                 foreach (var prop in value)
131                 {
132                     handle.SetProperty(prop.Key, prop.Value);
133                     Log.Info(string.Format("Properties is changed to [{0}, {1}]", prop.Key, prop.Value));
134                 }
135             }
136         }
137
138         /// <summary>
139         /// Gets or sets route optimization.
140         /// </summary>
141         public RouteOptimization Optimization
142         {
143             get
144             {
145                 return (RouteOptimization)handle.Optimization;
146             }
147             set
148             {
149                 Log.Info(string.Format("Optimization is changed from {0} to {1}", handle.Optimization, value));
150                 handle.Optimization = (Interop.RouteOptimization)value;
151             }
152         }
153
154         /// <summary>
155         /// Gets or sets route transport mode.
156         /// </summary>
157         public TransportMode Mode
158         {
159             get
160             {
161                 return (TransportMode)handle.TransportMode;
162             }
163             set
164             {
165                 Log.Info(string.Format("TransportMode is changed from {0} to {1}", handle.TransportMode, value));
166                 handle.TransportMode = (Interop.RouteTransportMode)value;
167             }
168         }
169
170         /// <summary>
171         /// Gets or sets route feature weight.
172         /// </summary>
173         public RouteFeatureWeight RouteFeatureWeight
174         {
175             get
176             {
177                 return (RouteFeatureWeight)handle.FeatureWeight;
178             }
179             set
180             {
181                 Log.Info(string.Format("RouteFeatureWeight is changed from {0} to {1}", handle.FeatureWeight, value));
182                 handle.FeatureWeight = (Interop.RouteFeatureWeight)value;
183             }
184         }
185
186         /// <summary>
187         /// Gets or sets route feature.
188         /// </summary>
189         public RouteFeature RouteFeature
190         {
191             get
192             {
193                 return (RouteFeature)handle.Feature;
194             }
195             set
196             {
197                 Log.Info(string.Format("RouteFeature is changed from {0} to {1}", handle.Feature, value));
198                 handle.Feature = (Interop.RouteRequestFeature)value;
199             }
200         }
201
202         /// <summary>
203         /// Gets or sets if searching for alternative routes is enabled.
204         /// </summary>
205         public bool SearchAlternativeRoutes
206         {
207             get
208             {
209                 return handle.AlternativesEnabled;
210             }
211             set
212             {
213                 Log.Info(string.Format("SearchAlternativeRoutes is {0}", (value ? "enabled" : "disabled")));
214                 handle.AlternativesEnabled = value;
215             }
216         }
217
218         #region IDisposable Support
219         private bool _disposedValue = false;
220
221         protected virtual void Dispose(bool disposing)
222         {
223             if (!_disposedValue)
224             {
225                 handle.Dispose();
226                 _disposedValue = true;
227             }
228         }
229
230         /// <summary>
231         /// Releases all resources used by this object.
232         /// </summary>
233         public void Dispose()
234         {
235             Dispose(true);
236             GC.SuppressFinalize(this);
237         }
238         #endregion
239     }
240 }