Beispiel #1
0
        //public HttpWebRequest DownloadRequest(long instart, long inend, File file, ShardInfo shard)
        //{
        //    string downloadkey = string.Empty;
        //    if (shard.Type == ShardType.WeblinkGet)
        //        downloadkey = Authent.DownloadToken;

        //    string url = shard.Type == ShardType.Get
        //        ? $"{shard.Url}{Uri.EscapeDataString(file.FullPath)}"
        //        : $"{shard.Url}{new Uri(ConstSettings.PublishFileLink + file.PublicLink).PathAndQuery.Remove(0, "/public".Length)}?key={downloadkey}";

        //    var request = (HttpWebRequest)WebRequest.Create(url);

        //    request.Headers.Add("Accept-Ranges", "bytes");
        //    request.AddRange(instart, inend);
        //    request.Proxy = HttpSettings.Proxy;
        //    request.CookieContainer = Authent.Cookies;
        //    request.Method = "GET";
        //    request.ContentType = MediaTypeNames.Application.Octet;
        //    request.Accept = "*/*";
        //    request.UserAgent = HttpSettings.UserAgent;
        //    request.AllowReadStreamBuffering = false;

        //    request.Timeout = 15 * 1000;

        //    return request;
        //}


        //public void BanShardInfo(ShardInfo banShard)
        //{
        //    if (!_bannedShards.Value.Any(bsh => bsh.Type == banShard.Type && bsh.Url == banShard.Url))
        //    {
        //        Logger.Warn($"Shard {banShard.Url} temporarily banned");
        //        _bannedShards.Value.Add(banShard);
        //    }
        //}


        /// <summary>
        /// Get shard info that to do post get request. Can be use for anonymous user.
        /// </summary>
        /// <param name="shardType">Shard type as numeric type.</param>
        /// <returns>Shard info.</returns>
        public override async Task <ShardInfo> GetShardInfo(ShardType shardType)
        {
            bool refreshed = false;

            for (int i = 0; i < 10; i++)
            {
                Thread.Sleep(80 * i);
                var ishards = await Task.Run(() => _cachedShards.Value);

                var ishard = ishards[shardType];
                var banned = _bannedShards.Value;
                if (banned.All(bsh => bsh.Url != ishard.Url))
                {
                    if (refreshed)
                    {
                        Authent.ExpireDownloadToken();
                    }
                    return(ishard);
                }
                _cachedShards.Expire();
                refreshed = true;
            }

            Logger.Error("Cannot get working shard.");

            var shards = await Task.Run(() => _cachedShards.Value);

            var shard = shards[shardType];

            return(shard);
        }
Beispiel #2
0
        public void Expire_MarksTheValueAsExpired()
        {
            var called = 0;
            var temp   = new Cached <int>(() =>
            {
                called++;
                return(-1);
            }, 1000);

            var x = temp.Value;

            temp.Expire();
            Assert.IsTrue(called == 1);
        }
Beispiel #3
0
        public void Expire_WillForceTheValueToBeRefreshed()
        {
            var called = 0;
            var temp   = new Cached <int>(() =>
            {
                called++;
                return(-1);
            }, 1000);

            var x = temp.Value;

            temp.Expire();

            x = temp.Value;

            Assert.IsTrue(called == 2);
        }
Beispiel #4
0
 public void ExpireDownloadToken()
 {
     _cachedDownloadToken.Expire();
 }