protected override async Task ExecuteAsync(CancellationToken stoppingToken)
        {
            while (!stoppingToken.IsCancellationRequested)
            {
                using var scope = _serviceProvider.CreateScope();

                var writeMovieRepository = scope.ServiceProvider.GetRequiredService <WriteMovieRepository>();
                var readMovieRepository  = scope.ServiceProvider.GetRequiredService <ReadMovieRepository>();

                try
                {
                    await foreach (var item in _channel.ReadAsync(stoppingToken))
                    {
                        var movie = await writeMovieRepository.GetByIdAsync(item.MovieId, stoppingToken);

                        if (movie != null)
                        {
                            await readMovieRepository.AddAsync(new Movie
                            {
                                MovieId     = movie.Id,
                                Director    = movie.Director.FullName,
                                Name        = movie.Name,
                                PublishYear = movie.PublishYear,
                                BoxOffice   = movie.BoxOffice,
                                ImdbRate    = movie.ImdbRate
                            }, stoppingToken);
                        }
                    }
                }
                catch (Exception e)
                {
                    _logger.LogError(e, e.Message);
                }
            }
        }
        public async Task WriteReadAsync02()
        {
            var channel = new ChannelQueue <PersonProper>();
            var people  = this.GetPersonProperArray(Tristate.False);

            await channel.WriteAsync(people).ConfigureAwait(false);

            while (channel.Count > 0)
            {
                base.Consumer.Consume(await channel.ReadAsync().ConfigureAwait(false));
            }
        }
예제 #3
0
        public async Task WriteReadAsync02()
        {
            var channel = new ChannelQueue <PersonProper>();
            var people  = this.PersonProperList;

            await channel.WriteAsync(people).ConfigureAwait(false);

            while (channel.Count > 0)
            {
                this.Consumer.Consume(await channel.ReadAsync().ConfigureAwait(false));
            }
        }
        public async Task WriteReadAsyncTest01()
        {
            var channel = new ChannelQueue <PersonProper>();
            var person  = RandomData.GenerateRefPerson <PersonProper>();
            var token   = CancellationToken.None;

            await channel.WriteAsync(person, cancellationToken : token).ConfigureAwait(false);

            Assert.IsTrue(channel.Count == 1);

            _ = await channel.ReadAsync(token).ConfigureAwait(false);

            Assert.IsTrue(channel.Count == 0);
        }
        public async Task WriteReadAsync01()
        {
            var channel = new ChannelQueue <PersonProper>();
            var people  = this.GetPersonProperArray(Tristate.False);

            for (var personCount = 0; personCount < people.Length; personCount++)
            {
                await channel.WriteAsync(people[personCount]).ConfigureAwait(false);
            }

            while (channel.Count > 0)
            {
                base.Consumer.Consume(await channel.ReadAsync().ConfigureAwait(false));
            }
        }
예제 #6
0
        public async Task WriteReadAsync01()
        {
            var channel = new ChannelQueue <PersonProper>();
            var people  = this.PersonProperList;

            for (var personCount = 0; personCount < people.Count; personCount++)
            {
                await channel.WriteAsync(people[personCount]).ConfigureAwait(false);
            }

            while (channel.Count > 0)
            {
                this.Consumer.Consume(await channel.ReadAsync().ConfigureAwait(false));
            }
        }
        public async Task WriteReadAsyncTest04()
        {
            const int Capacity = 100;
            var       channel  = new ChannelQueue <PersonProper>(Capacity);
            var       people   = RandomData.GeneratePersonRefCollection <PersonProper>(Capacity);
            var       token    = CancellationToken.None;

            foreach (var person in people)
            {
                await channel.WriteAsync(person, cancellationToken : token).ConfigureAwait(false);
            }

            Assert.IsTrue(channel.Count == Capacity);

            do
            {
                _ = await channel.ReadAsync(token).ConfigureAwait(false);
            } while (channel.Count != 0);

            Assert.IsTrue(channel.Count == 0);
        }
예제 #8
0
        protected override async Task ExecuteAsync(CancellationToken stoppingToken)
        {
            while (!stoppingToken.IsCancellationRequested)
            {
                try
                {
                    using var scope = _serviceProvider.CreateScope();

                    var readMovieRepository = scope.ServiceProvider.GetRequiredService <ReadMovieRepository>();

                    await foreach (var item in _channel.ReadAsync(stoppingToken))
                    {
                        await readMovieRepository.DeleteByMovieIdAsync(item.MovieId, stoppingToken);
                    }
                }
                catch (Exception e)
                {
                    _logger.LogError(e, e.Message);
                }
            }
        }