当前位置: 首页>>代码示例>>C#>>正文


C# ODataMessageReader.CreateODataParameterReader方法代码示例

本文整理汇总了C#中ODataMessageReader.CreateODataParameterReader方法的典型用法代码示例。如果您正苦于以下问题:C# ODataMessageReader.CreateODataParameterReader方法的具体用法?C# ODataMessageReader.CreateODataParameterReader怎么用?C# ODataMessageReader.CreateODataParameterReader使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在ODataMessageReader的用法示例。


在下文中一共展示了ODataMessageReader.CreateODataParameterReader方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Read

        /// <inheritdoc />
        public override object Read(ODataMessageReader messageReader, ODataDeserializerContext readContext)
        {
            if (messageReader == null)
            {
                throw Error.ArgumentNull("messageReader");
            }

            // Create the correct resource type;
            ODataActionParameters payload = new ODataActionParameters();

            IEdmFunctionImport action = GetFunctionImport(readContext);
            ODataParameterReader reader = messageReader.CreateODataParameterReader(action);

            while (reader.Read())
            {
                string parameterName = null;
                IEdmFunctionParameter parameter = null;

                switch (reader.State)
                {
                    case ODataParameterReaderState.Value:
                        parameterName = reader.Name;
                        parameter = action.Parameters.SingleOrDefault(p => p.Name == parameterName);
                        // ODataLib protects against this but asserting just in case.
                        Contract.Assert(parameter != null, String.Format(CultureInfo.InvariantCulture, "Parameter '{0}' not found.", parameterName));
                        payload[parameterName] = Convert(reader.Value, parameter.Type, readContext);
                        break;

                    case ODataParameterReaderState.Collection:
                        parameterName = reader.Name;
                        parameter = action.Parameters.SingleOrDefault(p => p.Name == parameterName);
                        // ODataLib protects against this but asserting just in case.
                        Contract.Assert(parameter != null, String.Format(CultureInfo.InvariantCulture, "Parameter '{0}' not found.", parameterName));
                        IEdmCollectionTypeReference collectionType = parameter.Type as IEdmCollectionTypeReference;
                        Contract.Assert(collectionType != null);

                        payload[parameterName] = Convert(reader.CreateCollectionReader(), collectionType, readContext);
                        break;

                    default:
                        break;
                }
            }

            return payload;
        }
开发者ID:brianly,项目名称:aspnetwebstack,代码行数:47,代码来源:ODataActionPayloadDeserializer.cs

示例2: RunParameterReaderTest

        private ParameterReaderResult RunParameterReaderTest(string payload)
        {
            var message = new InMemoryMessage();

            message.Stream = new MemoryStream(Encoding.UTF8.GetBytes(payload));
            message.SetHeader("Content-Type", "application/json");

            var parameterReaderResult = new ParameterReaderResult();
            using (var messageReader = new ODataMessageReader((IODataRequestMessage)message, null, this.model))
            {
                var parameterReader = messageReader.CreateODataParameterReader(this.action);

                while (parameterReader.Read())
                {
                    switch (parameterReader.State)
                    {
                        case ODataParameterReaderState.Value:
                        {
                            parameterReaderResult.Values.Add(new KeyValuePair<string, object>(parameterReader.Name, parameterReader.Value));
                            break;
                        }
                        case ODataParameterReaderState.Collection:
                        {
                            var collection = new ParameterReaderCollection();
                            parameterReaderResult.Collections.Add(new KeyValuePair<string, ParameterReaderCollection>(parameterReader.Name, collection));
                            var collectionReader = parameterReader.CreateCollectionReader();
                            while (collectionReader.Read())
                            {
                                switch (collectionReader.State)
                                {
                                    case ODataCollectionReaderState.Value:
                                    {
                                        collection.Items.Add(collectionReader.Item);
                                        break;
                                    }
                                }
                            }
                            break;
                        }
                        case ODataParameterReaderState.Entry:
                        {
                            var entryReader = parameterReader.CreateEntryReader();

                            var entryList = new List<ODataEntry>();
                            parameterReaderResult.Entries.Add(new KeyValuePair<string, IList<ODataEntry>>(parameterReader.Name, entryList));
                            while (entryReader.Read())
                            {
                                switch (entryReader.State)
                                {
                                    case ODataReaderState.EntryEnd:
                                        entryList.Add((ODataEntry)entryReader.Item);
                                        break;

                                }
                            }
                            break;
                        }
                        case ODataParameterReaderState.Feed:
                        {
                            var entryReader = parameterReader.CreateFeedReader();
                            
                            var entryList = new List<ODataEntry>();
                            parameterReaderResult.Entries.Add(new KeyValuePair<string, IList<ODataEntry>>(parameterReader.Name, entryList));

                            var feedList = new List<ODataFeed>();
                            parameterReaderResult.Feeds.Add(new KeyValuePair<string, IList<ODataFeed>>(parameterReader.Name, feedList));

                            while (entryReader.Read())
                            {
                                switch (entryReader.State)
                                {
                                    case ODataReaderState.EntryEnd:
                                        entryList.Add((ODataEntry)entryReader.Item);
                                        break;
                                    case ODataReaderState.FeedEnd:
                                        feedList.Add((ODataFeed)entryReader.Item);
                                        break;
                                }
                            }
                            break;
                        }
                    }
                }
            }

            return parameterReaderResult;
        }
