Ejemplo n.º 1
0
        /// <summary>
        ///     Initializes a new instance of the <see cref="SqlCommandScheduler" /> class.
        /// </summary>
        /// <param name="configuration">The configuration.</param>
        public SqlCommandScheduler(
            Configuration configuration,
            Func<CommandSchedulerDbContext> createCommandSchedulerDbContext = null,
            GetClockName getClockName = null)
        {
            
            if (configuration == null)
            {
                throw new ArgumentNullException("configuration");
            }

            GetClockName = getClockName ?? (e => null);
            this.createCommandSchedulerDbContext = createCommandSchedulerDbContext ??
                                                   (() => new CommandSchedulerDbContext());

            var container = configuration.Container;

            var dispatchers = ConfigurationExtensions.InitializeSchedulersPerAggregateType(
                container,
                ClockName,
                activity);

            base.binders = dispatchers;

            ClockTrigger = new SchedulerClockTrigger(
                this.createCommandSchedulerDbContext,
                async (scheduled, result, db) =>
                {
                    var dispatcher = dispatchers.SingleOrDefault(d => d.AggregateType == scheduled.AggregateType);

                    if (dispatcher != null)
                    {
                        await dispatcher.Deliver(scheduled);
                        result.Add(scheduled.Result);
                    }

                    scheduled.Attempts++;

                    await db.SaveChangesAsync();
                });

            clockRepository = new SchedulerClockRepository(
                this.createCommandSchedulerDbContext,
                GetClockName);
        }
Ejemplo n.º 2
0
        /// <summary>
        ///     Initializes a new instance of the <see cref="SqlCommandScheduler" /> class.
        /// </summary>
        /// <param name="configuration">The configuration.</param>
        public SqlCommandScheduler(
            Configuration configuration,
            Func <CommandSchedulerDbContext> createCommandSchedulerDbContext = null,
            GetClockName getClockName = null)
        {
            if (configuration == null)
            {
                throw new ArgumentNullException("configuration");
            }

            GetClockName = getClockName ?? (e => null);
            this.createCommandSchedulerDbContext = createCommandSchedulerDbContext ??
                                                   (() => new CommandSchedulerDbContext());

            var container = configuration.Container;

            var dispatchers = ConfigurationExtensions.InitializeSchedulersPerAggregateType(
                container,
                ClockName,
                activity);

            base.binders = dispatchers;

            ClockTrigger = new SchedulerClockTrigger(
                this.createCommandSchedulerDbContext,
                async(scheduled, result, db) =>
            {
                var dispatcher = dispatchers.SingleOrDefault(d => d.AggregateType == scheduled.AggregateType);

                if (dispatcher != null)
                {
                    await dispatcher.Deliver(scheduled);
                    result.Add(scheduled.Result);
                }

                scheduled.Attempts++;

                await db.SaveChangesAsync();
            });

            clockRepository = new SchedulerClockRepository(
                this.createCommandSchedulerDbContext,
                GetClockName);
        }