main
 1using System;
 2using gorilla.utility;
 3using solidware.financials.infrastructure;
 4using solidware.financials.messages;
 5using solidware.financials.windows.ui.presenters.validation;
 6using solidware.financials.windows.ui.views.controls;
 7using utility;
 8
 9namespace solidware.financials.windows.ui.presenters
10{
11    public class AddNewStockSymbolPresenter : DialogPresenter
12    {
13        public AddNewStockSymbolPresenter(UICommandBuilder builder)
14        {
15            this.builder = builder;
16            Symbol = new ObservableProperty<string>();
17        }
18
19        public ObservableCommand Add { get; set; }
20        public ObservableCommand Cancel { get; set; }
21        public virtual Observable<string> Symbol { get; set; }
22        public virtual Action close { get; set; }
23
24        public void present()
25        {
26            Add = builder.build<AddCommand, IsValid>(this);
27            Cancel = builder.build<CancelCommand>(this);
28
29            Symbol.Notify(Add);
30            Symbol.Register<Error>(x => x.is_blank(), () => "Please specify a symbol.");
31        }
32
33        UICommandBuilder builder;
34
35        public class AddCommand : UICommand<AddNewStockSymbolPresenter>
36        {
37            ServiceBus bus;
38
39            public AddCommand(ServiceBus bus)
40            {
41                this.bus = bus;
42            }
43
44            public override void run(AddNewStockSymbolPresenter presenter)
45            {
46                bus.publish(new StartWatchingSymbol {Symbol = presenter.Symbol.Value.ToUpperInvariant()});
47                presenter.close();
48            }
49        }
50
51        public class IsValid : UISpecification<AddNewStockSymbolPresenter>
52        {
53            public override bool is_satisfied_by(AddNewStockSymbolPresenter presenter)
54            {
55                return presenter.Symbol.not(x => x.Value.is_blank());
56            }
57        }
58    }
59}