Exemplo n.º 1
0
        public async Task ExecuteAsync(Stream requestStream, Stream responseStream, String contentType, CancellationToken cancellationToken)
        {
            var            context      = new OeMessageContext(_baseUri, _model, _dataAdapter.EntitySetMetaAdapters);
            OeBatchMessage batchMessage = OeBatchMessage.CreateBatchMessage(context, requestStream, contentType);

            if (batchMessage.Changeset != null)
            {
                await ExecuteChangeset(batchMessage.Changeset, cancellationToken).ConfigureAwait(false);
            }
            else if (batchMessage.Operation != null)
            {
                await ExecuteOperation(batchMessage.Operation, cancellationToken).ConfigureAwait(false);
            }

            var batchWriter = new Writers.OeBatchWriter(context.BaseUri, context.Model);

            batchWriter.Write(responseStream, batchMessage);
        }
Exemplo n.º 2
0
        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));
                    batchWriter.WriteOperationAsync(context.HttpContext.Response.Body, operation).GetAwaiter().GetResult();
                }
                finally
                {
                    dataAdapter.CloseDataContext(dataContext);
                }
            }
        }