コード例 #1
0
 public CountedMessageSubscriber(IGeneralBus bus) : base(bus)
 {
     EventOrder = new List <int>();
     MsgOrder   = new List <int>();
     Subscribe <CountedTestMessage>(this);
     Subscribe <CountedEvent>(this);
 }
コード例 #2
0
        protected QueuedSubscriber(IGeneralBus bus, bool idempotent = true)
        {
            if (bus == null)
            {
                throw new ArgumentNullException(nameof(bus));
            }
            _generalBus  = bus;
            _internalBus = new CommandBus("SubscriptionBus");

            if (idempotent)
            {
                _messageQueue = new QueuedHandler(
                    new IdempotentHandler <Message>(
                        new AdHocHandler <Message>(_internalBus.Publish)
                        ),
                    "SubscriptionQueue");
            }
            else
            {
                _messageQueue = new QueuedHandler(
                    new AdHocHandler <Message>(_internalBus.Publish),
                    "SubscriptionQueue");
            }
            _messageQueue.Start();
        }
コード例 #3
0
 public TestCommandSubscriber(IGeneralBus bus)
 {
     _bus = bus;
     TestCommand2Handled = 0;
     _bus.Subscribe <TestCommands.TestCommand2> (this);
     _bus.Subscribe <TestCommands.TestCommand3>(this);
 }
コード例 #4
0
        private static ReactiveCommand FireCommandEx(
            IGeneralBus bus,
            Func <Object, Command> commandFunc,
            IObservable <bool> canExecute = null,
            IScheduler scheduler          = null,
            string userErrorMsg           = null,
            TimeSpan?responseTimeout      = null,
            TimeSpan?ackTimeout           = null)
        {
            if (scheduler == null)
            {
                scheduler = RxApp.MainThreadScheduler;
            }
            Func <object, Task> task = async _ => await Task.Run(() =>
            {
                var c = commandFunc(_);
                if (c != null)
                {
                    bus.Fire(c, userErrorMsg, responseTimeout, ackTimeout);
                }
            });

            var cmd = ReactiveCommand.CreateFromTask(task, canExecute, scheduler);

            cmd.ThrownExceptions
            .SelectMany(ex => UserError.Throw(userErrorMsg ?? ex.Message, ex))
            .ObserveOn(MainThreadScheduler).Subscribe(result =>
            {
                //This will return the recovery option returned from the registered user error handler
                //right now this is a simple message box in the view code behind
                /* n.b. this forces evaluation/execution of the select many  */
            });
            return(cmd);
        }
コード例 #5
0
        public BusConnector(IGeneralBus left, IGeneralBus right)
        {
            _left  = new BusAdapter(left);
            _right = new BusAdapter(right);

            _left.Subscribe(_right);
            _right.Subscribe(_left);
        }
コード例 #6
0
 public TcpBusServerSide(
     IPAddress hostIp,
     int commandPort,
     IGeneralBus messageBus)
     : base(hostIp, commandPort, messageBus)
 {
     _commandPortListener = ConfigureTcpListener(CommandEndpoint, TcpMessageArrived);
 }
コード例 #7
0
 protected TransientSubscriber(IGeneralBus bus) : this((IBus)bus)
 {
     if (bus == null)
     {
         throw new ArgumentNullException(nameof(bus));
     }
     _commandSubscriber = bus;
 }
コード例 #8
0
 public TcpOutboundMessageHandler(
     IGeneralBus messageBus,
     QueuedHandler outboundMessageQueuedHandler)
 {
     _messageBus = messageBus;
     _outboundMessageQueuedHandler = outboundMessageQueuedHandler;
     _messageBus.Subscribe(this);
 }
コード例 #9
0
 public TcpBusClientSide(
     IGeneralBus messageBus,
     IPAddress hostIP,
     int commandPort,
     ITcpConnection tcpConnection = null)
     : base(hostIP, commandPort, messageBus)
 {
     _tcpConnection = tcpConnection ?? CreateTcpConnection(CommandEndpoint);
 }
