示例#1
0
 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);
 }
示例#2
0
        public async Task <ActionResult> RateProgress([FromBody] SolutionProgress progress)
        {
            progress.Timestamp = DateTime.Now;

            await solutionService.RateProgress(progress).ConfigureAwait(false);

            return(Ok());
        }
示例#3
0
        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();
            }
        }
示例#4
0
 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();
     }
 }