예제 #1
0
        protected NavigationSourceConfiguration(ODataModelBuilder modelBuilder, EntityTypeConfiguration entityType, string name)
        {
            if (modelBuilder == null)
            {
                throw Error.ArgumentNull("modelBuilder");
            }

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

            if (String.IsNullOrEmpty(name))
            {
                throw Error.ArgumentNullOrEmpty("name");
            }

            _modelBuilder = modelBuilder;
            Name          = name;
            EntityType    = entityType;
            ClrType       = entityType.ClrType;
            _url          = Name;

            _editLinkBuilder = null;
            _readLinkBuilder = null;
            _navigationPropertyLinkBuilders = new Dictionary <NavigationPropertyConfiguration, NavigationLinkBuilder>();
            _navigationPropertyBindings     = new Dictionary <NavigationPropertyConfiguration, NavigationPropertyBindingConfiguration>();
        }
예제 #2
0
        /// <summary>
        /// Configures the read link for this navigation source.
        /// </summary>
        /// <param name="readLinkBuilder">The builder used to generate the read link.</param>
        /// <returns>Returns itself so that multiple calls can be chained.</returns>
        public virtual INavigationSourceConfiguration HasReadLink(SelfLinkBuilder <Uri> readLinkBuilder)
        {
            if (readLinkBuilder == null)
            {
                throw Error.ArgumentNull("readLinkBuilder");
            }

            _readLinkBuilder = readLinkBuilder;
            return(this);
        }
예제 #3
0
        /// <summary>
        /// Configures the ID link for this navigation source.
        /// </summary>
        /// <param name="idLinkBuilder">The builder used to generate the ID.</param>
        /// <returns>Returns itself so that multiple calls can be chained.</returns>
        public virtual INavigationSourceConfiguration HasIdLink(SelfLinkBuilder <Uri> idLinkBuilder)
        {
            if (idLinkBuilder == null)
            {
                throw Error.ArgumentNull("idLinkBuilder");
            }

            _idLinkBuilder = idLinkBuilder;
            return(this);
        }
예제 #4
0
        /// <summary>
        /// Configures the ID for the entities from this entity set.
        /// </summary>
        /// <param name="idLinkBuilder">The builder used to generate the ID.</param>
        /// <returns>Returns itself so that multiple calls can be chained.</returns>
        public virtual EntitySetConfiguration HasIdLink(SelfLinkBuilder <string> idLinkBuilder)
        {
            if (idLinkBuilder == null)
            {
                throw Error.ArgumentNull("idLinkBuilder");
            }

            _idLinkBuilder = idLinkBuilder;
            return(this);
        }
예제 #5
0
        /// <summary>
        /// Configures the edit link for this navigation source.
        /// </summary>
        /// <param name="editLinkBuilder">The builder used to generate the edit link.</param>
        /// <returns>Returns itself so that multiple calls can be chained.</returns>
        public virtual INavigationSourceConfiguration HasEditLink(SelfLinkBuilder <Uri> editLinkBuilder)
        {
            if (editLinkBuilder == null)
            {
                throw Error.ArgumentNull("editLinkBuilder");
            }

            _editLinkBuilder = editLinkBuilder;
            return(this);
        }
        public void HasReadLink_RoundTrips()
        {
            // Arrange
            SelfLinkBuilder <Uri> readLinkBuilder = new SelfLinkBuilder <Uri>((ctxt) => null, followsConventions: true);

            // Act
            _entityset.HasReadLink(readLinkBuilder);

            // Assert
            Assert.Equal(readLinkBuilder, _entityset.GetReadLink());
        }
