本文整理汇总了C#中IReactiveCommand类的典型用法代码示例。如果您正苦于以下问题:C# IReactiveCommand类的具体用法?C# IReactiveCommand怎么用?C# IReactiveCommand使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
IReactiveCommand类属于命名空间,在下文中一共展示了IReactiveCommand类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GistFileItemViewModel
public GistFileItemViewModel(string name, string content)
{
Name = name;
Content = content;
EditCommand = ReactiveCommand.Create();
DeleteCommand = ReactiveCommand.Create();
}
示例2: IssueEditViewModel
public IssueEditViewModel(IApplicationService applicationService)
{
_applicationService = applicationService;
GoToDescriptionCommand = new ReactiveCommand(this.WhenAnyValue(x => x.Issue, x => x != null));
GoToDescriptionCommand.Subscribe(_ =>
{
var vm = CreateViewModel<ComposerViewModel>();
vm.Text = Issue.Body;
vm.SaveCommand.Subscribe(__ =>
{
Issue.Body = vm.Text;
vm.DismissCommand.ExecuteIfCan();
});
ShowViewModel(vm);
});
this.WhenAnyValue(x => x.Issue).Where(x => x != null).Subscribe(x =>
{
Title = x.Title;
AssignedTo = x.Assignee;
Milestone = x.Milestone;
Labels = x.Labels.ToArray();
Content = x.Body;
IsOpen = string.Equals(x.State, "open");
});
}
示例3: UserItemViewModel
internal UserItemViewModel(string name, string avatarUrl, bool organization, Action gotoAction)
{
Name = name;
Avatar = new GitHubAvatar(avatarUrl);
IsOrganization = organization;
GoToCommand = ReactiveCommand.Create().WithSubscription(_ => gotoAction());
}
示例4: ReadmeViewModel
public ReadmeViewModel(
ISessionService applicationService,
IActionMenuFactory actionMenuService)
{
Title = "Readme";
var nonNullContentModel = this.WhenAnyValue(x => x.ContentModel).Select(x => x != null);
ShareCommand = ReactiveCommand.Create(nonNullContentModel);
ShareCommand.Subscribe(sender => actionMenuService.ShareUrl(sender, ContentModel.HtmlUrl));
GoToGitHubCommand = ReactiveCommand.Create(nonNullContentModel);
GoToGitHubCommand.Select(_ => ContentModel.HtmlUrl).Subscribe(GoToWebBrowser);
GoToLinkCommand = ReactiveCommand.Create();
GoToLinkCommand.OfType<string>().Subscribe(x => GoToWebBrowser(new Uri(x)));
ShowMenuCommand = ReactiveCommand.CreateAsyncTask(nonNullContentModel, sender => {
var menu = actionMenuService.Create();
menu.AddButton("Share", ShareCommand);
menu.AddButton("Show in GitHub", GoToGitHubCommand);
return menu.Show(sender);
});
LoadCommand = ReactiveCommand.CreateAsyncTask(x => {
var contentTask = applicationService.GitHubClient.Repository.Content.GetReadmeHtml(RepositoryOwner, RepositoryName)
.ContinueWith(t => ContentText = t.Result, TaskScheduler.FromCurrentSynchronizationContext());
var modelTask = applicationService.GitHubClient.Repository.Content.GetReadme(RepositoryOwner, RepositoryName)
.ContinueWith(t => ContentModel = t.Result, TaskScheduler.FromCurrentSynchronizationContext());
return Task.WhenAll(contentTask, modelTask);
});
}
示例5: EditSourceViewModel
public EditSourceViewModel(IApplicationService applicationService)
{
SaveCommand = new ReactiveCommand();
SaveCommand.Subscribe(_ =>
{
var vm = CreateViewModel<CommitMessageViewModel>();
vm.SaveCommand.RegisterAsyncTask(async t =>
{
var request = applicationService.Client.Users[Username].Repositories[Repository]
.UpdateContentFile(Path, vm.Message, Text, BlobSha, Branch);
var response = await applicationService.Client.ExecuteAsync(request);
Content = response.Data;
DismissCommand.ExecuteIfCan();
});
ShowViewModel(vm);
});
LoadCommand.RegisterAsyncTask(async t =>
{
var path = Path;
if (!path.StartsWith("/", StringComparison.Ordinal))
path = "/" + path;
var request = applicationService.Client.Users[Username].Repositories[Repository].GetContentFile(path, Branch ?? "master");
request.UseCache = false;
var data = await applicationService.Client.ExecuteAsync(request);
BlobSha = data.Data.Sha;
Text = System.Text.Encoding.UTF8.GetString(Convert.FromBase64String(data.Data.Content));
});
}
示例6: IssueLabelsViewModel
public IssueLabelsViewModel(Func<Task<IReadOnlyList<Label>>> loadLabels)
{
var labels = new ReactiveList<Label>();
Selected = new ReactiveList<Label>();
Labels = labels.CreateDerivedCollection(x =>
{
var vm = new IssueLabelItemViewModel(x);
vm.IsSelected = Selected.Any(y => string.Equals(y.Name, x.Name));
// vm.GoToCommand
// .Select(_ => x)
// .Where(y => vm.IsSelected)
// .Where(y => Selected.All(l => l.Url != y.Url))
// .Subscribe(Selected.Add);
// vm.GoToCommand
// .Select(_ => x)
// .Where(y => !vm.IsSelected)
// .Select(y => Selected.Where(l => l.Url == y.Url).ToArray())
// .Subscribe(Selected.RemoveAll);
return vm;
});
SelectLabelsCommand = ReactiveCommand.CreateAsyncTask(t => {
var selectedLabelsUrl = Selected.Select(x => x.Url).ToArray();
var prevSelectedLabelsUrl = _previouslySelectedLabels.Select(x => x.Url).ToArray();
var intersect = selectedLabelsUrl.Intersect(prevSelectedLabelsUrl).ToArray();
var different = selectedLabelsUrl.Length != prevSelectedLabelsUrl.Length || intersect.Length != selectedLabelsUrl.Length;
return Task.FromResult(0); //different ? updateIssue(new ReadOnlyCollection<Label>(Selected)) : Task.FromResult(0);
});
LoadCommand = ReactiveCommand.CreateAsyncTask(async _ => {
labels.Reset(await loadLabels());
});
}
示例7: IssueMilestonesViewModel
public IssueMilestonesViewModel(
Func<Task<IReadOnlyList<Milestone>>> loadMilestones,
Func<Task<Milestone>> loadSelectedFunc,
Func<Milestone, Task> saveFunc)
{
var milestones = new ReactiveList<Milestone>();
Milestones = milestones.CreateDerivedCollection(x => CreateItemViewModel(x));
this.WhenAnyValue(x => x.Selected)
.Subscribe(x => {
foreach (var a in Milestones)
a.IsSelected = a.Number == x?.Number;
});
DismissCommand = ReactiveCommand.Create();
SaveCommand = ReactiveCommand.CreateAsyncTask(_ => {
DismissCommand.ExecuteIfCan();
return _selected != _previouslySelected ? saveFunc(_selected) : Task.FromResult(0);
});
LoadCommand = ReactiveCommand.CreateAsyncTask(async _ => {
_previouslySelected = Selected = await loadSelectedFunc();
milestones.Reset(await loadMilestones());
});
}
示例8: IssueMilestonesViewModel
public IssueMilestonesViewModel(IApplicationService applicationService)
{
Milestones = new ReactiveCollection<MilestoneModel>();
SelectMilestoneCommand = new ReactiveCommand();
SelectMilestoneCommand.RegisterAsyncTask(async t =>
{
var milestone = t as MilestoneModel;
if (milestone != null)
SelectedMilestone = milestone;
if (SaveOnSelect)
{
try
{
int? milestoneNumber = null;
if (SelectedMilestone != null) milestoneNumber = SelectedMilestone.Number;
var updateReq = applicationService.Client.Users[RepositoryOwner].Repositories[RepositoryName].Issues[IssueId].UpdateMilestone(milestoneNumber);
await applicationService.Client.ExecuteAsync(updateReq);
}
catch (Exception e)
{
throw new Exception("Unable to to save milestone! Please try again.", e);
}
}
DismissCommand.ExecuteIfCan();
});
LoadCommand.RegisterAsyncTask(t =>
Milestones.SimpleCollectionLoad(
applicationService.Client.Users[RepositoryOwner].Repositories[RepositoryName].Milestones.GetAll(),
t as bool?));
}
示例9: ReleaseItemViewModel
internal ReleaseItemViewModel(Octokit.Release release)
{
Id = release.Id;
Created = ((release.PublishedAt.HasValue ? release.PublishedAt.Value : release.CreatedAt).LocalDateTime).Humanize();
Name = string.IsNullOrEmpty(release.Name) ? release.TagName : release.Name;
GoToCommand = ReactiveCommand.Create();
}
示例10: MarkdownAccessoryViewModel
public MarkdownAccessoryViewModel(
IImgurService imgurService,
IMediaPickerFactory mediaPicker,
IAlertDialogFactory alertDialogFactory,
IDefaultValueService defaultValueService)
{
PostToImgurCommand = ReactiveCommand.CreateAsyncTask(async _ => {
if (!defaultValueService.GetOrDefault(IMGUR_UPLOAD_WARN, false))
{
defaultValueService.Set(IMGUR_UPLOAD_WARN, true);
await alertDialogFactory.Alert("Please Read!", IMGUR_UPLOAD_WARN_MESSAGE);
}
var photo = await mediaPicker.PickPhoto();
var memoryStream = new MemoryStream();
await photo.Save(Splat.CompressedBitmapFormat.Jpeg, 0.8f, memoryStream);
using (alertDialogFactory.Activate("Uploading..."))
{
var model = await imgurService.SendImage(memoryStream.ToArray());
if (model == null || model.Data == null || model.Data.Link == null)
throw new InvalidOperationException("Unable to upload to Imgur. Please try again later.");
return model.Data.Link;
}
});
PostToImgurCommand.ThrownExceptions
.Where(x => !(x is TaskCanceledException))
.Subscribe(x => alertDialogFactory.Alert("Upload Error", x.Message));
}
示例11: GistViewableFileViewModel
public GistViewableFileViewModel(IApplicationService applicationService, IFilesystemService filesystemService)
{
GoToFileSourceCommand = ReactiveCommand.Create();
LoadCommand = ReactiveCommand.CreateAsyncTask(async t =>
{
string data;
using (var ms = new System.IO.MemoryStream())
{
await applicationService.Client.DownloadRawResource(GistFile.RawUrl, ms);
ms.Position = 0;
var sr = new System.IO.StreamReader(ms);
data = sr.ReadToEnd();
}
if (GistFile.Language.Equals("Markdown"))
data = await applicationService.Client.Markdown.GetMarkdown(data);
string path;
using (var stream = filesystemService.CreateTempFile(out path, "gist.html"))
{
using (var fs = new System.IO.StreamWriter(stream))
{
fs.Write(data);
}
}
FilePath = path;
});
}
示例12: MyIssuesViewModel
public MyIssuesViewModel(ISessionService sessionService)
: base(sessionService)
{
_sessionService = sessionService;
Title = "My Issues";
Filter = MyIssuesFilterModel.CreateOpenFilter();
_selectedFilter = this.WhenAnyValue(x => x.Filter)
.Select(x =>
{
if (x == null || _openFilter.Equals(x))
return 0;
return _closedFilter.Equals(x) ? 1 : -1;
})
.ToProperty(this, x => x.SelectedFilter);
this.WhenAnyValue(x => x.Filter).Skip(1).Subscribe(filter => {
InternalItems.Clear();
LoadCommand.ExecuteIfCan();
CustomFilterEnabled = !(filter == _closedFilter || filter == _openFilter);
});
GoToFilterCommand = ReactiveCommand.Create();
GoToFilterCommand.Subscribe(_ => {
var vm = this.CreateViewModel<MyIssuesFilterViewModel>();
vm.Init(Filter);
vm.SaveCommand.Subscribe(filter => Filter = filter);
NavigateTo(vm);
});
}
示例13: AccountsViewModel
public AccountsViewModel(ISessionService sessionService, IAccountsRepository accountsRepository)
{
_accountsRepository = accountsRepository;
_sessionService = sessionService;
Title = "Accounts";
Accounts = _accounts.CreateDerivedCollection(CreateAccountItem);
this.WhenAnyValue(x => x.ActiveAccount)
.Select(x => x == null ? string.Empty : x.Key)
.Subscribe(x =>
{
foreach (var account in Accounts)
account.Selected = account.Id == x;
});
var canDismiss = this.WhenAnyValue(x => x.ActiveAccount).Select(x => x != null);
DismissCommand = ReactiveCommand.Create(canDismiss).WithSubscription(x => Dismiss());
GoToAddAccountCommand = ReactiveCommand.Create()
.WithSubscription(_ => NavigateTo(this.CreateViewModel<NewAccountViewModel>()));
// Activate immediately since WhenActivated triggers off Did* instead of Will* in iOS
UpdateAccounts();
this.WhenActivated(d => UpdateAccounts());
}
示例14: PullRequestsViewModel
public PullRequestsViewModel(IApplicationService applicationService)
{
PullRequests = new ReactiveList<PullRequestModel>();
GoToPullRequestCommand = ReactiveCommand.Create();
GoToPullRequestCommand.OfType<PullRequestModel>().Subscribe(pullRequest =>
{
var vm = CreateViewModel<PullRequestViewModel>();
vm.RepositoryOwner = RepositoryOwner;
vm.RepositoryName = RepositoryName;
vm.PullRequestId = pullRequest.Number;
vm.PullRequest = pullRequest;
vm.WhenAnyValue(x => x.PullRequest).Skip(1).Subscribe(x =>
{
var index = PullRequests.IndexOf(pullRequest);
if (index < 0) return;
PullRequests[index] = x;
PullRequests.Reset();
});
ShowViewModel(vm);
});
this.WhenAnyValue(x => x.SelectedFilter).Skip(1).Subscribe(_ => LoadCommand.ExecuteIfCan());
LoadCommand = ReactiveCommand.CreateAsyncTask(t =>
{
var state = SelectedFilter == 0 ? "open" : "closed";
var request = applicationService.Client.Users[RepositoryOwner].Repositories[RepositoryName].PullRequests.GetAll(state: state);
return PullRequests.SimpleCollectionLoad(request, t as bool?);
});
}
示例15: IssueAssignedToViewModel
public IssueAssignedToViewModel(IApplicationService applicationService)
{
_applicationService = applicationService;
Users = new ReactiveCollection<BasicUserModel>();
SelectUserCommand = new ReactiveCommand();
SelectUserCommand.RegisterAsyncTask(async t =>
{
var selectedUser = t as BasicUserModel;
if (selectedUser != null)
SelectedUser = selectedUser;
if (SaveOnSelect)
{
var assignee = SelectedUser != null ? SelectedUser.Login : null;
var updateReq = _applicationService.Client.Users[RepositoryOwner].Repositories[RepositoryName].Issues[IssueId].UpdateAssignee(assignee);
await _applicationService.Client.ExecuteAsync(updateReq);
}
DismissCommand.ExecuteIfCan();
});
LoadCommand.RegisterAsyncTask(t =>
Users.SimpleCollectionLoad(applicationService.Client.Users[RepositoryOwner].Repositories[RepositoryName].GetAssignees(), t as bool?));
}