コード例 #1
0
        protected static object GetPropertyValue(IOidStrategy oidStrategy, HttpRequestMessage req, IAssociationFacade property, IObjectFacade target, RestControlFlags flags, bool valueOnly = false)
        {
            IObjectFacade valueNakedObject = property.GetValue(target);
            string        title            = RestUtils.SafeGetTitle(property, valueNakedObject);

            if (valueNakedObject == null)
            {
                return(null);
            }
            if (property.Specification.IsParseable || property.Specification.IsCollection)
            {
                return(RestUtils.ObjectToPredefinedType(valueNakedObject.GetDomainObject()));
            }

            if (valueOnly)
            {
                return(RefValueRepresentation.Create(oidStrategy, new ValueRelType(property, new UriMtHelper(oidStrategy, req, valueNakedObject)), flags));
            }

            var helper    = new UriMtHelper(oidStrategy, req, property.IsInline ? target : valueNakedObject);
            var optionals = new List <OptionalProperty> {
                new OptionalProperty(JsonPropertyNames.Title, title)
            };

            if (property.IsEager(target))
            {
                optionals.Add(new OptionalProperty(JsonPropertyNames.Value, ObjectRepresentation.Create(oidStrategy, valueNakedObject, req, flags)));
            }

            return(LinkRepresentation.Create(oidStrategy, new ValueRelType(property, helper), flags, optionals.ToArray()));
        }
コード例 #2
0
        private void SetLinks(HttpRequestMessage req, PropertyTypeContextSurface propertyContext)
        {
            IList <LinkRepresentation> tempLinks = CreateLinks(req, propertyContext);

            tempLinks.Add(LinkRepresentation.Create(new DomainTypeRelType(RelValues.ReturnType, new UriMtHelper(req, propertyContext.Property.Specification)), Flags));
            Links = tempLinks.ToArray();
        }
コード例 #3
0
        private LinkRepresentation CreateObjectLink(HttpRequestMessage req, INakedObjectSurface no)
        {
            var           helper = new UriMtHelper(req, no);
            ObjectRelType rt     = no.Specification.IsService() ? new ServiceRelType(helper) : new ObjectRelType(RelValues.Element, helper);

            return(LinkRepresentation.Create(rt, Flags, new OptionalProperty(JsonPropertyNames.Title, RestUtils.SafeGetTitle(no))));
        }
コード例 #4
0
        private LinkRepresentation CreateMenuLink(IOidStrategy oidStrategy, HttpRequestMessage req, IMenuFacade menu)
        {
            var helper = new UriMtHelper(oidStrategy, req, menu);
            var rt     = new MenuRelType(helper);

            return(LinkRepresentation.Create(oidStrategy, rt, Flags, new OptionalProperty(JsonPropertyNames.Title, menu.Name)));
        }
コード例 #5
0
        private LinkRepresentation CreatePromptLink(HttpRequestMessage req, INakedObjectSurface nakedObject, INakedObjectActionParameterSurface parameter)
        {
            var opts = new List <OptionalProperty>();

            var parameterContext = new ParameterContextSurface {
                Action    = parameter.Action,
                Target    = nakedObject,
                Parameter = parameter
            };

            if (parameter.IsAutoCompleteEnabled)
            {
                var arguments  = new OptionalProperty(JsonPropertyNames.Arguments, MapRepresentation.Create(new OptionalProperty(JsonPropertyNames.XRoSearchTerm, MapRepresentation.Create(new OptionalProperty(JsonPropertyNames.Value, null, typeof(object))))));
                var extensions = new OptionalProperty(JsonPropertyNames.Extensions, MapRepresentation.Create(new OptionalProperty(JsonPropertyNames.MinLength, parameter.AutoCompleteMinLength())));

                opts.Add(arguments);
                opts.Add(extensions);
            }
            else
            {
                Tuple <string, INakedObjectSpecificationSurface>[] parms = parameter.GetChoicesParameters();
                OptionalProperty[] args = parms.Select(tuple => RestUtils.CreateArgumentProperty(req, tuple, Flags)).ToArray();
                var arguments           = new OptionalProperty(JsonPropertyNames.Arguments, MapRepresentation.Create(args));
                opts.Add(arguments);
            }

            return(LinkRepresentation.Create(new PromptRelType(new UriMtHelper(req, parameterContext)), Flags, opts.ToArray()));
        }
