当前位置: 首页>>代码示例>>C#>>正文


C# Uri.Query方法代码示例

本文整理汇总了C#中System.Uri.Query方法的典型用法代码示例。如果您正苦于以下问题:C# Uri.Query方法的具体用法?C# Uri.Query怎么用?C# Uri.Query使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在System.Uri的用法示例。


在下文中一共展示了Uri.Query方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: query

    public void query()
    {
      Assert.Throws<ArgumentNullException>(() => NetworkExtensions.Query(null, new Dictionary<string, object>()));
      Assert.Throws<ArgumentNullException>(() => NetworkExtensions.Query(null, new Dictionary<string, string>()));
      Assert.Throws<ArgumentNullException>(() => NetworkExtensions.Query(null, new object()));

      var uri = new Uri("http://yandex.ru");
      Assert.Equal(0, uri.Query.Length);

      Assert.False(ReferenceEquals(uri, uri.Query(new Dictionary<string, object>())));
      Assert.Equal(uri, uri.Query(new Dictionary<string, object>()));

      Assert.False(ReferenceEquals(uri, uri.Query(new Dictionary<string, string>())));
      Assert.Equal(uri, uri.Query(new Dictionary<string, string>()));

      Assert.False(ReferenceEquals(uri, uri.Query(new { })));
      Assert.Equal(uri, uri.Query(new { }));

      Assert.Equal("http://yandex.ru/?first=1", uri.Query(new Dictionary<string, object> { { "first", 1 } }).ToString());
      Assert.Equal("?first=1&second%23=second%3F", uri.Query(new Dictionary<string, object> { { "first", 1 }, { "second#", "second?" } }).Query);

      Assert.Equal("http://yandex.ru/?first=1", uri.Query(new Dictionary<string, string> { { "first", "1" } }).ToString());
      Assert.Equal("?first=1&second%23=second%3F", uri.Query(new Dictionary<string, string> { { "first", "1" }, { "second#", "second?" } }).Query);

      Assert.Equal("http://yandex.ru/?first=1", uri.Query(new { first = 1 }).ToString());
      Assert.Equal("?first=1&second=second%3F", uri.Query(new Dictionary<string, string> { { "first", "1" }, { "second", "second?" } }).Query);


      uri = new Uri("http://yandex.ru?first=1");
      Assert.Equal(8, uri.Query.Length);

      Assert.Equal("http://yandex.ru/?first=1", uri.Query(new Dictionary<string, object>()).ToString());
      Assert.Equal("?first=1&second%23=second%3F", uri.Query(new Dictionary<string, object> { { "second#", "second?" } }).Query);

      Assert.Equal("http://yandex.ru/?first=1", uri.Query(new Dictionary<string, string>()).ToString());
      Assert.Equal("?first=1&second%23=second%3F", uri.Query(new Dictionary<string, string> { { "second#", "second?" } }).Query);
    }
开发者ID:prokhor-ozornin,项目名称:Catharsis.NET.Commons,代码行数:37,代码来源:NetworkExtensionsTest.cs