예제 #7
0
        /// <summary>
        /// Constructs an instance of an <see cref="NavigationSourceLinkBuilderAnnotation" /> from an <see cref="NavigationSourceConfiguration" />.
        /// </summary>
        public NavigationSourceLinkBuilderAnnotation(NavigationSourceConfiguration navigationSource)
        {
            if (navigationSource == null)
            {
                throw Error.ArgumentNull("navigationSource");
            }

            _idLinkBuilder   = navigationSource.GetIdLink();
            _editLinkBuilder = navigationSource.GetEditLink();
            _readLinkBuilder = navigationSource.GetReadLink();
        }
        public void HasEditLink_RoundTrips()
        {
            // Arrange
            SelfLinkBuilder <Uri> editLinkBuilder = new SelfLinkBuilder <Uri>((ctxt) => null, followsConventions: true);

            // Act
            _singleton.HasEditLink(editLinkBuilder);

            // Assert
            Assert.Equal(editLinkBuilder, _singleton.GetEditLink());
        }
        /// <summary>
        /// Constructs an instance of an <see cref="EntitySetLinkBuilderAnnotation" /> from an <see cref="EntitySetConfiguration" />.
        /// </summary>
        public EntitySetLinkBuilderAnnotation(EntitySetConfiguration entitySet)
        {
            if (entitySet == null)
            {
                throw Error.ArgumentNull("entitySet");
            }

            _entitySetName       = entitySet.Name;
            _feedSelfLinkBuilder = entitySet.GetFeedSelfLink();
            _idLinkBuilder       = entitySet.GetIdLink();
            _editLinkBuilder     = entitySet.GetEditLink();
            _readLinkBuilder     = entitySet.GetReadLink();
        }
예제 #10
0
        /// <summary>
        /// Constructs an instance of an <see cref="NavigationSourceLinkBuilderAnnotation" /> class.
        /// </summary>
        /// <param name="navigationSource">The navigation source for which the link builder is being constructed.</param>
        /// <param name="idLinkBuilder">The ID link builder which is used to build the ID link.</param>
        /// <param name="editLinkBuilder">The Edit link builder which is used to build the Edit link.</param>
        /// <param name="readLinkBuilder">The Read link builder which is used to build the Read link.</param>
        public NavigationSourceLinkBuilderAnnotation(
            IEdmNavigationSource navigationSource,
            SelfLinkBuilder <Uri> idLinkBuilder,
            SelfLinkBuilder <Uri> editLinkBuilder,
            SelfLinkBuilder <Uri> readLinkBuilder)
        {
            if (navigationSource == null)
            {
                throw Error.ArgumentNull("navigationSource");
            }

            _idLinkBuilder   = idLinkBuilder;
            _editLinkBuilder = editLinkBuilder;
            _readLinkBuilder = readLinkBuilder;
        }
        /// <summary>
        /// Constructs an instance of an <see cref="EntitySetLinkBuilderAnnotation" />.
        /// <remarks>Every parameter must be non-null.</remarks>
        /// </summary>
        public EntitySetLinkBuilderAnnotation(
            IEdmEntitySet entitySet,
            Func <FeedContext, Uri> feedSelfLinkBuilder,
            SelfLinkBuilder <string> idLinkBuilder,
            SelfLinkBuilder <Uri> editLinkBuilder,
            SelfLinkBuilder <Uri> readLinkBuilder)
        {
            if (entitySet == null)
            {
                throw Error.ArgumentNull("entitySet");
            }

            _entitySetName       = entitySet.Name;
            _feedSelfLinkBuilder = feedSelfLinkBuilder;
            _idLinkBuilder       = idLinkBuilder;
            _editLinkBuilder     = editLinkBuilder;
            _readLinkBuilder     = readLinkBuilder;
        }