コード例 #6
0
        private LinkRepresentation CreateObjectLink(IOidStrategy oidStrategy, HttpRequestMessage req, IObjectFacade no)
        {
            var           helper = new UriMtHelper(oidStrategy, req, no);
            ObjectRelType rt     = no.Specification.IsService ? new ServiceRelType(helper) : new ObjectRelType(RelValues.Element, helper);

            return(LinkRepresentation.Create(oidStrategy, rt, Flags, new OptionalProperty(JsonPropertyNames.Title, RestUtils.SafeGetTitle(no))));
        }
コード例 #7
0
 private void SetLinks(UriMtHelper helper)
 {
     Links = new List <LinkRepresentation> {
         LinkRepresentation.Create(SelfRelType, Flags)
         // temp disable icons
         //LinkRepresentation.Create(new IconRelType(helper), Flags)
     }.ToArray();
 }
コード例 #8
0
        protected IList <LinkRepresentation> CreateLinks(HttpRequestMessage req, PropertyTypeContextFacade propertyContext)
        {
            var domainTypeUri = new UriMtHelper(OidStrategy, req, propertyContext);

            return(new List <LinkRepresentation> {
                LinkRepresentation.Create(OidStrategy, SelfRelType, Flags),
                LinkRepresentation.Create(OidStrategy, new DomainTypeRelType(RelValues.Up, domainTypeUri), Flags)
            });
        }
コード例 #9
0
        private void SetLinks(HttpRequestMessage req, ObjectContextFacade objectContext)
        {
            var tempLinks = new List <LinkRepresentation>();

            if (Flags.FormalDomainModel)
            {
                tempLinks.Add(LinkRepresentation.Create(OidStrategy, new DomainTypeRelType(RelValues.ReturnType, new UriMtHelper(OidStrategy, req, objectContext.Specification)), Flags));
            }
            Links = tempLinks.ToArray();
        }
