Example #1
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="Period"></param>
        /// <param name="LoggerProviderName"></param>
        /// <param name="logLevel"></param>
        /// <param name="keyFormatString"></param>
        /// <param name="groupByClause"></param>
        /// <returns></returns>
        public JsonResult ChartDataByTimePeriod(string Period, string LoggerProviderName, string logLevel, string keyFormatString, Func <LogEvent, Object> groupByClause)
        {
            TimePeriod timePeriod = TimePeriodHelper.GetUtcTimePeriod(Period);

            // Grab ALL entries for the chart (DO NOT PAGE REPORTING DATA!!!)
            IPagedList <LogEvent> chartEntries = loggingRepository.GetByDateRangeAndType(0, Int32.MaxValue, timePeriod.Start, timePeriod.End, LoggerProviderName, logLevel);

            var groupedByDate = chartEntries.GroupBy(groupByClause).OrderBy(y => y.Key);

            var groupedByDateAndThenName = groupedByDate.Select(group => new { Key = group.Key, NestedGroup = group.ToLookup(result => result.LoggerProviderName, result => result.Id) });

            var LoggerNames = (from logEvent in chartEntries
                               select new { Name = logEvent.LoggerProviderName }
                               ).Distinct().OrderBy(item => item.Name);

            ChartData chartData = new ChartData();

            // Add columns
            chartData.AddColumn(new ChartColumn("0", "Period", "string"));
            int columnIndex = 1;

            foreach (var name in LoggerNames)
            {
                chartData.AddColumn(new ChartColumn(columnIndex.ToString(), name.Name.ToString(), "number"));
                columnIndex++;
            }

            // add row data
            foreach (var myDate in groupedByDateAndThenName)
            {
                ChartRow row = new ChartRow();

                string dateString = (myDate.Key is DateTime) ? ((DateTime)myDate.Key).ToString(keyFormatString) : myDate.Key.ToString();
                row.AddCellItem(new ChartCellItem(dateString, ""));

                foreach (var name in LoggerNames)
                {
                    bool valueFound = false;
                    foreach (var myLogger in myDate.NestedGroup)
                    {
                        if (myLogger.Key == name.Name.ToString())
                        {
                            row.AddCellItem(new ChartCellItem(myLogger.Count(), ""));
                            valueFound = true;
                        }
                    }
                    if (!valueFound)
                    {
                        row.AddCellItem(new ChartCellItem(0, ""));
                    }
                }

                chartData.AddRow(row);
            }

            return(Json(chartData, "text/x-json", System.Text.Encoding.UTF8, JsonRequestBehavior.AllowGet));
        }
Example #2
0
        public DefectChangeLogsTableDto GetAll(DefectChangeLogsTableFilterModelDto defecetChangeLogsTableFilter)
        {
            DefectChangeLogQuery defectChangeLogQuery = _mapper.Map <DefectChangeLogQuery>(defecetChangeLogsTableFilter);

            IPagedList <DefectChangeLog> defectChangeLog = _defectChangeLogService.GetDefectChangeLogs(defectChangeLogQuery);

            var groupedDefects = defectChangeLog.GroupBy(def => def.DefectId)
                                 .Select(deg => deg.OrderBy(def => def.DateModified).LastOrDefault());

            List <DefectChangeLogsTableRowDto> defectChangeLogsTableRowDtos =
                _mapper.Map <IEnumerable <DefectChangeLog>, IEnumerable <DefectChangeLogsTableRowDto> >(groupedDefects).ToList();

            return(new DefectChangeLogsTableDto
            {
                DefectChangeLogsTableRows = defectChangeLogsTableRowDtos,
                TotalDisplayedRecords = groupedDefects.Count(),
                TotalRecords = groupedDefects.Count()
            });
        }