コード例 #1
0
        public SuggestionQueryResult Map(IEnumerable <GeoDataEntry> results, SuggestionQuery suggestionQuery, ILinkBuilder linkBuilder)
        {
            if (linkBuilder == null)
            {
                throw new ArgumentNullException(nameof(linkBuilder));
            }

            IEnumerable <Suggestion> suggestions = null;

            if (results?.Count() > 0)
            {
                suggestions = CertaintyRanker.Rank(results, suggestionQuery.Q, suggestionQuery.Coordinates())
                              .OrderByDescending(o => o.Certainty)
                              .Take(suggestionQuery.MaxResults)
                              .Select(c => new Suggestion()
                {
                    Certainty = c.Certainty,
                    Longitude = c.Entry.Longitude,
                    Latitude  = c.Entry.Latitude,
                    Name      = c.Entry.Name,
                    Links     = linkBuilder.BuildLinks(c.Entry)
                }).OrderByDescending(r => r.Certainty);
            }

            //if suggestions are null, return an empty array
            return(new SuggestionQueryResult()
            {
                Suggestions = suggestions ?? new Suggestion[] {}
            });
        }
コード例 #2
0
        public BuiltResource Build <TResource>(TResource resource) where TResource : IResource
        {
            Type resourceType = resource.GetType();
            IEnumerable <PropertyInfo> properties = resourceType.GetProperties().Where(p =>
                                                                                       p.Name != nameof(IEntityResource.Id) && p.Name != nameof(IVersionedResource.Version));

            return(new BuiltResource
            {
                Id = resource is IEntityResource entityResource ?  entityResource.Id : (Guid?)null,
                Type = resourceType,
                Properties = properties.Where(p => !p.GetCustomAttributes <IgnoreAttribute>().Any()).Select(p => new Property
                {
                    Type = p.PropertyType,
                    FieldType = GetFieldType(p),
                    Name = p.Name,
                    Value = p.GetValue(resource),
                    Constraints = new Constraints
                    {
                        IsReadonly = p.GetCustomAttribute <ReadOnlyAttribute>()?.IsReadOnly,
                        IsSortable = p.GetCustomAttribute <SortableAttribute>()?.IsSortable,
                        IsHidden = p.GetCustomAttribute <HiddenAttribute>()?.IsHidden
                    },
                    ValidationConstraints = new ValidationConstraints
                    {
                        IsRequired = p.GetCustomAttribute <RequiredAttribute>()?.IsRequired,
                        MinLenth = p.GetCustomAttribute <LengthAttribute>()?.MinLength ?? p.GetCustomAttribute <MinLengthAttribute>()?.MinLength,
                        MaxLength = p.GetCustomAttribute <LengthAttribute>()?.MaxLength ?? p.GetCustomAttribute <MaxLengthAttribute>()?.MaxLength
                    }
                }),
                Links = _linkBuilder.BuildLinks(resource),
                Version = resource is IVersioned <IConcurrencyVersion> versionedResource ? versionedResource.Version : null
            });
コード例 #3
0
 public SuccessResponseLinksDecorator(Response response, ILinkBuilder linkBuilder)
 {
     this.Response = response;
     this.Links    = linkBuilder.BuildLinks();
 }