コード例 #10
0
        private void SetMembers(ObjectContextSurface objectContext, HttpRequestMessage req, List <LinkRepresentation> tempLinks)
        {
            PropertyContextSurface[] visiblePropertiesAndCollections = objectContext.VisibleProperties;

            if (!Flags.BlobsClobs)
            {
                // filter any blobs and clobs
                visiblePropertiesAndCollections = visiblePropertiesAndCollections.Where(vp => !RestUtils.IsBlobOrClob(vp.Specification)).ToArray();
            }

            PropertyContextSurface[] visibleProperties = visiblePropertiesAndCollections.Where(p => !p.Property.IsCollection()).ToArray();

            if (!objectContext.Target.IsTransient() && visibleProperties.Any(p => p.Property.IsUsable(objectContext.Target).IsAllowed))
            {
                string[]           ids   = visibleProperties.Where(p => p.Property.IsUsable(objectContext.Target).IsAllowed&& !p.Property.IsInline()).Select(p => p.Id).ToArray();
                OptionalProperty[] props = ids.Select(s => new OptionalProperty(s, MapRepresentation.Create(new OptionalProperty(JsonPropertyNames.Value, null, typeof(object))))).ToArray();

                LinkRepresentation modifyLink = LinkRepresentation.Create(new ObjectRelType(RelValues.Update, new UriMtHelper(req, objectContext.Target))
                {
                    Method = RelMethod.Put
                }, Flags,
                                                                          new OptionalProperty(JsonPropertyNames.Arguments, MapRepresentation.Create(props)));

                tempLinks.Add(modifyLink);
            }

            if (objectContext.Target.IsTransient())
            {
                KeyValuePair <string, object>[] ids = objectContext.Target.Specification.Properties.Where(p => !p.IsCollection() && !p.IsInline()).ToDictionary(p => p.Id, p => GetPropertyValue(req, p, objectContext.Target, Flags, true)).ToArray();
                OptionalProperty[] props            = ids.Select(kvp => new OptionalProperty(kvp.Key, MapRepresentation.Create(new OptionalProperty(JsonPropertyNames.Value, kvp.Value)))).ToArray();

                var argMembers = new OptionalProperty(JsonPropertyNames.Members, MapRepresentation.Create(props));
                var args       = new List <OptionalProperty> {
                    argMembers
                };

                LinkRepresentation persistLink = LinkRepresentation.Create(new ObjectsRelType(RelValues.Persist, new UriMtHelper(req, objectContext.Target.Specification))
                {
                    Method = RelMethod.Post
                }, Flags,
                                                                           new OptionalProperty(JsonPropertyNames.Arguments, MapRepresentation.Create(args.ToArray())));

                tempLinks.Add(persistLink);
            }

            InlineMemberAbstractRepresentation[] properties = visiblePropertiesAndCollections.Select(p => InlineMemberAbstractRepresentation.Create(req, p, Flags)).ToArray();

            InlineActionRepresentation[] actions = objectContext.Target.IsTransient() ? new InlineActionRepresentation[] {}
                : objectContext.VisibleActions.Select(a => InlineActionRepresentation.Create(req, a, Flags)).ToArray();


            IEnumerable <InlineMemberAbstractRepresentation> allMembers = properties.Union(actions);

            Members = RestUtils.CreateMap(allMembers.ToDictionary(m => m.Id, m => (object)m));
        }
コード例 #11
0
        private void SetLinks(HttpRequestMessage req, ITypeFacade spec)
        {
            var tempLinks = new List <LinkRepresentation>();

            if (Flags.FormalDomainModel)
            {
                tempLinks.Add(LinkRepresentation.Create(OidStrategy, new DomainTypeRelType(RelValues.ElementType, new UriMtHelper(OidStrategy, req, spec)), Flags));
            }

            Links = tempLinks.ToArray();
        }
コード例 #12
0
 private void SetTypeActions(INakedObjectSpecificationSurface spec, HttpRequestMessage req)
 {
     TypeActions = new[] {
         LinkRepresentation.Create(new TypeActionRelType(new UriMtHelper(req, spec), WellKnownIds.IsSubtypeOf), Flags,
                                   new OptionalProperty(JsonPropertyNames.Id, WellKnownIds.IsSubtypeOf),
                                   new OptionalProperty(JsonPropertyNames.Arguments, MapRepresentation.Create(new OptionalProperty(JsonPropertyNames.SubType, MapRepresentation.Create(new OptionalProperty(JsonPropertyNames.Href, null, typeof(object))))))),
         LinkRepresentation.Create(new TypeActionRelType(new UriMtHelper(req, spec), WellKnownIds.IsSupertypeOf), Flags,
                                   new OptionalProperty(JsonPropertyNames.Id, WellKnownIds.IsSupertypeOf),
                                   new OptionalProperty(JsonPropertyNames.Arguments, MapRepresentation.Create(new OptionalProperty(JsonPropertyNames.SuperType, MapRepresentation.Create(new OptionalProperty(JsonPropertyNames.Href, null, typeof(object)))))))
     };
 }
