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); }
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); }
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); }
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)); }
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)); }
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() }); }
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); }
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)); }