示例#1
0
        public Db.OeAsyncEnumerator GetAsyncEnumerator(ODataUri odataUri, Stream requestStream, OeRequestHeaders headers, Object dataContext, out Type returnClrType)
        {
            var importSegment = (OperationImportSegment)odataUri.Path.LastSegment;

            List <KeyValuePair <String, Object> > parameters = GetParameters(importSegment, requestStream, headers.ContentType);
            IEdmOperationImport operationImport = importSegment.OperationImports.Single();

            returnClrType = null;
            if (operationImport.Operation.ReturnType != null)
            {
                IEdmTypeReference returnEdmTypeReference = operationImport.Operation.ReturnType;
                if (returnEdmTypeReference is IEdmCollectionTypeReference)
                {
                    returnEdmTypeReference = (returnEdmTypeReference.Definition as IEdmCollectionType).ElementType;
                }
                returnClrType = OeEdmClrHelper.GetClrType(_model, returnEdmTypeReference.Definition);
            }

            if (_model.IsDbFunction(operationImport.Operation))
            {
                return(_dataAdapter.OperationAdapter.ExecuteFunction(dataContext, operationImport.Name, parameters, returnClrType));
            }
            else
            {
                return(_dataAdapter.OperationAdapter.ExecuteProcedure(dataContext, operationImport.Name, parameters, returnClrType));
            }
        }
示例#2
0
        public async Task ExecuteAsync(ODataUri odataUri, Stream requestStream, OeRequestHeaders headers, Stream responseStream, CancellationToken cancellationToken)
        {
            var importSegment = (OperationImportSegment)odataUri.Path.LastSegment;

            List <KeyValuePair <String, Object> > parameters = GetParameters(importSegment, requestStream, headers.ContentType);
            Object dataContext = null;

            try
            {
                dataContext = _dataAdapter.CreateDataContext();

                var operation = (EdmOperation)importSegment.OperationImports.Single().Operation;

                String procedureName;
                if (String.IsNullOrEmpty(operation.Namespace))
                {
                    procedureName = operation.Name;
                }
                else
                {
                    procedureName = operation.Namespace + "." + operation.Name;
                }

                Type returnClrType = null;
                if (operation.ReturnType != null)
                {
                    IEdmTypeReference returnEdmTypeReference = operation.ReturnType;
                    if (returnEdmTypeReference is IEdmCollectionTypeReference)
                    {
                        returnEdmTypeReference = (returnEdmTypeReference.Definition as IEdmCollectionType).ElementType;
                    }
                    returnClrType = OeEdmClrHelper.GetClrType(_model, returnEdmTypeReference.Definition);
                }

                using (Db.OeEntityAsyncEnumerator asyncEnumerator = _dataAdapter.ExecuteProcedure(dataContext, procedureName, parameters, returnClrType))
                {
                    if (returnClrType == null)
                    {
                        if (await asyncEnumerator.MoveNextAsync() && asyncEnumerator.Current != null)
                        {
                            byte[] buffer = System.Text.Encoding.UTF8.GetBytes(asyncEnumerator.Current.ToString());
                            responseStream.Write(buffer, 0, buffer.Length);
                        }
                    }
                    else
                    {
                        String        entitySetName               = _dataAdapter.EntitySetMetaAdapters.FindByClrType(returnClrType).EntitySetName;
                        IEdmEntitySet entitySet                   = _model.FindDeclaredEntitySet(entitySetName);
                        Parsers.OePropertyAccessor[] accessors    = Parsers.OePropertyAccessor.CreateFromType(returnClrType, entitySet);
                        Parsers.OeEntryFactory       entryFactory = Parsers.OeEntryFactory.CreateEntryFactory(entitySet, accessors);

                        var parseUriContext = new Parsers.OeParseUriContext(_model, odataUri, entitySet, null, false)
                        {
                            EntryFactory = entryFactory,
                            Headers      = headers
                        };
                        await Writers.OeGetWriter.SerializeAsync(_baseUri, parseUriContext, asyncEnumerator, responseStream).ConfigureAwait(false);
                    }
                }
            }
            finally
            {
                if (dataContext != null)
                {
                    _dataAdapter.CloseDataContext(dataContext);
                }
            }

            await Task.CompletedTask;
        }