public async Task InsertKPIsAsync(List <AggregationItem> items, long searchIndexId, DateTime logDate) { List <KPIMetric> metrics = new List <KPIMetric>(); using (var context = new SmartKPIDbContext(this._connectionString)) { foreach (var item in items) { KPIMetric metric = this.GetKPI(item, searchIndexId, logDate); if (metric != null) { metrics.Add(metric); } } context.KPIMetrics.AddRange(metrics); int result = await context.SaveChangesAsync(); if (result > 0) { this.InsertOrUpdateMetricTimer(indexId: searchIndexId, logDate: logDate); } await Task.WhenAll(); } }
public async Task InserKPIAsync(AggregationItem item, long searchIndexId, DateTime logDate) { using (var context = new SmartKPIDbContext(this._connectionString)) { KPIMetric metric = this.GetKPI(item, searchIndexId, logDate); if (metric != null) { context.KPIMetrics.Add(metric); await context.SaveChangesAsync(); } } }
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(); }