コード例 #13
0
        private void SetParameters(HttpRequestMessage req, ActionTypeContextSurface actionTypeContext)
        {
            IEnumerable <LinkRepresentation> parms = actionTypeContext.ActionContext.VisibleParameters.
                                                     Select(p => LinkRepresentation.Create(new ParamTypeRelType(new UriMtHelper(req, new ParameterTypeContextSurface {
                Action = actionTypeContext.ActionContext.Action,
                OwningSpecification = actionTypeContext.OwningSpecification,
                Parameter           = p.Parameter
            })), Flags));

            Parameters = parms.ToArray();
        }
コード例 #14
0
        private void SetLinks(HttpRequestMessage req, INakedObjectSpecificationSurface spec)
        {
            var tempLinks = new List <LinkRepresentation>();

            if (Flags.FormalDomainModel)
            {
                tempLinks.Add(LinkRepresentation.Create(new DomainTypeRelType(RelValues.ElementType, new UriMtHelper(req, spec)), Flags));
            }

            Links = tempLinks.ToArray();
        }
コード例 #15
0
 private void SetLinks(HttpRequestMessage req, ActionResultContextSurface actionResult)
 {
     if (actionResult.ActionContext.Action.IsQueryOnly())
     {
         Links = new[] { LinkRepresentation.Create(SelfRelType, Flags, new OptionalProperty(JsonPropertyNames.Arguments, CreateArguments(req, actionResult))) };
     }
     else
     {
         Links = new LinkRepresentation[] {};
     }
 }
コード例 #16
0
        private void SetLinks(HttpRequestMessage req, ParameterTypeContextFacade parameterTypeContext)
        {
            var domainTypeUri = new UriMtHelper(OidStrategy, req, parameterTypeContext);

            var tempLinks = new List <LinkRepresentation> {
                LinkRepresentation.Create(OidStrategy, SelfRelType, Flags),
                LinkRepresentation.Create(OidStrategy, new TypeMemberRelType(RelValues.Up, domainTypeUri), Flags),
                LinkRepresentation.Create(OidStrategy, new DomainTypeRelType(RelValues.ReturnType, new UriMtHelper(OidStrategy, req, parameterTypeContext.Parameter.Specification)), Flags)
            };

            Links = tempLinks.ToArray();
        }
        private void SetLinks(HttpRequestMessage req, TypeActionInvokeContext context)
        {
            string uri = new DomainTypeRelType(new UriMtHelper(OidStrategy, req, context.OtherSpecification)).GetUri().AbsoluteUri;

            var tempLinks = new List <LinkRepresentation> {
                LinkRepresentation.Create(OidStrategy, SelfRelType,
                                          Flags,
                                          new OptionalProperty(JsonPropertyNames.Arguments,
                                                               MapRepresentation.Create(new OptionalProperty(context.ParameterId,
                                                                                                             MapRepresentation.Create(new OptionalProperty(JsonPropertyNames.Href,
                                                                                                                                                           uri))))))
            };

            Links = tempLinks.ToArray();
        }
        private void SetLinks(HttpRequestMessage req, FilterFromInvokeContext context)
        {
            var uris = context.OtherSpecifications.Select(os => new DomainTypeRelType(new UriMtHelper(OidStrategy, req, os)).GetUri().AbsoluteUri).ToArray();

            var tempLinks = new List <LinkRepresentation> {
                LinkRepresentation.Create(OidStrategy, SelfRelType,
                                          Flags,
                                          new OptionalProperty(JsonPropertyNames.Arguments,
                                                               MapRepresentation.Create(new OptionalProperty(context.ParameterId, uris.Select(uri =>
                                                                                                                                              MapRepresentation.Create(new OptionalProperty(JsonPropertyNames.Href,
                                                                                                                                                                                            uri))).ToArray()))))
            };

            Links = tempLinks.ToArray();
        }
