コード例 #1
0
        internal static bool TryCreate(BindingElementCollection elements, out Binding binding)
        {
            binding = null;
            if (elements.Count != 3)
            {
                return(false);
            }
            PeerResolverBindingElement          element   = null;
            PeerTransportBindingElement         transport = null;
            BinaryMessageEncodingBindingElement encoding  = null;

            foreach (BindingElement element4 in elements)
            {
                if (element4 is TransportBindingElement)
                {
                    transport = element4 as PeerTransportBindingElement;
                }
                else if (element4 is BinaryMessageEncodingBindingElement)
                {
                    encoding = element4 as BinaryMessageEncodingBindingElement;
                }
                else if (element4 is PeerResolverBindingElement)
                {
                    element = element4 as PeerResolverBindingElement;
                }
                else
                {
                    return(false);
                }
            }
            if (transport == null)
            {
                return(false);
            }
            if (encoding == null)
            {
                return(false);
            }
            if (element == null)
            {
                return(false);
            }
            NetPeerTcpBinding binding2 = new NetPeerTcpBinding();

            binding2.InitializeFrom(transport, encoding);
            if (!binding2.IsBindingElementsMatch(transport, encoding))
            {
                return(false);
            }
            PeerCustomResolverBindingElement element5 = element as PeerCustomResolverBindingElement;

            if (element5 != null)
            {
                binding2.Resolver.Custom.Address  = element5.Address;
                binding2.Resolver.Custom.Binding  = element5.Binding;
                binding2.Resolver.Custom.Resolver = element5.CreatePeerResolver();
            }
            else if ((element is PnrpPeerResolverBindingElement) && IsPnrpAvailable)
            {
                binding2.Resolver.Mode = PeerResolverMode.Pnrp;
            }
            binding = binding2;
            return(true);
        }
コード例 #2
0
        internal static bool TryCreate(BindingElementCollection elements, out Binding binding)
        {
            binding = null;
            if (elements.Count != 3)
                return false;

            PeerResolverBindingElement resolver = null;
            PeerTransportBindingElement transport = null;
            BinaryMessageEncodingBindingElement encoding = null;

            foreach (BindingElement element in elements)
            {
                if (element is TransportBindingElement)
                    transport = element as PeerTransportBindingElement;
                else if (element is BinaryMessageEncodingBindingElement)
                    encoding = element as BinaryMessageEncodingBindingElement;
                else if (element is PeerResolverBindingElement)
                    resolver = element as PeerResolverBindingElement;
                else
                    return false;
            }

            if (transport == null)
                return false;

            if (encoding == null)
                return false;

            if (resolver == null)
                return false;

            NetPeerTcpBinding netPeerTcpBinding = new NetPeerTcpBinding();
            netPeerTcpBinding.InitializeFrom(transport, encoding);
            if (!netPeerTcpBinding.IsBindingElementsMatch(transport, encoding))
                return false;

            PeerCustomResolverBindingElement customResolver = resolver as PeerCustomResolverBindingElement;
            if (customResolver != null)
            {
                netPeerTcpBinding.Resolver.Custom.Address = customResolver.Address;
                netPeerTcpBinding.Resolver.Custom.Binding = customResolver.Binding;
                netPeerTcpBinding.Resolver.Custom.Resolver = customResolver.CreatePeerResolver();
            }
            else if (resolver is PnrpPeerResolverBindingElement)
            {

                if (NetPeerTcpBinding.IsPnrpAvailable)
                    netPeerTcpBinding.Resolver.Mode = PeerResolverMode.Pnrp;
            }
            binding = netPeerTcpBinding;
            return true;
        }
コード例 #3
0
        internal static bool TryCreate(BindingElementCollection elements, out Binding binding)
        {
            binding = null;
            if (elements.Count != 3)
            {
                return(false);
            }

            PeerResolverBindingElement          resolver  = null;
            PeerTransportBindingElement         transport = null;
            BinaryMessageEncodingBindingElement encoding  = null;

            foreach (BindingElement element in elements)
            {
                if (element is TransportBindingElement)
                {
                    transport = element as PeerTransportBindingElement;
                }
                else if (element is BinaryMessageEncodingBindingElement)
                {
                    encoding = element as BinaryMessageEncodingBindingElement;
                }
                else if (element is PeerResolverBindingElement)
                {
                    resolver = element as PeerResolverBindingElement;
                }
                else
                {
                    return(false);
                }
            }

            if (transport == null)
            {
                return(false);
            }

            if (encoding == null)
            {
                return(false);
            }

            if (resolver == null)
            {
                return(false);
            }

            NetPeerTcpBinding netPeerTcpBinding = new NetPeerTcpBinding();

            netPeerTcpBinding.InitializeFrom(transport, encoding);
            if (!netPeerTcpBinding.IsBindingElementsMatch(transport, encoding))
            {
                return(false);
            }

            PeerCustomResolverBindingElement customResolver = resolver as PeerCustomResolverBindingElement;

            if (customResolver != null)
            {
                netPeerTcpBinding.Resolver.Custom.Address  = customResolver.Address;
                netPeerTcpBinding.Resolver.Custom.Binding  = customResolver.Binding;
                netPeerTcpBinding.Resolver.Custom.Resolver = customResolver.CreatePeerResolver();
            }
            else if (resolver is PnrpPeerResolverBindingElement)
            {
                if (NetPeerTcpBinding.IsPnrpAvailable)
                {
                    netPeerTcpBinding.Resolver.Mode = PeerResolverMode.Pnrp;
                }
            }
            binding = netPeerTcpBinding;
            return(true);
        }
 internal static bool TryCreate(BindingElementCollection elements, out Binding binding)
 {
     binding = null;
     if (elements.Count != 3)
     {
         return false;
     }
     PeerResolverBindingElement element = null;
     PeerTransportBindingElement transport = null;
     BinaryMessageEncodingBindingElement encoding = null;
     foreach (BindingElement element4 in elements)
     {
         if (element4 is TransportBindingElement)
         {
             transport = element4 as PeerTransportBindingElement;
         }
         else if (element4 is BinaryMessageEncodingBindingElement)
         {
             encoding = element4 as BinaryMessageEncodingBindingElement;
         }
         else if (element4 is PeerResolverBindingElement)
         {
             element = element4 as PeerResolverBindingElement;
         }
         else
         {
             return false;
         }
     }
     if (transport == null)
     {
         return false;
     }
     if (encoding == null)
     {
         return false;
     }
     if (element == null)
     {
         return false;
     }
     NetPeerTcpBinding binding2 = new NetPeerTcpBinding();
     binding2.InitializeFrom(transport, encoding);
     if (!binding2.IsBindingElementsMatch(transport, encoding))
     {
         return false;
     }
     PeerCustomResolverBindingElement element5 = element as PeerCustomResolverBindingElement;
     if (element5 != null)
     {
         binding2.Resolver.Custom.Address = element5.Address;
         binding2.Resolver.Custom.Binding = element5.Binding;
         binding2.Resolver.Custom.Resolver = element5.CreatePeerResolver();
     }
     else if ((element is PnrpPeerResolverBindingElement) && IsPnrpAvailable)
     {
         binding2.Resolver.Mode = PeerResolverMode.Pnrp;
     }
     binding = binding2;
     return true;
 }