示例2: Open

        public FtpClient Open(bool isSource, ref Uri url)
        {
            var queue = Queue[Key(isSource, url)];
            var ftp = queue.DequeueOrBlock();
            try {
                if (ftp == null) {
                    ftp = new Silversite.FtpSync.FtpClient(Sync, url.Host, url.Port, url.Scheme == "ftps" ? FtpSecurityProtocol.Tls1Explicit : FtpSecurityProtocol.None, ++clientIndex, isSource);
                    //ftp.IsLoggingOn = Sync.Verbose;
                    if (Sync.Verbose) {
                        ftp.ClientRequest += new EventHandler<FtpRequestEventArgs>((sender, args) => {
                            lock (Log.Lock) { Log.YellowLabel("FTP" + ftp.Index + "> "); Log.Text(args.Request.Text); }
                        });
                        ftp.ServerResponse += new EventHandler<FtpResponseEventArgs>((sender, args) => {
                            lock (Log.Lock) { Log.Label("FTP" + ftp.Index + ": "); Log.Text(args.Response.Text); }
                        });
                    }
                    if (url.Query()["passive"] != null || url.Query()["active"] == null) ftp.DataTransferMode = TransferMode.Passive;
                    else ftp.DataTransferMode = TransferMode.Active;
                    ftp.AutoChecksumValidation = HashingFunction.None;
                    if (url.Query()["md5"] != null) ftp.AutoChecksumValidation = HashingFunction.Md5;
                    else if (url.Query()["sha"] != null) ftp.AutoChecksumValidation = HashingFunction.Sha1;
                    else if (url.Query()["crc"] != null) ftp.AutoChecksumValidation = HashingFunction.Crc32;
                } else {
                    if (!ftp.IsConnected) ftp.Reopen();
                }
                if (!ftp.IsConnected) {
                    if (!string.IsNullOrEmpty(url.UserInfo)) {
                        if (url.UserInfo.Contains(':')) {
                            var user = url.UserInfo.Split(':');
                            ftp.Open(user[0], user[1]);
                        } else {
                            ftp.Open(url.UserInfo, string.Empty);
                        }
                    } else {
                        ftp.Open("Anonymous", "anonymous");
                    }
                    // enable UTF8
                    ftp.Quote("OPTS UTF8 ON");
                }

                // change path
                var path = url.Path();
                if (!path.StartsWith("/")) path = "/" + path;
                path = ftp.CorrectPath(path);
                if (url.Query()["raw"] != null && ftp.IsCompressionEnabled) ftp.CompressionOff();
                if (url.Query()["zip"] != null && ftp.IsCompressionEnabled) ftp.CompressionOn();
                if (ftp.CurrentDirectory != path) {
                    try {
                        if (url.Query()["old"] != null) ftp.ChangeDirectoryMultiPath(path);
                        else ftp.ChangeDirectory(path);
                    } catch (Exception ex) {
                        ftp.MakeDirectory(path);
                        if (url.Query()["old"] != null) ftp.ChangeDirectoryMultiPath(path);
                        else ftp.ChangeDirectory(path);
                    }
                }
                // get server local time offset
                var offset = TimeOffset(url);
                if (offset.HasValue) ftp.TimeOffset = offset;
                else if (!ftp.TimeOffset.HasValue) {
                    lock (queue) {
                        var offsetclient = queue.FirstOrDefault(client => client != null && client.TimeOffset.HasValue);
                        if (offsetclient != null) ftp.TimeOffset = offsetclient.TimeOffset;
                        ftp.TimeOffset = ftp.ServerTimeOffset;
                    }
                }
            } catch (FtpDataConnectionException ex) {
                if (url.Query()["passive"] == null) {
                    url = new Uri(url.ToString() + (url.Query().Count > 0 ? "&" : "%3F") + "passive");
                    //ftp.Close();
                    ftp.DataTransferMode = TransferMode.Passive;
                    Pass(ftp);
                    return Open(isSource, ref url);
                } else {
                    Log.Exception(ex);
                }
            } catch (Exception e) {
                Log.Exception(e);
            }
            return ftp;
        }
开发者ID:simonegli8,项目名称:Silversite,代码行数:81,代码来源:FtpConnections.cs

示例3: Proxy

 string Proxy(Uri url)
 {
     var query = url.Query();
     string proxy = (query["proxy"] ?? "").ToString();
     return proxy;
 }
开发者ID:simonegli8,项目名称:Silversite,代码行数:6,代码来源:FtpConnections.cs

示例4: TimeOffset

 int? TimeOffset(Uri url)
 {
     var query = url.Query();
     int zone = 0;
     string zonestr = (string)query["time"];
     if (string.IsNullOrEmpty(zonestr)) return null;
     zonestr = zonestr.ToLower();
     if (zonestr == "z" || zonestr == "utc") return 0;
     if (!int.TryParse(zonestr, out zone)) return null;
     return zone;
 }
开发者ID:simonegli8,项目名称:Silversite,代码行数:11,代码来源:FtpConnections.cs

示例5: Connections

 int? Connections(Uri url)
 {
     var query = url.Query();
     int con;
     if (int.TryParse((query["connections"] ?? "").ToString(), out con)) return con;
     else return null;
 }
开发者ID:simonegli8,项目名称:Silversite,代码行数:7,代码来源:FtpConnections.cs


注:本文中的System.Uri.Query方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。