Пример #1
0
        private async Task <IReadOnlyList <RemoteUniversalPackageVersion> > ListVersionsInternalAsync(UniversalPackageId id, UniversalPackageVersion version, bool includeFileList, int?maxCount, CancellationToken cancellationToken)
        {
            if (this.Endpoint.IsLocalDirectory)
            {
                if (version == null)
                {
                    return(this.localRepository.Value.ListPackageVersions(id).ToList());
                }
                else
                {
                    var v = this.localRepository.Value.GetPackageVersion(id, version);
                    return(v != null ? new[] { v } : new RemoteUniversalPackageVersion[0]);
                }
            }

            var url     = FormatUrl("versions", ("group", id?.Group), ("name", id?.Name), ("version", version?.ToString()), ("includeFileList", includeFileList), ("count", maxCount));
            var request = new ApiRequest(this.Endpoint, url);

            using (var response = await this.transport.GetResponseAsync(request, cancellationToken).ConfigureAwait(false))
            {
                if (response.ContentType?.StartsWith("application/json", StringComparison.OrdinalIgnoreCase) != true)
                {
                    throw new InvalidDataException($"Server returned {response.ContentType} content type; expected application/json.");
                }

                using (var responseStream = response.GetResponseStream())
                    using (var reader = new StreamReader(responseStream, AH.UTF8))
                        using (var jsonReader = new JsonTextReader(reader))
                        {
                            if (version == null)
                            {
                                var arr = await JArray.LoadAsync(jsonReader, cancellationToken).ConfigureAwait(false);

                                var results = new List <RemoteUniversalPackageVersion>(arr.Count);

                                foreach (var token in arr)
                                {
                                    if (!(token is JObject obj))
                                    {
                                        throw new InvalidDataException("Unexpected token in JSON array.");
                                    }

                                    results.Add(new RemoteUniversalPackageVersion(obj));
                                }

                                return(results.AsReadOnly());
                            }
                            else
                            {
                                var obj = await JObject.LoadAsync(jsonReader, cancellationToken).ConfigureAwait(false);

                                return(new[] { new RemoteUniversalPackageVersion(obj) });
                            }
                        }
            }
        }
Пример #2
0
        /// <summary>
        /// Returns a list of packages that contain the specified search term.
        /// </summary>
        /// <param name="searchTerm">Text to search package metadata for.</param>
        /// <param name="cancellationToken">Cancellation token for asynchronous operations.</param>
        /// <returns>List of packages that match the specified search term.</returns>
        public async Task <IReadOnlyList <RemoteUniversalPackage> > SearchPackagesAsync(string searchTerm, CancellationToken cancellationToken)
        {
            if (string.IsNullOrEmpty(searchTerm))
            {
                return(await this.ListPackagesAsync(null, null, cancellationToken).ConfigureAwait(false));
            }

            if (this.Endpoint.IsLocalDirectory)
            {
                return(this.localRepository.Value.SearchPackages(searchTerm).ToList());
            }

            var url = FormatUrl("search", ("term", searchTerm));

            var request = new ApiRequest(this.Endpoint, url);

            using (var response = await this.transport.GetResponseAsync(request, cancellationToken).ConfigureAwait(false))
            {
                if (response.ContentType?.StartsWith("application/json", StringComparison.OrdinalIgnoreCase) != true)
                {
                    throw new InvalidDataException($"Server returned {response.ContentType} content type; expected application/json.");
                }

                using (var responseStream = response.GetResponseStream())
                    using (var reader = new StreamReader(responseStream, Encoding.UTF8))
                        using (var jsonReader = new JsonTextReader(reader))
                        {
                            var arr = await JArray.LoadAsync(jsonReader, cancellationToken).ConfigureAwait(false);

                            var results = new List <RemoteUniversalPackage>(arr.Count);

                            foreach (var token in arr)
                            {
                                if (!(token is JObject obj))
                                {
                                    throw new InvalidDataException("Unexpected token in JSON array.");
                                }

                                results.Add(new RemoteUniversalPackage(obj));
                            }

                            return(results.AsReadOnly());
                        }
            }
        }
Пример #3
0
        public void NoInputTest()
        {
            var t = new FormatUrl();

            t.BuildEngine = new MockEngine(_out);

            t.Execute().ShouldBeTrue();
            t.OutputUrl.ShouldBe(string.Empty);
        }
Пример #4
0
        public void WhitespaceTestOnWindows()
        {
            var t = new FormatUrl();

            t.BuildEngine = new MockEngine(_out);

            t.InputUrl = " ";
            Should.Throw <ArgumentException>(() => t.Execute());
        }