コード例 #19
0
        private void SetLinks(HttpRequestMessage req, PropertyContextSurface propertyContext, RelType parentRelType)
        {
            var tempLinks = new List <LinkRepresentation> {
                LinkRepresentation.Create(parentRelType, Flags),
                LinkRepresentation.Create(SelfRelType, Flags)
            };

            if (Flags.FormalDomainModel)
            {
                tempLinks.Add(LinkRepresentation.Create(new DomainTypeRelType(RelValues.ReturnType, new UriMtHelper(req, propertyContext.Property)), Flags));
                tempLinks.Add(LinkRepresentation.Create(new DomainTypeRelType(RelValues.ElementType, new UriMtHelper(req, propertyContext.Property.ElementSpecification)), Flags));
            }

            Links = tempLinks.ToArray();
        }
コード例 #20
0
        private void SetLinksAndMembers(HttpRequestMessage req, IMenuFacade menu)
        {
            var tempLinks = new List <LinkRepresentation>();

            tempLinks.Add(LinkRepresentation.Create(OidStrategy, SelfRelType, Flags));

            if (Flags.FormalDomainModel)
            {
                //tempLinks.Add(LinkRepresentation.Create(OidStrategy, new DomainTypeRelType(RelValues.DescribedBy, new UriMtHelper(OidStrategy, req, menu.Specification)), Flags));
            }

            // temp disable icons
            //tempLinks.Add(LinkRepresentation.Create(new IconRelType(objectUri), Flags));
            SetMembers(menu, req, tempLinks);
            Links = tempLinks.ToArray();
        }
コード例 #21
0
        private void SetLinks(HttpRequestMessage req)
        {
            var tempLinks = new List <LinkRepresentation> {
                LinkRepresentation.Create(SelfRelType, Flags),
                LinkRepresentation.Create(new UserRelType(new UriMtHelper(req)), Flags),
                LinkRepresentation.Create(new ListRelType(RelValues.Services, SegmentValues.Services, new UriMtHelper(req)), Flags),
                LinkRepresentation.Create(new VersionRelType(new UriMtHelper(req)), Flags)
            };

            if (Flags.FormalDomainModel)
            {
                tempLinks.Add(LinkRepresentation.Create(new TypesRelType(new UriMtHelper(req)), Flags));
            }

            Links = tempLinks.ToArray();
        }
コード例 #22
0
        private void SetLinks(HttpRequestMessage req, ActionTypeContextSurface actionTypeContext)
        {
            var domainTypeUri = new UriMtHelper(req, actionTypeContext);
            var tempLinks     = new List <LinkRepresentation> {
                LinkRepresentation.Create(SelfRelType, Flags),
                LinkRepresentation.Create(new DomainTypeRelType(RelValues.Up, domainTypeUri), Flags),
                LinkRepresentation.Create(new DomainTypeRelType(RelValues.ReturnType, new UriMtHelper(req, actionTypeContext.ActionContext.Action.ReturnType)), Flags)
            };

            if (actionTypeContext.ActionContext.Action.ReturnType.IsCollection())
            {
                tempLinks.Add(LinkRepresentation.Create(new DomainTypeRelType(RelValues.ElementType, new UriMtHelper(req, actionTypeContext.ActionContext.Action.ElementType)), Flags));
            }

            Links = tempLinks.ToArray();
        }
コード例 #23
0
        private void SetLinksAndMembers(HttpRequestMessage req, ObjectContextSurface objectContext)
        {
            var tempLinks = new List <LinkRepresentation>();

            if (!objectContext.Mutated && !objectContext.Target.IsTransient())
            {
                tempLinks.Add(LinkRepresentation.Create(SelfRelType, Flags));
            }

            if (Flags.FormalDomainModel)
            {
                tempLinks.Add(LinkRepresentation.Create(new DomainTypeRelType(RelValues.DescribedBy, new UriMtHelper(req, objectContext.Specification)), Flags));
            }

            // temp disable icons
            //tempLinks.Add(LinkRepresentation.Create(new IconRelType(objectUri), Flags));
            SetMembers(objectContext, req, tempLinks);
            Links = tempLinks.ToArray();
        }
