private void FireCreditOrDebit() { if (!Amount.HasValue || Amount < 0) { throw new InvalidOperationException("Amount must be > 0."); } switch (CreditOrDebitSelection) { case "Credit": _bus.Fire(new ApplyCredit( _accountId, Amount.Value, Guid.NewGuid(), Guid.Empty), responseTimeout: TimeSpan.FromSeconds(60)); break; case "Debit": _bus.Fire(new ApplyDebit( _accountId, Amount.Value, Guid.NewGuid(), Guid.Empty), responseTimeout: TimeSpan.FromSeconds(60)); break; default: throw new InvalidOperationException("User choice must be either credit or debit."); } }
//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); } } }
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); }
public void Fire(Command command, string exceptionMsg = null, TimeSpan?responseTimeout = null, TimeSpan?ackTimeout = null) { if (RedirectToNull || _target == null) { return; } _target.Fire(command, exceptionMsg, responseTimeout, ackTimeout); }
public CommandResponse Handle(TestTokenCancellableCmd command) { _bus.Fire(new NestedTestTokenCancellableCmd(Guid.NewGuid(), command.MsgId, command.CancellationToken)); if (command.IsCanceled) { return(command.Canceled()); } else { return(command.Succeed()); } }
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(); }