Beispiel #1
0
        /// <exception cref="OverflowException">
        /// The dictionary already contains the maximum number of elements ( <see cref="F:System.Int32.MaxValue" />).
        /// </exception>
        /// <exception cref="ArgumentNullException">
        /// <paramref name="key" /> is null.
        /// </exception>
        public void Add(string region, LolUrlType type, RLolApiName rla)
        {
            var rut = new RUrlType();

            rut.Add(type, rla);
            Add(region, rut);
        }
Beispiel #2
0
 /// <summary>
 /// </summary>
 /// <param name="type">
 /// </param>
 /// <param name="name">
 /// </param>
 /// <param name="limits">
 /// </param>
 /// <param name="methods">
 /// </param>
 /// <returns>
 /// </returns>
 public RateLimitBuilder AddRateLimitFor(LolUrlType type, LolApiName name, List <ApiLimit> limits, params LolApiMethodName[] methods)
 {
     return(AddRateLimitFor(type, new List <LolApiName>()
     {
         name
     }, limits, methods));
 }
Beispiel #3
0
        /// <exception cref="OverflowException">
        /// The dictionary already contains the maximum number of elements ( <see cref="F:System.Int32.MaxValue" />).
        /// </exception>
        /// <exception cref="ArgumentNullException">
        /// <paramref name="key" /> is null.
        /// </exception>
        public void Add(string region, LolUrlType type, LolApiName name, List <LolApiMethodName> apiMethods, List <ApiLimit> limits)
        {
            var rut = new RUrlType();

            rut.Add(type, new RLolApiMethodName(name, apiMethods, limits.ToArray()));
            Add(region, rut);
        }
Beispiel #4
0
        /// <exception cref="KeyNotFoundException">
        /// The property is retrieved and <paramref name="key" /> does not exist in the collection.
        /// </exception>
        /// <exception cref="ArgumentNullException">
        /// <paramref name="key" /> is null.
        /// </exception>
        public RLolApiMethodName Find(string region, LolUrlType type, LolApiName name, LolApiMethodName method)
        {
            var rut  = Find(region);
            var rla  = rut?.Find(type);
            var rlan = rla?.Find(name, method);

            return(rlan);
        }
Beispiel #5
0
 public RLolApiName Find(LolUrlType type)
 {
     if (ContainsUrlTypes(type))
     {
         return(UrlTypes[type]);
     }
     else
     {
         return(null);
     }
 }
Beispiel #6
0
        /// <summary>
        /// get data from Retry-After
        /// </summary>
        /// <param name="prop">
        /// </param>
        /// <param name="name">
        /// </param>
        /// <param name="limitType">
        /// </param>
        /// <param name="retryAfterSeconds">
        /// value of Retry-After
        /// </param>
        /// <param name="region">
        /// </param>
        /// <param name="type">
        /// </param>
        /// <exception cref="RiotGamesApiException">
        /// Condition.
        /// </exception>
        public void SetRetryTime(string region, LolUrlType type, LolApiName name, RateLimitType limitType, LolApiMethodName method, int retryAfterSeconds)
        {
            var regionLimit = Rates.Find(region, type, name, method);

            if (regionLimit == null)
            {
                throw new RiotGamesApiException($"Undefined {limitType} limit type for region:{region},type:{type},name:{name}");
            }
            regionLimit.RetryAfter        = DateTime.Now.AddSeconds(retryAfterSeconds);
            regionLimit.UsedRateLimitType = limitType;
        }
Beispiel #7
0
        /// <summary>
        /// add cache rule for non-static api
        /// </summary>
        /// <param name="urlType">
        /// api url type
        /// </param>
        /// <param name="apiName">
        /// api method name
        /// </param>
        /// <param name="expiryTime">
        /// expiry time (max-limit: 1 hour)
        /// </param>
        public void AddCacheRule(LolUrlType urlType, LolApiName apiName, TimeSpan expiryTime)
        {
            if (urlType != LolUrlType.Static)
            {
                if (expiryTime.Hours >= 1)
                {
                    expiryTime = new TimeSpan(1, 0, 0);
                }

                var found = FindCacheRule(urlType, apiName);
                if (found != null)
                {
                    CustomCacheRules.Remove(found);
                }
                CustomCacheRules.Add(new CustomCacheRule(urlType, apiName, expiryTime));
            }
        }
Beispiel #8
0
        /// <summary>
        /// </summary>
        /// <param name="type">
        /// </param>
        /// <param name="names">
        /// </param>
        /// <param name="limits">
        /// </param>
        /// <param name="methods">
        /// </param>
        /// <returns>
        /// </returns>
        public RateLimitBuilder AddRateLimitFor(LolUrlType type, List <LolApiName> names, List <ApiLimit> limits, params LolApiMethodName[] methods)
        {
            var rla  = new RLolApiName();
            var rlan = new RLolApiMethodName();

            rlan.Add(names, methods.Distinct().ToArray());
            rlan.AddLimit(limits.ToArray());
            rla.Add(rlan);
            if (!Limits.ContainsKey(type))
            {
                Limits.TryAdd(type, rla);
            }
            else
            {
                Limits[type].Add(rlan);
            }
            return(this);
        }
Beispiel #9
0
 public void Add(LolUrlType val, RLolApiMethodName rlan)
 {
     UrlTypes.TryAdd(val, new RLolApiName(rlan));
 }
Beispiel #10
0
 /// <summary>
 /// removs cache rule
 /// </summary>
 /// <param name="urlType">
 /// </param>
 /// <param name="apiName">
 /// </param>
 public void RemoveCacheRule(LolUrlType urlType, LolApiName apiName)
 {
     CustomCacheRules.RemoveAll(p => p.UrlType == urlType && p.ApiName == apiName);
 }
Beispiel #11
0
 public void Add(LolUrlType val, RLolApiName rlan)
 {
     UrlTypes.TryAdd(val, rlan);
 }
Beispiel #12
0
 public CustomCacheRule(LolUrlType urlType, LolApiName apiName, TimeSpan expiryTime)
 {
     this.UrlType    = urlType;
     this.ApiName    = apiName;
     this.ExpiryTime = expiryTime;
 }
Beispiel #13
0
 public bool ContainsUrlTypes(LolUrlType name)
 {
     return(UrlTypes.ContainsKey(name));
 }
Beispiel #14
0
 public UrlTypeAttribute(LolUrlType _apitype)
 {
     this.ApiType = _apitype;
 }
Beispiel #15
0
 public RLolApiMethodName FindRate(string platform, LolUrlType type, LolApiName apiName, LolApiMethodName method)
 {
     return(Rates.Find(platform, type, apiName, method));
 }
Beispiel #16
0
 /// <summary>
 /// specify new rate-limit for api
 /// </summary>
 /// <param name="region">
 /// </param>
 /// <param name="type">
 /// </param>
 /// <param name="rla">
 /// pre-defined when web-server starts
 /// </param>
 public void Add(string region, LolUrlType type, RLolApiName rla)
 {
     Rates.Add(region, type, rla);
 }
Beispiel #17
0
        /// <summary>
        /// finds exists cache rules
        /// </summary>
        /// <param name="urlType">
        /// </param>
        /// <param name="apiName">
        /// </param>
        /// <returns>
        /// </returns>
        /// <exception cref="ArgumentNullException">
        /// <paramref name="source" /> or <paramref name="predicate" /> is null.
        /// </exception>
        public CustomCacheRule FindCacheRule(LolUrlType urlType, LolApiName apiName)
        {
            var found = CustomCacheRules.FirstOrDefault(p => p.UrlType == urlType && p.ApiName == apiName);

            return(found);
        }