本文整理汇总了C#中ReactiveCommand.SelectMany方法的典型用法代码示例。如果您正苦于以下问题:C# ReactiveCommand.SelectMany方法的具体用法?C# ReactiveCommand.SelectMany怎么用?C# ReactiveCommand.SelectMany使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ReactiveCommand
的用法示例。
在下文中一共展示了ReactiveCommand.SelectMany方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: OpenCacheViewModel
public OpenCacheViewModel(IScreen hostScreen, IAppState appState)
{
HostScreen = hostScreen;
var isCachePathValid = this.WhenAny(
x => x.CachePath, x => x.OpenAsEncryptedCache, x => x.OpenAsSqlite3Cache,
(cp, _, sql) => new { Path = cp.Value, Sqlite3 = sql.Value })
.Throttle(TimeSpan.FromMilliseconds(250), RxApp.MainThreadScheduler)
.Select(x => x.Sqlite3 ? File.Exists(x.Path) : Directory.Exists(x.Path));
OpenCache = new ReactiveCommand(isCachePathValid);
OpenCache.SelectMany(_ => openAkavacheCache(CachePath, OpenAsEncryptedCache, OpenAsSqlite3Cache))
.LoggedCatch(this, Observable.Return<IBlobCache>(null))
.ObserveOn(RxApp.MainThreadScheduler)
.Subscribe(x => {
if (x == null) {
UserError.Throw("Couldn't open this cache");
return;
}
appState.CurrentCache = x;
hostScreen.Router.Navigate.Execute(new CacheViewModel(hostScreen, appState));
});
}
示例2: ServicesControllerViewModel
public ServicesControllerViewModel(IEnumerable<ServiceViewModel> serviceViewModels)
{
var selectedServiceObs = this.ObservableForProperty(x => x.SelectedService).Value();
//Combine the latest value from either the start or continue executes
//to determine if you can press the "play" button
StartCommand = new ReactiveCommand
(
selectedServiceObs.SelectMany
(
s => s.StartCommand.CanExecuteObservable.StartWith(true)
.CombineLatest
(
s.ContinueCommand.CanExecuteObservable.StartWith(false),
(l,r) => l || r
)
)
);
StopCommand = new ReactiveCommand(selectedServiceObs.SelectMany(s => s.StopCommand.CanExecuteObservable).StartWith(false));
PauseCommand = new ReactiveCommand(selectedServiceObs.SelectMany(s => s.PauseCommand.CanExecuteObservable).StartWith(false));
StartCommand
.SelectMany
(
_ => new ReactiveCommand[]
{
_SelectedService.StartCommand,
_SelectedService.ContinueCommand
}
.Where(cmd => cmd.CanExecute(null))
.ToObservable()
)
.Do(cmd => cmd.Execute(null))
.Subscribe();
StopCommand.Subscribe(_ => SelectedService.StopCommand.Execute(null));
PauseCommand.Subscribe(_ => SelectedService.PauseCommand.Execute(null));
Services = serviceViewModels;
SelectedService = Services.FirstOrDefault();
}
示例3: WelcomeViewModel
public WelcomeViewModel(
IScreen screen,
ILoginMethods loginMethods,
[Named("connectToServer")] [Optional] Func<string, string, IObservable<Unit>> connectToServerMock)
{
HostScreen = screen;
var canOk = this.WhenAny(x => x.BaseUrl, x => x.Token,
(b, u) => isValidUrl(b.Value) && !String.IsNullOrWhiteSpace(u.Value));
OkButton = new ReactiveCommand(canOk);
OpenTokenPage = new ReactiveCommand(this.WhenAny(x => x.BaseUrl, x => isValidUrl(x.Value)));
var connectToServer = connectToServerMock ?? ConnectToPlay;
Observable.Defer(() => OkButton.SelectMany(_ => connectToServer(BaseUrl, Token)))
.Select(_ => true).Catch(Observable.Return(false))
.Repeat()
.Subscribe(result => {
if (result == false) {
UserError.Throw("Couldn't connect to Play instance.");
return;
}
loginMethods.SaveCredentials(BaseUrl, Token);
screen.Router.NavigateBack.Execute(null);
});
OpenTokenPage.Subscribe(_ => Process.Start(String.Format("{0}/token", BaseUrl)));
var error = new Subject<string>();
UserError.RegisterHandler(ex => {
error.OnNext(ex.ErrorMessage);
return Observable.Return(RecoveryOptionResult.CancelOperation);
});
this.WhenAny(x => x.Token, x => x.BaseUrl, (_, __) => Unit.Default)
.Subscribe(_ => error.OnNext(null));
error.ToProperty(this, x => x.ErrorMessage);
}
示例4: OpenCacheViewModel
public OpenCacheViewModel(IScreen hostScreen, IAppState appState)
{
HostScreen = hostScreen;
var isCachePathValid = this.WhenAny(x => x.CachePath, x => x.OpenAsEncryptedCache, (cp, _) => cp.Value)
.Throttle(TimeSpan.FromMilliseconds(250), RxApp.DeferredScheduler)
.Select(Directory.Exists);
OpenCache = new ReactiveCommand(isCachePathValid);
OpenCache.SelectMany(_ => openAkavacheCache(OpenAsEncryptedCache))
.LoggedCatch(this, Observable.Return<IBlobCache>(null))
.Subscribe(x => {
if (x == null) {
UserError.Throw("Couldn't open this cache");
return;
}
appState.CurrentCache = x;
hostScreen.Router.Navigate.Execute(RxApp.GetService<ICacheViewModel>());
});
}
示例5: Initialize
private void Initialize(string dataType, string componentType, string portName)
{
UpdateDataTypeCommand = new ReactiveCommand();
UpdatePortNameCommand = new ReactiveCommand();
UpdateCompoentTypeCommand = new ReactiveCommand();
DataTypes = UpdateDataTypeCommand
.SelectMany(_=>Observable.Start(()=>_recordDescriptionRepository.GetDataTypes(componentType,portName))
.Catch((Exception ex) => Messenger.Raise(new InformationMessage("データベースアクセスに失敗しました。", "エラー", "ShowError"))))
.Do(_ => DataTypes.ClearOnScheduler())
.SelectMany(_=>_)
.ToReactiveCollection();
PortNames = UpdatePortNameCommand
.SelectMany(_=>Observable.Start(()=>_recordDescriptionRepository.GetPortNames(dataType,componentType))
.Catch((Exception ex) => Messenger.Raise(new InformationMessage("データベースアクセスに失敗しました。", "エラー", "ShowError"))))
.Do(_ => PortNames.ClearOnScheduler())
.SelectMany(_=>_)
.ToReactiveCollection();
ComponentTypes = UpdateCompoentTypeCommand
.SelectMany(_=>Observable.Start(()=>_recordDescriptionRepository.GetComponentTypes(dataType,portName))
.Catch((Exception ex) => Messenger.Raise(new InformationMessage("データベースアクセスに失敗しました。", "エラー", "ShowError"))))
.Do(_ => ComponentTypes.ClearOnScheduler())
.SelectMany(_=>_)
.ToReactiveCollection();
DataType = dataType;
PortName = portName;
ComponentType = componentType;
UpdateDataTypeCommand.Execute(null);
UpdatePortNameCommand.Execute(null);
UpdateCompoentTypeCommand.Execute(null);
}