Ejemplo n.º 1
0
        private void FillParameters(List <KeyValuePair <String, Object> > parameters, Stream requestStream, IEdmOperation operation, String contentType)
        {
            if (!operation.Parameters.Any())
            {
                return;
            }

            IODataRequestMessage requestMessage = new OeInMemoryMessage(requestStream, contentType);
            var settings = new ODataMessageReaderSettings()
            {
                EnableMessageStreamDisposal = false
            };

            using (var messageReader = new ODataMessageReader(requestMessage, settings, _model))
            {
                ODataParameterReader parameterReader = messageReader.CreateODataParameterReader(operation);
                while (parameterReader.Read())
                {
                    Object value;
                    switch (parameterReader.State)
                    {
                    case ODataParameterReaderState.Value:
                    {
                        value = OeEdmClrHelper.GetValue(_model, parameterReader.Value);
                        break;
                    }

                    case ODataParameterReaderState.Collection:
                    {
                        ODataCollectionReader collectionReader = parameterReader.CreateCollectionReader();
                        value = OeEdmClrHelper.GetValue(_model, ReadCollection(collectionReader));
                        break;
                    }

                    case ODataParameterReaderState.Resource:
                    {
                        ODataReader reader = parameterReader.CreateResourceReader();
                        value = OeEdmClrHelper.GetValue(_model, ReadResource(reader));
                        break;
                    }

                    case ODataParameterReaderState.ResourceSet:
                    {
                        ODataReader reader = parameterReader.CreateResourceSetReader();
                        value = OeEdmClrHelper.GetValue(_model, ReadResourceSet(reader));
                        break;
                    }

                    default:
                        continue;
                    }

                    parameters.Add(new KeyValuePair <String, Object>(parameterReader.Name, value));
                }
            }
        }
Ejemplo n.º 2
0
        public static OeRequestHeaders Parse(String acceptHeader, String preferHeader)
        {
            OeRequestHeaders requestHeaders = Parse(acceptHeader);

            if (String.IsNullOrEmpty(preferHeader))
            {
                return(requestHeaders);
            }

            var message = new OeInMemoryMessage(null, null);

            message.SetHeader("Prefer", preferHeader);
            ODataPreferenceHeader preferenceHeader = message.PreferHeader();

            if (preferenceHeader.MaxPageSize == null)
            {
                return(requestHeaders);
            }

            return(requestHeaders.SetMaxPageSize(preferenceHeader.MaxPageSize.GetValueOrDefault()));
        }