示例#1
0
        public virtual async Task <long> Add(BenchmarkResultDto entity)
        {
            var newEntity = new Result()
            {
                BenchmarkId     = entity.BenchmarkId,
                Browser         = entity.Browser,
                DevicePlatform  = entity.DevicePlatform,
                OperatingSystem = entity.OS,
                RawUastring     = entity.RawUserAgenString,
                UserId          = entity.UserId,
                ResultRow       = new List <ResultRow>(),
                Version         = entity.BenchmarkVersion,
                Created         = DateTime.UtcNow
            };

            foreach (var row in entity.ResultRows)
            {
                var dbrow = new ResultRow()
                {
                    ExecutionsPerSecond   = row.ExecutionsPerSecond,
                    TestName              = row.TestName,
                    NumberOfSamples       = row.NumberOfSamples,
                    RelativeMarginOfError = row.RelativeMarginOfError
                };
                newEntity.ResultRow.Add(dbrow);
            }

            this.Validate(newEntity);

            this.m_db.Result.Add(newEntity);
            await this.m_db.SaveChangesAsync().ConfigureAwait(false);

            return(newEntity.Id);
        }
示例#2
0
        private BenchmarkResultDto DbEntityToModel([NotNull] Result entity)
        {
            var result = new BenchmarkResultDto()
            {
                Id                = entity.Id,
                BenchmarkId       = entity.BenchmarkId,
                Browser           = entity.Browser,
                DevicePlatform    = entity.DevicePlatform,
                OS                = entity.OperatingSystem,
                RawUserAgenString = entity.RawUastring,
                UserId            = entity.UserId,
                ResultRows        = new List <ResultsRowModel>(),
                WhenCreated       = entity.Created
            };

            foreach (var row in entity.ResultRow)
            {
                var rowModel = new ResultsRowModel()
                {
                    ExecutionsPerSecond   = row.ExecutionsPerSecond,
                    NumberOfSamples       = row.NumberOfSamples,
                    RelativeMarginOfError = row.RelativeMarginOfError,
                    TestName = row.TestName
                };
                result.ResultRows.Add(rowModel);
            }
            return(result);
        }
示例#3
0
        private IList <BenchmarkResultDto> ProcessQueryResult(IEnumerable <Result> entities)
        {
            var result = new List <BenchmarkResultDto>();

            foreach (var benchmark in entities)
            {
                BenchmarkResultDto model = DbEntityToModel(benchmark);
                result.Add(model);
            }

            return(result);
        }
示例#4
0
        public async Task <IActionResult> PublishResults(BenchmarkResultDto model)
        {
            if (!this.ModelState.IsValid)
            {
                return(this.View(model));
            }

            ApplicationUser user = await this.GetCurrentUserAsync();

            model.UserId = user?.Id;

            ClientInfo clientInfo = null;

            if (HttpContext.Request.Headers.ContainsKey("User-Agent"))
            {
                string userAgent = HttpContext.Request.Headers["User-Agent"];
                model.RawUserAgenString = userAgent;

                try
                {
                    clientInfo = UAParser.Parser.GetDefault().Parse(userAgent);

                    if (clientInfo != null)
                    {
                        string browser = clientInfo.UserAgent.Family + " " + clientInfo.UserAgent.Major;
                        if (detection.Browser != null && detection.Browser.Type.ToString().ToLower().Contains("edge"))
                        {
                            browser = detection.Browser?.Maker + " " + detection.Browser?.Type.ToString() + " " + detection.Browser?.Version;
                        }
                        model.Browser        = browser;
                        model.DevicePlatform = detection.Device?.Type.ToString();
                        model.OS             = clientInfo.OS.ToString();
                    }
                }
                catch (Exception ex)
                {
                    m_logger.LogError("Error while parsing UA String: " + ex.Message);
                }
            }

            if (this.m_resultsConfig.Value.UploadResultsToDb)
            {
                if (user != null || this.m_resultsConfig.Value.UploadGuestUserResultsToDb)
                {
                    long id = await this.m_publishResultRepository.Add(model);

                    model.Id = id;
                }
            }

            return(this.PartialView(model));
        }
示例#5
0
        public async Task <IViewComponentResult> InvokeAsync(
            long benchmarkId)
        {
            Preconditions.ToBeNonNegative(benchmarkId);
            BenchmarkResultDto latestResult = await this.m_publishResultRepository.GetLatestResultForBenchmark(benchmarkId);

            if (latestResult == null)
            {
                return(View("NoResults"));
            }

            return(View(latestResult));
        }
示例#6
0
        public static BenchmarkResultModel ToModel(this BenchmarkResultDto benchmarkResultDto)
        {
            if (benchmarkResultDto == null)
            {
                throw new ArgumentNullException(nameof(benchmarkResultDto));
            }

            return(new BenchmarkResultModel
            {
                Name = benchmarkResultDto.Name,
                TaskResults = benchmarkResultDto.TaskResults.Select(r => r.ToModel()).ToList()
            });
        }
示例#7
0
        public virtual async Task <BenchmarkResultDto> GetLatestResultForBenchmark(long benchmarkId)
        {
            var entity = await this.m_db.Result
                         .OrderByDescending(m => m.Created)
                         .Include(b => b.ResultRow)
                         .FirstOrDefaultAsync(m => m.BenchmarkId == benchmarkId)
                         .ConfigureAwait(false);

            if (entity == null)
            {
                return(null);
            }

            BenchmarkResultDto result = DbEntityToModel(entity);

            return(result);
        }
示例#8
0
        public virtual async Task <ShowResultModel> GetResultWithBenchmark(long id)
        {
            var entity = await this.m_db.Result
                         .Include(b => b.ResultRow)
                         .Include(b => b.Benchmark)
                         .Include(b => b.Benchmark.BenchmarkTest)
                         .FirstOrDefaultAsync(m => m.Id == id)
                         .ConfigureAwait(false);

            if (entity == null)
            {
                return(null);
            }

            BenchmarkResultDto result    = DbEntityToModel(entity);
            BenchmarkDto       benchmark = SqlServerBenchmarkRepository.DbEntityToModel(entity.Benchmark);

            return(new ShowResultModel(result, benchmark));
        }