示例#1
0
        public async Task <StorageSearchResult> SearchAsync(string path, Func <string, string> getUrl)
        {
            if (!string.IsNullOrWhiteSpace(path))
            {
                if (path.Contains('?'))
                {
                    throw new ArgumentException(string.Format("The '{0}' pattern contains invalid characters.", path));
                }

                var index = path.IndexOf('*');

                if (index >= 0 && index < path.Length - 1)
                {
                    throw new ArgumentException(string.Format("The '*' character at last only in the '{0}' pattern.", path));
                }

                path = path.Trim('*');
            }

            string baseName, resourcePath;
            var    url      = _serviceCenter.GetBaseUrl(path, out baseName, out resourcePath) + "?prefix=" + Uri.EscapeDataString(resourcePath) + "&delimiter=%2F&max-keys=21";
            var    response = await _http.GetAsync(url);

            //确保返回的内容是成功
            response.EnsureSuccessStatusCode();

            var resolver = new StorageSearchResultResolver(_serviceCenter, _http, getUrl);

            return(await resolver.Resolve(response));
        }
        internal StorageSearchResult(string name, string pattern, string marker, StorageSearchResultResolver resolver)
        {
            if (string.IsNullOrWhiteSpace(name))
            {
                throw new ArgumentNullException("name");
            }

            _index    = -1;
            _name     = name.Trim('/', ' ', '\t', '\r', '\n');
            _pattern  = pattern;
            _marker   = marker;
            _items    = new List <Zongsoft.IO.PathInfo>();
            _resolver = resolver;
        }
		public async Task<StorageSearchResult> SearchAsync(string path, Func<string, string> getUrl)
		{
			if(!string.IsNullOrWhiteSpace(path))
			{
				if(path.Contains('?'))
					throw new ArgumentException(string.Format("The '{0}' pattern contains invalid characters.", path));

				var index = path.IndexOf('*');

				if(index >= 0 && index < path.Length - 1)
					throw new ArgumentException(string.Format("The '*' character at last only in the '{0}' pattern.", path));

				path = path.Trim('*');
			}

			string baseName, resourcePath;
			var url = _serviceCenter.GetBaseUrl(path, out baseName, out resourcePath) + "?prefix=" + Uri.EscapeDataString(resourcePath) + "&delimiter=%2F&max-keys=21";

			var client = this.CreateHttpClient();

			var response = await client.GetAsync(url);

			//确保返回的内容是成功
			response.EnsureSuccessStatusCode();

			var resolver = new StorageSearchResultResolver(_serviceCenter, client, getUrl);
			return await resolver.Resolve(response);
		}