Code:
/ WCF / WCF / 3.5.30729.1 / untmp / Orcas / SP / ndp / cdf / src / WCF / ServiceModel / System / ServiceModel / Configuration / CustomBindingElement.cs / 1 / CustomBindingElement.cs
//------------------------------------------------------------------------------
// Copyright (c) Microsoft Corporation. All rights reserved.
//-----------------------------------------------------------------------------
namespace System.ServiceModel.Configuration
{
using System.Collections.Generic;
using System.ServiceModel.Channels;
using System.ComponentModel;
using System.Configuration;
using System.Globalization;
public partial class CustomBindingElement
: NamedServiceModelExtensionCollectionElement,
ICollection,
IBindingConfigurationElement
{
public CustomBindingElement()
: this(null)
{}
public CustomBindingElement(string name) :
base(ConfigurationStrings.BindingElementExtensions, name)
{}
[ConfigurationProperty(ConfigurationStrings.CloseTimeout, DefaultValue=ServiceDefaults.CloseTimeoutString)]
[TypeConverter(typeof(TimeSpanOrInfiniteConverter))]
[ServiceModelTimeSpanValidator(MinValueString = ConfigurationStrings.TimeSpanZero)]
public TimeSpan CloseTimeout
{
get { return (TimeSpan)base[ConfigurationStrings.CloseTimeout]; }
set
{
base[ConfigurationStrings.CloseTimeout] = value;
this.SetIsModified();
}
}
[ConfigurationProperty(ConfigurationStrings.OpenTimeout, DefaultValue=ServiceDefaults.OpenTimeoutString)]
[TypeConverter(typeof(TimeSpanOrInfiniteConverter))]
[ServiceModelTimeSpanValidator(MinValueString = ConfigurationStrings.TimeSpanZero)]
public TimeSpan OpenTimeout
{
get { return (TimeSpan)base[ConfigurationStrings.OpenTimeout]; }
set
{
base[ConfigurationStrings.OpenTimeout] = value;
this.SetIsModified();
}
}
[ConfigurationProperty(ConfigurationStrings.ReceiveTimeout, DefaultValue=ServiceDefaults.ReceiveTimeoutString)]
[TypeConverter(typeof(TimeSpanOrInfiniteConverter))]
[ServiceModelTimeSpanValidator(MinValueString = ConfigurationStrings.TimeSpanZero)]
public TimeSpan ReceiveTimeout
{
get { return (TimeSpan)base[ConfigurationStrings.ReceiveTimeout]; }
set
{
base[ConfigurationStrings.ReceiveTimeout] = value;
this.SetIsModified();
}
}
[ConfigurationProperty(ConfigurationStrings.SendTimeout, DefaultValue=ServiceDefaults.SendTimeoutString)]
[TypeConverter(typeof(TimeSpanOrInfiniteConverter))]
[ServiceModelTimeSpanValidator(MinValueString = ConfigurationStrings.TimeSpanZero)]
public TimeSpan SendTimeout
{
get { return (TimeSpan)base[ConfigurationStrings.SendTimeout]; }
set
{
base[ConfigurationStrings.SendTimeout] = value;
this.SetIsModified();
}
}
public override void Add(BindingElementExtensionElement element)
{
if (null == element)
{
throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("element");
}
BindingElementExtensionElement existingElement = null;
if (!this.CanAddEncodingElement(element, ref existingElement))
{
throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ConfigurationErrorsException(SR.GetString(SR.ConfigMessageEncodingAlreadyInBinding,
existingElement.ConfigurationElementName,
existingElement.GetType().AssemblyQualifiedName)));
}
else if (!this.CanAddStreamUpgradeElement(element, ref existingElement))
{
throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ConfigurationErrorsException(SR.GetString(SR.ConfigStreamUpgradeElementAlreadyInBinding,
existingElement.ConfigurationElementName,
existingElement.GetType().AssemblyQualifiedName)));
}
else if (!this.CanAddTransportElement(element, ref existingElement))
{
throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ConfigurationErrorsException(SR.GetString(SR.ConfigTransportAlreadyInBinding,
existingElement.ConfigurationElementName,
existingElement.GetType().AssemblyQualifiedName)));
}
else
{
base.Add(element);
}
}
public void ApplyConfiguration(Binding binding)
{
if (null == binding)
{
throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("binding");
}
if (binding.GetType() != typeof(CustomBinding))
{
throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgument(SR.GetString(SR.ConfigInvalidTypeForBinding,
typeof(CustomBinding).AssemblyQualifiedName,
binding.GetType().AssemblyQualifiedName));
}
binding.CloseTimeout = this.CloseTimeout;
binding.OpenTimeout = this.OpenTimeout;
binding.ReceiveTimeout = this.ReceiveTimeout;
binding.SendTimeout = this.SendTimeout;
this.OnApplyConfiguration(binding);
}
public override bool CanAdd(BindingElementExtensionElement element)
{
if (null == element)
{
throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("element");
}
BindingElementExtensionElement existingElement = null;
return !this.ContainsKey(element.GetType()) && this.CanAddEncodingElement(element, ref existingElement) &&
this.CanAddStreamUpgradeElement(element, ref existingElement) && this.CanAddTransportElement(element, ref existingElement);
}
bool CanAddEncodingElement(BindingElementExtensionElement element, ref BindingElementExtensionElement existingElement)
{
return this.CanAddExclusiveElement(typeof(MessageEncodingBindingElement), element.BindingElementType, ref existingElement);
}
bool CanAddExclusiveElement(Type exclusiveType, Type bindingElementType, ref BindingElementExtensionElement existingElement)
{
bool retval = true;
if (exclusiveType.IsAssignableFrom(bindingElementType))
{
foreach (BindingElementExtensionElement existing in this)
{
if (exclusiveType.IsAssignableFrom(existing.BindingElementType))
{
retval = false;
existingElement = existing;
break;
}
}
}
return retval;
}
bool CanAddStreamUpgradeElement(BindingElementExtensionElement element, ref BindingElementExtensionElement existingElement)
{
return this.CanAddExclusiveElement(typeof(StreamUpgradeBindingElement), element.BindingElementType, ref existingElement);
}
bool CanAddTransportElement(BindingElementExtensionElement element, ref BindingElementExtensionElement existingElement)
{
return this.CanAddExclusiveElement(typeof(TransportBindingElement), element.BindingElementType, ref existingElement);
}
protected void OnApplyConfiguration(Binding binding)
{
CustomBinding theBinding = (CustomBinding) binding;
foreach (BindingElementExtensionElement bindingConfig in this)
{
theBinding.Elements.Add(bindingConfig.CreateBindingElement());
}
}
}
}
// File provided for Reference Use Only by Microsoft Corporation (c) 2007.
// Copyright (c) Microsoft Corporation. All rights reserved.
Link Menu

