<commit_before>﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Threading.Tasks;
using Microsoft.Data.Edm;
using Microsoft.Data.OData;
using Simple.OData.Client.Extensions;

#pragma warning disable 1591

namespace Simple.OData.Client.V3.Adapter
{
    public class ResponseReader : ResponseReaderBase
    {
        private readonly IEdmModel _model;
        private bool _hasResponse = false;

        public ResponseReader(ISession session, IEdmModel model)
            : base(session)
        {
            _model = model;
        }

        public override Task<ODataResponse> GetResponseAsync(HttpResponseMessage responseMessage, bool includeAnnotationsInResults = false)
        {
            return GetResponseAsync(new ODataResponseMessage(responseMessage), includeAnnotationsInResults);
        }

        protected override void ConvertEntry(ResponseNode entryNode, object entry, bool includeAnnotationsInResults)
        {
            if (entry != null)
            {
                var odataEntry = entry as Microsoft.Data.OData.ODataEntry;
                foreach (var property in odataEntry.Properties)
                {
                    entryNode.Entry.Add(property.Name, GetPropertyValue(property.Value));
                }
                if (includeAnnotationsInResults)
                {
                    var resourceType = odataEntry.TypeName;
                    entryNode.Entry.Add(FluentCommand.ResourceTypeLiteral, resourceType.Split('.').Last());
                    var annotations = CreateAnnotations(odataEntry);
                    entryNode.Entry.Add(FluentCommand.AnnotationsLiteral, annotations);
                }
            }
        }

        private ODataEntryAnnotations CreateAnnotations(Microsoft.Data.OData.ODataEntry odataEntry)
        {
            return new ODataEntryAnnotations
            {
                Id = odataEntry.Id,
                TypeName = odataEntry.TypeName,
                ReadLink = odataEntry.ReadLink,
                EditLink = odataEntry.EditLink,
                ETag = odataEntry.ETag,
                AssociationLinks = odataEntry.AssociationLinks == null
                    ? null
                    : new List<ODataEntryAnnotations.AssociationLink>(
                    odataEntry.AssociationLinks.Select(x => new ODataEntryAnnotations.AssociationLink
                    {
                        Name = x.Name,
                        Uri = x.Url,
                    })),
                InstanceAnnotations = odataEntry.InstanceAnnotations,
            };
        }

#if SILVERLIGHT
        public async Task<ODataResponse> GetResponseAsync(IODataResponseMessage responseMessage, bool includeAnnotationsInResults = false)
#else
        public async Task<ODataResponse> GetResponseAsync(IODataResponseMessageAsync responseMessage, bool includeAnnotationsInResults = false)
#endif
        {
            var readerSettings = new ODataMessageReaderSettings();
            readerSettings.MessageQuotas.MaxReceivedMessageSize = Int32.MaxValue;
            using (var messageReader = new ODataMessageReader(responseMessage, readerSettings, _model))
            {
                var payloadKind = messageReader.DetectPayloadKind();
                if (payloadKind.Any(x => x.PayloadKind != ODataPayloadKind.Property))
                    _hasResponse = true;<commit_msg>Annotation change for V3 adapter.<commit_after>﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Threading.Tasks;
using Microsoft.Data.Edm;
using Microsoft.Data.OData;
using Simple.OData.Client.Extensions;

#pragma warning disable 1591

namespace Simple.OData.Client.V3.Adapter
{
    public class ResponseReader : ResponseReaderBase
    {
        private readonly IEdmModel _model;
        private bool _hasResponse = false;

        public ResponseReader(ISession session, IEdmModel model)
            : base(session)
        {
            _model = model;
        }

        public override Task<ODataResponse> GetResponseAsync(HttpResponseMessage responseMessage, bool includeAnnotationsInResults = false)
        {
            return GetResponseAsync(new ODataResponseMessage(responseMessage), includeAnnotationsInResults);
        }

        protected override void ConvertEntry(ResponseNode entryNode, object entry, bool includeAnnotationsInResults)
        {
            if (entry != null)
            {
                var odataEntry = entry as Microsoft.Data.OData.ODataEntry;
                foreach (var property in odataEntry.Properties)
                {
                    entryNode.Entry.Add(property.Name, GetPropertyValue(property.Value));
                }
                if (includeAnnotationsInResults)
                {
                    var resourceType = odataEntry.TypeName;
                    entryNode.Entry.Add(FluentCommand.ResourceTypeLiteral, resourceType.Split('.').Last());
                    var annotations = CreateAnnotations(odataEntry);
                    entryNode.Entry.Add(FluentCommand.AnnotationsLiteral, annotations);
                }
            }
        }

        private ODataEntryAnnotations CreateAnnotations(Microsoft.Data.OData.ODataEntry odataEntry)
        {
            return new ODataEntryAnnotations
            {
                Id = odataEntry.Id,
                TypeName = odataEntry.TypeName,
                ReadLink = odataEntry.ReadLink,
                EditLink = odataEntry.EditLink,
                ETag = odataEntry.ETag,
                AssociationLinks = odataEntry.AssociationLinks == null
                    ? null
                    : new List<ODataEntryAnnotations.AssociationLink>(
                    odataEntry.AssociationLinks.Select(x => new ODataEntryAnnotations.AssociationLink
                    {
                        Name = x.Name,
                        Uri = x.Url,
                    })),
                MediaResource = odataEntry.MediaResource == null
                    ? null
                    : new ODataEntryAnnotations.MediaResourceAnnotations
                    {
                        ContentType = odataEntry.MediaResource.ContentType,
                        ReadLink = odataEntry.MediaResource.ReadLink,
                        EditLink = odataEntry.MediaResource.EditLink,
                        ETag = odataEntry.MediaResource.ETag,
                    },
                InstanceAnnotations = odataEntry.InstanceAnnotations,
            };
        }

#if SILVERLIGHT
        public async Task<ODataResponse> GetResponseAsync(IODataResponseMessage responseMessage, bool includeAnnotationsInResults = false)
#else
        public async Task<ODataResponse> GetResponseAsync(IODataResponseMessageAsync responseMessage, bool includeAnnotationsInResults = false)
#endif
        {
            var readerSettings = new ODataMessageReaderSettings();
            readerSettings.MessageQuotas.MaxReceivedMessageSize = Int32.MaxValue;
            using (var messageReader = new ODataMessageReader(responseMessage, readerSettings, _model))
            {
                var payloadKind = messageReader.DetectPayloadKind();
                if (payloadKind.Any(x => x.PayloadKind != ODataPayloadKind.Property))
                    _hasResponse = true;
{'fraction_non_alphanumeric': 0.06777597402597403, 'fraction_numerical': 0.002029220779220779, 'mean_word_length': 2.0101791530944624, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 15, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2883134', 'n_tokens_mistral': 1808, 'n_tokens_neox': 1711, 'n_words': 353}