Esempio n. 1
0
 public RecalculateBreakAvailabilityService(
     ILogger <IRecalculateBreakAvailabilityService> logger,
     ISqlServerDbContextFactory <ISqlServerLongRunningTenantDbContext> tenantDbContextFactory,
     RecalculateBreakAvailabilityOptions recalculateOptions)
 {
     _logger = logger ?? throw new ArgumentNullException(nameof(logger));
     _tenantDbContextFactory = tenantDbContextFactory ?? throw new ArgumentNullException(nameof(tenantDbContextFactory));
     _recalculateOptions     = recalculateOptions ?? throw new ArgumentNullException(nameof(recalculateOptions));
 }
Esempio n. 2
0
 public BreakAvailabilityUpdater(
     ILogger logger,
     ISqlServerDbContextFactory <ISqlServerLongRunningTenantDbContext> tenantDbContextFactory,
     RecalculateBreakAvailabilityOptions recalculateOptions,
     CancellationToken cancellationToken)
 {
     _logger = logger ?? throw new ArgumentNullException(nameof(logger));
     _tenantDbContextFactory = tenantDbContextFactory ?? throw new ArgumentNullException(nameof(tenantDbContextFactory));
     _recalculateOptions     = recalculateOptions ?? throw new ArgumentNullException(nameof(recalculateOptions));
     _cancellationToken      = cancellationToken;
 }
        public BreakAvailabilityCalculator(
            ILogger logger,
            ISqlServerDbContextFactory <ISqlServerLongRunningTenantDbContext> tenantDbContextFactory,
            RecalculateBreakAvailabilityOptions recalculateOptions,
            ITargetBlock <IBreakAvailability> targetBlock,
            CancellationToken cancellationToken)
        {
            _logger = logger ?? throw new ArgumentNullException(nameof(logger));
            _tenantDbContextFactory = tenantDbContextFactory ?? throw new ArgumentNullException(nameof(tenantDbContextFactory));
            _recalculateOptions     = recalculateOptions ?? throw new ArgumentNullException(nameof(recalculateOptions));
            _cancellationToken      = cancellationToken;

            _internalBlock = new TransformManyBlock <IBreakAvailability[], IBreakAvailability>(
                breaks => breaks.AsEnumerable(), new ExecutionDataflowBlockOptions
            {
                CancellationToken = _cancellationToken
            });
            _ = _internalBlock.LinkTo(targetBlock ?? throw new ArgumentNullException(nameof(targetBlock)));
            _ = _internalBlock.Completion.ContinueWith(_ => targetBlock.Complete());

            _lockDbContext = new SemaphoreSlim(_recalculateOptions.BoundedDbContextOperationCapacity,
                                               _recalculateOptions.BoundedDbContextOperationCapacity);
        }