Ejemplo n.º 1
0
        public void CanCreateActionWithNonbindingParameters()
        {
            // Arrange
            // Act
            ODataModelBuilder   builder = new ODataModelBuilder();
            ActionConfiguration action  = builder.Action("MyAction");

            action.Parameter <string>("p0");
            action.Parameter <int>("p1");
            action.Parameter <Address>("p2");
            action.CollectionParameter <string>("p3");
            action.CollectionParameter <int>("p4");
            action.CollectionParameter <ZipCode>("p5");
            action.EntityParameter <Customer>("p6");
            action.CollectionEntityParameter <Employee>("p7");
            ParameterConfiguration[]   parameters   = action.Parameters.ToArray();
            ComplexTypeConfiguration[] complexTypes = builder.StructuralTypes.OfType <ComplexTypeConfiguration>().ToArray();
            EntityTypeConfiguration[]  entityTypes  = builder.StructuralTypes.OfType <EntityTypeConfiguration>().ToArray();

            // Assert
            Assert.Equal(2, complexTypes.Length);
            Assert.Equal(typeof(Address).FullName, complexTypes[0].FullName);
            Assert.Equal(typeof(ZipCode).FullName, complexTypes[1].FullName);

            Assert.Equal(2, entityTypes.Length);
            Assert.Equal(typeof(Customer).FullName, entityTypes[0].FullName);
            Assert.Equal(typeof(Employee).FullName, entityTypes[1].FullName);

            Assert.Equal(8, parameters.Length);
            Assert.Equal("p0", parameters[0].Name);
            Assert.Equal("Edm.String", parameters[0].TypeConfiguration.FullName);
            Assert.Equal("p1", parameters[1].Name);
            Assert.Equal("Edm.Int32", parameters[1].TypeConfiguration.FullName);
            Assert.Equal("p2", parameters[2].Name);
            Assert.Equal(typeof(Address).FullName, parameters[2].TypeConfiguration.FullName);
            Assert.Equal("p3", parameters[3].Name);
            Assert.Equal("Collection(Edm.String)", parameters[3].TypeConfiguration.FullName);
            Assert.Equal("p4", parameters[4].Name);
            Assert.Equal("Collection(Edm.Int32)", parameters[4].TypeConfiguration.FullName);
            Assert.Equal("p5", parameters[5].Name);
            Assert.Equal(string.Format("Collection({0})", typeof(ZipCode).FullName), parameters[5].TypeConfiguration.FullName);

            Assert.Equal("p6", parameters[6].Name);
            Assert.Equal(typeof(Customer).FullName, parameters[6].TypeConfiguration.FullName);

            Assert.Equal("p7", parameters[7].Name);
            Assert.Equal(string.Format("Collection({0})", typeof(Employee).FullName), parameters[7].TypeConfiguration.FullName);
        }
Ejemplo n.º 2
0
        public static IEdmModel GetEdmModel()
        {
            ODataConventionModelBuilder        builder  = new ODataConventionModelBuilder();
            EntityTypeConfiguration <Customer> customer = builder.EntitySet <Customer>("Customers").EntityType;
            EntityTypeConfiguration <Order>    order    = builder.EntitySet <Order>("Orders").EntityType;

            // Add unbound function for get special customer.
            FunctionConfiguration getCustomersWithNameContaining = builder.Function("GetCustomersWithNameContaining");

            getCustomersWithNameContaining.Parameter <string>("ContainedString");
            getCustomersWithNameContaining.ReturnsCollectionFromEntitySet <Customer>("Customers");

            // Add bound action for updating order price.
            ActionConfiguration updateOrderPrice = order.Action("UpdateOrderPrice");

            updateOrderPrice.Parameter <string>("Price");
            updateOrderPrice.ReturnsFromEntitySet <Order>("Orders");

            // Add bound function for delete order from customer and return the rest orders.
            FunctionConfiguration deleteOrderFromCustomer = customer.Function("DeleteOrderFromCustomer");

            deleteOrderFromCustomer.Parameter <int>("OrderId");
            deleteOrderFromCustomer.ReturnsCollectionFromEntitySet <Order>("Orders");

            return(builder.GetEdmModel());
        }
Ejemplo n.º 3
0
        private IEdmModel GetEdmModel()
        {
            ODataModelBuilder builder = new ODataConventionModelBuilder();
            EntitySetConfiguration <WorkflowBase>        workflowBases = builder.EntitySet <WorkflowBase>("WorkflowBases");
            EntitySetConfiguration <Employee>            employees     = builder.EntitySet <Employee>("Employees");
            EntitySetConfiguration <Project>             projects      = builder.EntitySet <Project>("Projects");
            EntitySetConfiguration <Quote>               quotes        = builder.EntitySet <Quote>("Quotes");
            EntitySetConfiguration <JobCard>             jobcards      = builder.EntitySet <JobCard>("JobCards");
            EntitySetConfiguration <Party>               parties       = builder.EntitySet <Party>("Parties");
            EntitySetConfiguration <PermissionContainer> permissions   = builder.EntitySet <PermissionContainer>("Permissions");

            permissions.EntityType.HasKey(t => t.Key);
            workflowBases.EntityType.HasKey(t => t.Oid);
            employees.EntityType.HasKey(t => t.Oid);
            projects.EntityType.HasKey(t => t.Oid);
            quotes.EntityType.HasKey(t => t.Oid);
            jobcards.EntityType.HasKey(t => t.Oid);
            parties.EntityType.HasKey(t => t.Oid);

            FunctionConfiguration logon = builder.Function("Login");

            logon.Returns <int>();
            logon.Parameter <string>("userName");
            logon.Parameter <string>("password");
            builder.Action("Logoff");

            ActionConfiguration getPermissions = builder.Action("GetPermissions");

            getPermissions.Parameter <string>("typeName");
            getPermissions.CollectionParameter <string>("keys");
            return(builder.GetEdmModel());
        }
        private IEdmModel GetEdmModel()
        {
            ODataModelBuilder builder = new ODataConventionModelBuilder();
            EntitySetConfiguration <Employee>            employees   = builder.EntitySet <Employee>("Employees");
            EntitySetConfiguration <Party>               parties     = builder.EntitySet <Party>("Parties");
            EntitySetConfiguration <PermissionContainer> permissions = builder.EntitySet <PermissionContainer>("Permissions");
            EntitySetConfiguration <Department>          departments = builder.EntitySet <Department>("Departments");

            permissions.EntityType.HasKey(t => t.Key);
            employees.EntityType.HasKey(t => t.Oid);
            parties.EntityType.HasKey(t => t.Oid);
            departments.EntityType.HasKey(t => t.Oid);

            FunctionConfiguration logon = builder.Function("Login");

            logon.Returns <int>();
            logon.Parameter <string>("userName");
            logon.Parameter <string>("password");
            builder.Action("Logoff");

            ActionConfiguration getPermissions = builder.Action("GetPermissions");

            getPermissions.Parameter <string>("typeName");
            getPermissions.CollectionParameter <string>("keys");
            return(builder.GetEdmModel());
        }
