Exemplo n.º 1
0
        /// <summary>
        /// Set Org.OData.Capabilities.V1.NavigationRestrictions to target.
        /// </summary>
        /// <param name="model">The model referenced to.</param>
        /// <param name="target">The target entity set to set the inline annotation.</param>
        /// <param name="navigability">This entity set supports navigability.</param>
        /// <param name="restrictedProperties">These properties have navigation restrictions on.</param>
        public static void SetNavigationRestrictionsAnnotation(this EdmModel model, IEdmEntitySet target,
                                                               CapabilitiesNavigationType navigability,
                                                               IEnumerable <Tuple <IEdmNavigationProperty, CapabilitiesNavigationType> > restrictedProperties)
        {
            if (model == null)
            {
                throw Error.ArgumentNull("model");
            }

            if (target == null)
            {
                throw Error.ArgumentNull("target");
            }

            IEdmEnumType navigationType = model.GetCapabilitiesNavigationType();

            if (navigationType == null)
            {
                return;
            }

            restrictedProperties = restrictedProperties ?? new Tuple <IEdmNavigationProperty, CapabilitiesNavigationType> [0];

            string type = new EdmEnumTypeReference(navigationType, false).ToStringLiteral((long)navigability);

            IEnumerable <EdmRecordExpression> propertiesExpression = restrictedProperties.Select(p =>
            {
                var name = new EdmEnumTypeReference(navigationType, false).ToStringLiteral((long)p.Item2);
                return(new EdmRecordExpression(new IEdmPropertyConstructor[]
                {
                    new EdmPropertyConstructor(
                        CapabilitiesVocabularyConstants.NavigationPropertyRestrictionNavigationProperty,
                        new EdmNavigationPropertyPathExpression(p.Item1.Name)),
                    new EdmPropertyConstructor(CapabilitiesVocabularyConstants.NavigationRestrictionsNavigability,
                                               new EdmEnumMemberReferenceExpression(navigationType.Members.Single(m => m.Name == name)))
                }));
            });

            IList <IEdmPropertyConstructor> properties = new List <IEdmPropertyConstructor>
            {
                new EdmPropertyConstructor(CapabilitiesVocabularyConstants.NavigationRestrictionsNavigability,
                                           new EdmEnumMemberReferenceExpression(
                                               navigationType.Members.Single(m => m.Name == type))),

                new EdmPropertyConstructor(CapabilitiesVocabularyConstants.NavigationRestrictionsRestrictedProperties,
                                           new EdmCollectionExpression(propertiesExpression))
            };

            model.SetVocabularyAnnotation(target, properties, CapabilitiesVocabularyConstants.NavigationRestrictions);
        }
        /// <summary>
        /// Set Org.OData.Capabilities.V1.NavigationRestrictions to target.
        /// </summary>
        /// <param name="model">The model referenced to.</param>
        /// <param name="target">The target entity set to set the inline annotation.</param>
        /// <param name="navigability">This entity set supports navigability.</param>
        /// <param name="restrictedProperties">These properties have navigation restrictions on.</param>
        public static void SetNavigationRestrictionsAnnotation(this EdmModel model, IEdmEntitySet target,
            CapabilitiesNavigationType navigability,
            IEnumerable<Tuple<IEdmNavigationProperty, CapabilitiesNavigationType>> restrictedProperties)
        {
            if (model == null)
            {
                throw Error.ArgumentNull("model");
            }

            if (target == null)
            {
                throw Error.ArgumentNull("target");
            }

            IEdmEnumType navigationType = model.GetCapabilitiesNavigationType();
            if (navigationType == null)
            {
                return;
            }

            restrictedProperties = restrictedProperties ?? new Tuple<IEdmNavigationProperty, CapabilitiesNavigationType>[0];

            string type = new EdmEnumTypeReference(navigationType, false).ToStringLiteral((long)navigability);

            IEnumerable<EdmRecordExpression> propertiesExpression = restrictedProperties.Select(p =>
            {
                var name = new EdmEnumTypeReference(navigationType, false).ToStringLiteral((long)p.Item2);
                return new EdmRecordExpression(new IEdmPropertyConstructor[]
                {
                    new EdmPropertyConstructor(
                        CapabilitiesVocabularyConstants.NavigationPropertyRestrictionNavigationProperty,
                        new EdmNavigationPropertyPathExpression(p.Item1.Name)),
                    new EdmPropertyConstructor(CapabilitiesVocabularyConstants.NavigationRestrictionsNavigability,
                        new EdmEnumMemberReferenceExpression(navigationType.Members.Single(m => m.Name == name)))
                });
            });

            IList<IEdmPropertyConstructor> properties = new List<IEdmPropertyConstructor>
            {
                new EdmPropertyConstructor(CapabilitiesVocabularyConstants.NavigationRestrictionsNavigability,
                    new EdmEnumMemberReferenceExpression(
                        navigationType.Members.Single(m => m.Name == type))),

                new EdmPropertyConstructor(CapabilitiesVocabularyConstants.NavigationRestrictionsRestrictedProperties,
                    new EdmCollectionExpression(propertiesExpression))
            };

            model.SetVocabularyAnnotation(target, properties, CapabilitiesVocabularyConstants.NavigationRestrictions);
        }
