Ejemplo n.º 1
0
        private static OeSkipTokenNameValue[] ParseJson(IEdmModel model, String skipToken, IEdmStructuralProperty[] keys)
        {
            var skipTokenNameValues = new OeSkipTokenNameValue[keys.Length];

            using (var stream = new MemoryStream(Encoding.UTF8.GetBytes(skipToken)))
            {
                IODataRequestMessage requestMessage = new OeInMemoryMessage(stream, null);
                using (ODataMessageReader messageReader = new ODataMessageReader(requestMessage, ReaderSettings, model))
                {
                    var operation = new EdmAction("", "", null);
                    foreach (IEdmStructuralProperty key in keys)
                    {
                        operation.AddParameter(GetPropertyName(key), key.Type);
                    }

                    ODataParameterReader reader = messageReader.CreateODataParameterReader(operation);
                    int i = 0;
                    while (reader.Read())
                    {
                        Object value = reader.Value;
                        if (value is ODataEnumValue enumValue)
                        {
                            value = OeEdmClrHelper.GetValue(model, enumValue);
                        }
                        skipTokenNameValues[i++] = new OeSkipTokenNameValue(reader.Name, value);
                    }
                }
            }
            return(skipTokenNameValues);
        }
        public static IEnumerable <KeyValuePair <String, Object> > ParseJson(IEdmModel model, String skipToken, IEnumerable <IEdmStructuralProperty> keys)
        {
            using (var stream = new MemoryStream(Encoding.UTF8.GetBytes(skipToken)))
            {
                IODataRequestMessage requestMessage = new OeInMemoryMessage(stream, null);
                using (ODataMessageReader messageReader = new ODataMessageReader(requestMessage, ReaderSettings, model))
                {
                    var operation = new EdmAction("", "", null);
                    foreach (IEdmStructuralProperty key in keys)
                    {
                        operation.AddParameter(GetPropertyName(key), key.Type);
                    }

                    ODataParameterReader reader = messageReader.CreateODataParameterReader(operation);
                    while (reader.Read())
                    {
                        Object value = reader.Value;
                        if (value is ODataEnumValue enumValue)
                        {
                            value = OeEdmClrHelper.GetValue(model, enumValue);
                        }
                        yield return(new KeyValuePair <String, Object>(reader.Name, value));
                    }
                }
            }
        }
Ejemplo n.º 3
0
        private static void FillParameters(IEdmModel edmModel, List <KeyValuePair <String, Object> > parameters, Stream requestStream, IEdmOperation operation, String contentType)
        {
            if (!operation.Parameters.Any())
            {
                return;
            }

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

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

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

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

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

                    default:
                        continue;
                    }

                    parameters.Add(new KeyValuePair <String, Object>(parameterReader.Name, value));
                }
            }
        }
Ejemplo n.º 4
0
        public static IReadOnlyList <KeyValuePair <String, Object?> > GetParameters(IEdmModel edmModel, ODataPathSegment segment,
                                                                                    IDictionary <string, SingleValueNode> parameterAliasNodes, Stream?requestStream = null, String?contentType = null)
        {
            var parameters = new List <KeyValuePair <String, Object?> >();

            IEdmOperation operation;
            IEnumerable <OperationSegmentParameter> segmentParameters;

            if (segment is OperationSegment operationSegment)
            {
                segmentParameters = operationSegment.Parameters;
                operation         = operationSegment.Operations.Single();
            }
            else if (segment is OperationImportSegment operationImportSegment)
            {
                segmentParameters = operationImportSegment.Parameters;
                operation         = (EdmOperation)operationImportSegment.OperationImports.Single().Operation;
            }
            else
            {
                throw new InvalidOperationException("Not supported segment type " + segment.GetType().Name);
            }

            foreach (OperationSegmentParameter segmentParameter in segmentParameters)
            {
                Object?value;
                if (segmentParameter.Value is ConstantNode constantNode)
                {
                    value = OeEdmClrHelper.GetValue(edmModel, constantNode.Value);
                }
                else if (segmentParameter.Value is ConvertNode convertNode)
                {
                    value = OeEdmClrHelper.GetValue(edmModel, ((ConstantNode)convertNode.Source).Value);
                }
                else if (segmentParameter.Value is ParameterAliasNode parameterAliasNode)
                {
                    value = OeEdmClrHelper.GetValue(edmModel, ((ConstantNode)parameterAliasNodes[parameterAliasNode.Alias]).Value);
                }
                else
                {
                    value = OeEdmClrHelper.GetValue(edmModel, segmentParameter.Value);
                }

                parameters.Add(new KeyValuePair <String, Object?>(segmentParameter.Name, value));
            }

            if (parameters.Count == 0 && requestStream != null)
            {
                FillParameters(edmModel, parameters, requestStream, operation, contentType);
            }
            OrderParameters(operation.Parameters, parameters);

            return(parameters);
        }
