本文整理汇总了C#中IReactiveCommand.OfType方法的典型用法代码示例。如果您正苦于以下问题:C# IReactiveCommand.OfType方法的具体用法?C# IReactiveCommand.OfType怎么用?C# IReactiveCommand.OfType使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IReactiveCommand
的用法示例。
在下文中一共展示了IReactiveCommand.OfType方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: BranchesAndTagsViewModel
public BranchesAndTagsViewModel(IApplicationService applicationService)
{
Items = new ReactiveCollection<ViewObject>();
GoToSourceCommand = new ReactiveCommand();
GoToSourceCommand.OfType<BranchModel>().Subscribe(x =>
{
var vm = CreateViewModel<SourceTreeViewModel>();
vm.Username = RepositoryOwner;
vm.Repository = RepositoryName;
vm.Branch = x.Name;
vm.TrueBranch = true;
ShowViewModel(vm);
});
GoToSourceCommand.OfType<TagModel>().Subscribe(x =>
{
var vm = CreateViewModel<SourceTreeViewModel>();
vm.Username = RepositoryOwner;
vm.Repository = RepositoryName;
vm.Branch = x.Commit.Sha;
ShowViewModel(vm);
});
this.WhenAnyValue(x => x.SelectedFilter).Skip(1).Subscribe(_ => LoadCommand.ExecuteIfCan());
LoadCommand.RegisterAsyncTask(t =>
{
if (SelectedFilter == ShowIndex.Branches)
{
var request = applicationService.Client.Users[RepositoryOwner].Repositories[RepositoryName].GetBranches();
return this.RequestModel(request, t as bool?, response =>
{
this.CreateMore(response, m => Items.MoreTask = m, d => Items.AddRange(d.Where(x => x != null).Select(x => new ViewObject { Name = x.Name, Object = x })));
Items.Reset(response.Data.Where(x => x != null).Select(x => new ViewObject { Name = x.Name, Object = x }));
});
}
else
{
var request = applicationService.Client.Users[RepositoryOwner].Repositories[RepositoryName].GetTags();
return this.RequestModel(request, t as bool?, response =>
{
this.CreateMore(response, m => Items.MoreTask = m, d => Items.AddRange(d.Where(x => x != null).Select(x => new ViewObject { Name = x.Name, Object = x })));
Items.Reset(response.Data.Where(x => x != null).Select(x => new ViewObject { Name = x.Name, Object = x }));
});
}
});
}
示例2: 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?));
}
示例3: PullRequestsViewModel
public PullRequestsViewModel(IApplicationService applicationService)
{
PullRequests = new ReactiveCollection<PullRequestModel>();
GoToPullRequestCommand = new ReactiveCommand();
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.RegisterAsyncTask(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?);
});
}
示例4: BaseUserCollectionViewModel
protected BaseUserCollectionViewModel()
{
Users = new ReactiveCollection<BasicUserModel>();
GoToUserCommand = new ReactiveCommand();
GoToUserCommand.OfType<BasicUserModel>().Subscribe(x =>
{
var vm = CreateViewModel<ProfileViewModel>();
vm.Username = x.Login;
ShowViewModel(vm);
});
}
示例5: TeamsViewModel
public TeamsViewModel(IApplicationService applicationService)
{
Teams = new ReactiveCollection<TeamShortModel>();
GoToTeamCommand = new ReactiveCommand();
GoToTeamCommand.OfType<TeamShortModel>().Subscribe(x =>
{
var vm = CreateViewModel<TeamMembersViewModel>();
vm.Id = x.Id;
ShowViewModel(vm);
});
LoadCommand.RegisterAsyncTask(x =>
Teams.SimpleCollectionLoad(applicationService.Client.Organizations[OrganizationName].GetTeams(), x as bool?));
}
示例6: GistsViewModel
protected GistsViewModel()
{
Gists = new ReactiveCollection<GistModel>();
GoToGistCommand = new ReactiveCommand();
GoToGistCommand.OfType<GistModel>().Subscribe(x =>
{
var vm = CreateViewModel<GistViewModel>();
vm.Id = x.Id;
vm.Gist = x;
ShowViewModel(vm);
});
LoadCommand.RegisterAsyncTask(t => Gists.SimpleCollectionLoad(CreateRequest(), t as bool?));
}
示例7: OrganizationsViewModel
public OrganizationsViewModel(IApplicationService applicationService)
{
Organizations = new ReactiveCollection<BasicUserModel>();
GoToOrganizationCommand = new ReactiveCommand();
GoToOrganizationCommand.OfType<BasicUserModel>().Subscribe(x =>
{
var vm = CreateViewModel<OrganizationViewModel>();
vm.Name = x.Login;
ShowViewModel(vm);
});
LoadCommand.RegisterAsyncTask(t =>
Organizations.SimpleCollectionLoad(applicationService.Client.Users[Username].GetOrganizations(),
t as bool?));
}
示例8: ChangesetBranchesViewModel
public ChangesetBranchesViewModel(IApplicationService applicationService)
{
Branches = new ReactiveCollection<BranchModel>();
GoToBranchCommand = new ReactiveCommand();
GoToBranchCommand.OfType<BranchModel>().Subscribe(x =>
{
var vm = CreateViewModel<ChangesetsViewModel>();
vm.RepositoryOwner = RepositoryOwner;
vm.RepositoryName = RepositoryName;
ShowViewModel(vm);
});
LoadCommand.RegisterAsyncTask(t =>
Branches.SimpleCollectionLoad(
applicationService.Client.Users[RepositoryOwner].Repositories[RepositoryName].GetBranches(), t as bool?));
}
示例9: AccountsViewModel
public AccountsViewModel(IAccountsService accountsService)
{
_accountsService = accountsService;
_accounts = new ReactiveList<GitHubAccount>(accountsService.OrderBy(x => x.Username));
this.WhenActivated(d => _accounts.Reset(accountsService.OrderBy(x => x.Username)));
Accounts = _accounts.CreateDerivedCollection(CreateAccountItem);
this.WhenAnyValue(x => x.ActiveAccount)
.Subscribe(x =>
{
foreach (var account in Accounts)
account.Selected = Equals(account.Account, x);
});
DeleteAccountCommand = ReactiveCommand.Create();
DeleteAccountCommand.OfType<GitHubAccount>().Subscribe(x =>
{
if (Equals(accountsService.ActiveAccount, x))
ActiveAccount = null;
accountsService.Remove(x);
_accounts.Remove(x);
});
LoginCommand = ReactiveCommand.Create();
LoginCommand.OfType<GitHubAccount>().Subscribe(x =>
{
if (Equals(accountsService.ActiveAccount, x))
DismissCommand.ExecuteIfCan();
else
{
ActiveAccount = x;
MessageBus.Current.SendMessage(new LogoutMessage());
DismissCommand.ExecuteIfCan();
}
});
DismissCommand = ReactiveCommand.Create(this.WhenAnyValue(x => x.ActiveAccount).Select(x => x != null))
.WithSubscription(x => base.DismissCommand.ExecuteIfCan(x));
GoToAddAccountCommand = ReactiveCommand.Create()
.WithSubscription(_ => ShowViewModel(CreateViewModel<NewAccountViewModel>()));
}
示例10: RepositoriesViewModel
protected RepositoriesViewModel(IApplicationService applicationService, string filterKey = "RepositoryController")
{
ApplicationService = applicationService;
Repositories = new ReactiveCollection<RepositoryModel>();
Filter = applicationService.Account.Filters.GetFilter<RepositoriesFilterModel>(filterKey);
GoToRepositoryCommand = new ReactiveCommand();
GoToRepositoryCommand.OfType<RepositoryModel>().Subscribe(x =>
{
var vm = CreateViewModel<RepositoryViewModel>();
vm.RepositoryOwner = x.Owner.Login;
vm.RepositoryName = x.Name;
ShowViewModel(vm);
});
this.WhenAnyValue(x => x.Filter).Skip(1).Subscribe(_ => LoadCommand.ExecuteIfCan());
// _repositories.FilteringFunction = x => Repositories.Filter.Ascending ? x.OrderBy(y => y.Name) : x.OrderByDescending(y => y.Name);
// _repositories.GroupingFunction = CreateGroupedItems;
}
示例11: RepositoriesTrendingViewModel
public RepositoriesTrendingViewModel(IApplicationService applicationService, IJsonHttpClientService jsonHttpClient)
{
_applicationService = applicationService;
_jsonHttpClient = jsonHttpClient;
Languages = new ReactiveList<LanguageModel>();
Repositories = new ReactiveCollection<RepositoryModel>();
GoToRepositoryCommand = new ReactiveCommand();
GoToRepositoryCommand.OfType<RepositoryModel>().Subscribe(x =>
{
var vm = CreateViewModel<RepositoryViewModel>();
vm.RepositoryOwner = x.Owner;
vm.RepositoryName = x.Name;
ShowViewModel(vm);
});
SelectedTime = Times[0];
SelectedLanguage = _defaultLanguage;
GetLanguages().FireAndForget();
this.WhenAnyValue(x => x.SelectedTime, x => x.SelectedLanguage, (x, y) => Unit.Default)
.Skip(1).Subscribe(_ => LoadCommand.ExecuteIfCan());
LoadCommand.RegisterAsyncTask(async t =>
{
var query = "?";
if (SelectedLanguage != null && SelectedLanguage.Slug != null)
query += string.Format("language={0}&", SelectedLanguage.Slug);
if (SelectedTime != null && SelectedTime.Slug != null)
query += string.Format("since={0}", SelectedTime.Slug);
var repos = await _jsonHttpClient.Get<List<RepositoryModel>>(TrendingUrl + query);
Repositories.Reset(repos);
});
}
示例12: SourceTreeViewModel
public SourceTreeViewModel(IApplicationService applicationService)
{
Filter = applicationService.Account.Filters.GetFilter<SourceFilterModel>("SourceViewModel");
Content = new ReactiveCollection<ContentModel>();
GoToSubmoduleCommand = new ReactiveCommand();
GoToSubmoduleCommand.OfType<ContentModel>().Subscribe(x =>
{
var nameAndSlug = x.GitUrl.Substring(x.GitUrl.IndexOf("/repos/", StringComparison.OrdinalIgnoreCase) + 7);
var repoId = new RepositoryIdentifier(nameAndSlug.Substring(0, nameAndSlug.IndexOf("/git", StringComparison.OrdinalIgnoreCase)));
var vm = CreateViewModel<SourceTreeViewModel>();
vm.Username = repoId.Owner;
vm.Repository = repoId.Name;
vm.Branch = x.Sha;
ShowViewModel(vm);
});
GoToSourceCommand = new ReactiveCommand();
GoToSourceCommand.OfType<ContentModel>().Subscribe(x =>
{
var otherFiles = Content
.Where(y => string.Equals(y.Type, "file", StringComparison.OrdinalIgnoreCase))
.Where(y => y.Size.HasValue && y.Size.Value > 0)
.Select(y => new SourceViewModel.SourceItemModel
{
Name = y.Name,
Path = y.Path,
HtmlUrl = y.HtmlUrl,
GitUrl = y.GitUrl
}).ToArray();
var navObject = new SourceViewModel.NavObject
{
Branch = Branch,
Username = Username,
Repository = Repository,
TrueBranch = TrueBranch,
Items = otherFiles,
CurrentItemIndex = Array.FindIndex(otherFiles, f => string.Equals(f.GitUrl, x.GitUrl, StringComparison.OrdinalIgnoreCase))
};
var vm = CreateViewModel<SourceViewModel>(navObject);
ShowViewModel(vm);
});
GoToSourceTreeCommand = new ReactiveCommand();
GoToSourceTreeCommand.OfType<ContentModel>().Subscribe(x =>
{
var vm = CreateViewModel<SourceTreeViewModel>();
vm.Username = Username;
vm.Branch = Branch;
vm.Repository = Repository;
vm.TrueBranch = TrueBranch;
vm.Path = x.Path;
ShowViewModel(vm);
});
this.WhenAnyValue(x => x.Filter).Subscribe(filter =>
{
if (filter == null)
{
Content.OrderFunc = null;
}
else
{
Content.OrderFunc = x =>
{
switch (filter.OrderBy)
{
case SourceFilterModel.Order.FoldersThenFiles:
x = x.OrderBy(y => y.Type).ThenBy(y => y.Name);
break;
default:
x = x.OrderBy(y => y.Name);
break;
}
return filter.Ascending ? x : x.Reverse();
};
}
});
LoadCommand.RegisterAsyncTask(t =>
Content.SimpleCollectionLoad(
applicationService.Client.Users[Username].Repositories[Repository].GetContent(
Path ?? string.Empty, Branch ?? "master"), t as bool?));
}
示例13: NotificationsViewModel
public NotificationsViewModel(IApplicationService applicationService)
{
_applicationService = applicationService;
Notifications = new ReactiveCollection<NotificationModel> {GroupFunc = x => x.Repository.FullName};
LoadCommand.RegisterAsyncTask(t =>
{
var req = applicationService.Client.Notifications.GetAll(all: Filter.All, participating: Filter.Participating);
return this.RequestModel(req, t as bool?, response => Notifications.Reset(response.Data));
});
GoToNotificationCommand = new ReactiveCommand();
GoToNotificationCommand.OfType<NotificationModel>().Subscribe(GoToNotification);
ReadAllCommand = new ReactiveCommand(this.WhenAnyValue(x => x.ShownIndex, x => x != 2));
ReadAllCommand.RegisterAsyncTask(async t =>
{
try
{
if (!Notifications.Any()) return;
await applicationService.Client.ExecuteAsync(applicationService.Client.Notifications.MarkAsRead());
Notifications.Clear();
}
catch (Exception e)
{
throw new Exception("Unable to mark all notifications as read. Please try again.", e);
}
});
ReadRepositoriesCommand = new ReactiveCommand();
ReadRepositoriesCommand.RegisterAsyncTask(async t =>
{
try
{
var repo = t as string;
if (repo == null) return;
var repoId = new CodeFramework.Core.Utils.RepositoryIdentifier(repo);
await applicationService.Client.ExecuteAsync(applicationService.Client.Notifications.MarkRepoAsRead(repoId.Owner, repoId.Name));
Notifications.RemoveAll(Notifications.Where(x => string.Equals(x.Repository.FullName, repo, StringComparison.OrdinalIgnoreCase)).ToList());
}
catch (Exception e)
{
throw new Exception("Unable to mark repositories' notifications as read. Please try again.", e);
}
});
this.WhenAnyValue(x => x.ShownIndex).Subscribe(x =>
{
switch (x)
{
case 0:
Filter = NotificationsFilterModel.CreateUnreadFilter();
break;
case 1:
Filter = NotificationsFilterModel.CreateParticipatingFilter();
break;
default:
Filter = NotificationsFilterModel.CreateAllFilter();
break;
}
});
this.WhenAnyValue(x => x.Filter).Skip(1).Subscribe(x => LoadCommand.ExecuteIfCan());
}
示例14: NotificationsViewModel
public NotificationsViewModel(IApplicationService applicationService)
{
_applicationService = applicationService;
var whenNotificationsChange =
_notifications.Changed.Select(_ => Unit.Default)
.Merge(_notifications.ItemChanged.Select(_ => Unit.Default));
_groupedNotifications = whenNotificationsChange.Select(_ =>
_notifications.GroupBy(x => x.Repository.FullName)
.Select(x => new NotificationGroupViewModel(x.Key, new ReactiveList<NotificationModel>(x), __ => { })))
.ToProperty(this, t => t.GroupedNotifications);
LoadCommand = ReactiveCommand.CreateAsyncTask(t =>
{
var req = applicationService.Client.Notifications.GetAll(all: Filter.All, participating: Filter.Participating);
return this.RequestModel(req, t as bool?, response => _notifications.Reset(response.Data));
});
GoToNotificationCommand = ReactiveCommand.Create();
GoToNotificationCommand.OfType<NotificationModel>().Subscribe(GoToNotification);
var canReadAll = _notifications.CountChanged.Select(x => x > 0).CombineLatest(
this.WhenAnyValue(x => x.ShownIndex).Select(x => x != 2), (x, y) => x & y);
ReadAllCommand = ReactiveCommand.CreateAsyncTask(canReadAll, async t =>
{
try
{
if (!_notifications.Any())
return;
await applicationService.Client.ExecuteAsync(applicationService.Client.Notifications.MarkAsRead());
_notifications.Clear();
}
catch (Exception e)
{
throw new Exception("Unable to mark all notifications as read. Please try again.", e);
}
});
ReadRepositoriesCommand = ReactiveCommand.CreateAsyncTask(async t =>
{
try
{
var repo = t as string;
if (repo == null) return;
var repoId = new RepositoryIdentifier(repo);
await applicationService.Client.ExecuteAsync(applicationService.Client.Notifications.MarkRepoAsRead(repoId.Owner, repoId.Name));
_notifications.RemoveAll(_notifications.Where(x => string.Equals(x.Repository.FullName, repo, StringComparison.OrdinalIgnoreCase)).ToList());
}
catch (Exception e)
{
throw new Exception("Unable to mark repositories' notifications as read. Please try again.", e);
}
});
this.WhenAnyValue(x => x.ShownIndex).Subscribe(x =>
{
switch (x)
{
case 0:
Filter = NotificationsFilterModel.CreateUnreadFilter();
break;
case 1:
Filter = NotificationsFilterModel.CreateParticipatingFilter();
break;
default:
Filter = NotificationsFilterModel.CreateAllFilter();
break;
}
});
this.WhenAnyValue(x => x.Filter).Skip(1).Subscribe(x => LoadCommand.ExecuteIfCan());
}