public ObservableBusyViewModel(IScarletCommandBuilder commandBuilder, IScarletDispatcher dispatcher)
        {
            _observableBusyStack = new ObservableBusyStack(hasItems => { IsBusy = hasItems; Debug.WriteLine("ObservableBusyViewModel is busy: " + hasItems); });

            BeBusyCommand = commandBuilder.Create(BeBusyInternal, () => !IsBusy)
                            .WithBusyNotification(_observableBusyStack)
                            .WithSingleExecution()
                            .Build();
        }
Example #2
0
        protected ViewModelBase(IScarletCommandBuilder commandBuilder)
            : base((commandBuilder?.Messenger) !)
        {
            CommandBuilder   = commandBuilder ?? throw new ArgumentNullException(nameof(commandBuilder));
            Dispatcher       = commandBuilder.Dispatcher ?? throw new ArgumentNullException(nameof(IScarletCommandBuilder.Dispatcher));
            CommandManager   = commandBuilder.CommandManager ?? throw new ArgumentNullException(nameof(IScarletCommandBuilder.CommandManager));
            Exit             = commandBuilder.Exit ?? throw new ArgumentNullException(nameof(IScarletCommandBuilder.Exit));
            WeakEventManager = commandBuilder.WeakEventManager ?? throw new ArgumentNullException(nameof(IScarletCommandBuilder.WeakEventManager));

            BusyStack = new ObservableBusyStack((hasItems) => IsBusy = hasItems);
        }
        public DispatcherProgress(IScarletDispatcher dispatcher, Action <T> callback, TimeSpan interval)
        {
            _dispatcher = dispatcher ?? throw new ArgumentNullException(nameof(dispatcher));
            _callback   = callback ?? throw new ArgumentNullException(nameof(callback));

            _observable = Observable.FromEventPattern <T>(
                fsHandler => ProgressChanged += fsHandler,
                fsHandler => ProgressChanged -= fsHandler);

            _disposable = _observable
                          .ObserveOn(System.Reactive.Concurrency.TaskPoolScheduler.Default)
                          .Sample(interval)
                          .Subscribe(e => ReportInternal(e.EventArgs));
        }
Example #4
0
 public static IScarletCommandBuilder GetTestCommandBuilder(IScarletDispatcher dispatcher             = null,
                                                            IScarletCommandManager commandManager     = null,
                                                            IScarletExceptionHandler exceptionHandler = null,
                                                            IMessenger messenger     = null,
                                                            IExitService exitService = null,
                                                            IScarletEventManager <INotifyPropertyChanged, PropertyChangedEventArgs> eventManager = null,
                                                            Func <Action <bool>, IBusyStack> busyStackFactory = null)
 {
     return(new ScarletCommandBuilder(dispatcher ?? GetTestDispatcher(),
                                      commandManager ?? GetTestCommandManager(),
                                      exceptionHandler ?? GetTestExceptionHandler(),
                                      messenger ?? GetTestMessenger(),
                                      exitService ?? GetTestExitService(),
                                      eventManager ?? GetTestEventManager(),
                                      busyStackFactory ?? GetTestBusyStackFactory()));
 }
Example #5
0
        protected PagedSourceListViewModelBase(IScarletCommandBuilder commandBuilder, SynchronizationContext synchronizationContext, Func <TViewModel, string> selector, IPagedDataProvider <TViewModel> pagedDataProvider)
            : base(synchronizationContext, selector)
        {
            CommandBuilder = commandBuilder ?? throw new ArgumentNullException(nameof(commandBuilder));
            Dispatcher     = commandBuilder.Dispatcher ?? throw new ArgumentNullException(nameof(IScarletCommandBuilder.Dispatcher));
            CommandManager = commandBuilder.CommandManager ?? throw new ArgumentNullException(nameof(IScarletCommandBuilder.CommandManager));

            _pagedDataProvider = pagedDataProvider ?? throw new ArgumentNullException(nameof(pagedDataProvider));

            SelectedItems = new ObservableCollection <TViewModel>();
            BusyStack     = new ObservableBusyStack((hasItems) => IsBusy = hasItems);
            PageSize      = 50;

            _loadCommand = commandBuilder
                           .Create(Load, CanLoad)
                           .WithSingleExecution()
                           .WithBusyNotification(BusyStack)
                           .WithAsyncCancellation()
                           .Build();

            _refreshCommand = commandBuilder
                              .Create(Refresh, CanRefresh)
                              .WithSingleExecution()
                              .WithBusyNotification(BusyStack)
                              .WithAsyncCancellation()
                              .Build();

            _unloadCommand = commandBuilder
                             .Create(Unload, CanUnload)
                             .WithSingleExecution()
                             .WithBusyNotification(BusyStack)
                             .WithAsyncCancellation()
                             .Build();

            NextCommand = commandBuilder
                          .Create(Next, CanNext)
                          .WithSingleExecution()
                          .WithBusyNotification(BusyStack)
                          .WithAsyncCancellation()
                          .Build();

            PreviousCommand = commandBuilder
                              .Create(Previous, CanPrevious)
                              .WithSingleExecution()
                              .WithBusyNotification(BusyStack)
                              .WithAsyncCancellation()
                              .Build();

            FirstCommand = commandBuilder
                           .Create(First, CanFirst)
                           .WithSingleExecution()
                           .WithBusyNotification(BusyStack)
                           .WithAsyncCancellation()
                           .Build();

            LastCommand = commandBuilder
                          .Create(Last, CanLast)
                          .WithSingleExecution()
                          .WithBusyNotification(BusyStack)
                          .WithAsyncCancellation()
                          .Build();
        }
Example #6
0
 public static Task Invoke(this IScarletDispatcher dispatcher, in Action action)