public HttpWebResponse Process( HttpAccess web, HttpWebResponse response, string method, string enctype, string url, Dictionary <string, object> updata, Dictionary <string, object> upfiles) { if (new[] { HttpStatusCode.MovedPermanently, // 301 HttpStatusCode.Redirect, // 302 HttpStatusCode.TemporaryRedirect, // 307 }.Contains(response.StatusCode)) { string location = response.Headers["Location"]; if (!new Regex("^https?://").Match(location).Success) { location = response.ResponseUri.For(_ => $"{_.Scheme}://{_.Authority}{location}"); } if (!location.IsNullOrWhiteSpace() && web.RedirectTimes < web.AllowRedirectTimes) { OnRedirect?.Invoke(location); web.RedirectTimes++; return(web.GetLastResponse(HttpVerb.GET, MimeMap.APPLICATION_X_WWW_FORM_URLENCODED, location, null, null)); } else { throw new WebException("Too many automatic redirections were attempted."); } } return(null); }
/// <summary> /// 点击网址框右侧按钮时调用 /// 根据输入的网址自动添加对应网址图片 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private async void GetWebsitePicture(object sender, RoutedEventArgs e) { if (HttpAccess.CheckURL(website.Text)) { item.Img = await HttpAccess.GetIco(website.Text) ?? ImageHelper.DefaultImg; } }
HttpWebResponse IProcessor.Process( HttpAccess web, HttpWebResponse response, string method, string enctype, string url, Dictionary <string, object> updata, Dictionary <string, object> upfiles) { return(LoginProcess(web, response)); }
/// <summary> /// check if the website is valid /// </summary> /// <param name="website"></param> /// <returns></returns> private bool CheckWebsite(string website) { return(HttpAccess.CheckURL(website)); }
internal static HttpAccessResult OnHttpAccess_Call(HttpAccess httpAccess) => OnHttpAccess?.Invoke(httpAccess);
private HttpAccessResult ZLMediaKitWebHookEvents_OnHttpAccess(HttpAccess arg) { throw new NotImplementedException(); }
public void Run(string[] args) { var conArgs = new ConArgs(args, "-"); var name = conArgs[1]; var resp = Http.PostFor <JSend>($"{Program.SUPPORT_URL}/Install", new Dictionary <string, object> { ["name"] = name, }); try { if (resp.IsSuccess()) { var model = resp.data as JObject; var cli_version = model["cli_version"].Value <string>(); if (new Version(Program.CLI_VERSION) >= new Version(cli_version)) { int fileCount = model["count"].Value <int>(); int fileDownload = 0; int fileSkip = 0; int fileDone() => fileDownload + fileSkip; int fileVerifySuccess = 0; int fileVerifyFailed = 0; int colLength1 = fileCount * 2 + 1; int[] tableLengths = new[] { colLength1, 67 - colLength1, 7 }; List <string> extractFileList = new List <string>(); foreach (var item in model["files"] as JArray) { var url = item["url"].Value <string>(); var md5 = item["md5"].Value <string>(); var fileName = item["fileName"].Value <string>(); var saveas = $@"{Program.DOWNLOAD_DIRECTORY}\{fileName}"; var extract = item["extract"].Value <bool>(); if (!File.Exists(saveas) || FileUtility.ComputeMD5(saveas) != md5) { #region Download files using (var file = new FileStream(saveas, FileMode.Create)) { var web = new HttpAccess(); web.DownloadProgress += (sender, _url, received, length) => { Echo.Row(new[] { $"{fileDone() + 1}/{fileCount}", $"| {fileName}", ((double)received / length).ToString("0.00%") }, tableLengths); }; int retry = 0, allowedRetry = 3; retry: try { web.GetDownload(file, url); if (extract) { extractFileList.Add(saveas); } fileDownload++; } catch (Exception ex) { Echo.Line(); if (retry < allowedRetry) { Echo.Print($" {ex.Message}, retry {++retry}/{allowedRetry}").Line(); goto retry; } else { Echo.Print($" File can not be downloaded from {url}").Line(); Echo.AskYN("Retry?", out var ansRetry); if (ansRetry) { retry = 0; goto retry; } else { fileSkip++; continue; } } } } #endregion #region Check file md5 var status = ""; if (FileUtility.ComputeMD5(saveas) == md5) { fileVerifySuccess++; status = "Safe"; } else { fileVerifyFailed++; status = "WARNING"; } Echo.Row(new[] { $"{fileDone()}/{fileCount}", $"| {Path.GetFileName(saveas)}", status }, tableLengths).Line(); #endregion } else { if (extract) { extractFileList.Add(saveas); } fileDownload++; Echo.Row(new[] { $"{fileDone()}/{fileCount}", $"| {Path.GetFileName(saveas)}", "Found" }, tableLengths).Line(); } } Echo .Line() .Print($" " + $"{fileDownload} downloaded." + $" {fileVerifySuccess} safe, {fileVerifyFailed} warning, {fileSkip} skiped.").Line() .Print($"---- All files has been downloaded using engine {typeof(Http).FullName} ----").Line() .Line(); // Setup void extractFiles() { foreach (var file in extractFileList) { ZipFile.ExtractToDirectory(file, Program.ProjectInfo.ProjectRoot, true); Echo.Print($"Extract {file} done.").Line(); } Echo .Print($"---- Extract files completed ----").Line() .Line(); }; if (fileVerifyFailed > 0) { Echo.AskYN("Setup now?", out var ans); if (ans) { extractFiles(); } } else { extractFiles(); } } else { Echo.Print($"Install service requires the lowest cli tool version: {cli_version}.").Line(); } } else { AlertUtility.PrintErrorMessage(resp); } } catch (JsonReaderException ex) { Echo.Print($"Error occurred. ({ex.Message})").Line(); } }
/// <summary> /// If this method cannot determine response, it should be return null. /// </summary> /// <param name="web"></param> /// <param name="response"></param> /// <returns></returns> public abstract HttpWebResponse LoginProcess(HttpAccess web, HttpWebResponse response);