示例#1
0
        public CacheViewModel(IScreen hostScreen, IAppState appState)
        {
            HostScreen = hostScreen;

            appState.WhenAny(x => x.CachePath, x => x.Value)
                .Where(x => !String.IsNullOrWhiteSpace(x))
                .Select(x => (new DirectoryInfo(x)).Name)
                .ToProperty(this, x => x.UrlPathSegment, out _UrlPathSegment);

            Keys = new ReactiveList<string>();
            appState.WhenAny(x => x.CurrentCache, x => x.Value)
                .SelectMany(x => Observable.Start(() => x.GetAllKeys(), RxApp.TaskpoolScheduler))
                .ObserveOn(RxApp.MainThreadScheduler)
                .Subscribe(newKeys => {
                    Keys.Clear();
                    newKeys.ForEach(x => Keys.Add(x));
                });

            FilteredKeys = Keys.CreateDerivedCollection(
                key => key,
                key => FilterText == null || key.IndexOf(FilterText, StringComparison.OrdinalIgnoreCase) > -1,
                signalReset: this.WhenAny(x => x.FilterText, x => x.Value));

            SelectedViewer = "Text";

            this.WhenAny(x => x.SelectedKey, x => x.SelectedViewer, (k, v) => k.Value)
                .Where(x => x != null && SelectedViewer != null)
                .SelectMany(x => appState.CurrentCache.GetAsync(x).Catch(Observable.Return(default(byte[]))))
                .Select(x => createValueViewModel(x, SelectedViewer))
                .LoggedCatch(this, Observable.Return<ICacheValueViewModel>(null))
                .ToProperty(this, x => x.SelectedValue, out _SelectedValue);
        }
        public CacheViewModel(IScreen hostScreen, IAppState appState)
        {
            HostScreen = hostScreen;

            appState.WhenAny(x => x.CachePath, x => x.Value)
            .Where(x => !String.IsNullOrWhiteSpace(x))
            .Select(x => (new DirectoryInfo(x)).Name)
            .ToProperty(this, x => x.UrlPathSegment, out _UrlPathSegment);

            Keys = new ReactiveList <string>();
            appState.WhenAny(x => x.CurrentCache, x => x.Value)
            .SelectMany(x => Observable.Start(() => x.GetAllKeys(), RxApp.TaskpoolScheduler))
            .ObserveOn(RxApp.MainThreadScheduler)
            .Subscribe(newKeys => {
                Keys.Clear();
                newKeys.ForEach(x => Keys.Add(x));
            });

            FilteredKeys = Keys.CreateDerivedCollection(
                key => key,
                key => FilterText == null || key.IndexOf(FilterText, StringComparison.OrdinalIgnoreCase) > -1,
                signalReset: this.WhenAny(x => x.FilterText, x => x.Value));

            SelectedViewer = "Text";

            this.WhenAny(x => x.SelectedKey, x => x.SelectedViewer, (k, v) => k.Value)
            .Where(x => x != null && SelectedViewer != null)
            .SelectMany(x => appState.CurrentCache.GetAsync(x).Catch(Observable.Return(default(byte[]))))
            .Select(x => createValueViewModel(x, SelectedViewer))
            .LoggedCatch(this, Observable.Return <ICacheValueViewModel>(null))
            .ToProperty(this, x => x.SelectedValue, out _SelectedValue);
        }
示例#3
0
        public CacheViewModel(IScreen hostScreen, IAppState appState)
        {
            HostScreen = hostScreen;

            appState.WhenAny(x => x.CachePath, x => x.Value)
                .Where(x => !String.IsNullOrWhiteSpace(x))
                .Select(x => (new DirectoryInfo(x)).Name)
                .ToProperty(this, x => x.UrlPathSegment);

            Keys = new ReactiveCollection<string>();
            appState.WhenAny(x => x.CurrentCache, x => x.Value).Subscribe(cache => {
                Keys.Clear();
                cache.GetAllKeys().ForEach(x => Keys.Add(x));
            });

            SelectedViewer = "Text";

            this.WhenAny(x => x.SelectedKey, x => x.SelectedViewer, (k,v) => k.Value)
                .Where(x => x != null && SelectedViewer != null)
                .SelectMany(x => appState.CurrentCache.GetAsync(x))
                .Select(x => createValueViewModel(x, SelectedViewer))
                .LoggedCatch(this, Observable.Return<ICacheValueViewModel>(null))
                .ToProperty(this, x => x.SelectedValue);
        }
示例#4
0
        public SimulationHomeViewModel(IAppState appState, IAppService appService)
        {
            _appState   = appState;
            _appService = appService;

            SharedStateViewModel = new SharedStateViewModel(appState, appService);

            BusyCancel = ReactiveCommand.Create(HandleBusyCancel);
            ChangeCommonConfiguration = ReactiveCommand.Create(HandleChangeCommonConfiguration);
            Export = ReactiveCommand.Create(
                HandleExport,
                appState.WhenAny(
                    @as => @as.ActiveUIComponent,
                    _ => appState.ActiveUIComponent.ViewModel is IExportedDataProvider
                    ));
            Close = ReactiveCommand.Create(HandleClose);

            _appState.Simulation.Subscribe(
                appService.SafeInvoke <Option <Simulation> >(
                    ObserveSimulation
                    )
                );

            _appState
            .ObservableForProperty(s => s.UIComponents)
            .Subscribe(appService.SafeInvoke <object>(ObserveUIComponents));

            _reactiveSafeInvoke = appService.GetReactiveSafeInvoke();

            _appState
            .WhenAny(s => s.ActiveUIComponent, _ => default(object))
            .Subscribe(ObserveActiveUIComponent);

            this
            .ObservableForProperty(vm => vm.UIComponentIndex)
            .Subscribe(_reactiveSafeInvoke.SuspendAndInvoke <object>(ObserveUIComponentIndex));

            MonitorTaskRunners();
        }