This book is available now!
Buy at Amazon US or
Buy at Amazon UK
- ButtonBase.cs
- DataGridViewToolTip.cs
- BitmapDownload.cs
- HttpRuntime.cs
- RelationshipType.cs
- SectionInput.cs
- FixedPage.cs
- RecommendedAsConfigurableAttribute.cs
- BrowserDefinitionCollection.cs
- XmlWriter.cs
- SqlInfoMessageEvent.cs
- ListViewItem.cs
- FixedSOMTableRow.cs
- TextEditorSelection.cs
- BitmapEffectGroup.cs
- SrgsGrammar.cs
- SoapHeader.cs
- DecimalConstantAttribute.cs
- WebServiceEnumData.cs
- TextProviderWrapper.cs
- WebPartZoneDesigner.cs
- DbInsertCommandTree.cs
- FamilyMap.cs
- WindowsFont.cs
- ECDiffieHellman.cs
- IgnoreFlushAndCloseStream.cs
- DataSourceView.cs
- TimeZoneNotFoundException.cs
- GenerateHelper.cs
- Polygon.cs
- ProcessHost.cs
- ReadOnlyHierarchicalDataSourceView.cs
- Package.cs
- WebPartCatalogCloseVerb.cs
- TextBox.cs
- SessionStateItemCollection.cs
- ApplicationInfo.cs
- ExpressionVisitor.cs
- PageBreakRecord.cs
- ConcurrentBag.cs
- UserControlCodeDomTreeGenerator.cs
- DataSysAttribute.cs
- TokenBasedSetEnumerator.cs
- WindowsSlider.cs
- PageTheme.cs
- AspNetSynchronizationContext.cs
- basecomparevalidator.cs
- DataChangedEventManager.cs
- ChangeToolStripParentVerb.cs
- SoapSchemaMember.cs
- ControlPaint.cs
- DataContractSerializerOperationGenerator.cs
- ContextBase.cs
- ColorConvertedBitmap.cs
- Pick.cs
- ConsoleCancelEventArgs.cs
- _CacheStreams.cs
- CodeSnippetExpression.cs
- TcpServerChannel.cs
- CrossSiteScriptingValidation.cs
- CdpEqualityComparer.cs
- NumericUpDown.cs
- EdmSchemaAttribute.cs
- ProcessHost.cs
- precedingquery.cs
- BaseTypeViewSchema.cs
- PathParser.cs
- TextTreeInsertUndoUnit.cs
- NavigationProgressEventArgs.cs
- ManagedFilter.cs
- ComboBox.cs
- Win32SafeHandles.cs
- DataPagerFieldCommandEventArgs.cs
- SystemIPInterfaceProperties.cs
- TypeSystemProvider.cs
- Odbc32.cs
- ConsoleKeyInfo.cs
- FileAuthorizationModule.cs
- WebExceptionStatus.cs
- ResourceDisplayNameAttribute.cs
- SqlCharStream.cs
- DataPointer.cs
- PlatformCulture.cs
- EntitySqlQueryCacheKey.cs
- PropertyItemInternal.cs
- _NetRes.cs
- MultiByteCodec.cs
- SrgsNameValueTag.cs
- ToolStripEditorManager.cs
- ToolTip.cs
- UIPermission.cs
- StringToken.cs
- HtmlImage.cs
- PartitionerStatic.cs
- ConfigurationSettings.cs
- RowVisual.cs
- HttpModulesSection.cs
- NullRuntimeConfig.cs
- CommonObjectSecurity.cs
- ClientConfigurationHost.cs