Ejemplo n.º 5
0
        private IEdmModel GetEdmModel()
        {
            ODataModelBuilder builder = new ODataConventionModelBuilder();
            EntitySetConfiguration <Employee>         employees         = builder.EntitySet <Employee>("Employees");
            EntitySetConfiguration <Department>       departments       = builder.EntitySet <Department>("Departments");
            EntitySetConfiguration <Party>            parties           = builder.EntitySet <Party>("Parties");
            EntitySetConfiguration <ObjectPermission> objectPermissions = builder.EntitySet <ObjectPermission>("ObjectPermissions");
            EntitySetConfiguration <MemberPermission> memberPermissions = builder.EntitySet <MemberPermission>("MemberPermissions");
            EntitySetConfiguration <TypePermission>   typePermissions   = builder.EntitySet <TypePermission>("TypePermissions");

            employees.EntityType.HasKey(t => t.Oid);
            departments.EntityType.HasKey(t => t.Oid);
            parties.EntityType.HasKey(t => t.Oid);

            ActionConfiguration login = builder.Action("Login");

            login.Parameter <string>("userName");
            login.Parameter <string>("password");

            builder.Action("Logout");

            ActionConfiguration getPermissions = builder.Action("GetPermissions");

            getPermissions.Parameter <string>("typeName");
            getPermissions.CollectionParameter <string>("keys");

            ActionConfiguration getTypePermissions = builder.Action("GetTypePermissions");

            getTypePermissions.Parameter <string>("typeName");
            getTypePermissions.ReturnsFromEntitySet <TypePermission>("TypePermissions");
            return(builder.GetEdmModel());
        }
Ejemplo n.º 6
0
        public static void Register(HttpConfiguration config)
        {
            // standard Web API routes
            config.MapHttpAttributeRoutes();
            config.Routes.MapHttpRoute(
                name: "DefaultApi",
                routeTemplate: "api/{controller}/{id}",
                defaults: new { id = RouteParameter.Optional }
                );

            // OData
            ODataConventionModelBuilder builder = new ODataConventionModelBuilder();

            builder.EntitySet <Customer>("Customers");
            builder.EntitySet <Invoice>("Invoices");

            // OData Action
            ActionConfiguration purchase = builder.Entity <Customer>().Action("Purchase");

            purchase.Parameter <int>("AmountOfShoes");
            purchase.ReturnsFromEntitySet <Invoice>("Invoices");

            config.Routes.MapODataServiceRoute("odata", "odata", builder.GetEdmModel());

            // OData with fixed metadata
            // see: http://www.getbreezenow.com/documentation/odata-server
            config.Routes.MapODataServiceRoute("odataFixed", "odataFixed", EdmBuilder.GetEdm <DataContext>(), new DefaultODataBatchHandler(GlobalConfiguration.DefaultServer));
        }
Ejemplo n.º 7
0
        private IEdmModel GetModel()
        {
            HttpConfiguration config = new HttpConfiguration();

            config.Services.Replace(typeof(IAssembliesResolver), new TestAssemblyResolver(typeof(Customer)));
            ODataModelBuilder builder = new ODataConventionModelBuilder(config);

            builder.ContainerName = "C";
            builder.Namespace     = "A.B";
            EntityTypeConfiguration <Customer> customer = builder.EntitySet <Customer>("Customers").EntityType;

            ActionConfiguration primitive = customer.Action("Primitive");

            primitive.Parameter <int>("Quantity");
            primitive.Parameter <string>("ProductCode");

            ActionConfiguration complex = customer.Action("Complex");

            complex.Parameter <int>("Quantity");
            complex.Parameter <MyAddress>("Address");

            ActionConfiguration primitiveCollection = customer.Action("PrimitiveCollection");

            primitiveCollection.Parameter <string>("Name");
            primitiveCollection.CollectionParameter <int>("Ratings");

            ActionConfiguration complexCollection = customer.Action("ComplexCollection");

            complexCollection.Parameter <string>("Name");
            complexCollection.CollectionParameter <MyAddress>("Addresses");

            return(builder.GetEdmModel());
        }
        private IEdmModel GetModel()
        {
            if (_model == null)
            {
                ODataModelBuilder builder = new ODataConventionModelBuilder();
                builder.ContainerName = "C";
                builder.Namespace     = "A.B";
                EntityTypeConfiguration <Customer> customer = builder.EntitySet <Customer>("Customers").EntityType;

                ActionConfiguration primitive = customer.Action("Primitive");
                primitive.Parameter <int>("Quantity");
                primitive.Parameter <string>("ProductCode");

                ActionConfiguration complex = customer.Action("Complex");
                complex.Parameter <int>("Quantity");
                complex.Parameter <MyAddress>("Address");

                ActionConfiguration primitiveCollection = customer.Action("PrimitiveCollection");
                primitiveCollection.Parameter <string>("Name");
                primitiveCollection.CollectionParameter <int>("Ratings");

                ActionConfiguration complexCollection = customer.Action("ComplexCollection");
                complexCollection.Parameter <string>("Name");
                complexCollection.CollectionParameter <MyAddress>("Addresses");

                _model = builder.GetEdmModel();
            }
            return(_model);
        }