コード例 #10
0
        public TestInheritedMessageSubscriber(IGeneralBus bus, bool idempotent = true) : base(bus, idempotent)
        {
            Reset();

            Subscribe <TestDomainEvent>(this);
            Subscribe <ParentTestDomainEvent>(this);
            Subscribe <ChildTestDomainEvent>(this);
            Subscribe <GrandChildTestDomainEvent>(this);
        }
コード例 #11
0
        public AccountSvc(IGeneralBus bus, IRepository repo)
            : base(bus)
        {
            _repo = repo;

            bus.Subscribe <CreateAccount>(this);
            bus.Subscribe <ApplyCredit>(this);
            bus.Subscribe <ApplyDebit>(this);
        }
コード例 #12
0
        //public IEventStoreConnection EsConnection { get; private set; }

        //public void Bootstrap()
        //{
        //    _es = new EventStoreLoader();
        //    _es.SetupEventStore(new DirectoryInfo(@"C:\Users\rosed18169\source\EventStore-OSS-Win-v3.9.4"));
        //    EsConnection = _es.Connection;
        //    _esRepository = new GetEventStoreRepository(_es.Connection);
        //    Locator.CurrentMutable.RegisterConstant(_esRepository, typeof(IRepository));
        //    _bus = new CommandBus("testBus", false);

        //}

        public void Run()
        {
            Console.WriteLine("Hit return on an empty line to cancel...");
            Console.WriteLine("Enter a value. Negative values are debits, positive are credits.");
            var accountId = Guid.NewGuid();

            _bus = new CommandBus("testBus", false);
            Bootstrap.Configure(_bus);
            //var svc = new AccountSvc(_bus, _esRepository);
            _bus.Fire(new CreateAccount(
                          accountId,
                          "TheAccount",
                          Guid.NewGuid(),
                          Guid.Empty));

            _accountReadModel = new AccountRM(accountId);

            while (true)
            {
                var line = Console.ReadLine();
                if (string.IsNullOrWhiteSpace(line))
                {
                    break;
                }

                try
                {
                    var input = new UserInput(line);
                    if (input.Type == UserInput.InputType.Debit)
                    {
                        _bus.Fire(new ApplyDebit(
                                      accountId,
                                      input.Amount,
                                      Guid.NewGuid(),
                                      Guid.Empty));
                    }
                    else
                    {
                        _bus.Fire(new ApplyCredit(
                                      accountId,
                                      input.Amount,
                                      Guid.NewGuid(),
                                      Guid.Empty),
                                  responseTimeout: TimeSpan.FromSeconds(60));
                    }
                }
                catch (CommandException e)
                {
                    var msg = e.InnerException == null ? e.Message : e.InnerException.Message;
                    Console.WriteLine(msg);
                }
                catch (InvalidOperationException ex)
                {
                    Console.WriteLine(ex.Message);
                }
            }
        }
コード例 #13
0
ファイル: Bootstrap.cs プロジェクト: pe-david/AccountDemo
        public static void Configure(IGeneralBus bus)
        {
            _es = new EventStoreLoader();
            _es.SetupEventStore(new DirectoryInfo(@"C:\Users\rosed18169\source\EventStore-OSS-Win-v3.9.4"));
            _esConnection = _es.Connection;
            _esRepository = new GetEventStoreRepository(_es.Connection);
            Locator.CurrentMutable.RegisterConstant(_esRepository, typeof(IRepository));

            _acctSvc = new AccountSvc(bus, _esRepository);
        }
コード例 #14
0
 public NullableBus(IGeneralBus target, bool directToNull = true, string name = null)
 {
     if (target == null)
     {
         throw new ArgumentNullException(nameof(target));
     }
     _target        = target;
     Name           = name ?? _target.Name;
     RedirectToNull = directToNull;
 }
コード例 #15
0
 public static ReactiveCommand <Unit> BuildFireCommand(
     this IGeneralBus bus,
     Func <Command> commandFunc,
     IScheduler scheduler     = null,
     string userErrorMsg      = null,
     TimeSpan?responseTimeout = null,
     TimeSpan?ackTimeout      = null)
 {
     return(FireCommands(bus, new[] { commandFunc }, null, scheduler, userErrorMsg, responseTimeout, ackTimeout));
 }
