コード例 #1
0
        private IEnumerable <Tuple <ODataItem, ODataDeltaReaderState, ODataReaderState> > ReadItem(string payload, IEdmModel model = null, IEdmNavigationSource navigationSource = null, IEdmEntityType entityType = null, bool odataSimplified = false)
        {
            MemoryStream stream = new MemoryStream(Encoding.UTF8.GetBytes(payload));

            ODataMessageReaderSettings settings = new ODataMessageReaderSettings();

            settings.ShouldIncludeAnnotation = s => true;
            settings.ODataSimplified         = odataSimplified;

            using (var inputContext = new ODataJsonLightInputContext(
                       ODataFormat.Json,
                       stream,
                       new ODataMediaType("application", "json"),
                       Encoding.UTF8,
                       settings,
                       /*readingResponse*/ true,
                       /*synchronous*/ true,
                       model ?? new EdmModel(),
                       /*urlResolver*/ null))
            {
                var jsonLightReader = new ODataJsonLightDeltaReader(inputContext, navigationSource, entityType);
                while (jsonLightReader.Read())
                {
                    yield return(new Tuple <ODataItem, ODataDeltaReaderState, ODataReaderState>(jsonLightReader.Item, jsonLightReader.State, jsonLightReader.SubState));
                }
            }
        }
コード例 #2
0
        private IEnumerable <Tuple <ODataItem, ODataDeltaReaderState, ODataReaderState> > ReadItem(string payload, IEdmModel model = null, IEdmNavigationSource navigationSource = null, IEdmEntityType entityType = null, bool enableReadingODataAnnotationWithoutPrefix = false)
        {
            var settings = new ODataMessageReaderSettings
            {
                ShouldIncludeAnnotation = s => true,
            };

            var messageInfo = new ODataMessageInfo
            {
                IsResponse = true,
                MediaType  = new ODataMediaType("application", "json"),
                IsAsync    = false,
                Model      = model ?? new EdmModel(),
                Container  = ContainerBuilderHelper.BuildContainer(null)
            };

            using (var inputContext = new ODataJsonLightInputContext(
                       new StringReader(payload), messageInfo, settings))
            {
                inputContext.Container.GetRequiredService <ODataSimplifiedOptions>()
                .EnableReadingODataAnnotationWithoutPrefix = enableReadingODataAnnotationWithoutPrefix;
                var jsonLightReader = new ODataJsonLightDeltaReader(inputContext, navigationSource, entityType);
                while (jsonLightReader.Read())
                {
                    yield return(new Tuple <ODataItem, ODataDeltaReaderState, ODataReaderState>(jsonLightReader.Item, jsonLightReader.State, jsonLightReader.SubState));
                }
            }
        }
コード例 #3
0
        private IEnumerable<Tuple<ODataItem, ODataDeltaReaderState>> ReadItem(string payload, IEdmModel model = null, IEdmNavigationSource navigationSource = null, IEdmEntityType entityType = null, bool odataSimplified = false)
        {
            MemoryStream stream = new MemoryStream(Encoding.UTF8.GetBytes(payload));

            ODataMessageReaderSettings settings = new ODataMessageReaderSettings();
            settings.ShouldIncludeAnnotation = s => true;
            settings.ODataSimplified = odataSimplified;

            using (var inputContext = new ODataJsonLightInputContext(
                ODataFormat.Json,
                stream,
                new ODataMediaType("application", "json"),
                Encoding.UTF8,
                settings,
                /*readingResponse*/ true,
                /*synchronous*/ true,
                model ?? new EdmModel(),
                /*urlResolver*/ null))
            {
                var jsonLightReader = new ODataJsonLightDeltaReader(inputContext, navigationSource, entityType);
                while (jsonLightReader.Read())
                {
                    yield return new Tuple<ODataItem, ODataDeltaReaderState>(jsonLightReader.Item, jsonLightReader.State);
                }
            }
        }