Exemplo n.º 3
0
        public static void SetNavigationRestrictionsCapabilitiesAnnotation(this EdmModel model, IEdmEntitySet entitySet, CapabilitiesNavigationType type, IEnumerable <Tuple <IEdmNavigationProperty, CapabilitiesNavigationType> > properties)
        {
            if (model == null)
            {
                throw new ArgumentNullException("model");
            }
            if (entitySet == null)
            {
                throw new ArgumentNullException("entitySet");
            }

            if (properties == null)
            {
                properties = new Tuple <IEdmNavigationProperty, CapabilitiesNavigationType> [0];
            }

            var target = entitySet;
            var term   = NavigationRestrictionsTerm;
            // handle type
            var typeLiteral = new EdmEnumTypeReference(NavigationTypeType, false).ToStringLiteral((long)type);
            // handle properties
            var propertiesExpression = properties.Select(p =>
            {
                var name = new EdmEnumTypeReference(NavigationTypeType, false).ToStringLiteral((long)p.Item2);
                return(new EdmRecordExpression(new IEdmPropertyConstructor[]
                {
                    new EdmPropertyConstructor("NavigationProperty", new EdmNavigationPropertyPathExpression(p.Item1.Name)),
                    new EdmPropertyConstructor("Navigability", new EdmEnumMemberReferenceExpression(NavigationTypeType.Members.Single(m => m.Name == name))),
                }));
            });

            var record = new EdmRecordExpression(new IEdmPropertyConstructor[]
            {
                new EdmPropertyConstructor("Navigability", new EdmEnumMemberReferenceExpression(NavigationTypeType.Members.Single(m => m.Name == typeLiteral))),
                new EdmPropertyConstructor("RestrictedProperties", new EdmCollectionExpression(propertiesExpression))
            });

            var annotation = new EdmAnnotation(target, term, record);

            annotation.SetSerializationLocation(model, entitySet.ToSerializationLocation());
            model.AddVocabularyAnnotation(annotation);
        }
Exemplo n.º 4
0
        public static void SetNavigationRestrictionsCapabilitiesAnnotation(this EdmModel model, IEdmEntitySet entitySet, CapabilitiesNavigationType type, IEnumerable<Tuple<IEdmNavigationProperty, CapabilitiesNavigationType>> properties)
        {
            if (model == null) throw new ArgumentNullException("model");
            if (entitySet == null) throw new ArgumentNullException("entitySet");

            if (properties == null)
            {
                properties = new Tuple<IEdmNavigationProperty, CapabilitiesNavigationType>[0];
            }

            var target = entitySet;
            var term = NavigationRestrictionsTerm;
            // handle type
            var typeLiteral = new EdmEnumTypeReference(NavigationTypeType, false).ToStringLiteral((long)type);
            // handle properties
            var propertiesExpression = properties.Select(p =>
            {
                var name = new EdmEnumTypeReference(NavigationTypeType, false).ToStringLiteral((long)p.Item2);
                return new EdmRecordExpression(new IEdmPropertyConstructor[]
                {
                    new EdmPropertyConstructor("NavigationProperty", new EdmNavigationPropertyPathExpression(p.Item1.Name)),
                    new EdmPropertyConstructor("Navigability", new EdmEnumMemberReferenceExpression(NavigationTypeType.Members.Single(m => m.Name == name))),
                });
            });

            var record = new EdmRecordExpression(new IEdmPropertyConstructor[]
            {
                new EdmPropertyConstructor("Navigability", new EdmEnumMemberReferenceExpression(NavigationTypeType.Members.Single(m => m.Name == typeLiteral))),
                new EdmPropertyConstructor("RestrictedProperties", new EdmCollectionExpression(propertiesExpression))
            });

            var annotation = new EdmAnnotation(target, term, record);
            annotation.SetSerializationLocation(model, entitySet.ToSerializationLocation());
            model.AddVocabularyAnnotation(annotation);
        }