Ejemplo n.º 5
0
        private static OeSkipTokenNameValue[] ParseJson(IEdmModel edmModel, String skipToken, IEdmStructuralProperty[] keys, out int?restCount)
        {
            restCount = null;
            var skipTokenNameValues = new OeSkipTokenNameValue[keys.Length];

            using (var stream = new MemoryStream(Encoding.UTF8.GetBytes(skipToken)))
            {
                IODataRequestMessage requestMessage = new Infrastructure.OeInMemoryMessage(stream, null);
                using (ODataMessageReader messageReader = new ODataMessageReader(requestMessage, ReaderSettings, edmModel))
                {
                    var operation = new EdmAction("", "", null);
                    foreach (IEdmStructuralProperty key in keys)
                    {
                        operation.AddParameter(GetPropertyName(key), key.Type);
                    }
                    operation.AddParameter(RestCountName, OeEdmClrHelper.GetEdmTypeReference(edmModel, typeof(int?)));

                    ODataParameterReader reader = messageReader.CreateODataParameterReader(operation);
                    int i = 0;
                    while (reader.Read())
                    {
                        Object value = reader.Value;
                        if (value is ODataEnumValue enumValue)
                        {
                            value = OeEdmClrHelper.GetValue(edmModel, enumValue);
                        }

                        if (reader.Name == RestCountName)
                        {
                            restCount = (int)value;
                        }
                        else
                        {
                            skipTokenNameValues[i++] = new OeSkipTokenNameValue(reader.Name, value);
                        }
                    }
                }
            }
            return(skipTokenNameValues);
        }
Ejemplo n.º 6
0
        private List <KeyValuePair <String, Object> > GetParameters(OperationImportSegment importSegment, IDictionary <string, SingleValueNode> parameterAliasNodes, Stream requestStream, String contentType)
        {
            var parameters = new List <KeyValuePair <String, Object> >();

            foreach (OperationSegmentParameter segmentParameter in importSegment.Parameters)
            {
                Object value;
                if (segmentParameter.Value is ConstantNode constantNode)
                {
                    value = OeEdmClrHelper.GetValue(_edmModel, constantNode.Value);
                }
                else if (segmentParameter.Value is ParameterAliasNode parameterAliasNode)
                {
                    value = ((ConstantNode)parameterAliasNodes[parameterAliasNode.Alias]).Value;
                    if (value is ODataCollectionValue collectionValue)
                    {
                        value = collectionValue.Items;
                    }
                }
                else
                {
                    value = OeEdmClrHelper.GetValue(_edmModel, segmentParameter.Value);
                }
                parameters.Add(new KeyValuePair <String, Object>(segmentParameter.Name, value));
            }

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

            if (parameters.Count == 0 && requestStream != null)
            {
                FillParameters(parameters, requestStream, operation, contentType);
            }
            OrderParameters(operation.Parameters, parameters);

            return(parameters);
        }