/// <summary> /// Loads the control. /// </summary> /// <param name="e">The <see cref="T:System.EventArgs" /> object that contains the event data.</param> protected override void OnLoad(EventArgs e) { base.OnLoad(e); if (!Page.IsPostBack) { //Set Exception Panel visibility to show Exception List SetExceptionPanelVisibility(None.Id); } lcExceptions.Options.SetChartStyle(this.ChartStyle); lcExceptions.Options.legend = lcExceptions.Options.legend ?? new Legend(); lcExceptions.Options.legend.show = this.GetAttributeValue("ShowLegend").AsBooleanOrNull(); lcExceptions.Options.legend.position = this.GetAttributeValue("LegendPosition"); // get data for graphs ExceptionLogService exceptionLogService = new ExceptionLogService(new RockContext()); var exceptionList = exceptionLogService.Queryable() .Where(x => x.HasInnerException == false && x.CreatedDateTime != null) .GroupBy(x => DbFunctions.TruncateTime(x.CreatedDateTime.Value)) .Select(eg => new { DateValue = eg.Key, ExceptionCount = eg.Count(), UniqueExceptionCount = eg.Select(y => y.ExceptionType).Distinct().Count() }).OrderBy(eg => eg.DateValue).ToList(); if (exceptionList.Count == 1) { // if there is only one datapoint for the Chart, the yaxis labeling gets messed up, plus the graph wouldn't be useful anyways lcExceptions.Visible = false; } }
/// <summary> /// Binds the exception occurrence grid. /// </summary> /// <param name="baseException">Exception to base the occurrence grid off of.</param> private void BindExceptionOccurrenceGrid(ExceptionLog baseException) { ExceptionLogService exceptionService = new ExceptionLogService(); var query = exceptionService.Queryable() .Where(e => e.HasInnerException == null || e.HasInnerException == false) .Where(e => e.SiteId == baseException.SiteId) .Where(e => e.PageId == baseException.PageId) .Where(e => e.Description == baseException.Description) .Select(e => new { Id = e.Id, ExceptionDateTime = e.ExceptionDateTime, FullName = e.CreatedByPerson.LastName + ", " + e.CreatedByPerson.NickName, Description = e.Description }); if (gExceptionOccurrences.SortProperty == null) { gExceptionOccurrences.DataSource = query.OrderByDescending(e => e.ExceptionDateTime).ToList(); } else { gExceptionOccurrences.DataSource = query.Sort(gExceptionOccurrences.SortProperty).ToList(); } gExceptionOccurrences.DataBind(); }
/// <summary> /// Binds the exception occurrence grid. /// </summary> /// <param name="baseException">Exception to base the occurrence grid off of.</param> private void BindExceptionOccurrenceGrid(ExceptionLog baseException) { ExceptionLogService exceptionService = new ExceptionLogService(new RockContext()); string url = String.Format("{0}?ExceptionId=", LinkedPageUrl("DetailPage")); var query = exceptionService.Queryable() .Where(e => e.HasInnerException == null || e.HasInnerException == false) .Where(e => e.Description.Substring(0, 28) == baseException.Description.Substring(0, 28)) .Select(e => new { Id = e.Id, CreatedDateTime = e.CreatedDateTime, PageName = e.Page.InternalName ?? e.PageUrl, FullName = (e.CreatedByPersonAlias != null && e.CreatedByPersonAlias.Person != null) ? e.CreatedByPersonAlias.Person.LastName + ", " + e.CreatedByPersonAlias.Person.NickName : "", Description = "<a href='" + url + e.Id + "'>" + e.Description + "</a>" }).OrderBy(e => e.CreatedDateTime); if (gExceptionOccurrences.SortProperty == null) { query = query.OrderByDescending(e => e.CreatedDateTime); } else { query = query.Sort(gExceptionOccurrences.SortProperty); } gExceptionOccurrences.EntityTypeId = EntityTypeCache.Read <ExceptionLog>().Id; gExceptionOccurrences.SetLinqDataSource(query); gExceptionOccurrences.DataBind(); }
/// <summary> /// Binds the exception occurrence grid. /// </summary> /// <param name="baseException">Exception to base the occurrence grid off of.</param> private void BindExceptionOccurrenceGrid(ExceptionLog baseException) { ExceptionLogService exceptionService = new ExceptionLogService(new RockContext()); var query = exceptionService.Queryable() .Where(e => e.HasInnerException == null || e.HasInnerException == false) .Where(e => e.SiteId == baseException.SiteId) .Where(e => e.PageId == baseException.PageId) .Where(e => e.Description == baseException.Description) .Select(e => new { Id = e.Id, CreatedDateTime = e.CreatedDateTime, FullName = (e.CreatedByPersonAlias != null && e.CreatedByPersonAlias.Person != null) ? e.CreatedByPersonAlias.Person.LastName + ", " + e.CreatedByPersonAlias.Person.NickName : "", Description = e.Description }).OrderBy(e => e.CreatedDateTime); if (gExceptionOccurrences.SortProperty == null) { gExceptionOccurrences.DataSource = query.OrderByDescending(e => e.CreatedDateTime).ToList(); } else { gExceptionOccurrences.DataSource = query.Sort(gExceptionOccurrences.SortProperty).ToList(); } gExceptionOccurrences.EntityTypeId = EntityTypeCache.Read <ExceptionLog>().Id; gExceptionOccurrences.DataBind(); }
/// <summary> /// Job that updates the JobPulse setting with the current date/time. /// This will allow us to notify an admin if the jobs stop running. /// /// Called by the <see cref="IScheduler" /> when a /// <see cref="ITrigger" /> fires that is associated with /// the <see cref="IJob" />. /// </summary> public virtual void Execute(IJobExecutionContext context) { // get the job map JobDataMap dataMap = context.JobDetail.JobDataMap; // delete accounts that have not been confirmed in X hours int userExpireHours = Int32.Parse(dataMap.GetString("HoursKeepUnconfirmedAccounts")); DateTime userAccountExpireDate = DateTime.Now.Add(new TimeSpan(userExpireHours * -1, 0, 0)); UserService userService = new UserService(); foreach (var user in userService.Queryable().Where(u => u.IsConfirmed == false && u.CreationDate < userAccountExpireDate)) { userService.Delete(user, null); } userService.Save(null, null); // purge exception log int exceptionExpireDays = Int32.Parse(dataMap.GetString("DaysKeepExceptions")); DateTime exceptionExpireDate = DateTime.Now.Add(new TimeSpan(userExpireHours * -1, 0, 0)); ExceptionLogService exceptionLogService = new ExceptionLogService(); foreach (var exception in exceptionLogService.Queryable().Where(e => e.ExceptionDate < exceptionExpireDate)) { exceptionLogService.Delete(exception, null); } exceptionLogService.Save(null, null); }
/// <summary> /// Loads the control. /// </summary> /// <param name="e">The <see cref="T:System.EventArgs" /> object that contains the event data.</param> protected override void OnLoad(EventArgs e) { base.OnLoad(e); if (!Page.IsPostBack) { LoadExceptionList(); pnlExceptionGroups.Visible = true; } lcExceptions.Options.legend = lcExceptions.Options.legend ?? new Legend(); lcExceptions.Options.legend.show = this.GetAttributeValue("ShowLegend").AsBooleanOrNull(); lcExceptions.Options.legend.position = this.GetAttributeValue("LegendPosition"); lcExceptions.Options.SetChartStyle(this.ChartStyle); bcExceptions.Options.legend = bcExceptions.Options.legend ?? new Legend(); bcExceptions.Options.legend.show = this.GetAttributeValue("ShowLegend").AsBooleanOrNull(); bcExceptions.Options.legend.position = this.GetAttributeValue("LegendPosition"); bcExceptions.Options.xaxis = new AxisOptions { mode = AxisMode.categories, tickLength = 0 }; bcExceptions.Options.series.bars.barWidth = 0.6; bcExceptions.Options.series.bars.align = "center"; // Set chart style after setting options so they are not overwritten. bcExceptions.Options.SetChartStyle(this.ChartStyle); bcExceptions.TooltipFormatter = @" function(item) { var itemDate = new Date(item.series.chartData[item.dataIndex].DateTimeStamp); var dateText = itemDate.toLocaleDateString(); var seriesLabel = item.series.label || ( item.series.labels ? item.series.labels[item.dataIndex] : null ); var pointValue = item.series.chartData[item.dataIndex].YValue || item.series.chartData[item.dataIndex].YValueTotal || '-'; return dateText + '<br />' + seriesLabel + ': ' + pointValue; } "; // get data for graphs ExceptionLogService exceptionLogService = new ExceptionLogService(new RockContext()); var exceptionListCount = exceptionLogService.Queryable() .Where(x => x.HasInnerException == false && x.CreatedDateTime != null) .GroupBy(x => DbFunctions.TruncateTime(x.CreatedDateTime.Value)) .Count(); if (exceptionListCount == 1) { // if there is only one x datapoint for the Chart, show it as a barchart lcExceptions.Visible = false; bcExceptions.Visible = true; } else { lcExceptions.Visible = true; bcExceptions.Visible = false; } }
/// <summary> /// Builds the base query for the Exception List grid data /// </summary> /// <returns>IQueryable containing filtered ExceptionLog records</returns> private IQueryable <ExceptionLog> BuildBaseExceptionListQuery() { ExceptionLogService exceptionLogService = new ExceptionLogService(); IQueryable <ExceptionLog> query = exceptionLogService.Queryable(); int siteId; if (int.TryParse(fExceptionList.GetUserPreference("Site"), out siteId) && siteId > 0) { query = query.Where(e => e.SiteId == siteId); } int pageId; if (int.TryParse(fExceptionList.GetUserPreference("Page"), out pageId) && pageId > 0) { query = query.Where(e => e.PageId == pageId); } int userPersonID; if (int.TryParse(fExceptionList.GetUserPreference("User"), out userPersonID) && userPersonID > 0) { query = query.Where(e => e.CreatedByPersonId == userPersonID); } string statusCode = fExceptionList.GetUserPreference("Status Code"); if (!String.IsNullOrEmpty(statusCode)) { query = query.Where(e => e.StatusCode == statusCode); } DateTime startDate; if (DateTime.TryParse(fExceptionList.GetUserPreference("Start Date"), out startDate)) { startDate = startDate.Date; query = query.Where(e => e.ExceptionDateTime >= startDate); } DateTime endDate; if (DateTime.TryParse(fExceptionList.GetUserPreference("End Date"), out endDate)) { endDate = endDate.Date.AddDays(1); query = query.Where(e => e.ExceptionDateTime < endDate); } //Only look for inner exceptions query = query.Where(e => e.HasInnerException == null || e.HasInnerException == false); return(query); }
/// <summary> /// Builds the base query for the Exception List grid data /// </summary> /// <returns>IQueryable containing filtered ExceptionLog records</returns> private IQueryable <ExceptionLog> BuildBaseExceptionListQuery(RockContext rockContext) { ExceptionLogService exceptionLogService = new ExceptionLogService(rockContext); IQueryable <ExceptionLog> query = exceptionLogService.Queryable(); int siteId; if (int.TryParse(fExceptionList.GetUserPreference("Site"), out siteId) && siteId > 0) { query = query.Where(e => e.SiteId == siteId); } int pageId; if (int.TryParse(fExceptionList.GetUserPreference("Page"), out pageId) && pageId > 0) { query = query.Where(e => e.PageId == pageId); } int userPersonID; if (int.TryParse(fExceptionList.GetUserPreference("User"), out userPersonID) && userPersonID > 0) { query = query.Where(e => e.CreatedByPersonAlias != null && e.CreatedByPersonAlias.PersonId == userPersonID); } string statusCode = fExceptionList.GetUserPreference("Status Code"); if (!String.IsNullOrEmpty(statusCode)) { query = query.Where(e => e.StatusCode == statusCode); } var dateRange = SlidingDateRangePicker.CalculateDateRangeFromDelimitedValues(fExceptionList.GetUserPreference("Date Range")); if (dateRange.Start.HasValue) { query = query.Where(e => e.CreatedDateTime.HasValue && e.CreatedDateTime.Value >= dateRange.Start.Value); } if (dateRange.End.HasValue) { query = query.Where(e => e.CreatedDateTime.HasValue && e.CreatedDateTime.Value < dateRange.End.Value); } //Only look for inner exceptions query = query.Where(e => e.HasInnerException == null || e.HasInnerException == false); return(query); }
/// <summary> /// Job that updates the JobPulse setting with the current date/time. /// This will allow us to notify an admin if the jobs stop running. /// /// Called by the <see cref="IScheduler" /> when a /// <see cref="ITrigger" /> fires that is associated with /// the <see cref="IJob" />. /// </summary> public virtual void Execute(IJobExecutionContext context) { // get the job map JobDataMap dataMap = context.JobDetail.JobDataMap; // delete accounts that have not been confirmed in X hours int userExpireHours = Int32.Parse( dataMap.GetString( "HoursKeepUnconfirmedAccounts" ) ); DateTime userAccountExpireDate = DateTime.Now.Add( new TimeSpan( userExpireHours * -1,0,0 ) ); UserService userService = new UserService(); foreach (var user in userService.Queryable().Where(u => u.IsConfirmed == false && u.CreationDate < userAccountExpireDate)) { userService.Delete( user, null ); } userService.Save( null, null ); // purge exception log int exceptionExpireDays = Int32.Parse( dataMap.GetString( "DaysKeepExceptions" ) ); DateTime exceptionExpireDate = DateTime.Now.Add( new TimeSpan( userExpireHours * -1, 0, 0 ) ); ExceptionLogService exceptionLogService = new ExceptionLogService(); foreach ( var exception in exceptionLogService.Queryable().Where( e => e.ExceptionDate < exceptionExpireDate ) ) { exceptionLogService.Delete( exception, null ); } exceptionLogService.Save( null, null ); }
/// <summary> /// Loads the control. /// </summary> /// <param name="e">The <see cref="T:System.EventArgs" /> object that contains the event data.</param> protected override void OnLoad(EventArgs e) { base.OnLoad(e); if (!Page.IsPostBack) { //Set Exception Panel visibility to show Exception List SetExceptionPanelVisibility(None.Id); } // get data for graphs ExceptionLogService exceptionLogService = new ExceptionLogService(new RockContext()); var exceptionList = exceptionLogService.Queryable() .Where(x => x.HasInnerException == false && x.CreatedDateTime != null) .GroupBy(x => DbFunctions.TruncateTime(x.CreatedDateTime.Value)) .Select(eg => new { DateValue = eg.Key, ExceptionCount = eg.Count(), UniqueExceptionCount = eg.Select(y => y.ExceptionType).Distinct().Count() }).OrderBy(eg => eg.DateValue).ToList(); if (exceptionList.Count > 1) { StringBuilder sbChartData = new StringBuilder(); //sbChartData.Append( "[['Date', 'Unique Exceptions', 'Total Exceptions']," ); sbChartData.Append("data.addColumn('date', 'Date');\n"); sbChartData.Append("data.addColumn('number', 'Unique Exceptions');\n"); sbChartData.Append("data.addColumn('number', 'Total Exceptions');\n"); // load datatable foreach (var exception in exceptionList) { //sbChartData.Append( String.Format( "['{0}', {1}, {2}],", exception.DateValue.Value.ToShortDateString(), exception.UniqueExceptionCount, exception.ExceptionCount ) ); sbChartData.Append(String.Format("data.addRow([new Date({0}, {1}, {2}), {3}, {4}]);\n", exception.DateValue.Value.Year, (exception.DateValue.Value.Month - 1), exception.DateValue.Value.Day, exception.UniqueExceptionCount, exception.ExceptionCount)); } lGraphScript.Text = String.Format(@" <script type=""text/javascript""> google.load(""visualization"", ""1"", {{ packages: [""corechart""] }}); google.setOnLoadCallback(drawChart); function drawChart() {{ var data = new google.visualization.DataTable(); {0} var options = {{ vAxis: {{ title: 'Exception Count', minValue: 0, titleTextStyle: {{ color: '#515151', italic: 'false' }} }}, backgroundColor: 'transparent', colors: ['#8498ab', '#a4b4c4', '#b9c7d5', '#c6d2df', '#d8e1ea'], hAxis: {{ textStyle: {{ color: '#515151' }}, baselineColor: '#515151' }}, legend: {{ position: 'bottom', textStyle: {{ color: '#515151' }} }} }}; var chart = new google.visualization.AreaChart(document.getElementById('exception-chart')); chart.draw(data, options); $(window).smartresize(function(){{ chart.draw(data, options); }}); }} </script>", sbChartData.ToString()); } else { pnlExceptionChart.Visible = false; } }
/// <summary> /// Job that executes routine Rock cleanup tasks /// /// Called by the <see cref="IScheduler" /> when a /// <see cref="ITrigger" /> fires that is associated with /// the <see cref="IJob" />. /// </summary> public virtual void Execute(IJobExecutionContext context) { // get the job map JobDataMap dataMap = context.JobDetail.JobDataMap; // delete accounts that have not been confirmed in X hours int userExpireHours = Int32.Parse(dataMap.GetString("HoursKeepUnconfirmedAccounts")); DateTime userAccountExpireDate = DateTime.Now.Add(new TimeSpan(userExpireHours * -1, 0, 0)); var userLoginService = new UserLoginService(); foreach (var user in userLoginService.Queryable().Where(u => u.IsConfirmed == false && u.CreationDateTime < userAccountExpireDate).ToList()) { userLoginService.Delete(user, null); userLoginService.Save(user, null); } // purge exception log int exceptionExpireDays = Int32.Parse(dataMap.GetString("DaysKeepExceptions")); DateTime exceptionExpireDate = DateTime.Now.Add(new TimeSpan(exceptionExpireDays * -1, 0, 0, 0)); ExceptionLogService exceptionLogService = new ExceptionLogService(); foreach (var exception in exceptionLogService.Queryable().Where(e => e.ExceptionDateTime < exceptionExpireDate).ToList()) { exceptionLogService.Delete(exception, null); exceptionLogService.Save(exception, null); } // purge audit log int auditExpireDays = Int32.Parse(dataMap.GetString("AuditLogExpirationDays")); DateTime auditExpireDate = DateTime.Now.Add(new TimeSpan(auditExpireDays * -1, 0, 0, 0)); AuditService auditService = new AuditService(); foreach (var audit in auditService.Queryable().Where(a => a.DateTime < auditExpireDate).ToList()) { auditService.Delete(audit, null); auditService.Save(audit, null); } // clean the cached file directory //get the attributes string cacheDirectoryPath = dataMap.GetString("BaseCacheDirectory"); int cacheExpirationDays = int.Parse(dataMap.GetString("DaysKeepCachedFiles")); DateTime cacheExpirationDate = DateTime.Now.Add(new TimeSpan(cacheExpirationDays * -1, 0, 0, 0)); //if job is being run by the IIS scheduler and path is not null if (context.Scheduler.SchedulerName == "RockSchedulerIIS" && !String.IsNullOrEmpty(cacheDirectoryPath)) { //get the physical path of the cache directory cacheDirectoryPath = System.Web.Hosting.HostingEnvironment.MapPath(cacheDirectoryPath); } //if directory is not blank and cache expiration date not in the future if (!String.IsNullOrEmpty(cacheDirectoryPath) && cacheExpirationDate <= DateTime.Now) { //Clean cache directory CleanCacheDirectory(cacheDirectoryPath, cacheExpirationDate); } // clean out any temporary binary files BinaryFileService binaryFileService = new BinaryFileService(); foreach (var binaryFile in binaryFileService.Queryable().Where(bf => bf.IsTemporary == true).ToList()) { if (binaryFile.LastModifiedDateTime < DateTime.Now.AddDays(-1)) { binaryFileService.Delete(binaryFile, null); binaryFileService.Save(binaryFile, null); } } }
/// <summary> /// Get the data source for the list after applying the specified filter settings. /// </summary> /// <param name="dataContext"></param> /// <param name="filterSettingsKeyValueMap"></param> /// <returns></returns> private void OnPopulateListItems(RockContext dataContext, Grid listControl, Dictionary <string, string> filterSettingsKeyValueMap, SortProperty sortProperty) { if (_exceptionTemplate == null) { return; } string filterDescriptionPrefix = null; filterDescriptionPrefix = _exceptionTemplate.Description; // Construct the query... var exceptionService = new ExceptionLogService(dataContext); // Get the set of exceptions in the filter group. var exceptionQuery = exceptionService.Queryable().AsNoTracking(); exceptionQuery = exceptionService.FilterByOutermost(exceptionQuery); exceptionQuery = exceptionService.FilterByDescriptionPrefix(exceptionQuery, filterDescriptionPrefix); // Filter by: SiteId int siteId = filterSettingsKeyValueMap.GetValueOrDefault(FilterSettingName.Site, string.Empty).AsInteger(); if (siteId != 0) { exceptionQuery = exceptionQuery.Where(e => e.SiteId == siteId); } // Filter by: PageId int pageId = filterSettingsKeyValueMap.GetValueOrDefault(FilterSettingName.Page, string.Empty).AsInteger(); if (pageId != 0) { exceptionQuery = exceptionQuery.Where(e => e.PageId == pageId); } // Filter by: PersonId int userPersonID = filterSettingsKeyValueMap.GetValueOrDefault(FilterSettingName.User, string.Empty).AsInteger(); if (userPersonID != 0) { exceptionQuery = exceptionQuery.Where(e => e.CreatedByPersonAlias != null && e.CreatedByPersonAlias.PersonId == userPersonID); } // Filter by: Date Range var dateRangeSettings = filterSettingsKeyValueMap.GetValueOrDefault(FilterSettingName.DateRange, string.Empty); var dateRange = SlidingDateRangePicker.CalculateDateRangeFromDelimitedValues(dateRangeSettings); if (dateRange.Start.HasValue) { exceptionQuery = exceptionQuery.Where(e => e.CreatedDateTime.HasValue && e.CreatedDateTime.Value >= dateRange.Start.Value); } if (dateRange.End.HasValue) { exceptionQuery = exceptionQuery.Where(e => e.CreatedDateTime.HasValue && e.CreatedDateTime.Value < dateRange.End.Value); } // Materialize the list items. var listQuery = exceptionQuery.Select(e => new { Id = e.Id, CreatedDateTime = e.CreatedDateTime, PageName = e.Page.InternalName ?? e.PageUrl, FullName = (e.CreatedByPersonAlias != null && e.CreatedByPersonAlias.Person != null) ? e.CreatedByPersonAlias.Person.LastName + ", " + e.CreatedByPersonAlias.Person.NickName : "", Description = e.Description, }); // Sort the results. if (sortProperty == null) { listQuery = listQuery.OrderByDescending(e => e.CreatedDateTime); } else { listQuery = listQuery.Sort(sortProperty); } // Populate the grid. gExceptionList.SetLinqDataSource(listQuery); gExceptionList.DataBind(); }