コード例 #1
0
        private static void AddNavigationBindings(EdmTypeMap edmMap,
                                                  NavigationSourceConfiguration navigationSourceConfiguration,
                                                  EdmNavigationSource navigationSource,
                                                  NavigationSourceLinkBuilderAnnotation linkBuilder,
                                                  Dictionary <string, EdmNavigationSource> edmNavigationSourceMap)
        {
            foreach (var binding in navigationSourceConfiguration.Bindings)
            {
                NavigationPropertyConfiguration navigationProperty = binding.NavigationProperty;
                bool isContained = navigationProperty.ContainsTarget;

                IEdmType               edmType               = edmMap.EdmTypes[navigationProperty.DeclaringType.ClrType];
                IEdmStructuredType     structuraType         = edmType as IEdmStructuredType;
                IEdmNavigationProperty edmNavigationProperty = structuraType.NavigationProperties()
                                                               .Single(np => np.Name == navigationProperty.Name);

                string bindingPath = ConvertBindingPath(edmMap, binding);
                if (!isContained)
                {
                    // calculate the binding path
                    navigationSource.AddNavigationTarget(
                        edmNavigationProperty,
                        edmNavigationSourceMap[binding.TargetNavigationSource.Name],
                        new EdmPathExpression(bindingPath));
                }

                NavigationLinkBuilder linkBuilderFunc = navigationSourceConfiguration.GetNavigationPropertyLink(navigationProperty);
                if (linkBuilderFunc != null)
                {
                    linkBuilder.AddNavigationPropertyLinkBuilder(edmNavigationProperty, linkBuilderFunc);
                }
            }
        }
コード例 #2
0
        public static IEdmModel BuildEdmModel(ODataModelBuilder builder)
        {
            if (builder == null)
            {
                throw Error.ArgumentNull("builder");
            }

            EdmModel           model     = new EdmModel();
            EdmEntityContainer container = new EdmEntityContainer(builder.Namespace, builder.ContainerName);

            // add types and sets, building an index on the way.
            IEnumerable <IEdmTypeConfiguration> configTypes = builder.StructuralTypes.Concat <IEdmTypeConfiguration>(builder.EnumTypes);
            EdmTypeMap edmMap = EdmTypeBuilder.GetTypesAndProperties(configTypes);
            Dictionary <Type, IEdmType> edmTypeMap = model.AddTypes(edmMap);

            // Add EntitySets and build the mapping between the EdmEntitySet and the NavigationSourceConfiguration
            NavigationSourceAndAnnotations[] entitySets = container.AddEntitySetAndAnnotations(builder, edmTypeMap);

            // Add Singletons and build the mapping between the EdmSingleton and the NavigationSourceConfiguration
            NavigationSourceAndAnnotations[] singletons = container.AddSingletonAndAnnotations(builder, edmTypeMap);

            // Merge EntitySets and Singletons together
            IEnumerable <NavigationSourceAndAnnotations> navigationSources = entitySets.Concat(singletons);

            // Build the navigation source map
            IDictionary <string, EdmNavigationSource> navigationSourceMap = model.GetNavigationSourceMap(edmMap, navigationSources);

            // Add the core vocabulary annotations
            model.AddCoreVocabularyAnnotations(entitySets, edmMap);

            // Add the capabilities vocabulary annotations
            model.AddCapabilitiesVocabularyAnnotations(entitySets, edmMap);

            // add operations
            model.AddOperations(builder.Operations, container, edmTypeMap, navigationSourceMap);

            // finish up
            model.AddElement(container);

            // build the map from IEdmEntityType to IEdmFunctionImport
            model.SetAnnotationValue <BindableOperationFinder>(model, new BindableOperationFinder(model));

            return(model);
        }
コード例 #3
0
        private static Dictionary <Type, IEdmType> AddTypes(this EdmModel model, EdmTypeMap edmTypeMap)
        {
            // build types
            Dictionary <Type, IEdmType> edmTypes = edmTypeMap.EdmTypes;

            // Add an annotate types
            model.AddTypes(edmTypes);
            model.AddClrTypeAnnotations(edmTypes);

            // add annotation for properties
            Dictionary <PropertyInfo, IEdmProperty> edmProperties = edmTypeMap.EdmProperties;

            model.AddClrPropertyInfoAnnotations(edmProperties);
            model.AddPropertyRestrictionsAnnotations(edmTypeMap.EdmPropertiesRestrictions);

            // add dynamic dictionary property annotation for open types
            model.AddDynamicPropertyDictionaryAnnotations(edmTypeMap.OpenTypes);

            return(edmTypes);
        }
