// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.IO;
using System.Runtime.Serialization;
using System.Text;
using System.Threading.Tasks;
using System.Xml;
using Microsoft.AspNet.Mvc.Internal;
using Microsoft.Framework.Internal;
using Microsoft.Net.Http.Headers;
namespace Microsoft.AspNet.Mvc.Xml
{
///
/// This class handles deserialization of input XML data
/// to strongly-typed objects using .
///
public class XmlDataContractSerializerInputFormatter : InputFormatter
{
private DataContractSerializerSettings _serializerSettings;
private ConcurrentDictionary _serializerCache = new ConcurrentDictionary();
private readonly XmlDictionaryReaderQuotas _readerQuotas = FormattingUtilities.GetDefaultXmlReaderQuotas();
///
/// Initializes a new instance of DataContractSerializerInputFormatter
///
public XmlDataContractSerializerInputFormatter()
{
SupportedEncodings.Add(UTF8EncodingWithoutBOM);
SupportedEncodings.Add(UTF16EncodingLittleEndian);
SupportedMediaTypes.Add(MediaTypeHeaderValues.ApplicationXml);
SupportedMediaTypes.Add(MediaTypeHeaderValues.TextXml);
_serializerSettings = new DataContractSerializerSettings();
WrapperProviderFactories = new List();
WrapperProviderFactories.Add(new SerializableErrorWrapperProviderFactory());
}
///
/// Gets the list of to
/// provide the wrapping type for de-serialization.
///
public IList WrapperProviderFactories { get; }
///
/// Indicates the acceptable input XML depth.
///
public int MaxDepth
{
get { return _readerQuotas.MaxDepth; }
set { _readerQuotas.MaxDepth = value; }
}
///
/// The quotas include - DefaultMaxDepth, DefaultMaxStringContentLength, DefaultMaxArrayLength,
/// DefaultMaxBytesPerRead, DefaultMaxNameTableCharCount
///
public XmlDictionaryReaderQuotas XmlDictionaryReaderQuotas
{
get { return _readerQuotas; }
}
///
/// Gets or sets the used to configure the
/// .
///
public DataContractSerializerSettings SerializerSettings
{
get { return _serializerSettings; }
set
{
if (value == null)
{
throw new ArgumentNullException(nameof(value));
}
_serializerSettings = value;
}
}
///
/// Reads the input XML.
///
/// The input formatter context which contains the body to be read.
/// Task which reads the input.
public override Task