Exemplo n.º 1
0
        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();
 }
Exemplo n.º 3
0
        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);
            }
        }
Exemplo n.º 4
0
        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);
        }
Exemplo n.º 5
0
        //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;
            }
        }
Exemplo n.º 6
0
        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;
        }
Exemplo n.º 7
0
        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;
        }
        void IPolicyImportExtension.ImportPolicy(MetadataImporter importer, PolicyConversionContext context)
        {
            if (importer == null)
            {
                throw new ArgumentNullException("importer");
            }

            if (context == null)
            {
                throw new ArgumentNullException("context");
            }

            ICollection <XmlElement>   bindingAssertions   = context.GetBindingAssertions();
            List <XmlElement>          processedAssertions = new List <XmlElement>();
            UdpTransportBindingElement udpBindingElement   = null;
            bool multicast = false;

            foreach (XmlElement assertion in bindingAssertions)
            {
                if (assertion.NamespaceURI != UdpPolicyStrings.UdpNamespace)
                {
                    continue;
                }

                switch (assertion.LocalName)
                {
                case UdpPolicyStrings.TransportAssertion:
                    udpBindingElement = new UdpTransportBindingElement();
                    break;

                case UdpPolicyStrings.MulticastAssertion:
                    multicast = true;
                    break;

                default:
                    continue;
                }

                processedAssertions.Add(assertion);
            }

            if (udpBindingElement != null)
            {
                udpBindingElement.Multicast = multicast;
                context.BindingElements.Add(udpBindingElement);
            }

            for (int i = 0; i < processedAssertions.Count; i++)
            {
                bindingAssertions.Remove(processedAssertions[i]);
            }
        }
Exemplo n.º 9
0
        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);
            this.maxBufferPoolSize = bindingElement.MaxBufferPoolSize;

            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();

            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);
        }
Exemplo n.º 10
0
        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);
        }
Exemplo n.º 11
0
        internal UdpChannelFactory(UdpTransportBindingElement bindingElement, BindingContext context)
            : base(context.Binding)
        {
            this.multicast     = bindingElement.Multicast;
            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;
            }
        }
Exemplo n.º 12
0
 protected UdpTransportBindingElement(UdpTransportBindingElement other)
     : base(other)
 {
     this.multicast = other.multicast;
 }
Exemplo n.º 13
0
        //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);
        }