예제 #1
0
        /// <summary>
        /// Gets the feature by its <c>Handle</c>.
        /// </summary>
        /// <param name="handle">The <see cref="Handle"/>.</param>
        /// <returns>A running TPL Task which you can use and read its result from the .Result property</returns>
        public Task<Feature> GetFeatureAsync(Handle handle)
        {
            if (handle == null)
            {
                throw new ArgumentNullException("handle");
            }

            return Task.Factory.StartNew(() => this.GetFeature(handle));
        }
예제 #2
0
 /// <summary>
 /// Gets the feature request.
 /// </summary>
 /// <param name="handle">The SimpleGeo feature handle.</param>
 /// <returns>A <c>RestRequest</c> prepared for Feature fetching but which you can either manipulate further or e.g. use in raw Async calls</returns>
 public RestRequest GetFeatureRequest(Handle handle)
 {
     return new RestRequest { Path = string.Format("features/{0}.json", handle) };
 }
예제 #3
0
        /// <summary>
        /// Gets the feature by its <c>Handle</c>.
        /// </summary>
        /// <param name="handle">The <see cref="Handle"/>.</param>
        /// <returns>The requested <c>Feature</c> if found, otherwise <c>null</c>.</returns>
        public Feature GetFeature(Handle handle)
        {
            if (handle == null)
            {
                throw new ArgumentNullException("handle");
            }

            var request = this.GetFeatureRequest(handle);

            string responseContent;

            lock (clientLocker)
            {
                responseContent = Request(request).Content;
            }

            return JsonConvert.DeserializeObject<Feature>(
                responseContent,
                new JsonSerializerSettings { TypeNameHandling = TypeNameHandling.All, TypeNameAssemblyFormat = FormatterAssemblyStyle.Simple });
        }