コード例 #16
0
 /// <summary>
 /// BuildFireCommandEx() does the same thing as BuildFireCommand(), except commandFunc must be defined
 /// as a function that takes Object as input and returns Command as result.
 /// </summary>
 /// <param name="bus"></param>
 /// <param name="commandFunc"></param>
 /// <param name="scheduler"></param>
 /// <param name="userErrorMsg"></param>
 /// <param name="responseTimeout"></param>
 /// <param name="ackTimeout"></param>
 /// <returns></returns>
 public static ReactiveCommand BuildFireCommandEx(
     this IGeneralBus bus,
     Func <Object, Command> commandFunc,
     IScheduler scheduler     = null,
     string userErrorMsg      = null,
     TimeSpan?responseTimeout = null,
     TimeSpan?ackTimeout      = null)
 {
     return(FireCommandEx(bus, commandFunc, null, scheduler, userErrorMsg, responseTimeout, ackTimeout));
 }
コード例 #17
0
 public static ReactiveCommand BuildFireCommand(
     this IGeneralBus bus,
     IEnumerable <Func <Command> > commands,
     IScheduler scheduler     = null,
     string userErrorMsg      = null,
     TimeSpan?responseTimeout = null,
     TimeSpan?ackTimeout      = null)
 {
     return(FireCommands(bus, commands, null, scheduler, userErrorMsg, responseTimeout, ackTimeout));
 }
コード例 #18
0
        public TestQueuedSubscriber(IGeneralBus bus) : base(bus)
        {
            TimesTestMessageHandled      = 0;
            TimesTestMessage2Handled     = 0;
            TimesChildTestMessageHandled = 0;
            ParentTestMessage            = 0;

            Subscribe <TestMessage>(this);
            Subscribe <TestMessage2>(this);
            Subscribe <ChildTestMessage>(this);
        }
コード例 #19
0
 public static ReactiveCommand BuildFireCommand(
     this IGeneralBus bus,
     IObservable <bool> canExecute,
     Func <Command> commandFunc,
     IScheduler scheduler     = null,
     string userErrorMsg      = null,
     TimeSpan?responseTimeout = null,
     TimeSpan?ackTimeout      = null)
 {
     return(FireCommands(bus, new[] { commandFunc }, canExecute, scheduler, userErrorMsg, responseTimeout, ackTimeout));
 }
コード例 #20
0
 protected TcpBusSide(
     IPAddress hostIp,
     int commandPort,
     IGeneralBus messageBus)
 {
     _hostIp             = hostIp;
     _commandPort        = commandPort;
     MessageBus          = messageBus;
     StatsTimer          = new Timer(60000);    // getting the stats takes a while - only do it once a minute
     StatsTimer.Elapsed += _statsTimer_Elapsed;
     StatsTimer.Enabled  = true;
 }
コード例 #21
0
 protected virtual void Dispose(bool disposing)
 {
     if (_disposed)
     {
         return;
     }
     if (disposing)
     {
         RedirectToNull = true;
         _target        = null;
     }
     _disposed = true;
 }
コード例 #22
0
 public EventStoreBusConnector(
     IGeneralBus bus,
     IEventStoreConnection es,
     string stream,
     string name)
 {
     _es     = es;
     _stream = stream;
     _bus    = new BusAdapter(bus);
     _name   = name;
     _bus.Subscribe(this);
     _es.SubscribeToStreamAsync(stream, true, EventAppeared, SubscriptionDropped);
 }
コード例 #23
0
 public EventStoreBusConnector(
     IGeneralBus bus,
     IEventStoreHttpConnection conn,
     string stream,
     string name)
 {
     _conn       = conn;
     _subscriber = EventStreamSubscriber.Create(_conn, HandleJsonEvent, new MemoryBackedStreamPositionRepositoryForDebugging());
     _stream     = stream;
     _name       = name;
     _bus        = new BusAdapter(bus);
     _bus.Subscribe(this);
     _subscriber.SubscribeTo(stream);
 }
コード例 #24
0
 protected CommandBusSpecification()
 {
     Bus       = new CommandBus("Fixture Bus", slowMsgThreshold: TimeSpan.FromMilliseconds(500));
     LocalBus  = new CommandBus("Fixture LocalBus");
     TestQueue = new TestQueue(Bus);
     try
     {
         Given();
         When();
     }
     catch (Exception)
     {
         throw;
     }
 }
