public ActivityInventoryViewModel()
        {
            Activities = new ObservableCollection <Activity>();

            var activityPropertyChanged     = new ObservableEventHandler <Activity, PropertyChangedEventArgs>();
            var activitiesCollectionChanged = new Utilities.ObservableEventHandler <NotifyCollectionChangedEventArgs>();

            Activities.CollectionChanged += activitiesCollectionChanged.Handler;

            activitiesCollectionChanged.Where(e => e.EventArgs.Action == NotifyCollectionChangedAction.Add)
            .SelectMany(e => e.EventArgs.NewItems.Cast <Activity>())
            .Subscribe(a => a.PropertyChanged += activityPropertyChanged.Handler);

            activitiesCollectionChanged.Where(e => e.EventArgs.Action == NotifyCollectionChangedAction.Remove)
            .SelectMany(e => e.EventArgs.OldItems.Cast <Activity>())
            .Subscribe(a => a.PropertyChanged -= activityPropertyChanged.Handler);

            activitiesCollectionChanged.Select(e => Unit.Default)
            .Merge(activityPropertyChanged.Where(e => e.EventArgs.PropertyName == "ExpectedEffort").Select(e => Unit.Default))
            .Subscribe(u => ExpectedEffortSum = Activities.Select(a => a.ExpectedEffort).Sum());

            activitiesCollectionChanged.Select(e => Unit.Default)
            .Merge(activityPropertyChanged.Where(e => e.EventArgs.PropertyName == "ActualEffort").Select(e => Unit.Default))
            .Subscribe(u => ActualEffortSum = Activities.Select(a => a.ActualEffort).Sum());

            var selectedActivitiesNotEmpty = new Func <bool>(() => !EnumerableExtensions.IsNullOrEmpty(SelectedActivities));

            DeleteActivityCommand       = new RelayCommand(() => SelectedActivities.ForEach(DeleteActivity), selectedActivitiesNotEmpty);
            ArchiveActivityCommand      = new RelayCommand(() => SelectedActivities.ForEach(ArchiveActivity), selectedActivitiesNotEmpty);
            IncreaseActualEffortCommand = new RelayCommand(() => SelectedActivities.ForEach(IncreaseActualEffort), selectedActivitiesNotEmpty);
            DecreaseActualEffortCommand = new RelayCommand(() => SelectedActivities.ForEach(DecreaseActualEffort), selectedActivitiesNotEmpty);
            EditActivityCommand         = new RelayCommand(() => EditActivity(SelectedActivities[0]), selectedActivitiesNotEmpty);
        }
        public static IObservable <TEvent> Observable <TEvent>(this EventBus eventBus) where TEvent : DomainEvent
        {
            return(System.Reactive.Linq.Observable.Create <TEvent>(observer =>
            {
                var handler = new ObservableEventHandler <TEvent>(async evt =>
                {
                    observer.OnNext(evt);
                });

                var subscribtion = eventBus.Subscribe(handler);

                return subscribtion;
            }));
        }
Beispiel #3
0
 public EventBindingSubscriber OnRaised(ObservableEventHandler callback)
 {
     binding.Property.Raised += callback;
     return(this);
 }