using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.ServiceModel.Channels;
using System.ServiceModel.Configuration;
using System.Configuration;
using System.ComponentModel;
using System.Reflection;
using System.Xml;
namespace InfoCaster.SocialProxy.lib.TextOrMtom
{
public class TextOrMtomEncodingElement : BindingElementExtensionElement
{
[ConfigurationProperty("maxArrayLength", DefaultValue = "2147483647")]
public string MaxArrayLength
{
get { return (string)base["maxArrayLength"]; }
set { base["maxArrayLength"] = value; }
}
[ConfigurationProperty("MaxDepth", DefaultValue = "2147483647")]
public string MaxDepth
{
get { return (string)base["MaxDepth"]; }
set { base["MaxDepth"] = value; }
}
[ConfigurationProperty("MaxStringContentLength", DefaultValue = "2147483647")]
public string MaxStringContentLength
{
get { return (string)base["MaxStringContentLength"]; }
set { base["MaxStringContentLength"] = value; }
}
[ConfigurationProperty("MaxBytesPerRead", DefaultValue = "2147483647")]
public string MaxBytesPerRead
{
get { return (string)base["MaxBytesPerRead"]; }
set { base["MaxBytesPerRead"] = value; }
}
///
/// Gets the reader quotas.
///
/// The reader quotas.
[ConfigurationProperty("readerQuotas")]
public XmlDictionaryReaderQuotasElement ReaderQuotas
{
get { return (XmlDictionaryReaderQuotasElement)base["readerQuotas"]; }
set { base["readerQuotas"] = value; }
}
///
/// Initializes a new instance of the class.
///
public TextOrMtomEncodingElement()
{ }
///
/// When overridden in a derived class, gets the object that represents the custom binding element.
///
///
/// A object that represents the custom binding type.
public override Type BindingElementType
{
get { return typeof(TextOrMtomEncodingBindingElement); }
}
///
/// Gets or sets the inner message encoding.
///
/// The inner message encoding.
[ConfigurationProperty("messageVersion", DefaultValue = "Soap11")]
public string MessageVersion
{
get { return (string)base["messageVersion"]; }
set { base["messageVersion"] = value; }
}
///
/// When overridden in a derived class, returns a custom binding element object.
///
///
/// A custom object.
///
protected override BindingElement CreateBindingElement()
{
TextOrMtomEncodingBindingElement bindingElement = new TextOrMtomEncodingBindingElement(this.ReaderQuotas);
this.ApplyConfiguration(bindingElement);
return bindingElement;
}
public override void ApplyConfiguration(BindingElement bindingElement)
{
TextOrMtomEncodingBindingElement binding = (TextOrMtomEncodingBindingElement)bindingElement;
binding.ReaderQuotas.MaxArrayLength = this.ReaderQuotas.MaxArrayLength;
binding.ReaderQuotas.MaxBytesPerRead = this.ReaderQuotas.MaxBytesPerRead;
binding.ReaderQuotas.MaxDepth = this.ReaderQuotas.MaxDepth;
binding.ReaderQuotas.MaxNameTableCharCount = this.ReaderQuotas.MaxNameTableCharCount;
binding.ReaderQuotas.MaxStringContentLength = this.ReaderQuotas.MaxStringContentLength;
// set the soap version here.
binding.MessageVersion = System.ServiceModel.Channels.MessageVersion.Soap11;
PropertyInfo pInfo = typeof(System.ServiceModel.Channels.MessageVersion).GetProperty(this.MessageVersion);
if (pInfo != null)
binding.MessageVersion = (System.ServiceModel.Channels.MessageVersion)pInfo.GetValue(null, null);
base.ApplyConfiguration(bindingElement);
}
}
public class TextOrMtomEncodingBindingElement : MessageEncodingBindingElement
{
public const string IsIncomingMessageMtomPropertyName = "IncomingMessageIsMtom";
public const string MtomBoundaryPropertyName = "__MtomBoundary";
public const string MtomStartInfoPropertyName = "__MtomStartInfo";
public const string MtomStartUriPropertyName = "__MtomStartUri";
MessageVersion _messageVersion = MessageVersion.Default;
XmlDictionaryReaderQuotas _readerQuotas;
public XmlDictionaryReaderQuotas ReaderQuotas { get { return this._readerQuotas; } }
public TextOrMtomEncodingBindingElement()
{
this._readerQuotas = new XmlDictionaryReaderQuotas();
}
public TextOrMtomEncodingBindingElement(TextOrMtomEncodingBindingElement elementToBeCloned)
: base (elementToBeCloned)
{
this._messageVersion = elementToBeCloned.MessageVersion;
elementToBeCloned.ReaderQuotas.CopyTo(this._readerQuotas);
}
public TextOrMtomEncodingBindingElement(XmlDictionaryReaderQuotasElement xmlDictionaryReaderQuotasElement)
: this()
{
this._readerQuotas.MaxArrayLength = xmlDictionaryReaderQuotasElement.MaxArrayLength;
this._readerQuotas.MaxBytesPerRead = xmlDictionaryReaderQuotasElement.MaxBytesPerRead;
this._readerQuotas.MaxDepth = xmlDictionaryReaderQuotasElement.MaxDepth;
this._readerQuotas.MaxNameTableCharCount = xmlDictionaryReaderQuotasElement.MaxNameTableCharCount;
this._readerQuotas.MaxStringContentLength = xmlDictionaryReaderQuotasElement.MaxStringContentLength;
}
public override MessageEncoderFactory CreateMessageEncoderFactory()
{
return new TextOrMtomEncoderFactory(this._messageVersion);
}
public override MessageVersion MessageVersion
{
get { return this._messageVersion; }
set { this._messageVersion = value; }
}
public override BindingElement Clone()
{
return this;
}
public override T GetProperty(BindingContext context)
{
if (typeof(T) == typeof(XmlDictionaryReaderQuotas))
{
return (T)(object)this._readerQuotas;
}
else
{
return base.GetProperty(context);
}
}
public override IChannelFactory BuildChannelFactory(BindingContext context)
{
context.BindingParameters.Add(this);
return context.BuildInnerChannelFactory();
}
public override IChannelListener BuildChannelListener(BindingContext context)
{
context.BindingParameters.Add(this);
return context.BuildInnerChannelListener();
}
public override bool CanBuildChannelFactory(BindingContext context)
{
return context.CanBuildInnerChannelFactory();
}
public override bool CanBuildChannelListener(BindingContext context)
{
return context.CanBuildInnerChannelListener();
}
}
}