Example #1
0
        public DataTableDto <ProjectDto> GetProjects(DataTableParameter args)
        {
            if (args == null)
            {
                throw new ArgumentNullException(nameof(args));
            }

            var query = from x in _context.Projects.AsNoTracking()
                        let count = _context.RunAttributes.AsNoTracking()
                                    .Where(a => a.GlutProjectName == x.GlutProjectName)
                                    .GroupBy(g => g.GlutProjectRunId)
                                    .Count()
                                    orderby x.ModifiedDateTimeUtc descending
                                    select new
            {
                ProjectName        = x.GlutProjectName,
                Runs               = count,
                LastChangeDateTime = x.ModifiedDateTimeUtc
            };

            int recordsTotal         = 0;
            int recordsFilteredTotal = 0;

            recordsTotal = query.Count();

            // Search
            if (!string.IsNullOrWhiteSpace(args.Search))
            {
                query = query.Where(x => x.ProjectName != null && EF.Functions.Like(x.ProjectName, $"%{args.Search}%"));
            }

            recordsFilteredTotal = query.Count();

            // Sort
            if (string.IsNullOrWhiteSpace(args.SortColumn) == false)
            {
                var sortColumn = LinqExtensions.GetPropertyNameIgnoreCase(typeof(ProjectDto), args.SortColumn);

                if (string.IsNullOrWhiteSpace(sortColumn))
                {
                    throw new InvalidOperationException($"Could not find column: {sortColumn}");
                }

                query = query.OrderBy(sortColumn, string.Equals(GlutWebConstants.SortDirectionAsc, args.SortDirection, StringComparison.CurrentCultureIgnoreCase));
            }

            // Paging
            var model = (from x in query.Skip(args.Skip).Take(args.Take)
                         select new ProjectDto
            {
                ProjectName = x.ProjectName,
                Runs = x.Runs,
                LastChangeDateTime = x.LastChangeDateTime.ToLocalTime()
            }).ToArray();

            var response = new DataTableDto <ProjectDto>
            {
                Draw            = args.Draw,
                RecordsFiltered = recordsFilteredTotal,
                RecordsTotal    = recordsTotal,
                Data            = model
            };

            return(response);
        }
Example #2
0
        public DataTableDto <ResultItemDto> GetResultItems(string projectName, int runId, DataTableParameter args)
        {
            if (string.IsNullOrWhiteSpace(projectName))
            {
                throw new ArgumentNullException(nameof(projectName));
            }
            if (runId <= 0)
            {
                throw new ArgumentException(nameof(runId));
            }
            if (args == null)
            {
                throw new ArgumentNullException(nameof(args));
            }

            var query = from x in _context.Results.AsNoTracking()
                        where x.GlutProjectName == projectName && x.GlutProjectRunId == runId
                        select new
            {
                StartDateTime       = x.StartDateTimeUtc,
                EndDateTime         = x.EndDateTimeUtc,
                Url                 = x.Url,
                IsSuccessStatusCode = x.IsSuccessStatusCode,
                StatusCode          = x.StatusCode,
                HeaderLength        = x.HeaderLength,
                ResponseLength      = x.ResponseLength,
                TotalLength         = x.TotalLength,
                RequestTicks        = x.RequestSentTicks,
                ResponseTicks       = x.ResponseTicks,
                TotalTicks          = x.TotalTicks,
                ResponseHeaders     = x.ResponseHeaders,
                Exception           = x.Exception,
                CreatedDateTime     = x.CreatedDateTimeUtc,
                CreatedByUser       = x.CreatedByUserName
            };

            int recordsTotal         = 0;
            int recordsFilteredTotal = 0;

            recordsTotal = query.Count();

            // Search
            if (!string.IsNullOrWhiteSpace(args.Search))
            {
                query = query.Where(x =>
                                    (x.Url != null && EF.Functions.Like(x.Url, $"%{args.Search}%")) ||
                                    // (EF.Functions.Like((string)x.StatusCode), $"%{args.Search}%")) || // TODO: https://github.com/aspnet/EntityFrameworkCore/issues/10227
                                    (x.ResponseHeaders != null && EF.Functions.Like(x.ResponseHeaders, $"%{args.Search}%")));
            }

            recordsFilteredTotal = query.Count();

            // Sort
            if (string.IsNullOrWhiteSpace(args.SortColumn) == false)
            {
                var sortColumn = LinqExtensions.GetPropertyNameIgnoreCase(typeof(ResultItemDto), args.SortColumn);

                if (string.IsNullOrWhiteSpace(sortColumn))
                {
                    throw new InvalidOperationException($"Could not find column :{sortColumn}");
                }

                query = query.OrderBy(sortColumn, string.Equals(GlutWebConstants.SortDirectionAsc, args.SortDirection, StringComparison.CurrentCultureIgnoreCase));
            }

            var model = (from x in query.Skip(args.Skip).Take(args.Take)
                         select new ResultItemDto
            {
                StartDateTime = x.StartDateTime.ToLocalTime(),
                EndDateTime = x.EndDateTime.ToLocalTime(),
                Url = x.Url,
                IsSuccessStatusCode = x.IsSuccessStatusCode,
                StatusCode = x.StatusCode,
                HeaderLength = ConvertToKb(x.HeaderLength),
                ResponseLength = ConvertToKb(x.ResponseLength),
                TotalLength = ConvertToKb(x.TotalLength),
                RequestTicks = ConvertToMillisecond(x.RequestTicks),
                ResponseTicks = ConvertToMillisecond(x.ResponseTicks),
                TotalTicks = ConvertToMillisecond(x.TotalTicks),
                ResponseHeaders = x.ResponseHeaders,
                Exception = x.Exception,
                CreatedDateTime = x.CreatedDateTime.ToLocalTime(),
                CreatedByUser = x.CreatedByUser
            }).ToArray();

            var response = new DataTableDto <ResultItemDto>
            {
                Draw            = args.Draw,
                RecordsFiltered = recordsFilteredTotal,
                RecordsTotal    = recordsTotal,
                Data            = model
            };

            return(response);
        }