/// <summary>
        /// Initializes a new instance of the <see cref="ServiceBusCommandQueueReceiver"/> class.
        /// </summary>
        /// <param name="settings">The service bus settings.</param>
        /// <param name="clockTrigger">The command clockTrigger.</param>
        /// <exception cref="System.ArgumentNullException">
        /// settings
        /// or
        /// clockTrigger
        /// </exception>
        public ServiceBusCommandQueueReceiver(
            ServiceBusSettings settings, 
            ISchedulerClockTrigger clockTrigger, 
            Func<CommandSchedulerDbContext> createCommandSchedulerDbContext)
        {
            if (settings == null)
            {
                throw new ArgumentNullException("settings");
            }
            if (clockTrigger == null)
            {
                throw new ArgumentNullException("clockTrigger");
            }
            if (createCommandSchedulerDbContext == null)
            {
                throw new ArgumentNullException("createCommandSchedulerDbContext");
            }
            this.settings = settings;
            this.clockTrigger = clockTrigger;
            this.createCommandSchedulerDbContext = createCommandSchedulerDbContext;

#if DEBUG
            exceptionSubject
                .Where(ex => !(ex is OperationCanceledException))
                .Subscribe(ex => Debug.WriteLine("ServiceBusCommandQueueReceiver error: " + ex));
#endif
        }
        public void SetUp()
        {
            eventStoreDbTest = new EventStoreDbTest();
            clockName = Any.CamelCaseName();

            Clock.Reset();

            disposables = new CompositeDisposable
            {
                Disposable.Create(() => eventStoreDbTest.TearDown()),
                Disposable.Create(Clock.Reset)
            };

            var bus = new FakeEventBus();
            orderRepository = new SqlEventSourcedRepository<Order>(bus);
            accountRepository = new SqlEventSourcedRepository<CustomerAccount>(bus);

            var configuration = new Configuration();
            configuration.UseEventBus(bus)
                         .UseDependency<IEventSourcedRepository<Order>>(t => orderRepository)
                         .UseDependency<IEventSourcedRepository<CustomerAccount>>(t => accountRepository);

            ConfigureScheduler(configuration);

            disposables.Add(ConfigurationContext.Establish(configuration));

            Console.WriteLine(new { clockName });

            clockTrigger = configuration.Container.Resolve<ISchedulerClockTrigger>();
            clockRepository = configuration.Container.Resolve<ISchedulerClockRepository>();
            clockRepository.CreateClock(clockName, Clock.Now());
        }
Esempio n. 3
0
        /// <summary>
        /// Allows awaiting delivery of all commands that are currently due on the command scheduler.
        /// </summary>
        /// <param name="scheduler">The command scheduler.</param>
        /// <param name="clockName">The name of the clock on which the commands are scheduled.</param>
        /// <returns></returns>
        public static async Task Done(
            this ISchedulerClockTrigger scheduler,
            string clockName = null)
        {
            clockName = clockName ?? SqlCommandScheduler.DefaultClockName;

            for (var i = 0; i < 10; i++)
            {
                using (var db = new CommandSchedulerDbContext())
                {
                    var due = db.ScheduledCommands
                              .Due()
                              .Where(c => c.Clock.Name == clockName);

                    if (!await due.AnyAsync())
                    {
                        return;
                    }

                    var commands = await due.ToArrayAsync();

                    foreach (var scheduledCommand in commands)
                    {
                        await scheduler.Trigger(
                            scheduledCommand,
                            new SchedulerAdvancedResult(),
                            db);
                    }

                    await Task.Delay(400);
                }
            }
        }
        public void SetUp()
        {
            clockName = Any.CamelCaseName();

            Clock.Reset();

            disposables = new CompositeDisposable
            {
                Disposable.Create(Clock.Reset)
            };

            var configuration = new Configuration()
                .UseSqlEventStore(c => c.UseConnectionString(TestDatabases.EventStore.ConnectionString))
                .UseSqlStorageForScheduledCommands(c => c.UseConnectionString(TestDatabases.CommandScheduler.ConnectionString));

            Configure(configuration);

            disposables.Add(ConfigurationContext.Establish(configuration));
            disposables.Add(configuration);

            orderRepository = configuration.Repository<Order>();
            accountRepository = configuration.Repository<CustomerAccount>();
            clockTrigger = configuration.SchedulerClockTrigger();
            clockRepository = configuration.SchedulerClockRepository();
            clockRepository.CreateClock(clockName, Clock.Now());
        }
Esempio n. 5
0
        /// <summary>
        /// Initializes a new instance of the <see cref="ServiceBusCommandQueueReceiver"/> class.
        /// </summary>
        /// <param name="settings">The service bus settings.</param>
        /// <param name="clockTrigger">The command clockTrigger.</param>
        /// <exception cref="System.ArgumentNullException">
        /// settings
        /// or
        /// clockTrigger
        /// </exception>
        public ServiceBusCommandQueueReceiver(
            ServiceBusSettings settings,
            ISchedulerClockTrigger clockTrigger,
            Func <CommandSchedulerDbContext> createCommandSchedulerDbContext)
        {
            if (settings == null)
            {
                throw new ArgumentNullException("settings");
            }
            if (clockTrigger == null)
            {
                throw new ArgumentNullException("clockTrigger");
            }
            if (createCommandSchedulerDbContext == null)
            {
                throw new ArgumentNullException("createCommandSchedulerDbContext");
            }
            this.settings     = settings;
            this.clockTrigger = clockTrigger;
            this.createCommandSchedulerDbContext = createCommandSchedulerDbContext;

#if DEBUG
            exceptionSubject
            .Where(ex => !(ex is OperationCanceledException))
            .Subscribe(ex => Debug.WriteLine("ServiceBusCommandQueueReceiver error: " + ex));
#endif
        }
Esempio n. 6
0
 public SessionHandler(
     Action <IScheduledCommand> onMessage,
     Action <Exception> onError,
     ISchedulerClockTrigger clockTrigger,
     Func <CommandSchedulerDbContext> createCommandSchedulerDbContext)
 {
     this.onMessage    = onMessage;
     this.onError      = onError;
     this.clockTrigger = clockTrigger;
     this.createCommandSchedulerDbContext = createCommandSchedulerDbContext;
 }
Esempio n. 7
0
        public static async Task Done(
            this ISchedulerClockTrigger scheduler,
            string clockName = null)
        {
            clockName = clockName ?? Sql.CommandScheduler.Clock.DefaultClockName;

            using (var db = new CommandSchedulerDbContext())
            {
                var now = Clock.Latest(Clock.Current, db.Clocks.Single(c => c.Name == clockName)).Now();
                await scheduler.AdvanceClock(clockName, now);
            }
        }
 public SessionHandler(
     Action<IScheduledCommand> onMessage,
     Action<Exception> onError,
     ISchedulerClockTrigger clockTrigger, 
     Func<CommandSchedulerDbContext> createCommandSchedulerDbContext)
 {
     this.onMessage = onMessage;
     this.onError = onError;
     this.clockTrigger = clockTrigger;
     this.createCommandSchedulerDbContext = createCommandSchedulerDbContext;
 }