Ejemplo n.º 9
0
        public static void Register(HttpConfiguration config)
        {
            // Web API configuration and services

            // Web API routes
            config.MapHttpAttributeRoutes();

            config.Routes.MapHttpRoute(
                name: "DefaultApi",
                routeTemplate: "api/{controller}/{id}",
                defaults: new { id = RouteParameter.Optional }
                );

            ODataConventionModelBuilder builder = new ODataConventionModelBuilder();

            builder.EntitySet <Product>("Products");
            builder.EntitySet <Supplier>("Suppliers");
            builder.EntitySet <ProductRating>("Ratings");

            //new code: Add an action to the EDM, and define the parameter and return type
            ActionConfiguration rateProduct = builder.Entity <Product>().Action("RateProduct");

            rateProduct.Parameter <int>("Rating");
            rateProduct.Returns <double>();

            var rateAllProducts = builder.Entity <Product>().Collection.Action("RateAllProducts");

            rateAllProducts.CollectionParameter <int>("Ratings");

            config.Routes.MapODataRoute("odata", "odata", builder.GetEdmModel());
        }
Ejemplo n.º 10
0
        public static IEdmModel GetModel()
        {
            HttpConfiguration configuration = new HttpConfiguration();

            configuration.Services.Replace(typeof(IAssembliesResolver), new TestAssemblyResolver());
            ODataConventionModelBuilder builder = new ODataConventionModelBuilder(configuration);

            builder.EntitySet <RoutingCustomer>("RoutingCustomers");
            builder.EntitySet <Product>("Products");
            builder.EntitySet <SalesPerson>("SalesPeople");
            builder.EntitySet <EmailAddress>("EmailAddresses");
            builder.EntitySet <üCategory>("üCategories");

            ActionConfiguration getRoutingCustomerById = builder.Action("GetRoutingCustomerById");

            getRoutingCustomerById.Parameter <int>("RoutingCustomerId");
            getRoutingCustomerById.ReturnsFromEntitySet <RoutingCustomer>("RoutingCustomers");

            ActionConfiguration getSalesPersonById = builder.Action("GetSalesPersonById");

            getSalesPersonById.Parameter <int>("salesPersonId");
            getSalesPersonById.ReturnsFromEntitySet <SalesPerson>("SalesPeople");

            ActionConfiguration getAllVIPs = builder.Action("GetAllVIPs");

            ActionReturnsCollectionFromEntitySet <VIP>(builder, getAllVIPs, "RoutingCustomers");

            builder.Entity <RoutingCustomer>().ComplexProperty <Address>(c => c.Address);
            builder.Entity <RoutingCustomer>().Action("GetRelatedRoutingCustomers").ReturnsCollectionFromEntitySet <RoutingCustomer>("RoutingCustomers");

            ActionConfiguration getBestRelatedRoutingCustomer = builder.Entity <RoutingCustomer>().Action("GetBestRelatedRoutingCustomer");

            ActionReturnsFromEntitySet <VIP>(builder, getBestRelatedRoutingCustomer, "RoutingCustomers");

            ActionConfiguration getVIPS = builder.Entity <RoutingCustomer>().Collection.Action("GetVIPs");

            ActionReturnsCollectionFromEntitySet <VIP>(builder, getVIPS, "RoutingCustomers");

            builder.Entity <RoutingCustomer>().Collection.Action("GetProducts").ReturnsCollectionFromEntitySet <Product>("Products");
            builder.Entity <VIP>().Action("GetSalesPerson").ReturnsFromEntitySet <SalesPerson>("SalesPeople");
            builder.Entity <VIP>().Collection.Action("GetSalesPeople").ReturnsCollectionFromEntitySet <SalesPerson>("SalesPeople");

            ActionConfiguration getMostProfitable = builder.Entity <VIP>().Collection.Action("GetMostProfitable");

            ActionReturnsFromEntitySet <VIP>(builder, getMostProfitable, "RoutingCustomers");

            ActionConfiguration getVIPRoutingCustomers = builder.Entity <SalesPerson>().Action("GetVIPRoutingCustomers");

            ActionReturnsCollectionFromEntitySet <VIP>(builder, getVIPRoutingCustomers, "RoutingCustomers");

            ActionConfiguration getVIPRoutingCustomersOnCollection = builder.Entity <SalesPerson>().Collection.Action("GetVIPRoutingCustomers");

            ActionReturnsCollectionFromEntitySet <VIP>(builder, getVIPRoutingCustomersOnCollection, "RoutingCustomers");

            builder.Entity <VIP>().HasRequired(v => v.RelationshipManager);
            builder.Entity <ImportantProduct>().HasRequired(ip => ip.LeadSalesPerson);

            return(builder.GetEdmModel());
        }
