本文整理汇总了C#中Subject.ToProperty方法的典型用法代码示例。如果您正苦于以下问题:C# Subject.ToProperty方法的具体用法?C# Subject.ToProperty怎么用?C# Subject.ToProperty使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Subject
的用法示例。
在下文中一共展示了Subject.ToProperty方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ApplyUpdatesViewModel
public ApplyUpdatesViewModel(
IScreen screen,
Func<UpdateManager> getUpdateManager)
{
this.getUpdateManager = getUpdateManager;
HostScreen = screen;
Apply = new ReactiveAsyncCommand();
Apply.Subscribe(_ => applyUpdates());
Restart = new ReactiveAsyncCommand();
Restart.Subscribe(_ => restart());
progress = new Subject<int>();
progressObservable = progress.ToProperty(this, vm => vm.Progress);
}
示例2: UninstallingViewModel
public UninstallingViewModel(IScreen hostScreen)
{
HostScreen = hostScreen;
var progress = new Subject<int>();
ProgressValue = progress;
progress.ToProperty(this, x => x.LatestProgress, 0);
this.WhenAny(x => x.PackageMetadata, x => x.Value)
.SelectMany(x => x != null ? Observable.Return(x.Title) : Observable.Empty<string>())
.ToProperty(this, x => x.Title);
this.WhenAny(x => x.PackageMetadata, x => x.Value)
.SelectMany(x => x != null ? Observable.Return(x.Description) : Observable.Empty<string>())
.ToProperty(this, x => x.Description);
}
示例3: CheckForUpdatesViewModel
public CheckForUpdatesViewModel(
IScreen screen,
ISettingsProvider settingsProvider,
Func<UpdateManager> getUpdateManager,
Lazy<DownloadUpdatesViewModel> getDownloadViewModel)
{
HostScreen = screen;
this.settingsProvider = settingsProvider;
this.getUpdateManager = getUpdateManager;
this.getDownloadViewModel = getDownloadViewModel;
CheckCommand = new ReactiveAsyncCommand();
CheckCommand.Subscribe(_ => checkForUpdates());
BackCommand = new ReactiveAsyncCommand();
BackCommand.Subscribe(_ => HostScreen.Router.NavigateBack.Execute(null));
progress = new Subject<int>();
progressObservable = progress.ToProperty(
this,
vm => vm.Progress);
}
示例4: DownloadUpdatesViewModel
public DownloadUpdatesViewModel(
IScreen screen,
Func<UpdateManager> getUpdateManager,
Lazy<ApplyUpdatesViewModel> getApplyViewModel)
{
HostScreen = screen;
this.getUpdateManager = getUpdateManager;
this.getApplyViewModel = getApplyViewModel;
Download = new ReactiveAsyncCommand();
Download.Subscribe(_ => downloadUpdates());
progress = new Subject<int>();
progressObs = progress.ToProperty(
this,
vm => vm.Progress);
var updateInfoChanges =
this.WhenAny(vm => vm.UpdateInfo, x => x.Value)
.Where(info => info != null);
updateCountObs =
updateInfoChanges
.Select(info => info.ReleasesToApply.Count())
.ToProperty(this, vm => vm.UpdateCount);
updateSizeObs =
updateInfoChanges
.Select(info => info.ReleasesToApply.Sum(x => x.Filesize))
.Select(total => String.Format("({0:n0} bytes)", total))
.ToProperty(this, vm => vm.UpdateSize);
latestVersionObs = updateInfoChanges
.Select(info => info.FutureReleaseEntry.Version.ToString())
.Where(x => !String.IsNullOrWhiteSpace(x))
.ToProperty(this, vm => vm.LatestVersion);
}
示例5: 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);
}
示例6: CommitHintViewModel
public CommitHintViewModel(string filePath, IVisualStudioOps vsOps, UserSettings settings = null, IGitRepoOps gitRepoOps = null, IFilesystemWatchCache watchCache = null)
{
FilePath = filePath;
watchCache = watchCache ?? _defaultWatchCache;
_gitRepoOps = gitRepoOps ?? new GitRepoOps();
UserSettings = settings ?? new UserSettings();
this.Log().Info("Starting Commit Hint for {0}", filePath);
this.WhenAny(x => x.FilePath, x => x.Value)
.Where(x => !String.IsNullOrWhiteSpace(x))
.Select(_gitRepoOps.FindGitRepo)
.ToProperty(this, x => x.RepoPath, out _RepoPath);
this.WhenAny(x => x.RepoPath, x => x.Value)
.Where(x => !String.IsNullOrWhiteSpace(x))
.Select(_gitRepoOps.ProtocolUrlForRepoPath)
.ToProperty(this, x => x.ProtocolUrl, out _ProtocolUrl);
Open = new ReactiveCommand(this.WhenAny(x => x.ProtocolUrl, x => !String.IsNullOrWhiteSpace(x.Value)));
GoAway = new ReactiveCommand();
RefreshStatus = new ReactiveAsyncCommand(this.WhenAny(x => x.RepoPath, x => !String.IsNullOrWhiteSpace(x.Value)));
RefreshLastCommitTime = new ReactiveAsyncCommand(this.WhenAny(x => x.RepoPath, x => !String.IsNullOrWhiteSpace(x.Value)));
var repoWatchSub = this.WhenAny(x => x.RepoPath, x => x.Value)
.Where(x => !String.IsNullOrWhiteSpace(x))
.Select(x => watchCache.Register(Path.Combine(x, ".git", "refs")).Select(_ => x))
.Switch()
.InvokeCommand(RefreshLastCommitTime);
RefreshLastCommitTime.RegisterAsyncObservable(_ => _gitRepoOps.LastCommitTime(RepoPath))
.StartWith(_gitRepoOps.ApplicationStartTime)
.ToProperty(this, x => x.LastRepoCommitTime, out _LastRepoCommitTime);
MessageBus.Current.Listen<Unit>("AnyDocumentChanged")
.Timestamp(RxApp.MainThreadScheduler)
.Select(x => x.Timestamp)
.StartWith(_gitRepoOps.ApplicationStartTime)
.ToProperty(this, x => x.LastTextActiveTime, out _LastTextActiveTime);
var refreshDisp = this.WhenAny(x => x.LastTextActiveTime, x => Unit.Default)
.Buffer(TimeSpan.FromSeconds(5), RxApp.TaskpoolScheduler)
.ObserveOn(RxApp.MainThreadScheduler)
.InvokeCommand(RefreshStatus);
this.WhenAny(x => x.LastRepoCommitTime, x => x.LastTextActiveTime, x => x.MinutesTimeOverride, (commit, active, _) => active.Value - commit.Value)
.Select(x => x.Ticks < 0 ? TimeSpan.Zero : x)
.Select(x => MinutesTimeOverride != null ? TimeSpan.FromMinutes(MinutesTimeOverride.Value) : x)
.Select(x => LastCommitTimeToOpacity(x))
.ToProperty(this, x => x.SuggestedOpacity, out _SuggestedOpacity, 1.0);
var hintState = new Subject<CommitHintState>();
hintState.ToProperty(this, x => x.HintState, out _HintState);
Open.Subscribe(_ => vsOps.SaveAll());
RefreshStatus.RegisterAsyncObservable(_ => _gitRepoOps.GetStatus(RepoPath))
.ToProperty(this, x => x.LatestRepoStatus, out _LatestRepoStatus);
this.WhenAny(x => x.SuggestedOpacity, x => x.LatestRepoStatus, (opacity, status) => new { Opacity = opacity.Value, Status = status.Value })
.Select(x => {
if (x.Status == null) return CommitHintState.Green;
if (!x.Status.Added.Any() &&
!x.Status.Removed.Any() &&
!x.Status.Modified.Any() &&
!x.Status.Missing.Any()) return CommitHintState.Green;
if (x.Opacity >= 0.95) return CommitHintState.Red;
if (x.Opacity >= 0.6) return CommitHintState.Yellow;
return CommitHintState.Green;
})
.Subscribe(hintState);
// NB: Because _LastRepoCommitTime at the end of the day creates a
// FileSystemWatcher, we have to dispose it or else we'll get FSW
// messages for evar.
_inner = new CompositeDisposable(repoWatchSub, _LastRepoCommitTime, _LastTextActiveTime);
}