Пример #1
0
            private async Task <HttpResponseMessage> GetWithMirroredRetry(Http.Client client, string url)
            {
                int retries    = 0;
                var downloader = DownloadDispatcher.GetInstance <WabbajackCDNDownloader>();

                if (downloader.Mirrors != null)
                {
                    url = ReplaceHost(downloader.Mirrors, url);
                }

TOP:

                try
                {
                    return(await client.GetAsync(url, retry : false));
                }
                catch (Exception ex)
                {
                    if (retries > 5)
                    {
                        Utils.Log($"Tried to read from {retries} CDN servers, giving up");
                        throw;
                    }
                    Utils.Log($"Error reading {url} retying with a mirror");
                    Utils.Log(ex.ToString());
                    downloader.Mirrors ??= await ClientAPI.GetCDNMirrorList();

                    url      = ReplaceHost(downloader.Mirrors, url);
                    retries += 1;
                    Interlocked.Increment(ref downloader.TotalRetries);
                    goto TOP;
                }
            }
Пример #2
0
        /// <summary>
        /// This is all we track for metrics, action, and value. The action will be like
        /// "downloaded", the value "Joe's list".
        /// </summary>
        /// <param name="action"></param>
        /// <param name="value"></param>
        public static async Task Send(string action, string value)
        {
            if (BuildServerStatus.IsBuildServerDown)
            {
                return;
            }

            var key = await GetMetricsKey();

            Utils.Log($"File hash check (-42) {key}");
            var client = new Http.Client();

            client.Headers.Add((Consts.MetricsKeyHeader, key));
            await client.GetAsync($"{Consts.WabbajackBuildServerUri}metrics/{action}/{value}");
        }
Пример #3
0
            private async Task <HttpResponseMessage> GetWithCDNRetry(Http.Client client, string url, CancellationToken?token = null)
            {
                int retries = 0;

TOP:

                try
                {
                    return(await client.GetAsync(url, retry : false, token : token));
                }
                catch (Exception ex)
                {
                    if (retries > 2)
                    {
                        Utils.Log($"Trying CDN...");
                        var remap = url.Replace(new Uri(url).Host, DomainRemaps.FirstOrDefault(x => x.Value == new Uri(url).Host).Key);
                        return(await client.GetAsync(remap, retry : false, token : token));
                    }
                    retries += 1;
                    Utils.Log($"Error reading {url} retrying [{retries}]");
                    Utils.Log(ex.ToString());
                    goto TOP;
                }
            }
Пример #4
0
        private static bool CheckBuildServer()
        {
            var client = new Http.Client();

            try
            {
                var result = client.GetAsync($"{Consts.WabbajackBuildServerUri}heartbeat").Result;
                _isBuildServerDown = result.StatusCode != HttpStatusCode.OK && result.StatusCode != HttpStatusCode.InternalServerError;
            }
            catch (Exception)
            {
                _isBuildServerDown = true;
            }
            finally
            {
                _didCheck = true;
            }

            Utils.Log($"Build server is {(_isBuildServerDown ? "down" : "alive")}");
            return(_isBuildServerDown);
        }
Пример #5
0
            private async Task <HTTPDownloader.State?> Resolve(CancellationToken?token = null)
            {
                var client = new Http.Client();
                var result = await client.GetAsync(Url, HttpCompletionOption.ResponseHeadersRead, token : token);

                if (!result.IsSuccessStatusCode)
                {
                    return(null);
                }

                if (result.Content.Headers.ContentType !.MediaType !.StartsWith("text/html",
                                                                                StringComparison.OrdinalIgnoreCase))
                {
                    var body = await client.GetHtmlAsync(Url);

                    var node = body.DocumentNode.DescendantsAndSelf().First(d => d.HasClass("input") && d.HasClass("popsok") &&
                                                                            d.GetAttributeValue("aria-label", "") == "Download file");
                    return(new HTTPDownloader.State(node.GetAttributeValue("href", "not-found")));
                }

                return(new HTTPDownloader.State(Url));
            }