コード例 #24
0
        private void SetTypeActions(ITypeFacade spec, HttpRequestMessage req)
        {
            TypeActions = new[] {
                LinkRepresentation.Create(OidStrategy, new TypeActionRelType(new UriMtHelper(OidStrategy, req, spec), WellKnownIds.IsSubtypeOf), Flags,
                                          new OptionalProperty(JsonPropertyNames.Id, WellKnownIds.IsSubtypeOf),
                                          new OptionalProperty(JsonPropertyNames.Arguments, MapRepresentation.Create(new OptionalProperty(JsonPropertyNames.SuperType, MapRepresentation.Create(new OptionalProperty(JsonPropertyNames.Href, null, typeof(object))))))),
                LinkRepresentation.Create(OidStrategy, new TypeActionRelType(new UriMtHelper(OidStrategy, req, spec), WellKnownIds.IsSupertypeOf), Flags,
                                          new OptionalProperty(JsonPropertyNames.Id, WellKnownIds.IsSupertypeOf),
                                          new OptionalProperty(JsonPropertyNames.Arguments, MapRepresentation.Create(new OptionalProperty(JsonPropertyNames.SubType, MapRepresentation.Create(new OptionalProperty(JsonPropertyNames.Href, null, typeof(object))))))),

                // extensions to 1.1 spec
                LinkRepresentation.Create(OidStrategy, new TypeActionRelType(new UriMtHelper(OidStrategy, req, spec), WellKnownIds.FilterSubtypesFrom), Flags,
                                          new OptionalProperty(JsonPropertyNames.Id, WellKnownIds.FilterSubtypesFrom),
                                          new OptionalProperty(JsonPropertyNames.Arguments, MapRepresentation.Create(new OptionalProperty(JsonPropertyNames.SubTypes, MapRepresentation.Create(new OptionalProperty(JsonPropertyNames.Href, null, typeof(object))))))),
                LinkRepresentation.Create(OidStrategy, new TypeActionRelType(new UriMtHelper(OidStrategy, req, spec), WellKnownIds.FilterSupertypesFrom), Flags,
                                          new OptionalProperty(JsonPropertyNames.Id, WellKnownIds.FilterSupertypesFrom),
                                          new OptionalProperty(JsonPropertyNames.Arguments, MapRepresentation.Create(new OptionalProperty(JsonPropertyNames.SuperTypes, MapRepresentation.Create(new OptionalProperty(JsonPropertyNames.Href, null, typeof(object)))))))
            };
        }
コード例 #25
0
        private void SetMembers(INakedObjectSpecificationSurface spec, HttpRequestMessage req)
        {
            INakedObjectAssociationSurface[] properties  = spec.Properties.Where(p => !p.IsCollection()).ToArray();
            INakedObjectAssociationSurface[] collections = spec.Properties.Where(p => p.IsCollection()).ToArray();
            INakedObjectActionSurface[]      actions     = spec.GetActionLeafNodes();

            IEnumerable <LinkRepresentation> propertyMembers = properties.Select(p => LinkRepresentation.Create(new TypeMemberRelType(RelValues.Property, new UriMtHelper(req, new PropertyTypeContextSurface {
                Property = p, OwningSpecification = spec
            })), Flags));
            IEnumerable <LinkRepresentation> collectionMembers = collections.Select(c => LinkRepresentation.Create(new TypeMemberRelType(RelValues.Collection, new UriMtHelper(req, new PropertyTypeContextSurface {
                Property = c, OwningSpecification = spec
            })), Flags));
            IEnumerable <LinkRepresentation> actionMembers = actions.Select(a => LinkRepresentation.Create(new TypeMemberRelType(RelValues.Action, new UriMtHelper(req, new ActionTypeContextSurface {
                ActionContext = new ActionContextSurface {
                    Action = a
                }, OwningSpecification = spec
            })), Flags));

            Members = propertyMembers.Union(collectionMembers).Union(actionMembers).ToArray();
        }
