public async Task RateProgress(SolutionProgress progress) { await using var conn = new NpgsqlConnection(ConnectionString); await conn.ExecuteAsync( @"insert into solution_rate (id, data) values (@Id, @Data)", new { progress.SolutionId, Data = progress }).ConfigureAwait(false); }
public async Task <ActionResult> RateProgress([FromBody] SolutionProgress progress) { progress.Timestamp = DateTime.Now; await solutionService.RateProgress(progress).ConfigureAwait(false); return(Ok()); }
private async Task SolveAsync() { _myCancellationTokenSource = new CancellationTokenSource(); SolutionInstance = null; try { IsWorking = true; InputHandler.ClearResults(SolutionMetadata.Day); SolutionInstance = SolutionMetadata.CreateInstance(); SolutionInstance.MillisecondsBetweenProgressUpdates = MillisBetweenProgressRender / 2; SolutionInstance.CancellationToken = _myCancellationTokenSource.Token; SolutionInstance.ProgressUpdated += OnProgressUpdate; CalculationStopwatch = Stopwatch.StartNew(); foreach (var(part, index) in new Func <string, Task <string> >[] { SolutionInstance.Part1Async, SolutionInstance.Part2Async }.Select((x, i) => (x, i))) { Progress = new SolutionProgress(); StateHasChanged(); await Task.Delay(1); if (IsWorking == false) { break; } Results[index] = await ExceptionToResult(part); } } finally { if (SolutionInstance != null) { SolutionInstance.ProgressUpdated -= OnProgressUpdate; } IsWorking = false; CalculationStopwatch?.Stop(); } }
private async Task InitAsync() { Cancel(); SolutionMetadata = null; Input = null; HasInputChanged = false; Results = null; Progress = new SolutionProgress(); CalculationStopwatch = null; SolutionInstance = null; if (int.TryParse(Day, out var dayNumber) && SolutionHandler.Solutions.TryGetValue(dayNumber, out var solutionMetadata)) { SolutionMetadata = solutionMetadata; Results = InputHandler.GetResults(SolutionMetadata.Day); if (InputHandler.IsCachedInputAvailable(solutionMetadata.Day)) { await LoadInputAsync().ConfigureAwait(false); } Description = "Loading description..."; LoadPuzzleMetadataInBackground(); } }