コード例 #1
0
        /// <summary>
        /// 尝试重连
        /// </summary>
        /// <param name="s">Session</param>
        /// <param name="x">RequestsParam</param>
        /// <param name="CheckFunc">检查HTML委托</param>
        /// <param name="num"></param>
        /// <returns></returns>
        public static async Task <HttpStreamInfo> TryRequests(this Session s, RequestParam x, Func <HttpStreamInfo, ValueTask <bool> > CheckFunc, int num = 3, int delay = 2, CancellationToken cancellationToken = default)
        {
            Exception e = null;

            for (var i = 0; i < num; i++)
            {
                try
                {
                    using (var r = await s.SendAsync(x, cancellationToken))
                    {
                        if (await CheckFunc(r))
                        {
                            return(r);
                        }
                    }
                }
                catch (Exception ex)
                {
                    e = ex;
                    await Task.Delay(delay *1000);
                }
            }
            throw e;
        }
コード例 #2
0
        /// <summary>
        /// 尝试请求
        /// </summary>
        /// <param name="s"></param>
        /// <param name="x"></param>
        /// <param name="num"></param>
        /// <returns></returns>
        public static async Task <HttpStreamInfo> TryRequests(this Session s, RequestParam x, int num = 3, int delay = 2, CancellationToken cancellationToken = default)
        {
            Func <HttpStreamInfo, ValueTask <bool> > check = (r) => new ValueTask <bool>(r.HttpResponseMessage.IsSuccessStatusCode == true);

            return(await TryRequests(s, x, check, num, delay, cancellationToken));
        }
コード例 #3
0
 public HttpStreamInfo(HttpResponseMessage httpResponseMessage, RequestParam request)
 {
     HttpResponseMessage = httpResponseMessage;
     RequestParam        = request;
 }