Ejemplo n.º 11
0
        public static IEdmModel GetEdmModelV1()
        {
            var builder = new ODataConventionModelBuilder();

            builder.EntitySet <Organization>("Organizations");
            builder.EntitySet <Department>("Departments");
            builder.EntitySet <Company>("Companies");
            builder.EntitySet <Customer>("Customers");
            builder.Singleton <Customer>("Me");

            var function = builder.Function("RateByOrder");

            function.Parameter <int>("order");
            function.Returns <int>();

            var action = builder.EntityType <Customer>().Action("RateByName");

            action.Parameter <string>("name");
            action.Parameter <int>("age");
            action.Returns <string>();

            // bound action
            ActionConfiguration boundAction = builder.EntityType <Customer>().Action("BoundAction");

            boundAction.Parameter <int>("p1");
            boundAction.Parameter <Address>("p2");
            boundAction.Parameter <Color?>("color");
            boundAction.CollectionParameter <string>("p3");
            boundAction.CollectionParameter <Address>("p4");
            boundAction.CollectionParameter <Color?>("colors");

            // bound function for organization
            var productPrice = builder.EntityType <Organization>().Collection.
                               Function("GetPrice").Returns <string>();

            productPrice.Parameter <string>("organizationId").Required();
            productPrice.Parameter <string>("partId").Required();

            productPrice = builder.EntityType <Organization>().Collection.
                           Function("GetPrice2").ReturnsCollectionFromEntitySet <Organization>("Organizations");
            productPrice.Parameter <string>("organizationId").Required();
            productPrice.Parameter <string>("partId").Required();
            productPrice.IsComposable = true;

            return(builder.GetEdmModel());
        }
Ejemplo n.º 12
0
        private IEdmModel GetEdmModel(ODataConventionModelBuilder builder)
        {
            builder.EntitySet <ConventionCustomer>("ConventionCustomers");
            builder.EntitySet <ConventionOrder>("ConventionOrders");
            builder.ComplexType <ConventionPerson>();
            builder.EntityType <ConventionCustomer>().ComplexProperty <ConventionAddress>(c => c.Address);

            // Top level action import
            ActionConfiguration createConventionCustomerById = builder.Action("CreateConventionCustomerById");

            createConventionCustomerById.Parameter <int>("ID");
            createConventionCustomerById.ReturnsFromEntitySet <ConventionCustomer>("ConventionCustomers");

            // Top level action import without parameter and with a collection of primitive return type
            ActionConfiguration topCollectionPrimitiveAction = builder.Action("CreateCollectionMessages");

            topCollectionPrimitiveAction.ReturnsCollection <string>();

            // Top level function import
            FunctionConfiguration getAllCustomers = builder.Function("GetAllConventionCustomers");

            getAllCustomers.ReturnsCollectionFromEntitySet <ConventionCustomer>("ConventionCustomers");

            // Top level function import with one parameter
            FunctionConfiguration getCustomersById = builder.Function("GetConventionCustomerById");

            getCustomersById.IsComposable = true;
            getCustomersById.Parameter <int>("CustomerId");
            getCustomersById.ReturnsFromEntitySet <ConventionCustomer>("ConventionCustomers");

            // Top level function import with two parameters
            FunctionConfiguration getOrder = builder.Function("GetConventionOrderByCustomerIdAndOrderName");

            getOrder.Parameter <int>("CustomerId");
            getOrder.Parameter <string>("OrderName");
            getOrder.ReturnsFromEntitySet <ConventionOrder>("ConventionOrders");

            // Top level function import with complex parameter
            FunctionConfiguration complexFunction = builder.Function("ComplexFunction");

            complexFunction.Parameter <ConventionAddress>("address");
            complexFunction.Returns <string>();

            // Top level function import with entity parameter
            FunctionConfiguration entityFunction = builder.Function("EntityFunction");

            entityFunction.Parameter <ConventionOrder>("order");
            entityFunction.Returns <string>();

            // Top level function import with optional parameter
            FunctionConfiguration optionalFunction = builder.Function("OptionalFunction");

            optionalFunction.Parameter <int>("param").HasDefaultValue("9");
            optionalFunction.Returns <string>();

            return(builder.GetEdmModel());
        }
        public static IEdmModel GetModel()
        {
            ODataConventionModelBuilder builder = new ODataConventionModelBuilder();

            builder.EntitySet <Customer>("Customers");
            builder.EntitySet <Product>("Products");
            builder.EntitySet <SalesPerson>("SalesPeople");
            builder.EntitySet <EmailAddress>("EmailAddresses");
            builder.EntitySet <üCategory>("üCategories");

            ActionConfiguration getCustomerById = new ActionConfiguration(builder, "GetCustomerById");

            getCustomerById.Parameter <int>("customerId");
            getCustomerById.ReturnsFromEntitySet <Customer>("Customers");

            ActionConfiguration getSalesPersonById = new ActionConfiguration(builder, "GetSalesPersonById");

            getSalesPersonById.Parameter <int>("salesPersonId");
            getSalesPersonById.ReturnsFromEntitySet <SalesPerson>("SalesPeople");

            ActionConfiguration getAllVIPs = new ActionConfiguration(builder, "GetAllVIPs");

            ActionReturnsCollectionFromEntitySet <VIP>(builder, getAllVIPs, "Customers");

            builder.Entity <Customer>().ComplexProperty <Address>(c => c.Address);
            builder.Entity <Customer>().Action("GetRelatedCustomers").ReturnsCollectionFromEntitySet <Customer>("Customers");

            ActionConfiguration getBestRelatedCustomer = builder.Entity <Customer>().Action("GetBestRelatedCustomer");

            ActionReturnsFromEntitySet <VIP>(builder, getBestRelatedCustomer, "Customers");

            ActionConfiguration getVIPS = builder.Entity <Customer>().Collection.Action("GetVIPs");

            ActionReturnsCollectionFromEntitySet <VIP>(builder, getVIPS, "Customers");

            builder.Entity <Customer>().Collection.Action("GetProducts").ReturnsCollectionFromEntitySet <Product>("Products");
            builder.Entity <VIP>().Action("GetSalesPerson").ReturnsFromEntitySet <SalesPerson>("SalesPeople");
            builder.Entity <VIP>().Collection.Action("GetSalesPeople").ReturnsCollectionFromEntitySet <SalesPerson>("SalesPeople");

            ActionConfiguration getMostProfitable = builder.Entity <VIP>().Collection.Action("GetMostProfitable");

            ActionReturnsFromEntitySet <VIP>(builder, getMostProfitable, "Customers");

            ActionConfiguration getVIPCustomers = builder.Entity <SalesPerson>().Action("GetVIPCustomers");

            ActionReturnsCollectionFromEntitySet <VIP>(builder, getVIPCustomers, "Customers");

            ActionConfiguration getVIPCustomersOnCollection = builder.Entity <SalesPerson>().Collection.Action("GetVIPCustomers");

            ActionReturnsCollectionFromEntitySet <VIP>(builder, getVIPCustomersOnCollection, "Customers");

            builder.Entity <VIP>().HasRequired(v => v.RelationshipManager);
            builder.Entity <ImportantProduct>().HasRequired(ip => ip.LeadSalesPerson);

            return(builder.GetEdmModel());
        }
        /// <summary>
        /// The execute.
        /// </summary>
        /// <param name="modelBuilder">
        /// The argument.
        /// </param>
        /// <param name="context">
        /// The context.
        /// </param>
        /// <returns>
        /// The <see cref="ODataConventionModelBuilder"/>.
        /// </returns>
        public override Task <ODataConventionModelBuilder> Run(ODataConventionModelBuilder modelBuilder, CommercePipelineExecutionContext context)
        {
            Condition.Requires(modelBuilder).IsNotNull($"{this.Name}: The argument cannot be null.");

            ActionConfiguration addWishlistItemAction = modelBuilder.Action("AddWishListLineItem");

            addWishlistItemAction.Parameter <string>("wishlistId");
            addWishlistItemAction.Parameter <string>("itemId");
            addWishlistItemAction.Parameter <System.Decimal>("quantity");
            addWishlistItemAction.ReturnsFromEntitySet <CommerceCommand>("Commands");

            ActionConfiguration removeWishlitItemAction = modelBuilder.Action("RemoveWishListLineItem");

            removeWishlitItemAction.Parameter <string>("wishlistId");
            removeWishlitItemAction.Parameter <string>("cartLineId");
            removeWishlitItemAction.ReturnsFromEntitySet <CommerceCommand>("Commands");

            return(Task.FromResult(modelBuilder));
        }
