Beispiel #1
0
        public static void Update(RateLimitEntity item, ref bool ifContain)
        {
            RateLimitEntity rateLimitOld = RateLimitAccess.GetRateLimitByID(item.TableID);

            if (item.ZoneId == rateLimitOld.ZoneId)
            {
                var list = RateLimitAccess.GetRateLimits(item.ZoneId, null, null, string.Empty);
                list.RemoveAt(list.FindIndex((r) => { return(r.TableID == item.TableID); }));

                if (IfContain(list, item))
                {
                    ifContain = true;
                    return;
                }
                else
                {
                    ifContain = false;
                }

                RateLimitAccess.Edit(item);
            }
            else
            {
                RateLimitBusiness.Add(item, ref ifContain);
                if (!ifContain)
                {
                    Delete(rateLimitOld.TableID, rateLimitOld.OrderNo, rateLimitOld.ZoneId);
                }
            }
        }
Beispiel #2
0
        public static void UpdateOrder(int action, int id, int order, string zoneId)
        {
            int             toOrder = action == 1 ? order - 1 : order + 1;
            RateLimitEntity toItem  = RateLimitAccess.GetRateLimitByOrderNo(toOrder, zoneId);

            if (toItem.TableID > 0)
            {
                RateLimitAccess.EditOrder(id, toOrder, toItem.TableID, order);
            }
        }
Beispiel #3
0
        public static void Add(RateLimitEntity item, ref bool ifContain)
        {
            var list     = RateLimitAccess.GetRateLimits(item.ZoneId, null, null, string.Empty);
            var orderMax = 0;

            if (null != list.LastOrDefault())
            {
                orderMax = list.LastOrDefault().OrderNo;
            }
            if (IfContain(list, item))
            {
                ifContain = true;
                return;
            }
            else
            {
                ifContain = false;
            }
            item.OrderNo = orderMax + 1;
            RateLimitAccess.Add(item);
        }
Beispiel #4
0
        public static dynamic GetRateLimit(int limit, int offset, string zoneID, DateTime?startTime, DateTime?endTime, string url)
        {
            //List<RateLimitEntity> list = new List<RateLimitEntity>();
            //for (int i = 0; i < 50; i++)
            //{
            //    var r = new Random(Guid.NewGuid().GetHashCode());
            //    RateLimitEntity en = new RateLimitEntity();
            //    en.ID = i;
            //    en.Period = r.Next(0, 100);
            //    en.Threshold = r.Next(0, 100);
            //    en.Url = "www.comm100.com";
            //    en.OrderNo = i + 1;
            //    en.RateLimitTriggerIpCount = r.Next(0, 100);
            //    en.EnlargementFactor = r.Next(0, 100);

            //    list.Add(en);
            //}
            List <RateLimitEntity> list = RateLimitAccess.GetRateLimits(zoneID, startTime, endTime, url);

            var total = list.Count;
            var rows  = list.Skip(offset).Take(limit).ToList();

            return(new { total, rows });
        }
Beispiel #5
0
 public static RateLimitEntity GetRateLimitByID(int id)
 {
     return(RateLimitAccess.GetRateLimitByID(id));
 }
Beispiel #6
0
 public static List <RateLimitEntity> GetList(string zoneId)
 {
     return(RateLimitAccess.GetRateLimits(zoneId, null, null, null));
 }
Beispiel #7
0
 public static int GetRateLimitMaxOrder(string zoneId)
 {
     return(RateLimitAccess.GetRateLimitMaxOrder(zoneId));
 }
Beispiel #8
0
 public static void Delete(int id, int order, string zoneId)
 {
     RateLimitAccess.Delete(id, order, zoneId);
 }
Beispiel #9
0
 public static void TriggerRateLimit(RateLimitEntity rateLimit)
 {
     RateLimitAccess.TriggerRateLimit(rateLimit);
 }