public IEnumerable <ExceptionInfo> GetLatestExceptions(int top) { List <ExceptionInfo> list = new List <ExceptionInfo>(); using (var context = new ELMAH_Entities()) { var result = (from x in context.ELMAH_Error orderby x.TimeUtc descending select new { ExceptionDate = x.TimeUtc, ExceptionId = x.ErrorId, Description = x.Message, Type = x.Type }).Take(top); foreach (var item in result) { ExceptionInfo info = new ExceptionInfo { Id = item.ExceptionId.ToString(), Date = item.ExceptionDate.ToLocalTime(), Message = item.Description, Type = item.Type }; list.Add(info); } return(list); } }
public ELMAH_Monthly_Info GetBarDataPerMonth(int month) { var random = new Random(); ELMAH_Monthly_Info barPerMonth = new ELMAH_Monthly_Info(); barPerMonth.Month = month; barPerMonth.MonthName = Enum.GetName(typeof(Enum_Month), month); barPerMonth.Color = String.Format("#{0:X6}", random.Next(0x1000000)); using (var context = new ELMAH_Entities()) { DateTime beginTime = DateHelper.GetDateMonthStart(DateTime.Today.Year, month).ToUniversalTime(); DateTime endTime = DateHelper.GetDateMonthEnd(DateTime.Today.Year, month).ToUniversalTime(); //int totalPerMonth = (from x in context.ELMAH_Error // where x.TimeUtc > beginTime // && x.TimeUtc < endTime // select x).Count(); var groupResult = from x in context.ELMAH_Error where x.TimeUtc > beginTime && x.TimeUtc < endTime group x by x.Type into grp select new { TypeName = grp.Key, Count = grp.Count() }; barPerMonth.ExceptionInfo = new List <Tuple <string, int> >(); foreach (var item in groupResult) { Tuple <string, int> t = new Tuple <string, int>(item.TypeName, item.Count); barPerMonth.ExceptionInfo.Add(t); } barPerMonth.TotalPerMonth = groupResult.Any() ? groupResult.Sum(p => p.Count) : 0; //totalPerMonth; } return(barPerMonth); }
public ChartData GetChartData(int top, int back) { ChartData d = new ChartData(); List <int> values = new List <int>(); List <string> labels = new List <string>(); List <string> colors = new List <string>(); List <string> ids = new List <string>(); using (var context = new ELMAH_Entities()) { var results = context.ELMAH_report(top, back).ToList(); var random = new Random(); if (results.Count() == 1 && results[0].Count == 0) { d.Labels = new List <string>(); d.Values = new List <int>(); d.Colors = new List <string>(); d.Ids = new List <string>(); return(d); } foreach (var item in results) { values.Add(item.Count.Value); labels.Add(item.Type); colors.Add(String.Format("#{0:X6}", random.Next(0x1000000))); ids.Add(item.Id.Value.ToString()); } d.Labels = labels; d.Values = values; d.Colors = colors; d.Ids = ids; return(d); } }
IEnumerable <ChartData> CalculateChartStatistics(int topParam, int daybackParam) { List <ChartData> chartData = new List <ChartData>(); /* * * * select @sumTotal = * ( * select sum([Count]) from * ( * select count ([Type]) as [Count] from [dbo].[ELMAH_Error] as a * where * ( @DaysBack = 1 AND (DATEADD(minute, DATEDIFF(minute,getutcdate(),getdate()), [TimeUtc]) >= DateAdd(hh, -24, GETDATE())) OR * @DaysBack = 2 AND (DATEADD(minute, DATEDIFF(minute,getutcdate(),getdate()), [TimeUtc]) >= DateAdd(dd, -3, GETDATE())) OR --3 days * @DaysBack = 3 AND (DATEADD(minute, DATEDIFF(minute,getutcdate(),getdate()), [TimeUtc]) >= DateAdd(dd, -7, GETDATE())) OR --1 week * @DaysBack = 4 AND (DATEADD(minute, DATEDIFF(minute,getutcdate(),getdate()), [TimeUtc]) >= DateAdd(mm, -1, GETDATE())) OR --1 month * @DaysBack = 5 AND (DATEADD(minute, DATEDIFF(minute,getutcdate(),getdate()), [TimeUtc]) >= DateAdd(mm, -12, GETDATE())) OR --1 year * @DaysBack = 0 AND (DATEADD(minute, DATEDIFF(minute,getutcdate(),getdate()), [TimeUtc]) >= dbo.getCurrentDateStartString()) -- today * ) * group by [Type] * ) as a * ) * */ using (var context = new ELMAH_Entities()) { int hours = 0; switch (daybackParam) { case 0: hours = -24; break; case 1: hours = -24; break; case 2: hours = -24 * 3; break; case 3: hours = -24 * 7; break; case 4: hours = -24 * 30; break; case 5: hours = -24 * 365; break; } var result = from x in context.ELMAH_Error where x.TimeUtc.ToLocalTime() >= x.TimeUtc.ToLocalTime().AddHours(hours) group x by x.Type into newGroup select new { Count = newGroup.Count() }; int totalExceptions = result.Sum(p => p.Count); } return(chartData); }