コード例 #4
0
        private static string ConvertBindingPath(EdmTypeMap edmMap, NavigationPropertyBindingConfiguration binding)
        {
            IList <string> bindings = new List <string>();

            foreach (var bindingInfo in binding.Path)
            {
                Type         typeCast     = bindingInfo as Type;
                PropertyInfo propertyInfo = bindingInfo as PropertyInfo;

                if (typeCast != null)
                {
                    IEdmType edmType = edmMap.EdmTypes[typeCast];
                    bindings.Add(edmType.FullTypeName());
                }
                else if (propertyInfo != null)
                {
                    bindings.Add(edmMap.EdmProperties[propertyInfo].Name);
                }
            }

            return(String.Join("/", bindings));
        }
コード例 #5
0
        private static Dictionary <Type, IEdmType> AddTypes(this EdmModel model, IEnumerable <StructuralTypeConfiguration> types,
                                                            IEnumerable <EnumTypeConfiguration> enumTypes
                                                            )
        {
            IEnumerable <IEdmTypeConfiguration> configTypes = types.Concat <IEdmTypeConfiguration>(enumTypes);
            // build types
            EdmTypeMap edmTypeMap = EdmTypeBuilder.GetTypesAndProperties(configTypes);
            Dictionary <Type, IEdmType> edmTypes = edmTypeMap.EdmTypes;

            // Add an annotate types
            model.AddTypes(edmTypes);
            model.AddClrTypeAnnotations(edmTypes);

            // add annotation for properties
            Dictionary <PropertyInfo, IEdmProperty> edmProperties = edmTypeMap.EdmProperties;

            model.AddClrPropertyInfoAnnotations(edmProperties);
            model.AddPropertyRestrictionsAnnotations(edmTypeMap.EdmPropertiesRestrictions);

            // add dynamic dictionary property annotation for open types
            model.AddDynamicPropertyDictionaryAnnotations(edmTypeMap.OpenTypes);

            return(edmTypes);
        }
コード例 #6
0
        private static void AddExpandRestrictionsAnnotation(this EdmModel model, IEdmEntitySet target,
                                                            EntitySetConfiguration entitySetConfiguration, EdmTypeMap edmTypeMap)
        {
            EntityTypeConfiguration             entityTypeConfig        = entitySetConfiguration.EntityType;
            IEnumerable <PropertyConfiguration> nonExpandableProperties = entityTypeConfig.Properties.Where(property => property.NotExpandable);
            IList <IEdmNavigationProperty>      properties = new List <IEdmNavigationProperty>();

            foreach (PropertyConfiguration property in nonExpandableProperties)
            {
                IEdmProperty value;
                if (edmTypeMap.EdmProperties.TryGetValue(property.PropertyInfo, out value))
                {
                    if (value != null && value.PropertyKind == EdmPropertyKind.Navigation)
                    {
                        properties.Add((IEdmNavigationProperty)value);
                    }
                }
            }

            if (properties.Any())
            {
                model.SetExpandRestrictionsAnnotation(target, true, properties);
            }
        }
コード例 #7
0
        private static void AddSortRestrictionsAnnotation(this EdmModel model, IEdmEntitySet target,
                                                          EntitySetConfiguration entitySetConfiguration, EdmTypeMap edmTypeMap)
        {
            EntityTypeConfiguration             entityTypeConfig      = entitySetConfiguration.EntityType;
            IEnumerable <PropertyConfiguration> nonSortableProperties = entityTypeConfig.Properties.Where(property => property.Unsortable);
            IList <IEdmProperty> properties = new List <IEdmProperty>();

            foreach (PropertyConfiguration property in nonSortableProperties)
            {
                IEdmProperty value;
                if (edmTypeMap.EdmProperties.TryGetValue(property.PropertyInfo, out value))
                {
                    if (value != null)
                    {
                        properties.Add(value);
                    }
                }
            }

            if (properties.Any())
            {
                model.SetSortRestrictionsAnnotation(target, true, null, null, properties);
            }
        }
コード例 #8
0
        private static void AddNavigationRestrictionsAnnotation(this EdmModel model, IEdmEntitySet target,
                                                                EntitySetConfiguration entitySetConfiguration, EdmTypeMap edmTypeMap)
        {
            EntityTypeConfiguration entityTypeConfig = entitySetConfiguration.EntityType;

            IEnumerable <PropertyConfiguration> notNavigableProperties = entityTypeConfig.Properties.Where(property => property.NotNavigable);

            IList <Tuple <IEdmNavigationProperty, CapabilitiesNavigationType> > properties =
                new List <Tuple <IEdmNavigationProperty, CapabilitiesNavigationType> >();

            foreach (PropertyConfiguration property in notNavigableProperties)
            {
                IEdmProperty value;
                if (edmTypeMap.EdmProperties.TryGetValue(property.PropertyInfo, out value))
                {
                    if (value != null && value.PropertyKind == EdmPropertyKind.Navigation)
                    {
                        properties.Add(new Tuple <IEdmNavigationProperty, CapabilitiesNavigationType>(
                                           (IEdmNavigationProperty)value, CapabilitiesNavigationType.Recursive));
                    }
                }
            }

            if (properties.Any())
            {
                model.SetNavigationRestrictionsAnnotation(target, CapabilitiesNavigationType.Recursive, properties);
            }
        }
