示例#1
0
        private async Task HandleSaveScore(byte[] data)
        {
            var view = new ScoreView();

            using (var memStream = new MemoryStream(data))
            {
                var binReader = new BinaryReader(memStream);
                view.FromString(binReader.ReadString());
            }

            if (view == new ScoreView())
            {
                _logger.LogError($"Score was not formatted correctly.");
                return;
            }

            using (var context = new ScoreViewContext(_contextOptions))
                using (var transaction = await context.Database.BeginTransactionAsync())
                {
                    await context.Scores.AddAsync(view);

                    await context.SaveChangesAsync();

                    transaction.Commit();
                    context.Dispose();
                }

            _logger.LogDebug($"Score {view.Id} submitted successfully.");
        }