Ejemplo n.º 15
0
        /// <summary>
        /// The execute.
        /// </summary>
        /// <param name="modelBuilder">
        /// The argument.
        /// </param>
        /// <param name="context">
        /// The context.
        /// </param>
        /// <returns>
        /// The <see cref="ODataConventionModelBuilder"/>.
        /// </returns>
        public override Task <ODataConventionModelBuilder> Run(ODataConventionModelBuilder modelBuilder, CommercePipelineExecutionContext context)
        {
            Condition.Requires(modelBuilder).IsNotNull($"{this.Name}: The argument cannot be null.");

            // Add the entities
            ActionConfiguration actionConfiguration1 = modelBuilder.Action("ExportPriceBooks");

            actionConfiguration1.Parameter <string>("fileName");
            actionConfiguration1.Parameter <string>("mode");
            actionConfiguration1.Parameter <int>("maximumItemsPerFile");
            actionConfiguration1.Returns <FileCallbackResult>();
            ActionConfiguration actionConfiguration2 = modelBuilder.Action("ImportPriceBooks");

            actionConfiguration2.Parameter <IFormFile>("importFile");
            actionConfiguration2.Parameter <string>("mode");
            actionConfiguration2.Parameter <int>("errorThreshold");
            actionConfiguration2.ReturnsFromEntitySet <CommerceCommand>("Commands");
            return(Task.FromResult(modelBuilder));
        }
Ejemplo n.º 16
0
        private static void CriaActionsTrade(ODataModelBuilder builder)
        {
            ActionConfiguration action = CreateAction <Trade>(builder, "ExecutaTrade");

            action.Parameter <int>("IdPapel");
            action.Parameter <string>("tipoOperacao");
            action.Parameter <int>("IdCarteira");
            action.Parameter <float>("PrecoAcao");
            action.Parameter <int>("quantidade");
            action.Parameter <float>("custoOperacao");
            action.Parameter <float>("PrecoStopOpcional");
            action.Parameter <bool>("IsClosing");
        }
Ejemplo n.º 17
0
        /// <summary>
        /// Helper to improve readability.
        /// </summary>
        public static ActionConfiguration AddParameter <TParameter>(
            this ActionConfiguration config,
            string name,
            bool optional = false)
        {
            var parameter = config.Parameter <TParameter>(name);

            parameter.OptionalParameter = optional;

            return(config);
        }
