protected OeAsyncEnumerator GetAsyncEnumerator(HttpContext httpContext, Stream responseStream, bool navigationNextLink = false, int?maxPageSize = null) { var odataParser = new ODataUriParser(_edmModel, UriHelper.GetBaseUri(httpContext.Request), UriHelper.GetUri(httpContext.Request)); odataParser.Resolver.EnableCaseInsensitive = true; ODataUri odataUri = odataParser.ParseUri(); var requestHeaders = (HttpRequestHeaders)httpContext.Request.Headers; OeRequestHeaders headers = GetRequestHeaders(requestHeaders, httpContext.Response, navigationNextLink, maxPageSize); if (odataUri.Path.LastSegment is OperationImportSegment) { return(Execute(odataUri, httpContext.Request.Body, headers, httpContext.RequestAborted)); } var getParser = new OeGetParser(_dataAdapter, _edmModel); _queryContext = getParser.CreateQueryContext(odataUri, headers.MaxPageSize, headers.NavigationNextLink, headers.MetadataLevel); return(Execute(headers, responseStream, httpContext.RequestAborted)); }
private Task InvokeServiceDocument(HttpContext httpContext) { httpContext.Response.ContentType = "application/schema+json"; return(GetServiceDocument(EdmModel, UriHelper.GetBaseUri(httpContext.Request), httpContext.Response.Body)); }
private IAsyncEnumerable <Object> GetAsyncEnumerator(IQueryable source = null) { _httpContext.Response.RegisterForDispose(this); ODataUri odataUri = OeParser.ParseUri(_edmModel, UriHelper.GetBaseUri(_httpContext.Request), UriHelper.GetUri(_httpContext.Request)); IEdmModel refModel = _edmModel.GetEdmModel(odataUri.Path); _dataAdapter = refModel.GetDataAdapter(refModel.EntityContainer); if (_dataContext == null) { _dataContext = _dataAdapter.CreateDataContext(); } var requestHeaders = (HttpRequestHeaders)_httpContext.Request.Headers; OeRequestHeaders headers = GetRequestHeaders(requestHeaders, _httpContext.Response); if (odataUri.Path.LastSegment is OperationImportSegment) { return(ExecutePost(refModel, odataUri, headers, _httpContext.Request.Body)); } else { return(ExecuteGet(refModel, odataUri, headers, source)); } }
public void OnActionExecuted(ActionExecutedContext context) { if (!(context.ModelState is BatchModelStateDictionary) && _asyncLocal.Value is BatchModelStateDictionary modelState) { //single operation _asyncLocal.Value = new ModelStateDictionary(); Db.OeDataAdapter dataAdapter = modelState.DataAdapter; Object dataContext = modelState.DataContext.DbContext; OeOperationMessage operation = modelState.DataContext.Operation; try { dataAdapter.SaveChangesAsync(dataContext, CancellationToken.None).GetAwaiter().GetResult(); dataAdapter.EntitySetAdapters.Find(operation.EntitySet).UpdateEntityAfterSave(dataContext, operation.Entry); context.HttpContext.Response.ContentType = context.HttpContext.Request.ContentType; var batchWriter = new Writers.OeBatchWriter(modelState.DataContext.EdmModel, UriHelper.GetBaseUri(context.HttpContext.Request)); Infrastructure.AsyncEnumeratorHelper.GetResult(batchWriter.WriteOperationAsync(context.HttpContext.Response.Body, operation)); } finally { dataAdapter.CloseDataContext(dataContext); } } }
public static async Task Get(HttpContext httpContext, Query.OeModelBoundProvider?modelBoundProvider = null) { var parser = new OeParser(UriHelper.GetBaseUri(httpContext.Request), httpContext.GetEdmModel(), modelBoundProvider, null); OeRequestHeaders headers = GetRequestHeaders(httpContext.Request.Headers, httpContext.Response); await parser.ExecuteGetAsync(UriHelper.GetUri(httpContext.Request), headers, httpContext.Response.Body, httpContext.RequestAborted).ConfigureAwait(false); }
protected virtual async Task BatchCore() { var actionDescriptors = GetService <IActionDescriptorCollectionProvider>().ActionDescriptors; var actionInvokerFactory = GetService <IActionInvokerFactory>(); String basePath = ""; if (base.HttpContext.Request.PathBase.HasValue) { basePath = base.HttpContext.Request.PathBase; } else { int i = base.HttpContext.Request.Path.Value.IndexOf('/', 1); if (i > 0) { basePath = base.HttpContext.Request.Path.Value.Substring(0, i); } } Uri baseUri = UriHelper.GetBaseUri(base.Request); OeBatchMessage batchMessage = OeBatchMessage.CreateBatchMessage(EdmModel, baseUri, base.HttpContext.Request.Body, base.HttpContext.Request.ContentType); OeDataAdapter dataAdapter = null; Object dataContext = null; try { IEdmModel refModel = null; foreach (OeOperationMessage operation in batchMessage.Changeset) { if (dataContext == null) { refModel = EdmModel.GetEdmModel(operation.EntitySet.Container); dataAdapter = refModel.GetDataAdapter(operation.EntitySet.Container); dataContext = dataAdapter.CreateDataContext(); } OeEntitySetAdapter entitySetAdapter = refModel.GetEntitySetAdapter(operation.EntitySet); String path = basePath + "/" + entitySetAdapter.EntitySetName; List <ActionDescriptor> candidates = OeRouter.SelectCandidates(actionDescriptors.Items, base.RouteData.Values, path, operation.Method); if (candidates.Count > 1) { throw new AmbiguousActionException(String.Join(Environment.NewLine, candidates.Select(c => c.DisplayName))); } if (candidates.Count == 0) { throw new InvalidOperationException("Action " + operation.Method + " for controller " + basePath + " not found"); } Object entity; if (operation.Method == ODataConstants.MethodPatch) { var properties = new Dictionary <String, Object>(); foreach (ODataProperty odataProperty in operation.Entry.Properties) { PropertyInfo propertyInfo = entitySetAdapter.EntityType.GetProperty(odataProperty.Name); properties[odataProperty.Name] = OeEdmClrHelper.GetClrValue(propertyInfo.PropertyType, odataProperty.Value); } entity = properties; } else { entity = OeEdmClrHelper.CreateEntity(entitySetAdapter.EntityType, operation.Entry); } var modelState = new OeBatchFilterAttributeAttribute.BatchModelStateDictionary() { Entity = entity, DataContext = new OeDataContext(entitySetAdapter, refModel, dataContext, operation) }; OnBeforeInvokeController(modelState.DataContext, operation.Entry); var actionContext = new ActionContext(base.HttpContext, base.HttpContext.GetRouteData(), candidates[0], modelState); IActionInvoker actionInvoker = actionInvokerFactory.CreateInvoker(actionContext); await actionInvoker.InvokeAsync(); } await SaveChangesAsync(dataContext).ConfigureAwait(false); } finally { if (dataContext != null) { dataAdapter.CloseDataContext(dataContext); } } base.HttpContext.Response.ContentType = base.HttpContext.Request.ContentType; var batchWriter = new OeBatchWriter(EdmModel, baseUri); batchWriter.Write(base.HttpContext.Response.Body, batchMessage); }