コード例 #9
0
        private static void AddCapabilitiesVocabularyAnnotations(this EdmModel model, NavigationSourceAndAnnotations[] entitySets, EdmTypeMap edmTypeMap)
        {
            Contract.Assert(model != null);
            Contract.Assert(edmTypeMap != null);

            if (entitySets == null)
            {
                return;
            }

            foreach (NavigationSourceAndAnnotations source in entitySets)
            {
                IEdmEntitySet entitySet = source.NavigationSource as IEdmEntitySet;
                if (entitySet == null)
                {
                    continue;
                }

                EntitySetConfiguration entitySetConfig = source.Configuration as EntitySetConfiguration;
                if (entitySetConfig == null)
                {
                    continue;
                }

                model.AddCountRestrictionsAnnotation(entitySet, entitySetConfig, edmTypeMap);
                model.AddNavigationRestrictionsAnnotation(entitySet, entitySetConfig, edmTypeMap);
                model.AddFilterRestrictionsAnnotation(entitySet, entitySetConfig, edmTypeMap);
                model.AddSortRestrictionsAnnotation(entitySet, entitySetConfig, edmTypeMap);
                model.AddExpandRestrictionsAnnotation(entitySet, entitySetConfig, edmTypeMap);
            }
        }
コード例 #10
0
        private static void AddOptimisticConcurrencyAnnotation(this EdmModel model, IEdmEntitySet target,
                                                               EntitySetConfiguration entitySetConfiguration, EdmTypeMap edmTypeMap)
        {
            EntityTypeConfiguration entityTypeConfig = entitySetConfiguration.EntityType;

            IEnumerable <StructuralPropertyConfiguration> concurrencyPropertyies =
                entityTypeConfig.Properties.OfType <StructuralPropertyConfiguration>().Where(property => property.ConcurrencyToken);

            IList <IEdmStructuralProperty> edmProperties = new List <IEdmStructuralProperty>();

            foreach (StructuralPropertyConfiguration property in concurrencyPropertyies)
            {
                IEdmProperty value;
                if (edmTypeMap.EdmProperties.TryGetValue(property.PropertyInfo, out value))
                {
                    var item = value as IEdmStructuralProperty;
                    if (item != null)
                    {
                        edmProperties.Add(item);
                    }
                }
            }

            if (edmProperties.Any())
            {
                model.SetOptimisticConcurrencyAnnotation(target, edmProperties);
            }
        }
コード例 #11
0
        private static void AddCoreVocabularyAnnotations(this EdmModel model, NavigationSourceAndAnnotations[] entitySets, EdmTypeMap edmTypeMap)
        {
            Contract.Assert(model != null);
            Contract.Assert(edmTypeMap != null);

            if (entitySets == null)
            {
                return;
            }

            foreach (NavigationSourceAndAnnotations source in entitySets)
            {
                IEdmEntitySet entitySet = source.NavigationSource as IEdmEntitySet;
                if (entitySet == null)
                {
                    continue;
                }

                EntitySetConfiguration entitySetConfig = source.Configuration as EntitySetConfiguration;
                if (entitySetConfig == null)
                {
                    continue;
                }

                model.AddOptimisticConcurrencyAnnotation(entitySet, entitySetConfig, edmTypeMap);
            }
        }
コード例 #12
0
        private static IDictionary <string, EdmNavigationSource> GetNavigationSourceMap(this EdmModel model, EdmTypeMap edmMap,
                                                                                        IEnumerable <NavigationSourceAndAnnotations> navigationSourceAndAnnotations)
        {
            // index the navigation source by name
            Dictionary <string, EdmNavigationSource> edmNavigationSourceMap = navigationSourceAndAnnotations.ToDictionary(e => e.NavigationSource.Name, e => e.NavigationSource);

            // apply the annotations
            foreach (NavigationSourceAndAnnotations navigationSourceAndAnnotation in navigationSourceAndAnnotations)
            {
                EdmNavigationSource navigationSource = navigationSourceAndAnnotation.NavigationSource;
                model.SetAnnotationValue(navigationSource, navigationSourceAndAnnotation.Url);
                model.SetNavigationSourceLinkBuilder(navigationSource, navigationSourceAndAnnotation.LinkBuilder);

                AddNavigationBindings(edmMap, navigationSourceAndAnnotation.Configuration, navigationSource, navigationSourceAndAnnotation.LinkBuilder,
                                      edmNavigationSourceMap);
            }

            return(edmNavigationSourceMap);
        }