コード例 #25
0
 public TcpBusClientSideTests()
 {
     _commandBus          = new CommandBus("TestBus");
     _hostAddress         = IPAddress.Loopback;
     _clientAddress       = IPAddress.Loopback;
     _clientTcpConnection = MockTcpConnection.CreateConnectingTcpConnection(Guid.NewGuid(),
                                                                            new IPEndPoint(_hostAddress, CommandPort),
                                                                            new TcpClientConnector(),
                                                                            TimeSpan.FromSeconds(120),
                                                                            conn =>
     {
     },
                                                                            (conn, err) =>
     {
     },
                                                                            verbose: true);
 }
コード例 #26
0
        public EventStoreMessageLogger(
            IGeneralBus bus,
            IEventStoreConnection es,
            string logStreamPrefix = "",
            bool enableLogging     = false,
            bool idempotent        = true) : base(bus, idempotent)
        {
            _bus          = bus;
            _eventStore   = es;
            Enabled       = enableLogging;
            _streamPrefix = logStreamPrefix;
            if (Enabled)
            {
                _eventStore?.ConnectAsync();
            }

            Subscribe <Message>(this);
        }
コード例 #27
0
        protected CommandQueueSpecification(
            int queueCount = 1,
            int slowCmdMs  = 500,
            int slowAckMs  = 500)
        {
            Bus = new CommandBus(
                "Fixture Bus",
                slowCmdThreshold: TimeSpan.FromMilliseconds(slowCmdMs),
                slowMsgThreshold: TimeSpan.FromMilliseconds(slowAckMs));

            Queue = new MultiQueuedHandler(
                queueCount,
                index => new QueuedHandler(
                    new AdHocHandler <Message>(
                        msg =>
            {
                if (msg is Command)
                {
                    Bus.TryFire((Command)msg);
                }
                else
                {
                    Bus.Publish(msg);
                }
            }),
                    $"Queue {index}"
                    )
                );
            Queue.Start();
            TestQueue = new TestQueue(Bus);
            try
            {
                Given();
                When();
            }
            catch (Exception)
            {
                throw;
            }
        }
コード例 #28
0
        public MainWindowViewModel(
            IGeneralBus bus,
            AccountRM accountRm,
            Guid accountId) : base(bus)
        {
            _bus       = bus;
            _accountRm = accountRm;
            _accountId = accountId;

            Output = new ReactiveList <string>()
            {
                "Initial balance: $0.00"
            };

            AddCreditOrDebitCommand = CommandBuilder.FromAction(
                canExecute: this.WhenAnyValue(x => x.Amount, x => x > 0),
                action: () =>
            {
                try
                {
                    FireCreditOrDebit();
                }
                catch (Exception e)
                {
                    //Application.Current.Dispatcher.Invoke(() => Output.Add(e.Message));
                }
            });

            _accountRm?
            .AccountUpdateMessage
            .ObserveOn(RxApp.MainThreadScheduler)
            .Subscribe(m =>
            {
                if (m != null)
                {
                    Output.Add(m);
                }
            });
        }
コード例 #29
0
ファイル: Bootstrap.cs プロジェクト: pe-david/AccountDemoWpf
        public void Run(StartupEventArgs args)
        {
            _bus = new CommandBus(
                "Main Bus",
                false,
                TimeSpan.FromMinutes(1), // TODO: Eliminate these timeouts and add the necessary timeouts to commands on a per-command basis.
                TimeSpan.FromMinutes(1));

            Configure(_bus);

            _bus.Fire(new CreateAccount(
                          Bootstrap.NewAccountId,
                          "TheAccount",
                          Guid.NewGuid(),
                          Guid.Empty));

            _accountRm = new AccountRM(NewAccountId);
            var mainWindow = new MainWindow()
            {
                ViewModel = new MainWindowViewModel(_bus, _accountRm, NewAccountId)
            };

            mainWindow.Show();
        }
コード例 #30
0
 public BusAdapter(IGeneralBus bus)
 {
     _idTracker       = null;
     _bus             = bus;
     _trackedMessages = new HashSet <Guid>();
 }