Beispiel #1
0
 public async Task <List <SearchIndex> > GetSearchIndicesAsync()
 {
     using (var context = new SmartKPIDbContext(this._connectionString))
     {
         return(await context.SearchIndices.Where(x => x.IsActive).ToListAsync());
     }
 }
Beispiel #2
0
        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();
            }
        }
Beispiel #3
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);
     }
 }
Beispiel #4
0
 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();
         }
     }
 }
Beispiel #5
0
 public DateTime GetSearchRange(long indexId)
 {
     using (var context = new SmartKPIDbContext(this._connectionString))
     {
         DateTime?maxLogDate = context.KPIMetricTimers.FirstOrDefault(x => x.IndexId == indexId)?.LastInsertDate;
         if (maxLogDate != null)
         {
             maxLogDate = maxLogDate.Value.AddMilliseconds(10);
             return(maxLogDate.Value);
         }
         return(DateTime.Now.AddDays(-7));
     }
 }
Beispiel #6
0
 public List <string> GetExcludedFileFormats()
 {
     if (_excludedFileExtensions.IsRunning)
     {
         return(_excludedFileExtensions.ToList());
     }
     else
     {
         using (var context = new SmartKPIDbContext(this._connectionString))
         {
             List <string>             excFileFormatList = new List <string>();
             List <ExcludedFileFormat> excludedFiles     = context.ExcludedFileFormats.ToList();
             var list = excludedFiles.Select(x => x.FormatExtension).ToList();
             this._excludedFileExtensions.AddRange(list);
             this._excludedFileExtensions.Run();
             return(list);
         }
     }
 }
Beispiel #7
0
        public bool InsertOrUpdateMetricTimer(long indexId, DateTime logDate)
        {
            using (var context = new SmartKPIDbContext(this._connectionString))
            {
                KPIMetricTimer metricTimer = context.KPIMetricTimers.FirstOrDefault(x => x.IndexId == indexId);
                if (metricTimer != null)
                {
                    metricTimer.LastInsertDate   = logDate;
                    metricTimer.RowModifyDateLog = DateTime.Now;
                    context.KPIMetricTimers.Update(metricTimer);
                }
                else
                {
                    metricTimer = new KPIMetricTimer {
                        IndexId = indexId, LastInsertDate = logDate
                    };
                    context.KPIMetricTimers.Add(metricTimer);
                }

                int result = context.SaveChanges();
                return(result > 0);
            }
        }
Beispiel #8
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();
        }