开发者ID:rossjempson,项目名称:odata.net,代码行数:87,代码来源:ParameterReaderTests.cs

示例3: ProcessActionInvokePostBody

        private Expression[] ProcessActionInvokePostBody(IODataRequestMessage message, IEdmOperation operation)
        {
            using (var messageReader = new ODataMessageReader(message, this.GetReaderSettings(), this.DataSource.Model))
            {
                List<Expression> parameterValues = new List<Expression>();
                var parameterReader = messageReader.CreateODataParameterReader(operation);

                while (parameterReader.Read())
                {
                    switch (parameterReader.State)
                    {
                        case ODataParameterReaderState.Value:
                            {
                                object clrValue = ODataObjectModelConverter.ConvertPropertyValue(parameterReader.Value);
                                parameterValues.Add(Expression.Constant(clrValue));
                                break;
                            }
                        case ODataParameterReaderState.Collection:
                            {
                                ODataCollectionReader collectionReader = parameterReader.CreateCollectionReader();
                                object clrValue = ODataObjectModelConverter.ConvertPropertyValue(ODataObjectModelConverter.ReadCollectionParameterValue(collectionReader));
                                parameterValues.Add(Expression.Constant(clrValue, clrValue.GetType()));
                                break;
                            }
                        case ODataParameterReaderState.Entry:
                            {
                                var entryReader = parameterReader.CreateEntryReader();
                                object clrValue = ODataObjectModelConverter.ConvertPropertyValue(ODataObjectModelConverter.ReadEntryParameterValue(entryReader));
                                parameterValues.Add(Expression.Constant(clrValue, clrValue.GetType()));
                                break;
                            }
                        case ODataParameterReaderState.Feed:
                            {
                                IList collectionList = null;
                                var feedReader = parameterReader.CreateFeedReader();
                                while (feedReader.Read())
                                {
                                    if (feedReader.State == ODataReaderState.EntryEnd)
                                    {
                                        object clrItem = ODataObjectModelConverter.ConvertPropertyValue(feedReader.Item);
                                        if (collectionList == null)
                                        {
                                            Type itemType = clrItem.GetType();
                                            Type listType = typeof(List<>).MakeGenericType(new[] { itemType });
                                            collectionList = (IList)Utility.QuickCreateInstance(listType);
                                        }

                                        collectionList.Add(clrItem);
                                    }
                                }

                                parameterValues.Add(Expression.Constant(collectionList, collectionList.GetType()));
                                break;
                            }
                    }
                }

                return parameterValues.ToArray();
            }
        }
开发者ID:AlineGuan,项目名称:odata.net,代码行数:60,代码来源:OperationHandler.cs

示例4: Read

        /// <inheritdoc />
        public override object Read(ODataMessageReader messageReader, Type type, ODataDeserializerContext readContext)
        {
            if (messageReader == null)
            {
                throw Error.ArgumentNull("messageReader");
            }

            IEdmFunctionImport action = GetFunctionImport(readContext);

            // Create the correct resource type;
            Dictionary<string, object> payload;
            if (type == typeof(ODataActionParameters))
            {
                payload = new ODataActionParameters();
            }
            else
            {
                payload = new ODataUntypedActionParameters(action);
            }

            ODataParameterReader reader = messageReader.CreateODataParameterReader(action);

            while (reader.Read())
            {
                string parameterName = null;
                IEdmFunctionParameter parameter = null;

                switch (reader.State)
                {
                    case ODataParameterReaderState.Value:
                        parameterName = reader.Name;
                        parameter = action.Parameters.SingleOrDefault(p => p.Name == parameterName);
                        // ODataLib protects against this but asserting just in case.
                        Contract.Assert(parameter != null, String.Format(CultureInfo.InvariantCulture, "Parameter '{0}' not found.", parameterName));
                        if (parameter.Type.IsPrimitive())
                        {
                            payload[parameterName] = reader.Value;
                        }
                        else
                        {
                            ODataEdmTypeDeserializer deserializer = DeserializerProvider.GetEdmTypeDeserializer(parameter.Type);
                            payload[parameterName] = deserializer.ReadInline(reader.Value, parameter.Type, readContext);
                        }
                        break;

                    case ODataParameterReaderState.Collection:
                        parameterName = reader.Name;
                        parameter = action.Parameters.SingleOrDefault(p => p.Name == parameterName);
                        // ODataLib protects against this but asserting just in case.
                        Contract.Assert(parameter != null, String.Format(CultureInfo.InvariantCulture, "Parameter '{0}' not found.", parameterName));
                        IEdmCollectionTypeReference collectionType = parameter.Type as IEdmCollectionTypeReference;
                        Contract.Assert(collectionType != null);
                        ODataCollectionValue value = ODataCollectionDeserializer.ReadCollection(reader.CreateCollectionReader());
                        ODataCollectionDeserializer collectionDeserializer = DeserializerProvider.GetEdmTypeDeserializer(collectionType) as ODataCollectionDeserializer;
                        payload[parameterName] = collectionDeserializer.ReadInline(value, collectionType, readContext);
                        break;

                    default:
                        break;
                }
            }

            return payload;
        }