Ejemplo n.º 18
0
        private static void AddBoundActionsAndFunctions(EntityTypeConfiguration <Account> account)
        {
            account.Function("GetAddressFunction").Returns <Address>();

            account.Function("GetShipAddresses").ReturnsCollection <Address>();
            account.Action("IncreaseAgeAction").Returns <AccountInfo>();

            ActionConfiguration addShipAddress = account.Action("AddShipAddress");

            addShipAddress.Parameter <Address>("address");
            addShipAddress.Returns <int>();// Total ship addresses count.
        }
        public void CanBuildBoundProcedureCacheForIEdmModel()
        {
            // Arrange            
            ODataModelBuilder builder = new ODataModelBuilder();
            EntityTypeConfiguration<Customer> customer = builder.EntitySet<Customer>("Customers").EntityType;
            customer.HasKey(c => c.ID);
            customer.Property(c => c.Name);
            customer.ComplexProperty(c => c.Address);

            EntityTypeConfiguration<Movie> movie = builder.EntitySet<Movie>("Movies").EntityType;
            movie.HasKey(m => m.ID);
            movie.HasKey(m => m.Name);
            EntityTypeConfiguration<Blockbuster> blockBuster = builder.Entity<Blockbuster>().DerivesFrom<Movie>();
            IEntityTypeConfiguration movieConfiguration = builder.StructuralTypes.OfType<IEntityTypeConfiguration>().Single(t => t.Name == "Movie");

            // build actions that are bindable to a single entity
            customer.Action("InCache1_CustomerAction");
            customer.Action("InCache2_CustomerAction");
            movie.Action("InCache3_MovieAction");
            ActionConfiguration incache4_MovieAction = new ActionConfiguration(builder, "InCache4_MovieAction");
            incache4_MovieAction.SetBindingParameter("bindingParameter", movieConfiguration, true);
            blockBuster.Action("InCache5_BlockbusterAction");

            // build actions that are either: bindable to a collection of entities, have no parameter, have only complex parameter 
            customer.Collection.Action("NotInCache1_CustomersAction");
            movie.Collection.Action("NotInCache2_MoviesAction");
            ActionConfiguration notInCache3_NoParameters = new ActionConfiguration(builder, "NotInCache3_NoParameters");
            ActionConfiguration notInCache4_AddressParameter = new ActionConfiguration(builder, "NotInCache4_AddressParameter");
            notInCache4_AddressParameter.Parameter<Address>("address");

            IEdmModel model = builder.GetEdmModel();
            IEdmEntityType customerType = model.SchemaElements.OfType<IEdmEntityType>().Single(e => e.Name == "Customer");
            IEdmEntityType movieType = model.SchemaElements.OfType<IEdmEntityType>().Single(e => e.Name == "Movie");
            IEdmEntityType blockBusterType = model.SchemaElements.OfType<IEdmEntityType>().Single(e => e.Name == "Blockbuster");

            // Act 
            BindableProcedureFinder annotation = new BindableProcedureFinder(model);
            IEdmFunctionImport[] movieActions = annotation.FindProcedures(movieType).ToArray();
            IEdmFunctionImport[] customerActions = annotation.FindProcedures(customerType).ToArray();
            IEdmFunctionImport[] blockBusterActions = annotation.FindProcedures(blockBusterType).ToArray();

            // Assert
            Assert.Equal(2, customerActions.Length);
            Assert.NotNull(customerActions.SingleOrDefault(a => a.Name == "InCache1_CustomerAction"));
            Assert.NotNull(customerActions.SingleOrDefault(a => a.Name == "InCache2_CustomerAction"));
            Assert.Equal(2, movieActions.Length);
            Assert.NotNull(movieActions.SingleOrDefault(a => a.Name == "InCache3_MovieAction"));
            Assert.NotNull(movieActions.SingleOrDefault(a => a.Name == "InCache4_MovieAction"));
            Assert.Equal(3, blockBusterActions.Length);
            Assert.NotNull(blockBusterActions.SingleOrDefault(a => a.Name == "InCache3_MovieAction"));
            Assert.NotNull(blockBusterActions.SingleOrDefault(a => a.Name == "InCache4_MovieAction"));
            Assert.NotNull(blockBusterActions.SingleOrDefault(a => a.Name == "InCache5_BlockbusterAction"));
        }
Ejemplo n.º 20
0
        public void CanCreateActionWithNonbindingParameters_AddParameterNonGenericMethod()
        {
            // Arrange
            // Act
            ODataModelBuilder   builder = new ODataModelBuilder();
            ActionConfiguration action  = builder.Action("MyAction");

            action.Parameter(typeof(string), "p0");
            action.Parameter(typeof(int), "p1");
            action.Parameter(typeof(Address), "p2");
            ParameterConfiguration[] parameters = action.Parameters.ToArray();

            // Assert
            Assert.Equal(3, parameters.Length);
            Assert.Equal("p0", parameters[0].Name);
            Assert.Equal("Edm.String", parameters[0].TypeConfiguration.FullName);
            Assert.Equal("p1", parameters[1].Name);
            Assert.Equal("Edm.Int32", parameters[1].TypeConfiguration.FullName);
            Assert.Equal("p2", parameters[2].Name);
            Assert.Equal(typeof(Address).FullName, parameters[2].TypeConfiguration.FullName);
        }
Ejemplo n.º 21
0
        public override Task <ODataConventionModelBuilder> Run(ODataConventionModelBuilder modelBuilder,
                                                               CommercePipelineExecutionContext context)
        {
            string entitySetName = "Commands";

            ActionConfiguration actionConfiguration = modelBuilder.Action("ImportEntity");

            actionConfiguration.Parameter <SourceEntityDetail>("sourceEntity");
            actionConfiguration.ReturnsFromEntitySet <CommerceCommand>(entitySetName);

            return(Task.FromResult(modelBuilder));
        }