コード例 #26
0
        private void SetLinks(HttpRequestMessage req, INakedObjectSurface nakedObject, INakedObjectActionParameterSurface parameter)
        {
            var tempLinks = new List <LinkRepresentation>();


            if (Flags.FormalDomainModel)
            {
                var parameterTypeContextSurface = new ParameterTypeContextSurface {
                    Action = parameter.Action,
                    OwningSpecification = nakedObject.Specification,
                    Parameter           = parameter
                };
                LinkRepresentation describedBy = LinkRepresentation.Create(new ParamTypeRelType(RelValues.DescribedBy, new UriMtHelper(req, parameterTypeContextSurface)), Flags);
                tempLinks.Add(describedBy);
            }

            if (parameter.IsAutoCompleteEnabled || parameter.GetChoicesParameters().Any())
            {
                tempLinks.Add(CreatePromptLink(req, nakedObject, parameter));
            }

            Links = tempLinks.ToArray();
        }
コード例 #27
0
        private void SetLinks(HttpRequestMessage req, IObjectFacade objectFacade, IActionParameterFacade parameter)
        {
            var tempLinks = new List <LinkRepresentation>();


            if (Flags.FormalDomainModel)
            {
                var parameterTypeContext = new ParameterTypeContextFacade {
                    Action = parameter.Action,
                    OwningSpecification = objectFacade.Specification,
                    Parameter           = parameter
                };
                LinkRepresentation describedBy = LinkRepresentation.Create(OidStrategy, new ParamTypeRelType(RelValues.DescribedBy, new UriMtHelper(OidStrategy, req, parameterTypeContext)), Flags);
                tempLinks.Add(describedBy);
            }

            if (parameter.IsAutoCompleteEnabled || parameter.GetChoicesParameters().Any())
            {
                tempLinks.Add(CreatePromptLink(req, objectFacade, parameter));
            }

            Links = tempLinks.ToArray();
        }
コード例 #28
0
 private LinkRepresentation CreateDomainLink(IOidStrategy oidStrategy, HttpRequestMessage req, ITypeFacade spec)
 {
     return(LinkRepresentation.Create(oidStrategy, new DomainTypeRelType(new UriMtHelper(oidStrategy, req, spec)), Flags));
 }
コード例 #29
0
 private void SetLinks(HttpRequestMessage req)
 {
     Links = new[] { LinkRepresentation.Create(OidStrategy, SelfRelType, Flags), LinkRepresentation.Create(OidStrategy, new HomePageRelType(RelValues.Up, new UriMtHelper(OidStrategy, req)), Flags) };
 }
コード例 #30
0
        public static InlineCollectionRepresentation Create(HttpRequestMessage req, PropertyContextSurface propertyContext, IList <OptionalProperty> optionals, RestControlFlags flags)
        {
            if (propertyContext.Property.IsEager(propertyContext.Target) && !propertyContext.Target.IsTransient())
            {
                IEnumerable <INakedObjectSurface> collectionItems = propertyContext.Property.GetNakedObject(propertyContext.Target).ToEnumerable();
                IEnumerable <LinkRepresentation>  items           = collectionItems.Select(i => LinkRepresentation.Create(new ValueRelType(propertyContext.Property, new UriMtHelper(req, i)), flags, new OptionalProperty(JsonPropertyNames.Title, RestUtils.SafeGetTitle(i))));
                optionals.Add(new OptionalProperty(JsonPropertyNames.Value, items.ToArray()));
            }

            var collectionRepresentationStrategy = new CollectionRepresentationStrategy(req, propertyContext, flags);

            if (optionals.Count == 0)
            {
                return(new InlineCollectionRepresentation(collectionRepresentationStrategy));
            }
            return(CreateWithOptionals <InlineCollectionRepresentation>(new object[] { collectionRepresentationStrategy }, optionals));
        }