// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
        {
            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
            }

            app.UseODataBatching();

            app.UseMvc(b =>
            {
                b.Count().Filter().OrderBy().Expand().Select().MaxTop(null);
                b.MapODataServiceRoute("odata", "odata", SingletonEdmModel.GetEdmModel(), new DefaultODataBatchHandler());
            });
        }
        public static TKey GetKeyFromUri <TKey>(HttpRequest request, Uri uri)
        {
            if (uri == null)
            {
                throw new ArgumentNullException("uri");
            }
            var rootPath       = uri.AbsoluteUri.Substring(0, uri.AbsoluteUri.LastIndexOf('/') + 1);
            var odataUriParser = new ODataUriParser(SingletonEdmModel.GetEdmModel(), new Uri(rootPath), uri);
            var odataPath      = odataUriParser.ParsePath();
            var keySegment     = odataPath.LastSegment as KeySegment;

            if (keySegment == null)
            {
                throw new InvalidOperationException("The link does not contain a key.");
            }
            return((TKey)keySegment.Keys.First().Value);
        }
Exemple #3
0
        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app, IHostingEnvironment env)
        {
            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
            }
            else
            {
                // The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts.
                app.UseHsts();
            }

            app.UseHttpsRedirection();
            app.UseMvc(b =>
            {
                b.Count().Filter().OrderBy().Expand().Select().MaxTop(null);
                b.MapODataServiceRoute("odata", "odata", SingletonEdmModel.GetEdmModel());
            });
        }
Exemple #4
0
        public static TKey GetKeyFromUri <TKey>(HttpRequest request, Uri uri)
        {
            // if (uri == null)
            // {
            //     throw new ArgumentNullException("uri");
            // }
            // var urlHelper = request.GetUrlHelper();// ?? new UrlHelper(request);
            // var pathHandler = (IODataPathHandler)request.GetRequestContainer().GetService(typeof(IODataPathHandler));
            // string serviceRoot = urlHelper.CreateODataLink(
            //     "request.ODataProperties().RouteName",
            //     pathHandler, new List<ODataPathSegment>());
            // var odataPath = pathHandler.Parse(serviceRoot, uri.LocalPath, request.GetRequestContainer());
            // var keySegment = odataPath.Segments.OfType<KeySegment>().FirstOrDefault();
            // if (keySegment == null)
            // {
            //     throw new InvalidOperationException("The link does not contain a key.");
            // }
            // var value = keySegment.Keys.FirstOrDefault().Value;
            // return (TKey)value;
            if (uri == null)
            {
                throw new ArgumentNullException("uri");
            }

            // Calculate root Uri
            var rootPath = uri.AbsoluteUri.Substring(0, uri.AbsoluteUri.LastIndexOf('/') + 1);

            var odataUriParser = new ODataUriParser(SingletonEdmModel.GetEdmModel(), new Uri(rootPath), uri);
            var odataPath      = odataUriParser.ParsePath();
            var keySegment     = odataPath.LastSegment as KeySegment;

            if (keySegment == null)
            {
                throw new InvalidOperationException("The link does not contain a key.");
            }

            return((TKey)keySegment.Keys.First().Value);
        }