當前位置: 首頁>>代碼示例>>C#>>正文


C# Uri.GetIpAddress方法代碼示例

本文整理匯總了C#中System.Uri.GetIpAddress方法的典型用法代碼示例。如果您正苦於以下問題:C# Uri.GetIpAddress方法的具體用法?C# Uri.GetIpAddress怎麽用?C# Uri.GetIpAddress使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在System.Uri的用法示例。


在下文中一共展示了Uri.GetIpAddress方法的9個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。

示例1: GetEndPoint

 public static IPEndPoint GetEndPoint(string server)
 {
     const int maxSplits = 2;
     var address = server.Split(':');
     if (address.Count() != maxSplits)
     {
         throw new ArgumentException("server");
     }
     IPAddress ipAddress;
     if (!IPAddress.TryParse(address[0], out ipAddress))
     {
         var uri = new Uri(String.Format("http://{0}", address[0]));
         ipAddress = uri.GetIpAddress(ClientConfiguration.UseInterNetworkV6Addresses);
         if (ipAddress == null)
         {
             throw new ArgumentException("ipAddress");
         }
     }
     int port;
     if (!int.TryParse(address[1], out port))
     {
         throw new ArgumentException("port");
     }
     return new IPEndPoint(ipAddress, port);
 }
開發者ID:RossMerr,項目名稱:CouchbaseNetClient,代碼行數:25,代碼來源:IPEndPointExtensions.cs

示例2: GetIpAddress_DnsEntry_NoDeadlock

        public void GetIpAddress_DnsEntry_NoDeadlock()
        {
            // Using an asynchronous view query within an MVC Web API action causes
            // a deadlock if you wait for the result synchronously.

            var context = new Mock<SynchronizationContext>
            {
                CallBase = true
            };

            SynchronizationContext.SetSynchronizationContext(context.Object);
            try
            {
                var uri = new Uri("http://localhost/");

                uri.GetIpAddress(false);

                // If view queries are incorrectly awaiting on the current SynchronizationContext
                // We will see calls to Post or Send on the mock

                context.Verify(m => m.Post(It.IsAny<SendOrPostCallback>(), It.IsAny<object>()), Times.Never);
                context.Verify(m => m.Send(It.IsAny<SendOrPostCallback>(), It.IsAny<object>()), Times.Never);
            }
            finally
            {
                SynchronizationContext.SetSynchronizationContext(null);
            }
        }
開發者ID:brantburnett,項目名稱:couchbase-net-client,代碼行數:28,代碼來源:UriExtensionsTests.cs

示例3: GetIpAddress_DnsEntry_ReturnsIp

        public void GetIpAddress_DnsEntry_ReturnsIp()
        {
            // Arrange

            var uri = new Uri("http://localhost/");

            // Act

            var result = uri.GetIpAddress(false);

            // Assert

            Assert.AreEqual(new IPAddress(new byte[] {127, 0, 0, 1}), result);
        }
開發者ID:brantburnett,項目名稱:couchbase-net-client,代碼行數:14,代碼來源:UriExtensionsTests.cs

示例4: GetEndPoint

 public static IPEndPoint GetEndPoint(Node node, BucketConfiguration clientConfig, IBucketConfig serverConfig)
 {
     var address = node.Hostname.Split(':').First();
     IPAddress ipAddress;
     if (!IPAddress.TryParse(address, out ipAddress))
     {
         var uri = new Uri(String.Format("http://{0}", address));
         ipAddress = uri.GetIpAddress();
         if (ipAddress == null)
         {
             throw new ArgumentException("ipAddress");
         }
     }
     var port = clientConfig.UseSsl ? node.Ports.SslDirect : node.Ports.Direct;
     return new IPEndPoint(ipAddress, port);
 }
開發者ID:orangeloop,項目名稱:couchbase-net-client,代碼行數:16,代碼來源:IPEndPointExtensions.cs

示例5: When_GetIpAddress_Called_With_IpAddress_Returns_HostIP

 public void When_GetIpAddress_Called_With_IpAddress_Returns_HostIP()
 {
     var uri = new Uri("http://127.0.0.1:8091/pools");
     var ipAddress = uri.GetIpAddress();
     Assert.AreEqual("127.0.0.1", ipAddress.ToString());
 }
開發者ID:orangeloop,項目名稱:couchbase-net-client,代碼行數:6,代碼來源:UriExtensionTests.cs

示例6: When_Hostname_Is_IPAddress_Return_It

 public void When_Hostname_Is_IPAddress_Return_It()
 {
     var uri = new Uri("http://192.168.56.102:8091/pools");
     var ipAddress = uri.GetIpAddress();
     Assert.AreEqual("192.168.56.102", ipAddress.ToString());
 }
開發者ID:orangeloop,項目名稱:couchbase-net-client,代碼行數:6,代碼來源:UriExtensionTests.cs

示例7: When_GetIPAddress_Called_With_LocalHost_Returns_LoopBackIP

 public void When_GetIPAddress_Called_With_LocalHost_Returns_LoopBackIP()
 {
     var uri = new Uri("http://localhost:8091/pools");
     var ipAddress = uri.GetIpAddress();
     Assert.AreEqual("127.0.0.1", ipAddress.ToString());
 }
開發者ID:kendallb,項目名稱:couchbase-net-client,代碼行數:6,代碼來源:UriExtensionTests.cs

示例8: When_GetIpAddress_Called_With_IpAddress_Returns_HostIP

 public void When_GetIpAddress_Called_With_IpAddress_Returns_HostIP()
 {
     var uri = new Uri("http://127.0.0.1:8091/pools");
     var ipAddress = uri.GetIpAddress(ClientConfiguration.UseInterNetworkV6Addresses);
     Assert.AreEqual("127.0.0.1", ipAddress.ToString());
 }
開發者ID:brantburnett,項目名稱:couchbase-net-client,代碼行數:6,代碼來源:UriExtensionTests.cs

示例9: When_Hostname_Is_IPAddress_Return_It

 public void When_Hostname_Is_IPAddress_Return_It()
 {
     var uri = new Uri("http://192.168.56.102:8091/pools");
     var ipAddress = uri.GetIpAddress(ClientConfiguration.UseInterNetworkV6Addresses);
     Assert.AreEqual("192.168.56.102", ipAddress.ToString());
 }
開發者ID:brantburnett,項目名稱:couchbase-net-client,代碼行數:6,代碼來源:UriExtensionTests.cs


注:本文中的System.Uri.GetIpAddress方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。