示例#1
0
        public async Task DoWork(BatchNumber batchNumber, CancellationToken cancellationToken)
        {
            using (IServiceScope scope = _scopeFactory.CreateScope())
            {
                IRepository <BatchNumber> batchNumberRepository = scope.ServiceProvider.GetRequiredService <IRepository <BatchNumber> >();

                await batchNumberRepository.ReloadAsync(batchNumber);

                batchNumber.Product = await _client.MultiplyNumber(batchNumber.Number);

                await batchNumberRepository.UpdateAsync(batchNumber);

                await Task.Run(() => UnitDone?.Invoke(this, new NumberProcessedEventArgs(batchNumber, cancellationToken)));
            }
        }
示例#2
0
        public async Task DoWork(Batch batch, CancellationToken cancellationToken)
        {
            await foreach (int number in _client.GenerateNumbers(batch.Count))
            {
                if (cancellationToken.IsCancellationRequested)
                {
                    break;
                }

                using (IServiceScope scope = _scopeFactory.CreateScope())
                {
                    IRepository <BatchNumber> batchNumberRepository = scope.ServiceProvider.GetRequiredService <IRepository <BatchNumber> >();
                    BatchNumber batchNumber = new BatchNumber {
                        BatchId = batch.Id, Number = number
                    };
                    await batchNumberRepository.InsertAsync(batchNumber);

                    await Task.Run(() => UnitDone?.Invoke(this, new NumberProcessedEventArgs(batchNumber, cancellationToken)));
                }
            }
        }