예제 #12
0
        /// <summary>
        /// Initializes a new instance of the <see cref="NavigationSourceLinkBuilderAnnotation"/> class.
        /// </summary>
        /// <param name="navigationSource">The navigation source for which the link builder is being constructed.</param>
        /// <param name="model">The EDM model that this navigation source belongs to.</param>
        /// <remarks>This constructor creates a link builder that generates URL's that follow OData conventions for the given navigation source.</remarks>
        public NavigationSourceLinkBuilderAnnotation(IEdmNavigationSource navigationSource, IEdmModel model)
        {
            if (navigationSource == null)
            {
                throw Error.ArgumentNull("navigationSource");
            }

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

            IEdmEntityType elementType = navigationSource.EntityType();
            IEnumerable <IEdmEntityType> derivedTypes = model.FindAllDerivedTypes(elementType).Cast <IEdmEntityType>();

            // Add navigation link builders for all navigation properties of entity.
            foreach (IEdmNavigationProperty navigationProperty in elementType.NavigationProperties())
            {
                Func <EntityInstanceContext, IEdmNavigationProperty, Uri> navigationLinkFactory =
                    (entityInstanceContext, navProperty) => entityInstanceContext.GenerateNavigationPropertyLink(navProperty, includeCast: false);
                AddNavigationPropertyLinkBuilder(navigationProperty, new NavigationLinkBuilder(navigationLinkFactory, followsConventions: true));
            }

            // Add navigation link builders for all navigation properties in derived types.
            bool derivedTypesDefineNavigationProperty = false;

            foreach (IEdmEntityType derivedEntityType in derivedTypes)
            {
                foreach (IEdmNavigationProperty navigationProperty in derivedEntityType.DeclaredNavigationProperties())
                {
                    derivedTypesDefineNavigationProperty = true;
                    Func <EntityInstanceContext, IEdmNavigationProperty, Uri> navigationLinkFactory =
                        (entityInstanceContext, navProperty) => entityInstanceContext.GenerateNavigationPropertyLink(navProperty, includeCast: true);
                    AddNavigationPropertyLinkBuilder(navigationProperty, new NavigationLinkBuilder(navigationLinkFactory, followsConventions: true));
                }
            }

            _navigationSourceName = navigationSource.Name;

            Func <EntityInstanceContext, Uri> selfLinkFactory =
                (entityInstanceContext) => entityInstanceContext.GenerateSelfLink(includeCast: derivedTypesDefineNavigationProperty);

            _idLinkBuilder = new SelfLinkBuilder <Uri>(selfLinkFactory, followsConventions: true);
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="EntitySetLinkBuilderAnnotation"/> class.
        /// </summary>
        /// <param name="entitySet">The entity set for which the link builder is being constructed.</param>
        /// <param name="model">The EDM model that this entity set belongs to.</param>
        /// <remarks>This constructor creates a link builder that generates URL's that follow OData conventions for the given entity set.</remarks>
        public EntitySetLinkBuilderAnnotation(IEdmEntitySet entitySet, IEdmModel model)
        {
            if (entitySet == null)
            {
                throw Error.ArgumentNull("entitySet");
            }
            if (model == null)
            {
                throw Error.ArgumentNull("model");
            }

            IEdmEntityType elementType = entitySet.ElementType;
            IEnumerable <IEdmEntityType> derivedTypes = model.FindAllDerivedTypes(elementType).Cast <IEdmEntityType>();
            bool derivedTypesDefineNavigationProperty = false;

            // Add navigation link builders for all navigation properties of entity.
            foreach (IEdmNavigationProperty navigationProperty in elementType.NavigationProperties())
            {
                Func <EntityInstanceContext, IEdmNavigationProperty, Uri> navigationLinkFactory =
                    (entityInstanceContext, navProperty) => entityInstanceContext.GenerateNavigationPropertyLink(navProperty, includeCast: false);
                AddNavigationPropertyLinkBuilder(navigationProperty, new NavigationLinkBuilder(navigationLinkFactory, followsConventions: true));
            }

            // Add navigation link builders for all navigation properties in derived types.
            foreach (IEdmEntityType derivedEntityType in derivedTypes)
            {
                foreach (IEdmNavigationProperty navigationProperty in derivedEntityType.DeclaredNavigationProperties())
                {
                    derivedTypesDefineNavigationProperty = true;
                    Func <EntityInstanceContext, IEdmNavigationProperty, Uri> navigationLinkFactory =
                        (entityInstanceContext, navProperty) => entityInstanceContext.GenerateNavigationPropertyLink(navProperty, includeCast: true);
                    AddNavigationPropertyLinkBuilder(navigationProperty, new NavigationLinkBuilder(navigationLinkFactory, followsConventions: true));
                }
            }

            _entitySetName       = entitySet.Name;
            _feedSelfLinkBuilder = (feedContext) => feedContext.GenerateFeedSelfLink();

            Func <EntityInstanceContext, string> selfLinkFactory =
                (entityInstanceContext) => entityInstanceContext.GenerateSelfLink(includeCast: derivedTypesDefineNavigationProperty);

            _idLinkBuilder = new SelfLinkBuilder <string>(selfLinkFactory, followsConventions: true);
        }