Ejemplo n.º 22
0
        private IEdmModel GetModel()
        {
            ODataModelBuilder builder = new ODataConventionModelBuilder();

            builder.ContainerName = "Container";
            builder.Namespace     = "org.odata";
            EntityTypeConfiguration <Customer> customer = builder.EntitySet <Customer>("Customers").EntityType;
            ActionConfiguration action = customer.Action("DoSomething");

            action.Parameter <int>("p1");
            action.Parameter <Address>("p2");
            action.Parameter <Color?>("color");
            action.CollectionParameter <string>("p3");
            action.CollectionParameter <Address>("p4");
            action.CollectionParameter <Color?>("colors");

            action = customer.Collection.Action("MyAction");
            action.EntityParameter <Customer>("Customer");
            action.CollectionEntityParameter <Customer>("Customers");
            return(builder.GetEdmModel());
        }
        public static void Register(HttpConfiguration config)
        {
            ODataConventionModelBuilder builder = new ODataConventionModelBuilder();

            builder.EntitySet <Product>("Products");
            builder.EntitySet <Supplier>("Suppliers");
            builder.EntitySet <ProductRating>("Ratings");
            ActionConfiguration rateProduct = builder.Entity <Product>().Action("RateProduct");

            rateProduct.Parameter <int>("Rating");
            rateProduct.Returns <double>();

            config.Routes.MapODataRoute("odata", "odata", builder.GetEdmModel());
        }
        public void RemoveProcedureByNameThrowsWhenAmbiguous()
        {
            // Arrange
            // Act
            ODataModelBuilder builder = new ODataModelBuilder();

            ActionConfiguration action1 = new ActionConfiguration(builder, "Format");
            ActionConfiguration action2 = new ActionConfiguration(builder, "Format");
            action2.Parameter<int>("SegmentSize");

            Assert.Throws<InvalidOperationException>(() =>
            {
                builder.RemoveProcedure("Format");
            });
        }
Ejemplo n.º 25
0
        /// <summary>
        /// The execute.
        /// </summary>
        /// <param name="modelBuilder">
        /// The argument.
        /// </param>
        /// <param name="context">
        /// The context.
        /// </param>
        /// <returns>
        /// The <see cref="ODataConventionModelBuilder"/>.
        /// </returns>
        public override Task <ODataConventionModelBuilder> Run(ODataConventionModelBuilder modelBuilder, CommercePipelineExecutionContext context)
        {
            Condition.Requires(modelBuilder).IsNotNull($"{this.Name}: The argument cannot be null.");

            // Add the entities
            //modelBuilder.AddEntityType(typeof(SampleEntity));

            // Add the entity sets
            //modelBuilder.EntitySet<SampleEntity>("Sample");

            // Add complex types

            // Add unbound functions

            // Add unbound actions
            //var configuration = modelBuilder.Action("SampleCommand");
            //configuration.Parameter<string>("Id");
            //configuration.ReturnsFromEntitySet<CommerceCommand>("Commands");


            ActionConfiguration actionConfiguration2 = modelBuilder.Action("AddWishListLineItem");

            actionConfiguration2.Parameter <string>("wishlistId");
            actionConfiguration2.Parameter <string>("itemId");
            actionConfiguration2.Parameter <System.Decimal>("quantity");
            //string entitySetName2 = "Commands";
            actionConfiguration2.ReturnsFromEntitySet <CommerceCommand>("Commands");

            ActionConfiguration actionConfiguration3 = modelBuilder.Action("RemoveWishListLineItem");

            actionConfiguration3.Parameter <string>("wishlistId");
            actionConfiguration3.Parameter <string>("cartLineId");
            actionConfiguration3.ReturnsFromEntitySet <CommerceCommand>("Commands");

            return(Task.FromResult(modelBuilder));
        }
Ejemplo n.º 26
0
        private static void MapCustomModules(ODataModelBuilder builder)
        {
            builder
            .EntitySet <MenuModel>("AUSLRE_BandiDiGaraMenu")
            .EntityType.HasKey(p => p.UniqueId);

            builder
            .EntitySet <ArchiveModel>("AUSLRE_BandiDiGaraArchives")
            .EntityType.HasKey(p => p.UniqueId);

            #region [ Functions ]
            FunctionConfiguration getMenu = builder
                                            .EntityType <MenuModel>().Collection
                                            .Function("GetMenu");

            getMenu.Namespace = "MenuModelService";
            getMenu.ReturnsCollectionFromEntitySet <MenuModel>("AUSLRE_BandiDiGaraMenu");

            ActionConfiguration countArchiveByGrid = builder
                                                     .EntityType <ArchiveModel>().Collection
                                                     .Action("CountArchiveByGrid");

            countArchiveByGrid.Namespace = "ArchiveModelService";
            countArchiveByGrid.ReturnsCollectionFromEntitySet <ArchiveModel>("AUSLRE_BandiDiGaraArchives");
            countArchiveByGrid.Parameter <ArchiveFinderModel>("finder");

            ActionConfiguration searchArchiveByGrid = builder
                                                      .EntityType <ArchiveModel>().Collection
                                                      .Action("SearchArchiveByGrid");

            searchArchiveByGrid.Namespace = "ArchiveModelService";
            searchArchiveByGrid.ReturnsCollectionFromEntitySet <ArchiveModel>("AUSLRE_BandiDiGaraArchives");
            searchArchiveByGrid.Parameter <ArchiveFinderModel>("finder");


            FunctionConfiguration getArchiveInfo = builder
                                                   .EntityType <ArchiveModel>().Collection
                                                   .Function("GetArchiveInfo");

            getArchiveInfo.Namespace = "ArchiveModelService";
            getArchiveInfo.Parameter <Guid>("uniqueId");
            getArchiveInfo.ReturnsCollectionFromEntitySet <ArchiveModel>("AUSLRE_BandiDiGaraArchives");
            #endregion

            #region [ Navigation Properties ]

            #endregion
        }
Ejemplo n.º 27
0
    public static void Register(HttpConfiguration config)
    {
        ODataConventionModelBuilder builder = new ODataConventionModelBuilder();

        builder.EntitySet <Product>("Products");
        builder.EntitySet <Supplier>("Suppliers");
        builder.EntitySet <ProductRating>("Ratings");

        // New code: Add an action to the EDM, and define the parameter and return type.
        ActionConfiguration rateProduct = builder.Entity > Product > ().Action("RateProduct");

        rateProduct.Parameter <int>("Rating");
        rateProduct.Returns <double>();

        config.Routes.MapODataRoute("odata", "odata", builder.GetEdmModel());
    }