Пример #5
0
        public void WhitespaceTestOnUnix()
        {
            var t = new FormatUrl();

            t.BuildEngine = new MockEngine(_out);

            t.InputUrl = " ";
            t.Execute().ShouldBeTrue();
            t.OutputUrl.ShouldBe(new Uri(Path.Combine(Environment.CurrentDirectory, t.InputUrl)).AbsoluteUri);
        }
Пример #6
0
        public void UrlParentPathTest()
        {
            var t = new FormatUrl();

            t.BuildEngine = new MockEngine(_out);

            t.InputUrl = @"https://example.com/Example/../Path";
            t.Execute().ShouldBeTrue();
            t.OutputUrl.ShouldBe(@"https://example.com/Path");
        }
Пример #7
0
        public void LocalWindowsAbsolutePathTest()
        {
            var t = new FormatUrl();

            t.BuildEngine = new MockEngine(_out);

            t.InputUrl = @"c:\folder\filename.ext";
            t.Execute().ShouldBeTrue();
            t.OutputUrl.ShouldBe(@"file:///c:/folder/filename.ext");
        }
Пример #8
0
        public void UrlLocalHostTest()
        {
            var t = new FormatUrl();

            t.BuildEngine = new MockEngine(_out);

            t.InputUrl = @"https://localhost/Example/Path";
            t.Execute().ShouldBeTrue();
            t.OutputUrl.ShouldBe(@"https://" + Environment.MachineName.ToLowerInvariant() + "/Example/Path");
        }
Пример #9
0
        public void LocalUnixAbsolutePathTest()
        {
            var t = new FormatUrl();

            t.BuildEngine = new MockEngine(_out);

            t.InputUrl = @"/usr/local/share";
            t.Execute().ShouldBeTrue();
            t.OutputUrl.ShouldBe(@"file:///usr/local/share");
        }
Пример #10
0
        public void LocalRelativePathTest()
        {
            var t = new FormatUrl();

            t.BuildEngine = new MockEngine(_out);

            t.InputUrl = @".";
            t.Execute().ShouldBeTrue();
            t.OutputUrl.ShouldBe(new Uri(Environment.CurrentDirectory).AbsoluteUri);
        }
Пример #11
0
        public void UncPathTest()
        {
            var t = new FormatUrl();

            t.BuildEngine = new MockEngine(_out);

            t.InputUrl = @"\\server\filename.ext";
            t.Execute().ShouldBeTrue();
            t.OutputUrl.ShouldBe(@"file://server/filename.ext");
        }
        public static void Run(string url, string uinkey)
        {
            var _Url = FormatUrl.Format(url, uinkey);

            try
            {
                //访问url
                var result = HttpHelper.Get(_Url.url);
                Log.Success($"[ReadNumTest : Success] {_Url.url}");
            }
            catch (Exception ex)
            {
                Log.Error($"[ReadNumTest : Error] {ex.Message} {_Url.url}");
            }
        }
Пример #13
0
        public static void Run(string url, string uinkey)
        {
            var _Url = FormatUrl.Format(url, uinkey);

            try
            {
                var ReadNum         = 0;
                var LikeNum         = 0;
                var cookieContainer = new CookieContainer();
                //访问url,获取req_id
                var html    = HttpHelper.Get(_Url.url, cookieContainer);
                var req_id  = Regex.Match(html, "var req_id = '(.+?)';").Groups[1].Value;
                var content = FormatContent.Format(html);
                //访问接口,获取数据
                var InterfaceUrl = $"https://mp.weixin.qq.com/mp/getappmsgext?__biz={_Url.biz}&mid={_Url.mid}&idx={_Url.idx}&sn={_Url.sn}{uinkey}";
                var parames      = $"is_only_read=1&req_id={req_id}&is_temp_url=0";
                var result       = HttpHelper.Post(InterfaceUrl, parames, cookieContainer);

                //判断
                if (result != null && Regex.IsMatch(result, "read_num\":(.+?),\"like_num\":(.+?),"))
                {
                    Match m = Regex.Match(result, "read_num\":(.+?),\"like_num\":(.+?),");
                    ReadNum = Convert.ToInt32(m.Groups[1].Value);
                    LikeNum = Convert.ToInt32(m.Groups[2].Value);


                    Log.Success($"[ReadNumTest : Success] - {content.msg_title} : ReadNum:{ReadNum} LikeNum:{LikeNum} - UinKey : {uinkey}");
                }
                else
                {
                    Log.Fail($"[ReadNumTest : Fail] {content.msg_title} {result} - UinKey : {uinkey}");
                }
            }
            catch (Exception ex)
            {
                Log.Error($"[ReadNumTest : Error] {ex.Message} {_Url.url}");
            }
        }