开发者ID:ZhaoYngTest01,项目名称:WebApi,代码行数:65,代码来源:ODataActionPayloadDeserializer.cs

示例5: Read

        public override object Read(ODataMessageReader messageReader, Type type, ODataDeserializerContext readContext)
        {
            if (messageReader == null)
            {
                throw Error.ArgumentNull("messageReader");
            }

            IEdmAction action = GetAction(readContext);
            Contract.Assert(action != null);

            // Create the correct resource type;
            Dictionary<string, object> payload;
            if (type == typeof(ODataActionParameters))
            {
                payload = new ODataActionParameters();
            }
            else
            {
                payload = new ODataUntypedActionParameters(action);
            }

            ODataParameterReader reader = messageReader.CreateODataParameterReader(action);

            while (reader.Read())
            {
                string parameterName = null;
                IEdmOperationParameter parameter = null;

                switch (reader.State)
                {
                    case ODataParameterReaderState.Value:
                        parameterName = reader.Name;
                        parameter = action.Parameters.SingleOrDefault(p => p.Name == parameterName);
                        // ODataLib protects against this but asserting just in case.
                        Contract.Assert(parameter != null, String.Format(CultureInfo.InvariantCulture, "Parameter '{0}' not found.", parameterName));
                        if (parameter.Type.IsPrimitive())
                        {
                            payload[parameterName] = reader.Value;
                        }
                        else
                        {
                            ODataEdmTypeDeserializer deserializer = DeserializerProvider.GetEdmTypeDeserializer(parameter.Type);
                            payload[parameterName] = deserializer.ReadInline(reader.Value, parameter.Type, readContext);
                        }
                        break;

                    case ODataParameterReaderState.Collection:
                        parameterName = reader.Name;
                        parameter = action.Parameters.SingleOrDefault(p => p.Name == parameterName);
                        // ODataLib protects against this but asserting just in case.
                        Contract.Assert(parameter != null, String.Format(CultureInfo.InvariantCulture, "Parameter '{0}' not found.", parameterName));
                        IEdmCollectionTypeReference collectionType = parameter.Type as IEdmCollectionTypeReference;
                        Contract.Assert(collectionType != null);
                        ODataCollectionValue value = ODataCollectionDeserializer.ReadCollection(reader.CreateCollectionReader());
                        ODataCollectionDeserializer collectionDeserializer = (ODataCollectionDeserializer)DeserializerProvider.GetEdmTypeDeserializer(collectionType);
                        payload[parameterName] = collectionDeserializer.ReadInline(value, collectionType, readContext);
                        break;

                    case ODataParameterReaderState.Entry:
                        parameterName = reader.Name;
                        parameter = action.Parameters.SingleOrDefault(p => p.Name == parameterName);
                        Contract.Assert(parameter != null, String.Format(CultureInfo.InvariantCulture, "Parameter '{0}' not found.", parameterName));

                        IEdmEntityTypeReference entityTypeReference = parameter.Type as IEdmEntityTypeReference;
                        Contract.Assert(entityTypeReference != null);

                        ODataReader entryReader = reader.CreateEntryReader();
                        object item = ODataEntityDeserializer.ReadEntryOrFeed(entryReader);
                        ODataEntityDeserializer entityDeserializer = (ODataEntityDeserializer)DeserializerProvider.GetEdmTypeDeserializer(entityTypeReference);
                        payload[parameterName] = entityDeserializer.ReadInline(item, entityTypeReference, readContext);
                        break;

                    case ODataParameterReaderState.Feed:
                        parameterName = reader.Name;
                        parameter = action.Parameters.SingleOrDefault(p => p.Name == parameterName);
                        Contract.Assert(parameter != null, String.Format(CultureInfo.InvariantCulture, "Parameter '{0}' not found.", parameterName));

                        IEdmCollectionTypeReference feedType = parameter.Type as IEdmCollectionTypeReference;
                        Contract.Assert(feedType != null);

                        ODataReader feedReader = reader.CreateFeedReader();
                        object feed = ODataEntityDeserializer.ReadEntryOrFeed(feedReader);
                        ODataFeedDeserializer feedDeserializer = (ODataFeedDeserializer)DeserializerProvider.GetEdmTypeDeserializer(feedType);

                        object result = feedDeserializer.ReadInline(feed, feedType, readContext);

                        IEdmTypeReference elementTypeReference = feedType.ElementType();
                        Contract.Assert(elementTypeReference.IsEntity());

                        IEnumerable enumerable = result as IEnumerable;
                        if (enumerable != null)
                        {
                            if (readContext.IsUntyped)
                            {
                                EdmEntityObjectCollection entityCollection = new EdmEntityObjectCollection(feedType);
                                foreach (EdmEntityObject entityObject in enumerable)
                                {
                                    entityCollection.Add(entityObject);
                                }

//.........这里部分代码省略.........
开发者ID:ZhaoYngTest01,项目名称:WebApi,代码行数:101,代码来源:ODataActionPayloadDeserializer.cs

示例6: ReadParams

        /// <summary>
        /// Reads Parameter names and values provided by a client in a POST request to invoke a particular Action.
        /// </summary>
        /// <param name="messageReader">Reader used to read all OData payloads (entries, feeds, metadata documents, service documents, etc.).</param>
        /// <param name="action">Represents an EDM operation.</param>
        /// <param name="readContext">
        /// Encapsulates the state and settings that get passed to System.Web.OData.Formatter.Deserialization.ODataDeserializer from the System.Web.OData.Formatter.ODataMediaTypeFormatter.
        /// </param>
        /// <returns>ActionPayload holds the Parameter names and values provided by a client in a POST request to invoke a particular Action.</returns>
        private ODataActionParameters ReadParams(ODataMessageReader messageReader, IEdmOperation action, ODataDeserializerContext readContext)
        {
            // Create the correct resource type;
            ODataActionParameters payload = new ODataActionParameters();

            try
            {
                ODataParameterReader reader = messageReader.CreateODataParameterReader(action);

                while (reader.Read())
                {
                    string parameterName = null;
                    IEdmOperationParameter parameter = null;

                    switch (reader.State)
                    {
                        case ODataParameterReaderState.Value:
                            parameterName = reader.Name;
                            parameter = action.Parameters.SingleOrDefault(p => p.Name == parameterName);
                            // ODataLib protects against this but asserting just in case.
                            Contract.Assert(parameter != null, String.Format(CultureInfo.InvariantCulture, "Parameter '{0}' not found.", parameterName));
                            if (parameter.Type.IsPrimitive())
                            {
                                payload[parameterName] = reader.Value;
                            }
                            else
                            {
                                ODataEdmTypeDeserializer deserializer = DefaultODataDeserializerProvider.Instance.GetEdmTypeDeserializer(parameter.Type);
                                payload[parameterName] = deserializer.ReadInline(reader.Value, parameter.Type, readContext);
                            }
                            break;

                        case ODataParameterReaderState.Collection:
                            parameterName = reader.Name;
                            parameter = action.Parameters.SingleOrDefault(p => p.Name == parameterName);
                            // ODataLib protects against this but asserting just in case.
                            Contract.Assert(parameter != null, String.Format(CultureInfo.InvariantCulture, "Parameter '{0}' not found.", parameterName));
                            IEdmCollectionTypeReference collectionType = parameter.Type as IEdmCollectionTypeReference;
                            Contract.Assert(collectionType != null);
                            ODataCollectionValue value = ReadCollection(reader.CreateCollectionReader());
                            ODataCollectionDeserializer collectionDeserializer = DefaultODataDeserializerProvider.Instance.GetEdmTypeDeserializer(collectionType) as ODataCollectionDeserializer;
                            payload[parameterName] = collectionDeserializer.ReadInline(value, collectionType, readContext);
                            break;

                        default:
                            break;
                    }
                }
            }
            catch (Exception exception)
            {
                DynamicLogger.Instance.WriteLoggerLogError("ReadParams", exception);
                throw exception;
            }

            return payload;
        }
开发者ID:arcelormittalkriviyrih,项目名称:odata_unified_svc,代码行数:66,代码来源:DynamicODataActionInvoker.cs


注:本文中的ODataMessageReader.CreateODataParameterReader方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。