//initialize a SampleProfileUdpBinding from the info collected in a ReliableSessionBindingElement if one is present. void InitializeFrom(UdpTransportBindingElement udpTransportBindingElement, TextMessageEncodingBindingElement textMessageEncodingBindingElement, ReliableSessionBindingElement reliableSessionBindingElement, CompositeDuplexBindingElement compositeDuplexBindingElement) { this.transport.Multicast = udpTransportBindingElement.Multicast; this.transport.MaxBufferPoolSize = udpTransportBindingElement.MaxBufferPoolSize; this.transport.MaxReceivedMessageSize = udpTransportBindingElement.MaxReceivedMessageSize; ((TextMessageEncodingBindingElement)this.encoding).WriteEncoding = textMessageEncodingBindingElement.WriteEncoding; textMessageEncodingBindingElement.ReaderQuotas.CopyTo(((TextMessageEncodingBindingElement)this.encoding).ReaderQuotas); this.ReliableSessionEnabled = reliableSessionBindingElement != null; if (reliableSessionBindingElement != null) { this.SessionInactivityTimeout = reliableSessionBindingElement.InactivityTimeout; this.OrderedSession = reliableSessionBindingElement.Ordered; } if (compositeDuplexBindingElement != null) { this.ClientBaseAddress = compositeDuplexBindingElement.ClientBaseAddress; } }
bool IsTransportMatch(BindingElement a, BindingElement b) { if (b == null) { return(false); } UdpTransportBindingElement transportA = a as UdpTransportBindingElement; UdpTransportBindingElement transportB = b as UdpTransportBindingElement; if (transportB == null) { return(false); } if (transportA.MaxBufferPoolSize != transportB.MaxBufferPoolSize) { return(false); } if (transportA.MaxReceivedMessageSize != transportB.MaxReceivedMessageSize) { return(false); } if (transportA.Multicast != transportB.Multicast) { return(false); } return(true); }
protected override BindingElement CreateBindingElement() { UdpTransportBindingElement bindingElement = new UdpTransportBindingElement(); this.ApplyConfiguration(bindingElement); return(bindingElement); }
void Initialize() { transport = new UdpTransportBindingElement(); session = new ReliableSessionBindingElement(); compositeDuplex = new CompositeDuplexBindingElement(); encoding = new TextMessageEncodingBindingElement(); }
void IPolicyImportExtension.ImportPolicy(MetadataImporter importer, PolicyConversionContext context) { if (importer == null) { throw new ArgumentNullException("importer"); } if (context == null) { throw new ArgumentNullException("context"); } UdpTransportBindingElement udpBindingElement = null; bool multicast = false; PolicyAssertionCollection policyAssertions = context.GetBindingAssertions(); if (policyAssertions.Remove(UdpPolicyStrings.TransportAssertion, UdpPolicyStrings.UdpNamespace) != null) { udpBindingElement = new UdpTransportBindingElement(); } if (policyAssertions.Remove(UdpPolicyStrings.MulticastAssertion, UdpPolicyStrings.UdpNamespace) != null) { multicast = true; } if (udpBindingElement != null) { udpBindingElement.Multicast = multicast; context.BindingElements.Add(udpBindingElement); } }
protected override void InitializeFrom(BindingElement bindingElement) { base.InitializeFrom(bindingElement); UdpTransportBindingElement udpBindingElement = (UdpTransportBindingElement)bindingElement; this.MaxBufferPoolSize = udpBindingElement.MaxBufferPoolSize; this.MaxReceivedMessageSize = (int)udpBindingElement.MaxReceivedMessageSize; this.Multicast = udpBindingElement.Multicast; }
public override void ApplyConfiguration(BindingElement bindingElement) { base.ApplyConfiguration(bindingElement); UdpTransportBindingElement udpBindingElement = (UdpTransportBindingElement)bindingElement; udpBindingElement.MaxBufferPoolSize = this.MaxBufferPoolSize; udpBindingElement.MaxReceivedMessageSize = this.MaxReceivedMessageSize; udpBindingElement.Multicast = this.Multicast; }
bool IsBindingElementsMatch(UdpTransportBindingElement udpTransportBindingElement, TextMessageEncodingBindingElement textMessageEncodingBindingElement, ReliableSessionBindingElement reliableSessionBindingElement, CompositeDuplexBindingElement compositeDuplexBindingElement) { if (!IsTransportMatch(this.transport, udpTransportBindingElement)) { return(false); } if (!IsEncodingMatch(this.encoding, textMessageEncodingBindingElement)) { return(false); } if (this.ReliableSessionEnabled) { if (!IsSessionMatch(this.session, reliableSessionBindingElement)) { return(false); } if (compositeDuplexBindingElement != null) { if (!IsCompositeDuplexMatch(this.compositeDuplex, compositeDuplexBindingElement)) { return(false); } } else { return(false); } } else if (reliableSessionBindingElement != null) { return(false); } return(true); }
internal UdpChannelListener(UdpTransportBindingElement bindingElement, BindingContext context) : base(context.Binding) { this.maxMessageSize = (int)bindingElement.MaxReceivedMessageSize; this.multicast = bindingElement.Multicast; this.bufferManager = BufferManager.CreateBufferManager(bindingElement.MaxBufferPoolSize, this.maxMessageSize); MessageEncodingBindingElement messageEncoderBindingElement = context.BindingParameters.Remove <MessageEncodingBindingElement>(); if (messageEncoderBindingElement != null) { this.messageEncoderFactory = messageEncoderBindingElement.CreateMessageEncoderFactory(); } else { this.messageEncoderFactory = UdpConstants.DefaultMessageEncoderFactory; } this.channelQueue = new InputQueue <IInputChannel>(); this.currentChannelLock = new object(); this.listenSockets = new List <Socket>(2); Uri baseAddress = context.ListenUriBaseAddress; if (baseAddress == null) { if (context.ListenUriMode == ListenUriMode.Unique) { UriBuilder uriBuilder = new UriBuilder(this.Scheme, Dns.GetHostEntry(String.Empty).HostName); uriBuilder.Path = Guid.NewGuid().ToString(); baseAddress = uriBuilder.Uri; } else { throw new InvalidOperationException( "Null is only a supported value for ListenUriBaseAddress when using ListenUriMode.Unique."); } } this.InitializeUri(baseAddress, context.ListenUriRelativeAddress, context.ListenUriMode); }
internal UdpChannelFactory(UdpTransportBindingElement bindingElement, BindingContext context) : base(context.Binding) { this.multicast = bindingElement.Multicast; _sendPort = bindingElement.SendPort; this.bufferManager = BufferManager.CreateBufferManager(bindingElement.MaxBufferPoolSize, int.MaxValue); Collection <MessageEncodingBindingElement> messageEncoderBindingElements = context.BindingParameters.FindAll <MessageEncodingBindingElement>(); if (messageEncoderBindingElements.Count > 1) { throw new InvalidOperationException("More than one MessageEncodingBindingElement was found in the BindingParameters of the BindingContext"); } else if (messageEncoderBindingElements.Count == 1) { this.messageEncoderFactory = messageEncoderBindingElements[0].CreateMessageEncoderFactory(); } else { this.messageEncoderFactory = UdpConstants.DefaultMessageEncoderFactory; } }
protected UdpTransportBindingElement(UdpTransportBindingElement other) : base(other) { this.multicast = other.multicast; this.SendPort = other.SendPort; }
//try to create a SampleProfileUdpBinding from the collection of BindingElement //returns true if it is possible, with the resulting binding. public static bool TryCreate(BindingElementCollection elements, out Binding binding) { binding = null; if (elements.Count > 4) { return(false); } ReliableSessionBindingElement reliableSessionBindingElement = null; CompositeDuplexBindingElement compositeDuplexBindingElement = null; TextMessageEncodingBindingElement textMessageEncodingBindingElement = null; UdpTransportBindingElement udpTransportBindingElement = null; foreach (BindingElement element in elements) { if (element is CompositeDuplexBindingElement) { compositeDuplexBindingElement = element as CompositeDuplexBindingElement; } else if (element is TransportBindingElement) { udpTransportBindingElement = element as UdpTransportBindingElement; } else if (element is TextMessageEncodingBindingElement) { textMessageEncodingBindingElement = element as TextMessageEncodingBindingElement; } else if (element is ReliableSessionBindingElement) { reliableSessionBindingElement = element as ReliableSessionBindingElement; } else { return(false); } } if (udpTransportBindingElement == null) { return(false); } if (textMessageEncodingBindingElement == null) { return(false); } if (((reliableSessionBindingElement != null) && (compositeDuplexBindingElement == null)) || ((reliableSessionBindingElement == null) && (compositeDuplexBindingElement != null))) { return(false); } SampleProfileUdpBinding sampleProfileUdpBinding = new SampleProfileUdpBinding(); sampleProfileUdpBinding.InitializeFrom(udpTransportBindingElement, textMessageEncodingBindingElement, reliableSessionBindingElement, compositeDuplexBindingElement); if (!sampleProfileUdpBinding.IsBindingElementsMatch(udpTransportBindingElement, textMessageEncodingBindingElement, reliableSessionBindingElement, compositeDuplexBindingElement)) { return(false); } binding = sampleProfileUdpBinding; return(true); }