Ejemplo n.º 28
0
        public void RemoveOperationByNameThrowsWhenAmbiguous()
        {
            // Arrange
            // Act
            ODataModelBuilder builder = new ODataModelBuilder();

            ActionConfiguration action1 = builder.Action("Format");
            ActionConfiguration action2 = builder.Action("Format");

            action2.Parameter <int>("SegmentSize");

            ExceptionAssert.Throws <InvalidOperationException>(() =>
            {
                builder.RemoveOperation("Format");
            });
        }
Ejemplo n.º 29
0
        /// <summary>
        /// Generates a model from a few seeds (i.e. the names and types of the entity sets)
        /// by applying conventions.
        /// </summary>
        /// <returns>An implicitly configured model</returns>
        static IEdmModel GetImplicitEdmModel()
        {
            ODataModelBuilder modelBuilder = new ODataConventionModelBuilder();

            modelBuilder.EntitySet <Product>("Products");
            modelBuilder.Entity <RatedProduct>().DerivesFrom <Product>();
            modelBuilder.EntitySet <ProductFamily>("ProductFamilies");
            modelBuilder.EntitySet <Supplier>("Suppliers");

            ActionConfiguration createProduct = modelBuilder.Entity <ProductFamily>().Action("CreateProduct");

            createProduct.Parameter <string>("Name");
            createProduct.Returns <int>();

            return(modelBuilder.GetEdmModel());
        }
        private static void BuildActions(ODataModelBuilder builder)
        {
            ActionConfiguration action = builder.EntityType <DCustomer>().Action("BoundAction");

            action.Parameter <Date>("modifiedDate");
            action.Parameter <TimeOfDay>("modifiedTime");
            action.Parameter <Date?>("nullableModifiedDate");
            action.Parameter <TimeOfDay?>("nullableModifiedTime");
            action.CollectionParameter <Date>("dates");

            action = builder.Action("UnboundAction");
            action.Parameter <Date>("modifiedDate");
            action.Parameter <TimeOfDay>("modifiedTime");
            action.Parameter <Date?>("nullableModifiedDate");
            action.Parameter <TimeOfDay?>("nullableModifiedTime");
            action.CollectionParameter <Date>("dates");

            // just for reset the data source
            builder.Action("ResetDataSource");
        }
Ejemplo n.º 31
0
        private static void CriaActionsCarteira(ODataModelBuilder builder)
        {
            ActionConfiguration action = CreateAction <Carteira>(builder, "DepositaFundos");

            action.Parameter <int>("IdCarteira");
            action.Parameter <float>("valor");
            action.Parameter <string>("descricao");

            action = CreateAction <Carteira>(builder, "RetiraFundos");
            action.Parameter <int>("IdCarteira");
            action.Parameter <float>("valor");
            action.Parameter <string>("descricao");
        }
Ejemplo n.º 32
0
        public static void Register(HttpConfiguration config)
        {
            ODataConventionModelBuilder builder = new ODataConventionModelBuilder();

            builder.EntitySet <Product>("Products");
            builder.EntitySet <Supplier>("Suppliers");
            builder.EntitySet <ProductRating>("Ratings");
            ActionConfiguration rateProduct = builder.Entity <Product>().Action("RateProduct");

            rateProduct.Parameter <int>("Rating");
            rateProduct.Returns <double>();

            var        model  = builder.GetEdmModel();
            HttpServer server = new HttpServer(config);

            config.Routes.MapODataServiceRoute("odata", "", model);
            config.EnableQuerySupport();

            config.Formatters.JsonFormatter.SerializerSettings.ReferenceLoopHandling = Newtonsoft.Json.ReferenceLoopHandling.Ignore;
        }
        public void CanCreateActionWithNonBindingParameters()
        {
            // Arrange
            // Act
            ODataModelBuilder builder = new ODataModelBuilder();
            ActionConfiguration action = new ActionConfiguration(builder, "MyAction");
            action.Parameter<string>("p0");
            action.Parameter<int>("p1");
            action.Parameter<Address>("p2");
            action.CollectionParameter<string>("p3");
            action.CollectionParameter<int>("p4");
            action.CollectionParameter<ZipCode>("p5");
            ParameterConfiguration[] parameters = action.Parameters.ToArray();
            ComplexTypeConfiguration[] complexTypes = builder.StructuralTypes.OfType<ComplexTypeConfiguration>().ToArray();

            // Assert
            Assert.Equal(2, complexTypes.Length);
            Assert.Equal(typeof(Address).FullName, complexTypes[0].FullName);
            Assert.Equal(typeof(ZipCode).FullName, complexTypes[1].FullName);
            Assert.Equal(6, parameters.Length);
            Assert.Equal("p0", parameters[0].Name);
            Assert.Equal("Edm.String", parameters[0].TypeConfiguration.FullName);
            Assert.Equal("p1", parameters[1].Name);
            Assert.Equal("Edm.Int32", parameters[1].TypeConfiguration.FullName);
            Assert.Equal("p2", parameters[2].Name);
            Assert.Equal(typeof(Address).FullName, parameters[2].TypeConfiguration.FullName);
            Assert.Equal("p3", parameters[3].Name);
            Assert.Equal("Collection(Edm.String)", parameters[3].TypeConfiguration.FullName);
            Assert.Equal("p4", parameters[4].Name);
            Assert.Equal("Collection(Edm.Int32)", parameters[4].TypeConfiguration.FullName);
            Assert.Equal("p5", parameters[5].Name);
            Assert.Equal(string.Format("Collection({0})", typeof(ZipCode).FullName), parameters[5].TypeConfiguration.FullName);
        }