Ejemplo n.º 1
0
 public long GetMaxComputeRuleId()
 {
     using (var context = new SmartKPIDbContext(this._connectionString))
     {
         DateTime    maxDate  = context.ComputeRules.Max(x => x.CreateDate);
         ComputeRule lastRule = context.ComputeRules.FirstOrDefault(x => x.CreateDate == maxDate);
         return(lastRule.ComputeRuleId);
     }
 }
Ejemplo n.º 2
0
        public async Task InsertComputeRule(IEnumerable <string> httpSuccessCodes)
        {
            httpSuccessCodes = httpSuccessCodes.OrderBy(x => x);
            string httpCodes = string.Join(',', httpSuccessCodes);

            ComputeRule computeRule = new ComputeRule {
                HttpSuccessCodes = httpCodes
            };

            using (var context = new SmartKPIDbContext(this._connectionString))
            {
                DateTime maxDate = await context.ComputeRules.MaxAsync(x => x.CreateDate);

                ComputeRule lastRule = await context.ComputeRules.FirstOrDefaultAsync(x => x.CreateDate == maxDate);

                if (lastRule.HttpSuccessCodes != httpCodes)
                {
                    context.ComputeRules.Add(computeRule);
                    await context.SaveChangesAsync();
                }
            }

            ServiceManager.LastRuleId = GetMaxComputeRuleId();
        }