本文整理汇总了C#中IReactiveCommand类的典型用法代码示例。如果您正苦于以下问题:C# IReactiveCommand类的具体用法?C# IReactiveCommand怎么用?C# IReactiveCommand使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
IReactiveCommand类属于命名空间,在下文中一共展示了IReactiveCommand类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C#代码示例。
示例1: GistFileItemViewModel
public GistFileItemViewModel(string name, string content)
{
Name = name;
Content = content;
EditCommand = ReactiveCommand.Create();
DeleteCommand = ReactiveCommand.Create();
}
开发者ID:runt18,项目名称:CodeHub,代码行数:7,代码来源:GistFileItemViewModel.cs
示例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");
});
}
开发者ID:GSerjo,项目名称:CodeHub,代码行数:27,代码来源:IssueEditViewModel.cs
示例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());
}
开发者ID:runt18,项目名称:CodeHub,代码行数:7,代码来源:UserItemViewModel.cs
示例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);
});
}
开发者ID:crazypebble,项目名称:CodeHub,代码行数:34,代码来源:ReadmeViewModel.cs
示例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));
});
}
开发者ID:GSerjo,项目名称:CodeHub,代码行数:30,代码来源:EditSourceViewModel.cs
示例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());
});
}
开发者ID:zdd910,项目名称:CodeHub,代码行数:33,代码来源:IssueLabelsViewModel.cs
示例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());
});
}
开发者ID:runt18,项目名称:CodeHub,代码行数:26,代码来源:IssueMilestonesViewModel.cs
示例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?));
}
开发者ID:GSerjo,项目名称:CodeHub,代码行数:34,代码来源:IssueMilestonesViewModel.cs
示例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();
}
开发者ID:runt18,项目名称:CodeHub,代码行数:7,代码来源:ReleaseItemViewModel.cs
示例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));
}
开发者ID:runt18,项目名称:CodeHub,代码行数:29,代码来源:MarkdownAccessoryViewModel.cs
示例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;
});
}
开发者ID:nelsonnan,项目名称:CodeHub,代码行数:29,代码来源:GistViewableFileViewModel.cs
示例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);
});
}
开发者ID:runt18,项目名称:CodeHub,代码行数:31,代码来源:MyIssuesViewModel.cs
示例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());
}
开发者ID:jianwoo,项目名称:CodeHub,代码行数:27,代码来源:AccountsViewModel.cs
示例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?);
});
}
开发者ID:nelsonnan,项目名称:CodeHub,代码行数:31,代码来源:PullRequestsViewModel.cs
示例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?));
}
开发者ID:GSerjo,项目名称:CodeHub,代码行数:25,代码来源:IssueAssignedToViewModel.cs
示例16: FeedbackComposerViewModel
public FeedbackComposerViewModel(ISessionService applicationService, IAlertDialogFactory alertDialogFactory)
{
this.WhenAnyValue(x => x.IsFeature).Subscribe(x => Title = x ? "New Feature" : "Bug Report");
SubmitCommand = ReactiveCommand.CreateAsyncTask(
this.WhenAnyValue(x => x.Subject).Select(x => !string.IsNullOrEmpty(x)),
async _ =>
{
if (string.IsNullOrEmpty(Subject))
throw new ArgumentException(string.Format("You must provide a title for this {0}!", IsFeature ? "feature" : "bug"));
var labels = await applicationService.GitHubClient.Issue.Labels.GetAllForRepository(CodeHubOwner, CodeHubName);
var createLabels = labels.Where(x => string.Equals(x.Name, IsFeature ? "feature request" : "bug", StringComparison.OrdinalIgnoreCase)).Select(x => x.Name).Distinct();
var createIssueRequest = new Octokit.NewIssue(Subject) { Body = Description };
foreach (var label in createLabels)
createIssueRequest.Labels.Add(label);
var createdIssue = await applicationService.GitHubClient.Issue.Create(CodeHubOwner, CodeHubName, createIssueRequest);
_createdIssueSubject.OnNext(createdIssue);
Dismiss();
});
DismissCommand = ReactiveCommand.CreateAsyncTask(async t =>
{
if (string.IsNullOrEmpty(Description) && string.IsNullOrEmpty(Subject))
return true;
var itemType = IsFeature ? "feature" : "bug";
return await alertDialogFactory.PromptYesNo("Discard " + itemType.Transform(To.TitleCase) + "?", "Are you sure you want to discard this " + itemType + "?");
});
DismissCommand.Where(x => x).Subscribe(_ => Dismiss());
}
开发者ID:runt18,项目名称:CodeHub,代码行数:32,代码来源:FeedbackComposerViewModel.cs
示例17: UserGistsViewModel
public UserGistsViewModel(ISessionService sessionService)
: base(sessionService)
{
_sessionService = sessionService;
Username = _sessionService.Account.Username;
GoToCreateGistCommand = ReactiveCommand.Create();
GoToCreateGistCommand.Subscribe(_ =>
{
var vm = this.CreateViewModel<GistCreateViewModel>();
vm.SaveCommand
.Delay(TimeSpan.FromMilliseconds(200))
.ObserveOn(RxApp.MainThreadScheduler)
.Subscribe(x => InternalItems.Insert(0, x));
NavigateTo(vm);
});
this.WhenAnyValue(x => x.Username).Subscribe(x =>
{
if (IsMine)
Title = "My Gists";
else if (x == null)
Title = "Gists";
else if (x.EndsWith("s", StringComparison.OrdinalIgnoreCase))
Title = x + "' Gists";
else
Title = x + "'s Gists";
});
}
开发者ID:runt18,项目名称:CodeHub,代码行数:29,代码来源:UserGistsViewModel.cs
示例18: PullRequestFilesViewModel
public PullRequestFilesViewModel(IApplicationService applicationService)
{
Files = new ReactiveCollection<CommitModel.CommitFileModel>
{
GroupFunc = y =>
{
var filename = "/" + y.Filename;
return filename.Substring(0, filename.LastIndexOf("/", StringComparison.Ordinal) + 1);
}
};
GoToSourceCommand = new ReactiveCommand();
GoToSourceCommand.OfType<CommitModel.CommitFileModel>().Subscribe(x =>
{
var vm = CreateViewModel<SourceViewModel>();
// vm.Name = x.Filename.Substring(x.Filename.LastIndexOf("/", StringComparison.Ordinal) + 1);
// vm.Path = x.Filename;
// vm.GitUrl = x.ContentsUrl;
// vm.ForceBinary = x.Patch == null;
ShowViewModel(vm);
});
LoadCommand.RegisterAsyncTask(t =>
Files.SimpleCollectionLoad(
applicationService.Client.Users[Username].Repositories[Repository].PullRequests[PullRequestId]
.GetFiles(), t as bool?));
}
开发者ID:GSerjo,项目名称:CodeHub,代码行数:27,代码来源:PullRequestFilesViewModel.cs
示例19: CreateFileViewModel
public CreateFileViewModel(ISessionService sessionService, IAlertDialogFactory alertDialogFactory)
{
Title = "Create File";
this.WhenAnyValue(x => x.Name)
.Subscribe(x => CommitMessage = "Created " + x);
GoToCommitMessageCommand = ReactiveCommand.Create(
this.WhenAnyValue(x => x.Name, x => !string.IsNullOrEmpty(x)));
SaveCommand = ReactiveCommand.CreateAsyncTask(
this.WhenAnyValue(x => x.Name).Select(x => !string.IsNullOrEmpty(x)), async _ => {
var content = Content ?? string.Empty;
var path = System.IO.Path.Combine(Path ?? string.Empty, Name);
var request = new Octokit.CreateFileRequest(CommitMessage, content) { Branch = Branch };
using (alertDialogFactory.Activate("Commiting..."))
return await sessionService.GitHubClient.Repository.Content.CreateFile(RepositoryOwner, RepositoryName, path, request);
});
SaveCommand.Subscribe(x => Dismiss());
DismissCommand = ReactiveCommand.CreateAsyncTask(async t => {
if (string.IsNullOrEmpty(Name) && string.IsNullOrEmpty(Content)) return true;
return await alertDialogFactory.PromptYesNo("Discard File?", "Are you sure you want to discard this file?");
});
DismissCommand.Where(x => x).Subscribe(_ => Dismiss());
}
开发者ID:runt18,项目名称:CodeHub,代码行数:26,代码来源:CreateFileViewModel.cs
示例20: UserItemViewModel
internal UserItemViewModel(string name, string url, bool organization, Action<UserItemViewModel> gotoAction)
{
Name = name;
Url = url;
IsOrganization = organization;
GoToCommand = ReactiveCommand.Create().WithSubscription(x => gotoAction(this));
}
开发者ID:nelsonnan,项目名称:CodeHub,代码行数:7,代码来源:UserItemViewModel.cs
注:本文中的IReactiveCommand类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论