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.Collections.Generic;
23 /// Preferences for route search requests
25 public class SearchPreference : IGeocodePreference, IPlaceSearchPreference, IRouteSearchPreference, IDisposable
27 internal Interop.PreferenceHandle handle;
28 private IDictionary<string, string> _properties = new Dictionary<string, string>();
31 /// Constructors a new search preference.
33 public SearchPreference()
35 handle = new Interop.PreferenceHandle();
39 /// Constructors a new search preference.
41 internal SearchPreference(Interop.PreferenceHandle nativeHandle)
43 handle = nativeHandle;
47 /// Gets or sets preferred language.
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
55 return handle.Language;
59 Log.Info(string.Format("Language is changed from {0} to {1}", handle.Language, value));
60 handle.Language = value;
65 /// Gets or sets the maximum result count for each service request.
67 /// <remarks>Setting negative value will not have any effect on MaxResults value</remarks>
72 return handle.MaxResult;
76 Log.Info(string.Format("MaxResult is changed from {0} to {1}", handle.MaxResult, value));
77 handle.MaxResult = value;
82 /// Gets or sets distance unit.
84 public DistanceUnit Unit
88 return (DistanceUnit)handle.Unit;
92 Log.Info(string.Format("Unit is changed from {0} to {1}", handle.Unit, value));
93 handle.Unit = (Interop.DistanceUnit)value;
98 /// Gets or sets preferred country.
100 public string CountryCode
104 return handle.CountryCode;
108 Log.Info(string.Format("CountryCode is changed from {0} to {1}", handle.CountryCode, value));
109 handle.CountryCode = value;
114 /// Gets or sets search properties as key value pair.
116 public IReadOnlyDictionary<string, string> Properties
120 Action<string, string> action = (key, value) =>
122 _properties[key] = value;
125 handle.ForeachProperty(action);
126 return (IReadOnlyDictionary<string, string>)_properties;
130 foreach (var prop in value)
132 handle.SetProperty(prop.Key, prop.Value);
133 Log.Info(string.Format("Properties is changed to [{0}, {1}]", prop.Key, prop.Value));
139 /// Gets or sets route optimization.
141 public RouteOptimization Optimization
145 return (RouteOptimization)handle.Optimization;
149 Log.Info(string.Format("Optimization is changed from {0} to {1}", handle.Optimization, value));
150 handle.Optimization = (Interop.RouteOptimization)value;
155 /// Gets or sets route transport mode.
157 public TransportMode Mode
161 return (TransportMode)handle.TransportMode;
165 Log.Info(string.Format("TransportMode is changed from {0} to {1}", handle.TransportMode, value));
166 handle.TransportMode = (Interop.RouteTransportMode)value;
171 /// Gets or sets route feature weight.
173 public RouteFeatureWeight RouteFeatureWeight
177 return (RouteFeatureWeight)handle.FeatureWeight;
181 Log.Info(string.Format("RouteFeatureWeight is changed from {0} to {1}", handle.FeatureWeight, value));
182 handle.FeatureWeight = (Interop.RouteFeatureWeight)value;
187 /// Gets or sets route feature.
189 public RouteFeature RouteFeature
193 return (RouteFeature)handle.Feature;
197 Log.Info(string.Format("RouteFeature is changed from {0} to {1}", handle.Feature, value));
198 handle.Feature = (Interop.RouteRequestFeature)value;
203 /// Gets or sets if searching for alternative routes is enabled.
205 public bool SearchAlternativeRoutes
209 return handle.AlternativesEnabled;
213 Log.Info(string.Format("SearchAlternativeRoutes is {0}", (value ? "enabled" : "disabled")));
214 handle.AlternativesEnabled = value;
218 #region IDisposable Support
219 private bool _disposedValue = false;
221 protected virtual void Dispose(bool disposing)
226 _disposedValue = true;
231 /// Releases all resources used by this object.
233 public void Dispose()
236 GC.SuppressFinalize(this);