Exemple #1
0
        private void CheckAndUpdateDoSLimits(HttpRequestMessage request, string emailId)
        {
            var    dosLimitCatalogProvider = PriceUpdateContext.Instance.CatalogFactory.GetDoSLimitCatalogProvider();
            string userIP = GetClientIp(request);

            DoSLimitArgs args = new DoSLimitArgs
            {
                UserIP  = userIP,
                EmailId = emailId
            };

            DoSLimitEntity dosEntity = dosLimitCatalogProvider.GetLimit(args);

            if (dosEntity == null)
            {
                dosEntity = new DoSLimitEntity
                {
                    UserIPAddress = args.UserIP,
                    EmailId       = args.EmailId
                };
            }

            //TODO: Should come from config
            if (dosEntity.Count <= 500)
            {
                dosEntity.Count += 1;
                dosLimitCatalogProvider.UpdateLimit(dosEntity);
            }
            else
            {
                throw new Exception("Request limits reached for this IP");
            }
        }
 public void UpdateLimit(DoSLimitEntity entityToUpdate)
 {
     this.dbContext.Save <DoSLimitEntity>(entityToUpdate);
 }