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()); }); }
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)); }); }
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()); }); }
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"); }); }
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(); }
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()); }
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()); }
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"; }); }
public EditSourceViewModel(IApplicationService applicationService) { SaveCommand = ReactiveCommand.Create(); SaveCommand.Subscribe(_ => { var vm = CreateViewModel<CommitMessageViewModel>(); vm.Username = Username; vm.Repository = Repository; vm.Path = Path; vm.Text = Text; vm.BlobSha = BlobSha; vm.Branch = Branch; vm.ContentChanged.Subscribe(x => Content = x); ShowViewModel(vm); }); LoadCommand = ReactiveCommand.CreateAsyncTask(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; var content = Convert.FromBase64String(data.Data.Content); Text = System.Text.Encoding.UTF8.GetString(content, 0, content.Length); }); }
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?)); }
public UpgradesViewModel(IFeaturesService featuresService) { LoadCommand = ReactiveCommand.CreateAsyncTask(async _ => { Keys = (await featuresService.GetAvailableFeatureIds()).ToArray(); }); }
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); }); }
internal UserItemViewModel(string name, string avatarUrl, bool organization, Action gotoAction) { Name = name; Avatar = new GitHubAvatar(avatarUrl); IsOrganization = organization; GoToCommand = ReactiveCommand.Create().WithSubscription(_ => gotoAction()); }
internal UserItemViewModel(string name, string url, bool organization, Action<UserItemViewModel> gotoAction) { Name = name; Url = url; IsOrganization = organization; GoToCommand = ReactiveCommand.Create().WithSubscription(x => gotoAction(this)); }
public IssueLabelsViewModel( Func<Task<IReadOnlyList<Label>>> loadAllLabelsFunc, Func<Task<IReadOnlyList<Label>>> loadSelectedFunc, Func<IEnumerable<Label>, Task> saveLabelsFunc) { var labels = new ReactiveList<Label>(); var selected = new ReactiveList<Label>(); Labels = labels.CreateDerivedCollection(x => { var vm = new IssueLabelItemViewModel(x); vm.IsSelected = selected.Any(y => y.Url == x.Url); return vm; }); SaveCommand = ReactiveCommand.CreateAsyncTask(_ => { var currentlySelected = Labels.Where(x => x.IsSelected).ToList(); var selectedLabelsUrl = currentlySelected.Select(x => x.Label.Url).ToArray(); var prevSelectedLabelsUrl = selected.Select(x => x.Url).ToArray(); var intersect = selectedLabelsUrl.Intersect(prevSelectedLabelsUrl).ToArray(); var different = selectedLabelsUrl.Length != prevSelectedLabelsUrl.Length || intersect.Length != selectedLabelsUrl.Length; return different ? saveLabelsFunc(currentlySelected.Select(x => x.Label)) : Task.FromResult(0); }); LoadCommand = ReactiveCommand.CreateAsyncTask(async _ => { selected.Clear(); selected.AddRange((await loadSelectedFunc()) ?? Enumerable.Empty<Label>()); labels.Reset(await loadAllLabelsFunc()); }); }
public CreateFileViewModel(ISessionService applicationService, IAlertDialogFactory alertDialogFactory) { Title = "Create File"; this.WhenAnyValue(x => x.Name).Subscribe(x => CommitMessage = "Created " + x); _canCommit = this.WhenAnyValue(x => x.Name) .Select(x => !string.IsNullOrEmpty(x)) .ToProperty(this, x => x.CanCommit); SaveCommand = ReactiveCommand.CreateAsyncTask( this.WhenAnyValue(x => x.Name).Select(x => !string.IsNullOrEmpty(x)), async _ => { var content = Content ?? string.Empty; var path = Path; if (string.IsNullOrEmpty(Path)) path = "/"; path = System.IO.Path.Combine(path, Name); var request = applicationService.Client.Users[RepositoryOwner].Repositories[RepositoryName].UpdateContentFile(path, CommitMessage, content, null, Branch); await applicationService.Client.ExecuteAsync(request); 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()); }
public GistFileItemViewModel(string name, string content) { Name = name; Content = content; EditCommand = ReactiveCommand.Create(); DeleteCommand = ReactiveCommand.Create(); }
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?)); }
public IssueAssigneeViewModel( Func<Task<IReadOnlyList<User>>> loadAssignees, Func<Task<User>> loadSelectedFunc, Func<User, Task> saveFunc) { var assignees = new ReactiveList<IssueAssigneeItemViewModel>(); Assignees = assignees.CreateDerivedCollection( x => x, filter: x => x.Name.ContainsKeyword(SearchKeyword), signalReset: this.WhenAnyValue(x => x.SearchKeyword)); this.WhenAnyValue(x => x.Selected) .Subscribe(x => { foreach (var a in Assignees) a.IsSelected = string.Equals(a.User.Login, x?.Login); }); DismissCommand = ReactiveCommand.Create(); SaveCommand = ReactiveCommand.CreateAsyncTask(_ => { DismissCommand.ExecuteIfCan(); return Selected != _previouslySelected ? saveFunc(_selected) : Task.FromResult(0); }); LoadCommand = ReactiveCommand.CreateAsyncTask(async _ => { _previouslySelected = Selected = await loadSelectedFunc(); assignees.Reset((await loadAssignees()).Select(CreateItemViewModel)); }); }
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?)); }
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); }); }
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()); }
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; }); }
public AccountsViewModel(IAccountsService accountsService) { _accountsService = accountsService; Accounts = new ReactiveList<GitHubAccount>(accountsService); LoginCommand = ReactiveCommand.Create(); GoToAddAccountCommand = ReactiveCommand.Create(); DeleteAccountCommand = ReactiveCommand.Create(); DeleteAccountCommand.OfType<GitHubAccount>().Subscribe(x => { if (Equals(accountsService.ActiveAccount, x)) ActiveAccount = null; accountsService.Remove(x); Accounts.Remove(x); }); LoginCommand.OfType<GitHubAccount>().Subscribe(x => { if (Equals(accountsService.ActiveAccount, x)) DismissCommand.ExecuteIfCan(); else { ActiveAccount = x; MessageBus.Current.SendMessage(new LogoutMessage()); DismissCommand.ExecuteIfCan(); } }); GoToAddAccountCommand.Subscribe(_ => ShowViewModel(CreateViewModel<NewAccountViewModel>())); this.WhenActivated(d => Accounts.Reset(accountsService)); }
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?); }); }
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)); }
public ExploreViewModel(ISessionService applicationService) { Title = "Explore"; Repositories = new RepositoryExploreViewModel(applicationService); Users = new UserExploreViewModel(applicationService); SearchCommand = ReactiveCommand.Create(); }
public NotificationsViewModel(ISessionService applicationService) { _applicationService = applicationService; Title = "Notifications"; ReadSelectedCommand = ReactiveCommand.Create().WithSubscription(_ => { if (GroupedNotifications.SelectMany(x => x.Notifications).All(x => !x.IsSelected)) { applicationService.Client.ExecuteAsync(applicationService.Client.Notifications.MarkAsRead()).ToBackground(); _notifications.Clear(); } else { var selected = GroupedNotifications.SelectMany(x => x.Notifications) .Where(x => x.IsSelected && x.Notification.Unread).ToList(); var tasks = selected .Select(t => _applicationService.GitHubClient.Notification.MarkAsRead(int.Parse(t.Id))); Task.WhenAll(tasks).ToBackground(); foreach (var s in selected) _notifications.Remove(s.Notification); } }); _notifications.Changed.Select(_ => Unit.Default) .Merge(_notifications.ItemChanged.Select(_ => Unit.Default)) .Subscribe(_ => { GroupedNotifications = _notifications.GroupBy(x => x.Repository.FullName).Select(x => { var items = x.Select(y => new NotificationItemViewModel(y, GoToNotification)); var notifications = new ReactiveList<NotificationItemViewModel>(items); return new NotificationGroupViewModel(x.Key, notifications); }).ToList(); }); LoadCommand = ReactiveCommand.CreateAsyncTask(async _ => { var all = ActiveFilter == AllFilter; var participating = ActiveFilter == ParticipatingFilter; var req = new Octokit.NotificationsRequest { All = all, Participating = participating, Since = DateTimeOffset.MinValue }; var notifications = await applicationService.GitHubClient.Notification.GetAllForCurrent(req); _notifications.Reset(notifications); }); LoadCommand .Where(_ => ActiveFilter == UnreadFilter) .Select(_ => _notifications.Count) .Subscribe(_notificationCount.OnNext); this.WhenAnyValue(x => x.ActiveFilter).Skip(1).Subscribe(x => { _notifications.Clear(); LoadCommand.ExecuteIfCan(); }); }
public TrayMainWindowViewModel(IViewModel mainArea, TrayMainWindowMenu menu, IStatusViewModel status, LoginInfo loginInfo, IWelcomeViewModel welcomeViewModel) { _mainArea = Consts.FirstRun /* || Cheat.Consts.IsTestVersion */ ? welcomeViewModel : mainArea; _menu = menu; _status = status; _loginInfo = loginInfo; welcomeViewModel.Close.Subscribe(x => MainArea = mainArea); _taskbarToolTip = this.WhenAnyValue(x => x.DisplayName, x => x.Status, FormatTaskbarToolTip) .ToProperty(this, x => x.TitleToolTip); _avatarUrl = this.WhenAnyValue<TrayMainWindowViewModel, Uri, AccountInfo>(x => x.LoginInfo.Account, x => new Uri("http:" + AvatarCalc.GetAvatarURL(x))) .ToProperty(this, x => x.AvatarUrl); _installUpdate = ReactiveCommand.CreateAsyncTask( this.WhenAnyValue(x => x.UpdateState, state => state == AppUpdateState.UpdateAvailable), async x => await RequestAsync(new OpenWebLink(ViewType.Update)).ConfigureAwait(false)) .DefaultSetup("InstallUpdate"); _goAccount = ReactiveCommand.CreateAsyncTask( async x => await RequestAsync(new OpenWebLink(ViewType.Profile)).ConfigureAwait(false)) .DefaultSetup("OpenProfile"); _goPremium = ReactiveCommand.CreateAsyncTask( async x => await RequestAsync( new OpenWebLink(_loginInfo.IsPremium ? ViewType.PremiumAccount : ViewType.GoPremium)) .ConfigureAwait(false)) .DefaultSetup("GoPremium"); IViewModel previousMain = null; _switchQueue = ReactiveCommand.CreateAsyncTask( async x => { if (previousMain == null) { previousMain = _mainArea; MainArea = await RequestAsync(new GetQueue()).ConfigureAwait(false); } else { MainArea = previousMain; previousMain = null; } }); status.SwitchQueue = _switchQueue; // TODO.. Listen<LoginChanged>() .Select(x => x.LoginInfo) .ObserveOnMainThread() .BindTo(this, x => x.LoginInfo); // We need to receive these right away.. // toDO: Think about how to make this only on WhenActivated Listen<AppStateUpdated>() .Select(x => x.UpdateState) .ObserveOnMainThread() .BindTo(this, x => x.UpdateState); }
protected GistFileModifyViewModel(Func<Tuple<string, string>, Task> saveFunc) { var validObservable = this.WhenAnyValue(x => x.Filename, x => x.Description, (x, y) => !string.IsNullOrEmpty(x) && !string.IsNullOrEmpty(y)); SaveCommand = ReactiveCommand.CreateAsyncTask(validObservable, async _ => await saveFunc(Tuple.Create(Filename, Description))); SaveCommand.Subscribe(_ => Dismiss()); }
public void AddButton(string title, IReactiveCommand command) { _buttonActions.Add(Tuple.Create(title, command)); }
public LoadableReactiveList(IReadOnlyReactiveList <T> items, IReactiveCommand <Unit> loadCommand) { Items = items; LoadCommand = loadCommand; loadCommand.Subscribe(_ => Loaded = true); }
public ActionMenuItem(string name, IReactiveCommand command) { Name = name; Command = command; }
public static System.Runtime.CompilerServices.TaskAwaiter <T> GetAwaiter <T>(this IReactiveCommand <T> command) { return(command.WaitUntilExecuteAsync(CancellationToken.None).GetAwaiter()); }
public ReactiveCommandDecorator(IReactiveCommand command) : base(command.CanExecuteObservable, null) { Command = command; }
/// <summary> /// RegisterAsyncTask registers an TPL/Async method that runs when a /// Command gets executed and returns no result. /// </summary> /// <param name="calculationFunc">The function to be run in the /// background.</param> /// <returns>An Observable that signals when the Task completes, on /// the UI thread.</returns> public static IObservable <Unit> RegisterAsyncTask(this IReactiveCommand This, Func <object, Task> calculationFunc) { Contract.Requires(calculationFunc != null); return(This.RegisterAsync(x => calculationFunc(x).ToObservable())); }
public NotificationsViewModel(IApplicationService applicationService) { _applicationService = applicationService; _notifications = new ReactiveList <NotificationModel>(); Notifications = _notifications.CreateDerivedCollection(x => x); 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); ReadAllCommand = ReactiveCommand.CreateAsyncTask( this.WhenAnyValue(x => x.ShownIndex).Select(x => x != 2), 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()); }
public RepositoryViewModel(IApplicationService applicationService, IAccountsService accountsService) { ApplicationService = applicationService; _accountsService = accountsService; ToggleStarCommand = ReactiveCommand.CreateAsyncTask( this.WhenAnyValue(x => x.IsStarred).Select(x => x.HasValue), t => ToggleStar()); ToggleWatchCommand = ReactiveCommand.CreateAsyncTask( this.WhenAnyValue(x => x.IsWatched, x => x.HasValue), t => ToggleWatch()); GoToOwnerCommand = ReactiveCommand.Create(); GoToOwnerCommand.Subscribe(_ => { var vm = CreateViewModel <ProfileViewModel>(); vm.Username = RepositoryOwner; ShowViewModel(vm); }); PinCommand = ReactiveCommand.Create(this.WhenAnyValue(x => x.Repository).Select(x => x != null)); PinCommand.Subscribe(x => PinRepository()); GoToForkParentCommand = ReactiveCommand.Create(this.WhenAnyValue(x => x.Repository, x => x != null && x.Fork && x.Parent != null)); GoToForkParentCommand.Subscribe(x => { var vm = CreateViewModel <RepositoryViewModel>(); vm.RepositoryOwner = Repository.Parent.Owner.Login; vm.RepositoryName = Repository.Parent.Name; vm.Repository = Repository.Parent; ShowViewModel(vm); }); GoToStargazersCommand = ReactiveCommand.Create(); GoToStargazersCommand.Subscribe(_ => { var vm = CreateViewModel <RepositoryStargazersViewModel>(); vm.RepositoryOwner = RepositoryOwner; vm.RepositoryName = RepositoryName; ShowViewModel(vm); }); GoToWatchersCommand = ReactiveCommand.Create(); GoToWatchersCommand.Subscribe(_ => { var vm = CreateViewModel <RepositoryWatchersViewModel>(); vm.RepositoryOwner = RepositoryOwner; vm.RepositoryName = RepositoryName; ShowViewModel(vm); }); GoToEventsCommand = ReactiveCommand.Create(); GoToEventsCommand.Subscribe(_ => { var vm = CreateViewModel <RepositoryEventsViewModel>(); vm.RepositoryOwner = RepositoryOwner; vm.RepositoryName = RepositoryName; ShowViewModel(vm); }); GoToIssuesCommand = ReactiveCommand.Create(); GoToIssuesCommand.Subscribe(_ => { var vm = CreateViewModel <IssuesViewModel>(); vm.RepositoryOwner = RepositoryOwner; vm.RepositoryName = RepositoryName; ShowViewModel(vm); }); GoToReadmeCommand = ReactiveCommand.Create(); GoToReadmeCommand.Subscribe(_ => { var vm = CreateViewModel <ReadmeViewModel>(); vm.RepositoryOwner = RepositoryOwner; vm.RepositoryName = RepositoryName; ShowViewModel(vm); }); GoToCommitsCommand = ReactiveCommand.Create(); GoToCommitsCommand.Subscribe(_ => { if (Branches != null && Branches.Count == 1) { var vm = CreateViewModel <ChangesetsViewModel>(); vm.RepositoryOwner = RepositoryOwner; vm.RepositoryName = RepositoryName; ShowViewModel(vm); } else { var vm = CreateViewModel <ChangesetBranchesViewModel>(); vm.RepositoryOwner = RepositoryOwner; vm.RepositoryName = RepositoryName; ShowViewModel(vm); } }); GoToPullRequestsCommand = ReactiveCommand.Create(); GoToPullRequestsCommand.Subscribe(_ => { var vm = CreateViewModel <PullRequestsViewModel>(); vm.RepositoryOwner = RepositoryOwner; vm.RepositoryName = RepositoryName; ShowViewModel(vm); }); GoToSourceCommand = ReactiveCommand.Create(); GoToSourceCommand.Subscribe(_ => { var vm = CreateViewModel <BranchesAndTagsViewModel>(); vm.RepositoryOwner = RepositoryOwner; vm.RepositoryName = RepositoryName; ShowViewModel(vm); }); GoToCollaboratorsCommand = ReactiveCommand.Create(); GoToCollaboratorsCommand.Subscribe(_ => { var vm = CreateViewModel <RepositoryCollaboratorsViewModel>(); vm.RepositoryOwner = RepositoryOwner; vm.RepositoryName = RepositoryName; ShowViewModel(vm); }); this.WhenAnyValue(x => x.Repository).Subscribe(x => { if (x == null) { RepositorySize = null; } else { if (x.Size / 1024f < 1) { RepositorySize = string.Format("{0:0.##}KB", x.Size); } else if ((x.Size / 1024f / 1024f) < 1) { RepositorySize = string.Format("{0:0.##}MB", x.Size / 1024f); } else { RepositorySize = string.Format("{0:0.##}GB", x.Size / 1024f / 1024f); } } }); GoToHtmlUrlCommand = ReactiveCommand.Create(this.WhenAnyValue(x => x.Repository, x => x != null && !string.IsNullOrEmpty(x.HtmlUrl))); GoToHtmlUrlCommand.Subscribe(_ => GoToUrlCommand.ExecuteIfCan(Repository.HtmlUrl)); LoadCommand = ReactiveCommand.CreateAsyncTask(t => { var forceCacheInvalidation = t as bool?; var t1 = this.RequestModel(ApplicationService.Client.Users[RepositoryOwner].Repositories[RepositoryName].Get(), forceCacheInvalidation, response => Repository = response.Data); this.RequestModel(ApplicationService.Client.Users[RepositoryOwner].Repositories[RepositoryName].GetReadme(), forceCacheInvalidation, response => Readme = response.Data).FireAndForget(); this.RequestModel(ApplicationService.Client.Users[RepositoryOwner].Repositories[RepositoryName].GetBranches(), forceCacheInvalidation, response => Branches = response.Data).FireAndForget(); this.RequestModel(ApplicationService.Client.Users[RepositoryOwner].Repositories[RepositoryName].IsWatching(), forceCacheInvalidation, response => IsWatched = response.Data).FireAndForget(); this.RequestModel(ApplicationService.Client.Users[RepositoryOwner].Repositories[RepositoryName].IsStarred(), forceCacheInvalidation, response => IsStarred = response.Data).FireAndForget(); this.RequestModel(ApplicationService.Client.Users[RepositoryOwner].Repositories[RepositoryName].GetCollaborators(), forceCacheInvalidation, response => Collaborators = response.Data.Count).FireAndForget(); return(t1); }); }
public static UniTask <T> .Awaiter GetAwaiter <T>(this IReactiveCommand <T> command) { return(command.WaitUntilExecuteAsync().GetAwaiter()); }
protected BaseIssueViewModel( ISessionService applicationService, IMarkdownService markdownService, IActionMenuFactory actionMenuFactory, IAlertDialogFactory alertDialogFactory) { _applicationService = applicationService; _markdownService = markdownService; _alertDialogFactory = alertDialogFactory; _assigneesCache = new Lazy <Task <IReadOnlyList <Octokit.User> > >(() => _applicationService.GitHubClient.Issue.Assignee.GetAllForRepository(RepositoryOwner, RepositoryName)); _milestonesCache = new Lazy <Task <IReadOnlyList <Octokit.Milestone> > >(() => _applicationService.GitHubClient.Issue.Milestone.GetAllForRepository(RepositoryOwner, RepositoryName)); _labelsCache = new Lazy <Task <IReadOnlyList <Octokit.Label> > >(() => _applicationService.GitHubClient.Issue.Labels.GetAllForRepository(RepositoryOwner, RepositoryName)); IssueUpdated.Subscribe(x => Issue = x); _avatar = this.WhenAnyValue(x => x.Issue.User.AvatarUrl) .Select(x => new GitHubAvatar(x)) .ToProperty(this, x => x.Avatar); var issuePresenceObservable = this.WhenAnyValue(x => x.Issue, x => x.CanModify) .Select(x => x.Item1 != null && x.Item2); Events = InternalEvents.CreateDerivedCollection(x => x); this.WhenAnyValue(x => x.Issue.Comments) .ToProperty(this, x => x.CommentCount, out _commentsCount); _participants = Events.Changed .Select(_ => Events.Select(y => y.Actor).Distinct().Count()) .Select(x => x == 0 ? 1 : x) .ToProperty(this, x => x.Participants); GoToAssigneesCommand = ReactiveCommand.Create(issuePresenceObservable); GoToLabelsCommand = ReactiveCommand.Create(issuePresenceObservable); GoToMilestonesCommand = ReactiveCommand.Create(issuePresenceObservable); _assignedUser = this.WhenAnyValue(x => x.Issue.Assignee) .ToProperty(this, x => x.AssignedUser); _assignedMilestone = this.WhenAnyValue(x => x.Issue.Milestone) .ToProperty(this, x => x.AssignedMilestone); _assignedLabels = this.WhenAnyValue(x => x.Issue.Labels) .ToProperty(this, x => x.AssignedLabels); _isClosed = this.WhenAnyValue(x => x.Issue.State) .Select(x => x == Octokit.ItemState.Closed) .ToProperty(this, x => x.IsClosed); _markdownDescription = this.WhenAnyValue(x => x.Issue) .Select(x => ((x == null || string.IsNullOrEmpty(x.Body)) ? null : x.Body)) .Where(x => x != null) .Select(x => GetMarkdownDescription().ToObservable()) .Switch() .ToProperty(this, x => x.MarkdownDescription, null, RxApp.MainThreadScheduler); LoadCommand = ReactiveCommand.CreateAsyncTask(t => Load(applicationService)); GoToOwnerCommand = ReactiveCommand.Create(this.WhenAnyValue(x => x.Issue).Select(x => x != null)); GoToOwnerCommand .Select(_ => this.CreateViewModel <UserViewModel>()) .Select(x => x.Init(Issue.User.Login)) .Subscribe(NavigateTo); ToggleStateCommand = ReactiveCommand.CreateAsyncTask(issuePresenceObservable, async t => { try { var updatedIssue = await applicationService.GitHubClient.Issue.Update(RepositoryOwner, RepositoryName, Id, new Octokit.IssueUpdate { State = (Issue.State == Octokit.ItemState.Open) ? Octokit.ItemState.Closed : Octokit.ItemState.Open }); _issueUpdatedObservable.OnNext(updatedIssue); } catch (Exception e) { var close = (Issue.State == Octokit.ItemState.Open) ? "close" : "open"; throw new Exception("Unable to " + close + " the item. " + e.Message, e); } RetrieveEvents().ToBackground(x => InternalEvents.Reset(x)); }); AddCommentCommand = ReactiveCommand.Create().WithSubscription(_ => { var vm = new ComposerViewModel(async s => { var request = applicationService.Client.Users[RepositoryOwner].Repositories[RepositoryName].Issues[Id].CreateComment(s); var comment = (await applicationService.Client.ExecuteAsync(request)).Data; InternalEvents.Add(new IssueCommentItemViewModel(comment)); _commentAddedSubject.OnNext(comment); }, alertDialogFactory); NavigateTo(vm); }); ShowMenuCommand = ReactiveCommand.CreateAsyncTask( this.WhenAnyValue(x => x.Issue).Select(x => x != null), sender => { var menu = actionMenuFactory.Create(); menu.AddButton("Edit", GoToEditCommand); menu.AddButton(Issue.State == Octokit.ItemState.Closed ? "Open" : "Close", ToggleStateCommand); menu.AddButton("Comment", AddCommentCommand); menu.AddButton("Share", ShareCommand); menu.AddButton("Show in GitHub", GoToHtmlUrlCommand); return(menu.Show(sender)); }); GoToEditCommand = ReactiveCommand.Create().WithSubscription(_ => { var vm = this.CreateViewModel <IssueEditViewModel>(); vm.RepositoryOwner = RepositoryOwner; vm.RepositoryName = RepositoryName; vm.Id = Id; vm.Issue = Issue; vm.SaveCommand.Subscribe(_issueUpdatedObservable.OnNext); NavigateTo(vm); }); GoToUrlCommand = ReactiveCommand.Create(); GoToUrlCommand.OfType <string>().Subscribe(GoToUrl); GoToUrlCommand.OfType <Uri>().Subscribe(x => GoToUrl(x.AbsoluteUri)); var hasHtmlObservable = this.WhenAnyValue(x => x.HtmlUrl).Select(x => x != null); ShareCommand = ReactiveCommand.Create(hasHtmlObservable); ShareCommand.Subscribe(sender => actionMenuFactory.ShareUrl(sender, HtmlUrl)); GoToHtmlUrlCommand = ReactiveCommand.Create(hasHtmlObservable); GoToHtmlUrlCommand.Subscribe(_ => GoToUrl(HtmlUrl.AbsoluteUri)); }
public LoginPageViewModel(INavigationService navigationService, IAuthenticationService authenticationService, IOperatingSystemVersionProvider operatingSystemVersionProvider, IDialogService dialogService) : base(navigationService, dialogService) { Title = "登录"; _authenticationService = authenticationService; _operatingSystemVersionProvider = operatingSystemVersionProvider; this.WhenAnyValue( x => x.UserName, x => x.Password, (u, p) => !string.IsNullOrEmpty(u) && !string.IsNullOrEmpty(p)) .Select(x => x) .Subscribe(x => this.IsEnabled = x).DisposeWith(DeactivateWith); #if DEBUG //13883655199 //13379270266 //15139466658 //15332249255 //13379270266 //18191173366 //15319386295 UserName = "******"; Password = "******"; #endif var name = this .WhenAnyValue(x => x.UserName) .Select(x => x == null || CommonHelper.IsPhoneNo(x, true)); var password = this .WhenAnyValue(x => x.Password) .Select(x => x == null || x?.Length >= 6); var agreemented = this .WhenAnyValue(x => x.Agreemented) .Select(x => x); this.AgreementedRule = this.ValidationRule(vm => vm.Agreemented, agreemented, "是否同意并接受云销管理服务协议条款?"); this.NameRule = this.ValidationRule(vm => vm.UserName, name, "用户名不能为空,且必须为手机号."); this.PasswordRule = this.ValidationRule(vm => vm.Password, password, "必须指定一个长度超过6个符号的有效密码."); //检查版本 this.Load = ReactiveCommand.Create(() => { try { CurrentAppVersion = _operatingSystemVersionProvider.GetVersion(); } catch (Exception) { } }); //登录 this.PerformLogin = ReactiveCommand.CreateFromTask <string>(async arg => { if (!AgreementedRule.IsValid) { _dialogService.ShortAlert(AgreementedRule.Message[0]); return; } if (!NameRule.IsValid) { _dialogService.ShortAlert(NameRule.Message[0]); return; } if (!PasswordRule.IsValid) { _dialogService.ShortAlert(PasswordRule.Message[0]); return; } bool isAuthenticated = false; using (var dig = UserDialogs.Instance.Loading("登录中...")) { try { Settings.IsInitData = false; var rcode = await _authenticationService.LoginAsync(UserName, Password); if (rcode == 1) { isAuthenticated = true; Settings.IsAuthenticated = true; } } catch (Exception ex) when(ex is WebException || ex is HttpRequestException) { dig.Hide(); await ShowAlert(false, "认证失败,网络异常!"); return; } catch (Exception) { dig.Hide(); await ShowAlert(false, "认证失败,网络异常!"); return; } //认证成功 if (isAuthenticated) { await this.NavigateAsync($"{nameof(MainLayoutPage)}"); } else { dig.Hide(); await ShowAlert(false, "认证失败,无效账户或错误凭证!"); return; } } }); //免责 this.AgreementedCmd = ReactiveCommand.Create(async() => { await CrossDiaglogKit.Current.PopViewAsync("免责申明", GlobalSettings.AgreementText); }); this.BindBusyCommand(Load); }
// this was my first attempt without actually analyzing the current NavigateCommandFor source public static IReactiveCommand <object> NavigateCommandFor1 <T>(this RoutingState This, IReactiveCommand <object> navigationCommand = null, IDependencyResolver dependencyResolver = null, string contract = null) where T : IRoutableViewModel { navigationCommand = navigationCommand ?? This.Navigate; var ret = ReactiveCommand.CreateAsyncObservable(navigationCommand.CanExecuteObservable, _ => navigationCommand.ExecuteAsync((dependencyResolver ?? Locator.Current).GetService <T>(contract))); return(ret.SubscribeToCommand()); }
// The original source allows for un-registered view models to be new()'d // this extension provides that same ability, but again with a strongly typed return value public static IReactiveCommand <T> NavigateCommandFor4 <T>(this RoutingState This, IReactiveCommand <object> navigationCommand = null, IDependencyResolver dependencyResolver = null, string contract = null) where T : IRoutableViewModel, new() { navigationCommand = navigationCommand ?? This.Navigate; var ret = new ReactiveCommand <T>(navigationCommand.CanExecuteObservable, _ => Observable.Return((T)((IRoutableViewModel)(dependencyResolver ?? Locator.Current).GetService <T>(contract) ?? new T()))); ret.InvokeCommand(navigationCommand); return(ret.SubscribeToCommand()); }
public InstallerVM(MainWindowVM mainWindowVM) { if (Path.GetDirectoryName(Assembly.GetEntryAssembly().Location.ToLower()) == KnownFolders.Downloads.Path.ToLower()) { MessageBox.Show( "Wabbajack is running inside your Downloads folder. This folder is often highly monitored by antivirus software and these can often " + "conflict with the operations Wabbajack needs to perform. Please move this executable outside of your Downloads folder and then restart the app.", "Cannot run inside Downloads", MessageBoxButton.OK, MessageBoxImage.Error); Environment.Exit(1); } MWVM = mainWindowVM; ModListLocation = new FilePickerVM() { ExistCheckOption = FilePickerVM.CheckOptions.On, PathType = FilePickerVM.PathTypeOptions.File, PromptTitle = "Select a modlist to install" }; // Swap to proper sub VM based on selected type _installer = this.WhenAny(x => x.TargetManager) // Delay so the initial VM swap comes in immediately, subVM comes right after .DelayInitial(TimeSpan.FromMilliseconds(50), RxApp.MainThreadScheduler) .Select <ModManager?, ISubInstallerVM>(type => { switch (type) { case ModManager.MO2: return(new MO2InstallerVM(this)); case ModManager.Vortex: return(new VortexInstallerVM(this)); default: return(null); } }) // Unload old VM .Pairwise() .Do(pair => { pair.Previous?.Unload(); }) .Select(p => p.Current) .ToProperty(this, nameof(Installer)); // Load settings MWVM.Settings.SaveSignal .Subscribe(_ => { MWVM.Settings.Installer.LastInstalledListLocation = ModListLocation.TargetPath; }) .DisposeWith(CompositeDisposable); _modList = this.WhenAny(x => x.ModListLocation.TargetPath) .ObserveOn(RxApp.TaskpoolScheduler) .Select(modListPath => { if (modListPath == null) { return(default(ModListVM)); } if (!File.Exists(modListPath)) { return(default(ModListVM)); } return(new ModListVM(modListPath)); }) .ObserveOnGuiThread() .StartWith(default(ModListVM)) .ToProperty(this, nameof(ModList)); _htmlReport = this.WhenAny(x => x.ModList) .Select(modList => modList?.ReportHTML) .ToProperty(this, nameof(HTMLReport)); _installing = this.WhenAny(x => x.Installer.ActiveInstallation) .Select(i => i != null) .ObserveOnGuiThread() .ToProperty(this, nameof(Installing)); _TargetManager = this.WhenAny(x => x.ModList) .Select(modList => modList?.ModManager) .ToProperty(this, nameof(TargetManager)); // Add additional error check on modlist ModListLocation.AdditionalError = this.WhenAny(x => x.ModList) .Select <ModListVM, IErrorResponse>(modList => { if (modList == null) { return(ErrorResponse.Fail("Modlist path resulted in a null object.")); } if (modList.Error != null) { return(ErrorResponse.Fail("Modlist is corrupt", modList.Error)); } return(ErrorResponse.Success); }); BackCommand = ReactiveCommand.Create( execute: () => { StartedInstallation = false; Completed = null; mainWindowVM.ActivePane = mainWindowVM.ModeSelectionVM; }, canExecute: this.WhenAny(x => x.Installing) .Select(x => !x)); _percentCompleted = this.WhenAny(x => x.Installer.ActiveInstallation) .StartWith(default(AInstaller)) .CombineLatest( this.WhenAny(x => x.Completed), (installer, completed) => { if (installer == null) { return(Observable.Return <float>(completed != null ? 1f : 0f)); } return(installer.PercentCompleted.StartWith(0f)); }) .Switch() .Debounce(TimeSpan.FromMilliseconds(25)) .ToProperty(this, nameof(PercentCompleted)); Slideshow = new SlideShow(this); // Set display items to modlist if configuring or complete, // or to the current slideshow data if installing _image = Observable.CombineLatest( this.WhenAny(x => x.ModList.Error), this.WhenAny(x => x.ModList) .Select(x => x?.ImageObservable ?? Observable.Empty <BitmapImage>()) .Switch() .StartWith(WabbajackLogo), this.WhenAny(x => x.Slideshow.Image) .StartWith(default(BitmapImage)), this.WhenAny(x => x.Installing), resultSelector: (err, modList, slideshow, installing) => { if (err != null) { return(WabbajackErrLogo); } var ret = installing ? slideshow : modList; return(ret ?? WabbajackLogo); }) .Select <BitmapImage, ImageSource>(x => x) .ToProperty(this, nameof(Image)); _titleText = Observable.CombineLatest( this.WhenAny(x => x.ModList.Name), this.WhenAny(x => x.Slideshow.TargetMod.ModName) .StartWith(default(string)), this.WhenAny(x => x.Installing), resultSelector: (modList, mod, installing) => installing ? mod : modList) .ToProperty(this, nameof(TitleText)); _authorText = Observable.CombineLatest( this.WhenAny(x => x.ModList.Author), this.WhenAny(x => x.Slideshow.TargetMod.ModAuthor) .StartWith(default(string)), this.WhenAny(x => x.Installing), resultSelector: (modList, mod, installing) => installing ? mod : modList) .ToProperty(this, nameof(AuthorText)); _description = Observable.CombineLatest( this.WhenAny(x => x.ModList.Description), this.WhenAny(x => x.Slideshow.TargetMod.ModDescription) .StartWith(default(string)), this.WhenAny(x => x.Installing), resultSelector: (modList, mod, installing) => installing ? mod : modList) .ToProperty(this, nameof(Description)); _modListName = Observable.CombineLatest( this.WhenAny(x => x.ModList.Error) .Select(x => x != null), this.WhenAny(x => x.ModList) .Select(x => x?.Name), resultSelector: (err, name) => { if (err) { return("Corrupted Modlist"); } return(name); }) .ToProperty(this, nameof(ModListName)); // Define commands ShowReportCommand = ReactiveCommand.Create(ShowReport); OpenReadmeCommand = ReactiveCommand.Create( execute: () => this.ModList?.OpenReadmeWindow(), canExecute: this.WhenAny(x => x.ModList) .Select(modList => !string.IsNullOrEmpty(modList?.Readme)) .ObserveOnGuiThread()); VisitWebsiteCommand = ReactiveCommand.Create( execute: () => Process.Start(ModList.Website), canExecute: this.WhenAny(x => x.ModList.Website) .Select(x => x?.StartsWith("https://") ?? false) .ObserveOnGuiThread()); _progressTitle = Observable.CombineLatest( this.WhenAny(x => x.Installing), this.WhenAny(x => x.StartedInstallation), resultSelector: (installing, started) => { if (!installing) { return("Configuring"); } return(started ? "Installing" : "Installed"); }) .ToProperty(this, nameof(ProgressTitle)); Dictionary <int, CPUDisplayVM> cpuDisplays = new Dictionary <int, CPUDisplayVM>(); // Compile progress updates and populate ObservableCollection this.WhenAny(x => x.Installer.ActiveInstallation) .SelectMany(c => c?.QueueStatus ?? Observable.Empty <CPUStatus>()) .ObserveOn(RxApp.TaskpoolScheduler) // Attach start times to incoming CPU items .Scan( new CPUDisplayVM(), (_, cpu) => { var ret = cpuDisplays.TryCreate(cpu.ID); ret.AbsorbStatus(cpu); return(ret); }) .ToObservableChangeSet(x => x.Status.ID) .Batch(TimeSpan.FromMilliseconds(250), RxApp.TaskpoolScheduler) .EnsureUniqueChanges() .Filter(i => i.Status.IsWorking && i.Status.ID != WorkQueue.UnassignedCpuId) .ObserveOn(RxApp.MainThreadScheduler) .Sort(SortExpressionComparer <CPUDisplayVM> .Ascending(s => s.StartTime)) .Bind(StatusList) .Subscribe() .DisposeWith(CompositeDisposable); BeginCommand = ReactiveCommand.CreateFromTask( canExecute: this.WhenAny(x => x.Installer.CanInstall) .Switch(), execute: async() => { try { await this.Installer.Install(); Completed = ErrorResponse.Success; try { this.ModList?.OpenReadmeWindow(); } catch (Exception ex) { Utils.Error(ex); } } catch (Exception ex) { while (ex.InnerException != null) { ex = ex.InnerException; } Utils.Log(ex.StackTrace); Utils.Log(ex.ToString()); Utils.Log($"{ex.Message} - Can't continue"); Completed = ErrorResponse.Fail(ex); } }); // When sub installer begins an install, mark state variable BeginCommand.StartingExecution() .Subscribe(_ => { StartedInstallation = true; }) .DisposeWith(CompositeDisposable); // Listen for user interventions, and compile a dynamic list of all unhandled ones var activeInterventions = this.WhenAny(x => x.Installer.ActiveInstallation) .SelectMany(c => c?.LogMessages ?? Observable.Empty <IStatusMessage>()) .WhereCastable <IStatusMessage, IUserIntervention>() .ToObservableChangeSet() .AutoRefresh(i => i.Handled) .Filter(i => !i.Handled) .AsObservableList(); // Find the top intervention /w no CPU ID to be marked as "global" _ActiveGlobalUserIntervention = activeInterventions.Connect() .Filter(x => x.CpuID == WorkQueue.UnassignedCpuId) .QueryWhenChanged(query => query.FirstOrDefault()) .ObserveOnGuiThread() .ToProperty(this, nameof(ActiveGlobalUserIntervention)); CloseWhenCompleteCommand = ReactiveCommand.Create( canExecute: this.WhenAny(x => x.Completed) .Select(x => x != null), execute: () => { MWVM.ShutdownApplication(); }); GoToInstallCommand = ReactiveCommand.Create( canExecute: Observable.CombineLatest( this.WhenAny(x => x.Completed) .Select(x => x != null), this.WhenAny(x => x.Installer.SupportsAfterInstallNavigation), resultSelector: (complete, supports) => complete && supports), execute: () => { Installer.AfterInstallNavigation(); }); }
public OrganizationViewModel(IApplicationService applicationService) { _applicationService = applicationService; GoToMembersCommand = ReactiveCommand.Create().WithSubscription(_ => { var vm = CreateViewModel <OrganizationMembersViewModel>(); vm.OrganizationName = Username; ShowViewModel(vm); }); GoToTeamsCommand = ReactiveCommand.Create().WithSubscription(_ => { var vm = CreateViewModel <TeamsViewModel>(); vm.OrganizationName = Username; ShowViewModel(vm); }); GoToFollowersCommand = ReactiveCommand.Create().WithSubscription(_ => { var vm = CreateViewModel <UserFollowersViewModel>(); vm.Username = Username; ShowViewModel(vm); }); GoToFollowingCommand = ReactiveCommand.Create().WithSubscription(_ => { var vm = CreateViewModel <UserFollowingsViewModel>(); vm.Username = Username; ShowViewModel(vm); }); GoToEventsCommand = ReactiveCommand.Create().WithSubscription(_ => { var vm = CreateViewModel <UserEventsViewModel>(); vm.Username = Username; ShowViewModel(vm); }); GoToGistsCommand = ReactiveCommand.Create().WithSubscription(_ => { var vm = CreateViewModel <UserGistsViewModel>(); vm.Username = Username; ShowViewModel(vm); }); GoToRepositoriesCommand = ReactiveCommand.Create().WithSubscription(_ => { var vm = CreateViewModel <OrganizationRepositoriesViewModel>(); vm.Name = Username; ShowViewModel(vm); }); ToggleFollowingCommand = ReactiveCommand.CreateAsyncTask( this.WhenAnyValue(x => x.IsFollowing).Select(x => x.HasValue), async _ => { if (!IsFollowing.HasValue) { return; } if (IsFollowing.Value) { await _applicationService.Client.ExecuteAsync(_applicationService.Client.AuthenticatedUser.Unfollow(Username)); } else { await _applicationService.Client.ExecuteAsync(_applicationService.Client.AuthenticatedUser.Follow(Username)); } IsFollowing = !IsFollowing.Value; }); LoadCommand = ReactiveCommand.CreateAsyncTask(t => { this.RequestModel(applicationService.Client.AuthenticatedUser.IsFollowing(Username), t as bool?, x => IsFollowing = x.Data).FireAndForget(); return(this.RequestModel(applicationService.Client.Organizations[Username].Get(), t as bool?, response => Organization = response.Data)); }); }
public SourceTreeViewModel(ISessionService applicationService) { Branch = "master"; Path = string.Empty; var content = new ReactiveList <ContentModel>(); Content = content.CreateDerivedCollection( x => CreateSourceItemViewModel(x), filter: x => x.Name.ContainsKeyword(SearchKeyword), signalReset: this.WhenAnyValue(x => x.SearchKeyword)); _canAddFile = this.WhenAnyValue(x => x.TrueBranch, y => y.PushAccess) .Select(x => x.Item1 && x.Item2.HasValue && x.Item2.Value) .ToProperty(this, x => x.CanAddFile); this.WhenAnyValue(x => x.Path, y => y.RepositoryName, (x, y) => new { Path = x, Repo = y }) .Subscribe(x => { if (string.IsNullOrEmpty(x.Path)) { Title = string.IsNullOrEmpty(x.Repo) ? "Source" : x.Repo; } else { var split = x.Path.TrimEnd('/').Split('/'); Title = split[split.Length - 1]; } }); GoToAddFileCommand = ReactiveCommand.Create( this.WhenAnyValue(x => x.PushAccess, x => x.TrueBranch) .Select(x => x.Item1.HasValue && x.Item1.Value && x.Item2)) .WithSubscription(_ => { var vm = this.CreateViewModel <CreateFileViewModel>(); vm.Init(RepositoryOwner, RepositoryName, Path, Branch); vm.SaveCommand.Subscribe(z => LoadCommand.ExecuteIfCan()); NavigateTo(vm); }); LoadCommand = ReactiveCommand.CreateAsyncTask(async _ => { if (!PushAccess.HasValue) { applicationService.GitHubClient.Repository.Get(RepositoryOwner, RepositoryName) .ToBackground(x => PushAccess = x.Permissions.Push); } var path = Path; if (string.Equals(path, "/", StringComparison.OrdinalIgnoreCase)) { path = string.Empty; } var request = applicationService.Client.Users[RepositoryOwner].Repositories[RepositoryName].GetContent(Path, Branch); var data = new List <ContentModel>(); var response = await applicationService.Client.ExecuteAsync(request); data.AddRange(response.Data); while (response.More != null) { response = await applicationService.Client.ExecuteAsync(response.More); data.AddRange(response.Data); } content.Reset(data.OrderBy(y => y.Type).ThenBy(y => y.Name)); }); }
public static IDisposable HandleExceptionsFromCommand(this IDialogService dialogService, IReactiveCommand command, Func <Exception, (string Title, string Message)> handler)
public TeamItemViewModel(string name, Action gotoCommand) { Name = name; GoToCommand = ReactiveCommand.Create().WithSubscription(x => gotoCommand()); }
public CommitViewModel(ISessionService applicationService, IActionMenuFactory actionMenuService, IAlertDialogFactory alertDialogFactory) { Title = "Commit"; var comments = new ReactiveList <CommentModel>(); Comments = comments.CreateDerivedCollection(x => new CommitCommentItemViewModel(x)); this.WhenAnyValue(x => x.Commit) .Select(x => new GitHubAvatar(x.GenerateGravatarUrl())) .ToProperty(this, x => x.Avatar, out _avatar); var files = this.WhenAnyValue(x => x.Commit.Files).IsNotNull(); files.Select(x => x.Count(y => string.Equals(y.Status, "added"))) .ToProperty(this, x => x.DiffAdditions, out _diffAdditions); files.Select(x => x.Count(y => string.Equals(y.Status, "removed"))) .ToProperty(this, x => x.DiffDeletions, out _diffDeletions); files.Select(x => x.Count(y => string.Equals(y.Status, "modified"))) .ToProperty(this, x => x.DiffModifications, out _diffModifications); GoToAddedFiles = ReactiveCommand.Create(this.WhenAnyValue(x => x.DiffAdditions).Select(x => x > 0)); GoToAddedFiles .Select(_ => new CommitFilesViewModel()) .Select(y => y.Init(RepositoryOwner, RepositoryName, Node, "Added", Commit.Files.Where(x => string.Equals(x.Status, "added")))) .Subscribe(NavigateTo); GoToRemovedFiles = ReactiveCommand.Create(this.WhenAnyValue(x => x.DiffDeletions).Select(x => x > 0)); GoToRemovedFiles .Select(_ => new CommitFilesViewModel()) .Select(y => y.Init(RepositoryOwner, RepositoryName, Node, "Removed", Commit.Files.Where(x => string.Equals(x.Status, "removed")))) .Subscribe(NavigateTo); GoToModifiedFiles = ReactiveCommand.Create(this.WhenAnyValue(x => x.DiffModifications).Select(x => x > 0)); GoToModifiedFiles .Select(_ => new CommitFilesViewModel()) .Select(y => y.Init(RepositoryOwner, RepositoryName, Node, "Modified", Commit.Files.Where(x => string.Equals(x.Status, "modified")))) .Subscribe(NavigateTo); GoToAllFiles = ReactiveCommand.Create(this.WhenAnyValue(x => x.Commit.Files).Select(x => x != null)); GoToAllFiles .Select(_ => new CommitFilesViewModel()) .Select(y => y.Init(RepositoryOwner, RepositoryName, Node, "All Changes", Commit.Files)) .Subscribe(NavigateTo); this.WhenAnyValue(x => x.Commit) .IsNotNull() .Select(x => x.GenerateCommiterName()) .ToProperty(this, x => x.CommiterName, out _commiterName); this.WhenAnyValue(x => x.Commit) .IsNotNull() .Select(x => x.Commit.Message ?? string.Empty) .Select(x => Emojis.FindAndReplace(x)) .ToProperty(this, x => x.CommitMessage, out _commitMessage); this.WhenAnyValue(x => x.CommitMessage) .IsNotNull() .Select(x => { var firstNewLine = x.IndexOf("\n", StringComparison.Ordinal); return(firstNewLine > 0 ? x.Substring(0, firstNewLine) : x); }) .ToProperty(this, x => x.CommitMessageSummary, out _commitMessageSummary); GoToHtmlUrlCommand = ReactiveCommand.Create(this.WhenAnyValue(x => x.Commit).Select(x => x != null)); GoToHtmlUrlCommand .Select(_ => this.CreateViewModel <WebBrowserViewModel>()) .Select(x => x.Init(Commit.HtmlUrl)) .Subscribe(NavigateTo); GoToRepositoryCommand = ReactiveCommand.Create(); GoToRepositoryCommand.Subscribe(_ => { var vm = this.CreateViewModel <RepositoryViewModel>(); vm.Init(RepositoryOwner, RepositoryName); NavigateTo(vm); }); AddCommentCommand = ReactiveCommand.Create().WithSubscription(_ => { var vm = new ComposerViewModel(async s => { var request = applicationService.Client.Users[RepositoryOwner].Repositories[RepositoryName].Commits[Node].Comments.Create(s); comments.Add((await applicationService.Client.ExecuteAsync(request)).Data); }, alertDialogFactory); NavigateTo(vm); }); GoToUrlCommand = ReactiveCommand.Create(); GoToUrlCommand.OfType <string>() .Select(x => this.CreateViewModel <WebBrowserViewModel>().Init(x)) .Subscribe(NavigateTo); var validCommitObservable = this.WhenAnyValue(x => x.Commit).Select(x => x != null); var copyShaCommand = ReactiveCommand.Create(validCommitObservable) .WithSubscription(x => actionMenuService.SendToPasteBoard(this.Commit.Sha)); var shareCommand = ReactiveCommand.Create(validCommitObservable) .WithSubscription(sender => actionMenuService.ShareUrl(sender, this.Commit.HtmlUrl)); var browseCodeCommand = ReactiveCommand.Create(validCommitObservable) .WithSubscription(x => { var vm = this.CreateViewModel <SourceTreeViewModel>(); vm.Init(RepositoryOwner, RepositoryName, Commit.Sha, trueBranch: false); NavigateTo(vm); }); ShowMenuCommand = ReactiveCommand.CreateAsyncTask(sender => { var menu = actionMenuService.Create(); menu.AddButton("Add Comment", AddCommentCommand); menu.AddButton("Copy SHA", copyShaCommand); menu.AddButton("Browse Code", browseCodeCommand); menu.AddButton("Goto Repository", GoToRepositoryCommand); menu.AddButton("Share", shareCommand); menu.AddButton("Show in GitHub", GoToHtmlUrlCommand); return(menu.Show(sender)); }); LoadCommand = ReactiveCommand.CreateAsyncTask(async t => { var commentRequest = applicationService.Client.Users[RepositoryOwner].Repositories[RepositoryName].Commits[Node].Comments.GetAll(); applicationService.Client.ExecuteAsync(commentRequest).ToBackground(x => comments.Reset(x.Data.Where(y => y.Position.HasValue))); Commit = await applicationService.GitHubClient.Repository.Commits.Get(RepositoryOwner, RepositoryName, Node); }); }
public SplitButton AddButton(string caption, string text, IReactiveCommand tapped) { return(AddButton(caption, text, () => tapped.ExecuteIfCan())); }
public MenuViewModel(IApplicationService applicationService, IAccountsService accountsService) : base(accountsService) { _applicationService = applicationService; GoToNotificationsCommand = ReactiveCommand.Create(); GoToNotificationsCommand.Subscribe(_ => { var vm = CreateViewModel <NotificationsViewModel>(); ShowViewModel(vm); }); GoToAccountsCommand = ReactiveCommand.Create(); GoToAccountsCommand.Subscribe(_ => CreateAndShowViewModel <AccountsViewModel>()); GoToProfileCommand = ReactiveCommand.Create(); GoToProfileCommand.Subscribe(_ => { var vm = CreateViewModel <ProfileViewModel>(); vm.Username = Account.Username; ShowViewModel(vm); }); GoToMyIssuesCommand = ReactiveCommand.Create(); GoToMyIssuesCommand.Subscribe(_ => CreateAndShowViewModel <MyIssuesViewModel>()); GoToUpgradesCommand = ReactiveCommand.Create(); GoToUpgradesCommand.Subscribe(_ => CreateAndShowViewModel <UpgradesViewModel>()); GoToAboutCommand = ReactiveCommand.Create(); GoToAboutCommand.Subscribe(_ => CreateAndShowViewModel <AboutViewModel>()); GoToRepositoryCommand = ReactiveCommand.Create(); GoToRepositoryCommand.OfType <RepositoryIdentifier>().Subscribe(x => { var vm = CreateViewModel <RepositoryViewModel>(); vm.RepositoryOwner = x.Owner; vm.RepositoryName = x.Name; ShowViewModel(vm); }); GoToSettingsCommand = ReactiveCommand.Create(); GoToSettingsCommand.Subscribe(_ => CreateAndShowViewModel <SettingsViewModel>()); GoToNewsCommand = ReactiveCommand.Create(); GoToNewsCommand.Subscribe(_ => CreateAndShowViewModel <NewsViewModel>()); GoToOrganizationsCommand = ReactiveCommand.Create(); GoToOrganizationsCommand.Subscribe(_ => { var vm = CreateViewModel <OrganizationsViewModel>(); vm.Username = Account.Username; ShowViewModel(vm); }); GoToTrendingRepositoriesCommand = ReactiveCommand.Create(); GoToTrendingRepositoriesCommand.Subscribe(_ => CreateAndShowViewModel <RepositoriesTrendingViewModel>()); GoToExploreRepositoriesCommand = ReactiveCommand.Create(); GoToExploreRepositoriesCommand.Subscribe(_ => CreateAndShowViewModel <RepositoriesExploreViewModel>()); GoToOrganizationEventsCommand = ReactiveCommand.Create(); GoToOrganizationEventsCommand.OfType <string>().Subscribe(name => { var vm = CreateViewModel <UserEventsViewModel>(); vm.Username = name; ShowViewModel(vm); }); GoToOrganizationCommand = ReactiveCommand.Create(); GoToOrganizationCommand.OfType <string>().Subscribe(name => { var vm = CreateViewModel <OrganizationViewModel>(); vm.Name = name; ShowViewModel(vm); }); GoToOwnedRepositoriesCommand = ReactiveCommand.Create(); GoToOwnedRepositoriesCommand.Subscribe(_ => { var vm = CreateViewModel <UserRepositoriesViewModel>(); vm.Username = Account.Username; ShowViewModel(vm); }); GoToStarredRepositoriesCommand = ReactiveCommand.Create(); GoToStarredRepositoriesCommand.Subscribe(_ => CreateAndShowViewModel <RepositoriesStarredViewModel>()); GoToPublicGistsCommand = ReactiveCommand.Create(); GoToPublicGistsCommand.Subscribe(_ => CreateAndShowViewModel <PublicGistsViewModel>()); GoToStarredGistsCommand = ReactiveCommand.Create(); GoToStarredGistsCommand.Subscribe(_ => CreateAndShowViewModel <StarredGistsViewModel>()); GoToMyGistsCommand = ReactiveCommand.Create(); GoToMyGistsCommand.Subscribe(_ => { var vm = CreateViewModel <UserGistsViewModel>(); vm.Username = Account.Username; ShowViewModel(vm); }); GoToMyEvents = ReactiveCommand.Create(); GoToMyEvents.Subscribe(_ => { var vm = CreateViewModel <UserEventsViewModel>(); vm.Username = Account.Username; ShowViewModel(vm); }); var loadCommand = ReactiveCommand.Create(); loadCommand.Subscribe(_ => { var notificationRequest = applicationService.Client.Notifications.GetAll(); notificationRequest.RequestFromCache = false; notificationRequest.CheckIfModified = false; applicationService.Client.ExecuteAsync(notificationRequest) .ContinueWith(t => Notifications = t.Result.Data.Count, TaskScheduler.FromCurrentSynchronizationContext()); applicationService.Client.ExecuteAsync(applicationService.Client.AuthenticatedUser.GetOrganizations()) .ContinueWith(t => Organizations = t.Result.Data.Select(y => y.Login).ToList(), TaskScheduler.FromCurrentSynchronizationContext()); }); LoadCommand = loadCommand; }
public NotificationsViewModel(ISessionService applicationService) { _applicationService = applicationService; Title = "Notifications"; _showEditButton = this.WhenAnyValue(x => x.ActiveFilter) .Select(x => x != AllFilter) .ToProperty(this, x => x.ShowEditButton); var groupedNotifications = new ReactiveList <NotificationGroupViewModel>(); GroupedNotifications = groupedNotifications; Notifications = _notifications.CreateDerivedCollection(y => new NotificationItemViewModel(y, GoToNotification, DeleteNotification)); Notifications.Changed.Where(x => x.Action == System.Collections.Specialized.NotifyCollectionChangedAction.Reset) .Select(_ => Notifications) .Subscribe(notifications => groupedNotifications.Reset(notifications.GroupBy(x => x.Notification.Repository.FullName).Select(x => { var items = notifications.CreateDerivedCollection(y => y, filter: y => y.Notification.Repository.FullName == x.Key); return(new NotificationGroupViewModel(x.Key, items)); }))); _anyItemsSelected = Notifications.Changed .SelectMany(x => Notifications) .Select(x => x.WhenAnyValue(y => y.IsSelected)) .Merge() .Select(x => Notifications.Select(y => y.IsSelected).Any(y => y)) .ToProperty(this, x => x.IsAnyItemsSelected); ReadSelectedCommand = ReactiveCommand.Create().WithSubscription(_ => { if (GroupedNotifications.SelectMany(x => x.Notifications).All(x => !x.IsSelected)) { var request = new Octokit.MarkAsReadRequest { LastReadAt = DateTimeOffset.Now }; applicationService.GitHubClient.Notification.MarkAsRead(request).ToBackground(); _notifications.Clear(); } else { var selected = GroupedNotifications.SelectMany(x => x.Notifications) .Where(x => x.IsSelected && x.Notification.Unread).ToList(); var tasks = selected .Select(t => _applicationService.GitHubClient.Notification.MarkAsRead(int.Parse(t.Id))); Task.WhenAll(tasks).ToBackground(); _notifications.RemoveAll(selected.Select(y => y.Notification)); } }); LoadCommand = ReactiveCommand.CreateAsyncTask(async _ => { var all = ActiveFilter == AllFilter; var participating = ActiveFilter == ParticipatingFilter; var req = new Octokit.NotificationsRequest { All = all, Participating = participating, Since = DateTimeOffset.Now.Subtract(TimeSpan.FromDays(365)) }; _notifications.Reset(await applicationService.GitHubClient.Notification.GetAllForCurrent(req)); }); _notifications.CountChanged .Where(_ => ActiveFilter == UnreadFilter) .Subscribe(_notificationCount.OnNext); this.WhenAnyValue(x => x.ActiveFilter).Skip(1).Subscribe(x => { _notifications.Clear(); LoadCommand.ExecuteIfCan(); }); }
public GistFileViewModel(IAccountsService accounts, IApplicationService applicationService, IFilesystemService filesystemService, IShareService shareService, IActionMenuService actionMenuService) : base(accounts) { this.WhenAnyValue(x => x.Filename).Subscribe(x => { Title = x == null ? "Gist" : x.Substring(x.LastIndexOf('/') + 1); }); GoToUrlCommand = this.CreateUrlCommand(); OpenWithCommand = ReactiveCommand.Create(this.WhenAnyValue(x => x.SourceItem).Select(x => x != null)); _isMarkdown = this.WhenAnyValue(x => x.GistFile).IsNotNull().Select(x => string.Equals(x.Language, MarkdownLanguage, StringComparison.OrdinalIgnoreCase)).ToProperty(this, x => x.IsMarkdown); ShowThemePickerCommand = ReactiveCommand.CreateAsyncTask(async _ => { var path = System.IO.Path.Combine("WebResources", "styles"); if (!System.IO.Directory.Exists(path)) { return; } var themes = System.IO.Directory.GetFiles(path) .Where(x => x.EndsWith(".css", StringComparison.Ordinal)) .Select(x => System.IO.Path.GetFileNameWithoutExtension(x)) .ToList(); var picker = actionMenuService.CreatePicker(); themes.ForEach(picker.Options.Add); picker.SelectedOption = themes.IndexOf(Theme ?? "idea"); var selected = await picker.Show(); if (selected >= 0 && selected <= themes.Count) { Theme = themes[selected]; } }); ShowMenuCommand = ReactiveCommand.CreateAsyncTask( this.WhenAnyValue(x => x.SourceItem).Select(x => x != null), _ => { var menu = actionMenuService.Create(Title); menu.AddButton("Open With", OpenWithCommand); if (!IsMarkdown) { menu.AddButton("Change Theme", ShowThemePickerCommand); } return(menu.Show()); }); LoadCommand = ReactiveCommand.CreateAsyncTask(async t => { if (GistFile == null) { var data = await applicationService.Client.ExecuteAsync(applicationService.Client.Gists[_id].Get()); GistFile = data.Data.Files[_filename]; } //Check to make sure... if (GistFile == null || GistFile.Content == null) { throw new Exception("Unable to retreive gist!"); } var content = GistFile.Content; if (MarkdownLanguage.Equals(GistFile.Language, StringComparison.OrdinalIgnoreCase)) { content = await applicationService.Client.Markdown.GetMarkdown(content); } var gistFileName = System.IO.Path.GetFileName(GistFile.Filename); string filePath; using (var stream = filesystemService.CreateTempFile(out filePath, gistFileName)) { using (var fs = new System.IO.StreamWriter(stream)) { fs.Write(content); } } var fileUri = new Uri(filePath); SourceItem = new FileSourceItemViewModel(fileUri, false); }); }
public GistViewModel(IApplicationService applicationService, IShareService shareService) { _applicationService = applicationService; Comments = new ReactiveList <GistCommentModel>(); ShareCommand = ReactiveCommand.Create(this.WhenAnyValue(x => x.Gist).Select(x => x != null)); ShareCommand.Subscribe(_ => shareService.ShareUrl(Gist.HtmlUrl)); ToggleStarCommand = ReactiveCommand.CreateAsyncTask( this.WhenAnyValue(x => x.IsStarred).Select(x => x.HasValue), async t => { try { if (!IsStarred.HasValue) { return; } var request = IsStarred.Value ? _applicationService.Client.Gists[Id].Unstar() : _applicationService.Client.Gists[Id].Star(); await _applicationService.Client.ExecuteAsync(request); IsStarred = !IsStarred.Value; } catch (Exception e) { throw new Exception("Unable to start gist. Please try again.", e); } }); ForkCommand = ReactiveCommand.CreateAsyncTask(async t => { var data = await _applicationService.Client.ExecuteAsync(_applicationService.Client.Gists[Id].ForkGist()); var forkedGist = data.Data; var vm = CreateViewModel <GistViewModel>(); vm.Id = forkedGist.Id; vm.Gist = forkedGist; ShowViewModel(vm); }); GoToViewableFileCommand = ReactiveCommand.Create(); GoToViewableFileCommand.OfType <GistFileModel>().Subscribe(x => { var vm = CreateViewModel <GistViewableFileViewModel>(); vm.GistFile = x; ShowViewModel(vm); }); GoToHtmlUrlCommand = ReactiveCommand.Create(this.WhenAnyValue(x => x.Gist).Select(x => x != null && !string.IsNullOrEmpty(x.HtmlUrl))); GoToHtmlUrlCommand.Subscribe(_ => GoToUrlCommand.ExecuteIfCan(Gist.HtmlUrl)); GoToFileSourceCommand = ReactiveCommand.Create(); GoToFileSourceCommand.OfType <GistFileModel>().Subscribe(x => { var vm = CreateViewModel <GistFileViewModel>(); vm.Id = Id; vm.GistFile = x; vm.Filename = x.Filename; ShowViewModel(vm); }); GoToUserCommand = ReactiveCommand.Create(this.WhenAnyValue(x => x.Gist).Select(x => x != null)); GoToUserCommand.Subscribe(x => { var vm = CreateViewModel <ProfileViewModel>(); vm.Username = Gist.Owner.Login; ShowViewModel(vm); }); GoToForksCommand = ReactiveCommand.Create(); LoadCommand = ReactiveCommand.CreateAsyncTask(t => { var forceCacheInvalidation = t as bool?; var t1 = this.RequestModel(_applicationService.Client.Gists[Id].Get(), forceCacheInvalidation, response => Gist = response.Data); this.RequestModel(_applicationService.Client.Gists[Id].IsGistStarred(), forceCacheInvalidation, response => IsStarred = response.Data).FireAndForget(); Comments.SimpleCollectionLoad(_applicationService.Client.Gists[Id].GetComments(), forceCacheInvalidation).FireAndForget(); return(t1); }); }
/// <summary> /// A utility method that will pipe an Observable to an ICommand (i.e. /// it will first call its CanExecute with the provided value, then if /// the command can be executed, Execute() will be called) /// </summary> /// <param name="command">The command to be executed.</param> /// <returns>An object that when disposes, disconnects the Observable /// from the command.</returns> public static IDisposable InvokeCommand <T, TResult>(this IObservable <T> This, IReactiveCommand <TResult> command) { return(This.Throttle(x => command.CanExecuteObservable.StartWith(command.CanExecute(x)).Where(b => b)) .Select(x => command.ExecuteAsync(x).Catch(Observable <TResult> .Empty)) .Switch() .Subscribe()); }
public PullRequestViewModel(IApplicationService applicationService, IMarkdownService markdownService, IActionMenuFactory actionMenuService) { _applicationService = applicationService; _markdownService = markdownService; Comments = new ReactiveList <Octokit.IssueComment>(); Events = new ReactiveList <Octokit.IssueEvent>(); this.WhenAnyValue(x => x.Id).Subscribe(x => Title = "Pull Request #" + x); _canMerge = this.WhenAnyValue(x => x.PullRequest) .Select(x => x != null && !x.Merged) .ToProperty(this, x => x.CanMerge); var canMergeObservable = this.WhenAnyValue(x => x.PullRequest).Select(x => x != null && !x.Merged && x.Mergeable.HasValue && x.Mergeable.Value); MergeCommand = ReactiveCommand.CreateAsyncTask(canMergeObservable, async t => { var req = new Octokit.MergePullRequest(null); var response = await _applicationService.GitHubClient.PullRequest.Merge(RepositoryOwner, RepositoryName, Id, req); if (!response.Merged) { throw new Exception(string.Format("Unable to merge pull request: {0}", response.Message)); } LoadCommand.ExecuteIfCan(); }); ToggleStateCommand = ReactiveCommand.CreateAsyncTask( this.WhenAnyValue(x => x.PullRequest).Select(x => x != null), async t => { var newState = PullRequest.State == Octokit.ItemState.Open ? Octokit.ItemState.Closed : Octokit.ItemState.Open; try { var req = new Octokit.PullRequestUpdate { State = newState }; PullRequest = await _applicationService.GitHubClient.PullRequest.Update(RepositoryOwner, RepositoryName, Id, req); } catch (Exception e) { throw new Exception("Unable to " + (newState == Octokit.ItemState.Closed ? "close" : "open") + " the item. " + e.Message, e); } }); GoToUrlCommand = ReactiveCommand.Create(); GoToUrlCommand.OfType <string>().Subscribe(x => { var vm = this.CreateViewModel <WebBrowserViewModel>(); vm.Url = x; NavigateTo(vm); }); GoToHtmlUrlCommand = ReactiveCommand.Create(this.WhenAnyValue(x => x.PullRequest).Select(x => x != null)); GoToHtmlUrlCommand.Select(_ => PullRequest.HtmlUrl).Subscribe(x => GoToUrlCommand.ExecuteIfCan(x.AbsolutePath)); GoToCommitsCommand = ReactiveCommand.Create().WithSubscription(_ => { var vm = this.CreateViewModel <PullRequestCommitsViewModel>(); vm.RepositoryOwner = RepositoryOwner; vm.RepositoryName = RepositoryName; vm.PullRequestId = Id; NavigateTo(vm); }); GoToFilesCommand = ReactiveCommand.Create().WithSubscription(_ => { var vm = this.CreateViewModel <PullRequestFilesViewModel>(); vm.Username = RepositoryOwner; vm.Repository = RepositoryName; vm.PullRequestId = Id; NavigateTo(vm); }); // // ShareCommand = ReactiveCommand.Create(this.WhenAnyValue(x => x.PullRequest).Select(x => x != null && !string.IsNullOrEmpty(x.HtmlUrl))) // .WithSubscription(_ => shareService.ShareUrl(PullRequest.HtmlUrl)); GoToEditCommand = ReactiveCommand.Create().WithSubscription(_ => { var vm = this.CreateViewModel <IssueEditViewModel>(); vm.RepositoryOwner = RepositoryOwner; vm.RepositoryName = RepositoryName; vm.Id = Id; //vm.Issue = Issue; // vm.WhenAnyValue(x => x.Issue).Skip(1).Subscribe(x => Issue = x); NavigateTo(vm); }); // // GoToLabelsCommand = ReactiveCommand.Create(this.WhenAnyValue(x => x.Issue).Select(x => x != null)).WithSubscription(_ => // { // var vm = this.CreateViewModel<IssueLabelsViewModel>(); // vm.RepositoryOwner = RepositoryOwner; // vm.RepositoryName = RepositoryName; // vm.Id = Id; // vm.SaveOnSelect = true; //// vm.SelectedLabels.Reset(Issue.Labels); //// vm.WhenAnyValue(x => x.Labels).Skip(1).Subscribe(x => //// { //// Issue.Labels = x.ToList(); //// this.RaisePropertyChanged("Issue"); //// }); // NavigateTo(vm); // }); // GoToMilestoneCommand = ReactiveCommand.Create(this.WhenAnyValue(x => x.Issue).Select(x => x != null)).WithSubscription(_ => // { // var vm = this.CreateViewModel<IssueMilestonesViewModel>(); // vm.RepositoryOwner = RepositoryOwner; // vm.RepositoryName = RepositoryName; // vm.IssueId = Id; // vm.SaveOnSelect = true; //// vm.SelectedMilestone = Issue.Milestone; //// vm.WhenAnyValue(x => x.SelectedMilestone).Skip(1).Subscribe(x => //// { //// Issue.Milestone = x; //// this.RaisePropertyChanged("Issue"); //// }); // NavigateTo(vm); // }); // // GoToAssigneeCommand = ReactiveCommand.Create(this.WhenAnyValue(x => x.Issue).Select(x => x != null)).WithSubscription(_ => // { // var vm = this.CreateViewModel<IssueAssignedToViewModel>(); // vm.RepositoryOwner = RepositoryOwner; // vm.RepositoryName = RepositoryName; // vm.IssueId = Id; // //vm.SaveOnSelect = true; //// vm.SelectedUser = Issue.Assignee; //// vm.WhenAnyValue(x => x.SelectedUser).Skip(1).Subscribe(x => //// { //// Issue.Assignee = x; //// this.RaisePropertyChanged("Issue"); //// }); // NavigateTo(vm); // }); GoToAddCommentCommand = ReactiveCommand.Create().WithSubscription(_ => { var vm = this.CreateViewModel <IssueCommentViewModel>(); vm.RepositoryOwner = RepositoryOwner; vm.RepositoryName = RepositoryName; vm.Id = Id; vm.SaveCommand.Subscribe(Comments.Add); NavigateTo(vm); }); ShowMenuCommand = ReactiveCommand.CreateAsyncTask( this.WhenAnyValue(x => x.PullRequest).Select(x => x != null), _ => { var menu = actionMenuService.Create(Title); menu.AddButton("Edit", GoToEditCommand); menu.AddButton(PullRequest.State == Octokit.ItemState.Closed ? "Open" : "Close", ToggleStateCommand); menu.AddButton("Comment", GoToAddCommentCommand); menu.AddButton("Share", ShareCommand); menu.AddButton("Show in GitHub", GoToHtmlUrlCommand); return(menu.Show()); }); _markdownDescription = this.WhenAnyValue(x => x.PullRequest).IsNotNull() .Select(x => _markdownService.Convert(x.Body)) .ToProperty(this, x => x.MarkdownDescription); LoadCommand = ReactiveCommand.CreateAsyncTask(async _ => { var pullRequest = _applicationService.GitHubClient.PullRequest.Get(RepositoryOwner, RepositoryName, Id); var comments = _applicationService.GitHubClient.PullRequest.Comment.GetAll(RepositoryOwner, RepositoryName, Id); var events = _applicationService.GitHubClient.Issue.Events.GetForIssue(RepositoryOwner, RepositoryName, Id); var issue = _applicationService.GitHubClient.Issue.Get(RepositoryOwner, RepositoryName, Id); await Task.WhenAll(pullRequest, issue, comments, events); PullRequest = pullRequest.Result; Issue = issue.Result; }); }
internal AccountItemViewModel() { DeleteCommand = ReactiveCommand.Create(); SelectCommand = ReactiveCommand.Create(); }
public TeamMembersViewModel(IApplicationService applicationService) { LoadCommand = ReactiveCommand.CreateAsyncTask( t => UsersCollection.SimpleCollectionLoad(applicationService.Client.Teams[Id].GetMembers(), t as bool?)); }
public MarkdownAccessoryView(UITextView controller, IReactiveCommand <string> postImage) : base(CreateButtons(controller, postImage)) { }
public RepositoryViewModel(IApplicationService applicationService, IAccountsService accountsService) { ApplicationService = applicationService; _accountsService = accountsService; this.WhenAnyValue(x => x.RepositoryName).Subscribe(x => Title = x); ToggleStarCommand = ReactiveCommand.CreateAsyncTask( this.WhenAnyValue(x => x.IsStarred).Select(x => x.HasValue), t => ToggleStar()); ToggleWatchCommand = ReactiveCommand.CreateAsyncTask( this.WhenAnyValue(x => x.IsWatched, x => x.HasValue), t => ToggleWatch()); GoToOwnerCommand = ReactiveCommand.Create(this.WhenAnyValue(x => x.Repository).Select(x => x != null)); GoToOwnerCommand.Select(_ => Repository.Owner).Subscribe(x => { if (string.Equals(x.Type, "organization", StringComparison.OrdinalIgnoreCase)) { var vm = CreateViewModel <OrganizationViewModel>(); vm.Username = RepositoryOwner; ShowViewModel(vm); } else { var vm = CreateViewModel <UserViewModel>(); vm.Username = RepositoryOwner; ShowViewModel(vm); } }); PinCommand = ReactiveCommand.Create(this.WhenAnyValue(x => x.Repository).Select(x => x != null)); PinCommand.Subscribe(x => PinRepository()); GoToForkParentCommand = ReactiveCommand.Create(this.WhenAnyValue(x => x.Repository, x => x != null && x.Fork && x.Parent != null)); GoToForkParentCommand.Subscribe(x => { var vm = CreateViewModel <RepositoryViewModel>(); vm.RepositoryOwner = Repository.Parent.Owner.Login; vm.RepositoryName = Repository.Parent.Name; vm.Repository = Repository.Parent; ShowViewModel(vm); }); GoToStargazersCommand = ReactiveCommand.Create(); GoToStargazersCommand.Subscribe(_ => { var vm = CreateViewModel <RepositoryStargazersViewModel>(); vm.RepositoryOwner = RepositoryOwner; vm.RepositoryName = RepositoryName; ShowViewModel(vm); }); GoToWatchersCommand = ReactiveCommand.Create(); GoToWatchersCommand.Subscribe(_ => { var vm = CreateViewModel <RepositoryWatchersViewModel>(); vm.RepositoryOwner = RepositoryOwner; vm.RepositoryName = RepositoryName; ShowViewModel(vm); }); GoToEventsCommand = ReactiveCommand.Create(); GoToEventsCommand.Subscribe(_ => { var vm = CreateViewModel <RepositoryEventsViewModel>(); vm.RepositoryOwner = RepositoryOwner; vm.RepositoryName = RepositoryName; ShowViewModel(vm); }); GoToIssuesCommand = ReactiveCommand.Create(); GoToIssuesCommand.Subscribe(_ => { var vm = CreateViewModel <IssuesViewModel>(); vm.RepositoryOwner = RepositoryOwner; vm.RepositoryName = RepositoryName; ShowViewModel(vm); }); GoToReadmeCommand = ReactiveCommand.Create(); GoToReadmeCommand.Subscribe(_ => { var vm = CreateViewModel <ReadmeViewModel>(); vm.RepositoryOwner = RepositoryOwner; vm.RepositoryName = RepositoryName; ShowViewModel(vm); }); GoToBranchesCommand = ReactiveCommand.Create().WithSubscription(_ => { var vm = CreateViewModel <CommitBranchesViewModel>(); vm.RepositoryOwner = RepositoryOwner; vm.RepositoryName = RepositoryName; ShowViewModel(vm); }); GoToCommitsCommand = ReactiveCommand.Create(); GoToCommitsCommand.Subscribe(_ => { if (Branches != null && Branches.Count == 1) { var vm = CreateViewModel <ChangesetsViewModel>(); vm.RepositoryOwner = RepositoryOwner; vm.RepositoryName = RepositoryName; vm.Branch = Repository == null ? null : Repository.DefaultBranch; ShowViewModel(vm); } else { GoToBranchesCommand.ExecuteIfCan(); } }); GoToPullRequestsCommand = ReactiveCommand.Create(); GoToPullRequestsCommand.Subscribe(_ => { var vm = CreateViewModel <PullRequestsViewModel>(); vm.RepositoryOwner = RepositoryOwner; vm.RepositoryName = RepositoryName; ShowViewModel(vm); }); GoToSourceCommand = ReactiveCommand.Create(); GoToSourceCommand.Subscribe(_ => { var vm = CreateViewModel <BranchesAndTagsViewModel>(); vm.RepositoryOwner = RepositoryOwner; vm.RepositoryName = RepositoryName; ShowViewModel(vm); }); GoToContributors = ReactiveCommand.Create(); GoToContributors.Subscribe(_ => { var vm = CreateViewModel <RepositoryContributorsViewModel>(); vm.RepositoryOwner = RepositoryOwner; vm.RepositoryName = RepositoryName; ShowViewModel(vm); }); GoToForksCommand = ReactiveCommand.Create().WithSubscription(_ => { var vm = CreateViewModel <RepositoryForksViewModel>(); vm.RepositoryOwner = RepositoryOwner; vm.RepositoryName = RepositoryName; ShowViewModel(vm); }); GoToReleasesCommand = ReactiveCommand.Create().WithSubscription(_ => { var vm = CreateViewModel <ReleasesViewModel>(); vm.RepositoryOwner = RepositoryOwner; vm.RepositoryName = RepositoryName; ShowViewModel(vm); }); GoToHtmlUrlCommand = ReactiveCommand.Create(this.WhenAnyValue(x => x.Repository, x => x != null && !string.IsNullOrEmpty(x.HtmlUrl))); GoToHtmlUrlCommand.Subscribe(_ => GoToUrlCommand.ExecuteIfCan(Repository.HtmlUrl)); LoadCommand = ReactiveCommand.CreateAsyncTask(t => { var forceCacheInvalidation = t as bool?; var t1 = this.RequestModel(ApplicationService.Client.Users[RepositoryOwner].Repositories[RepositoryName].Get(), forceCacheInvalidation, response => Repository = response.Data); this.RequestModel(ApplicationService.Client.Users[RepositoryOwner].Repositories[RepositoryName].GetReadme(), forceCacheInvalidation, response => Readme = response.Data).FireAndForget(); this.RequestModel(ApplicationService.Client.Users[RepositoryOwner].Repositories[RepositoryName].GetBranches(), forceCacheInvalidation, response => Branches = response.Data).FireAndForget(); this.RequestModel(ApplicationService.Client.Users[RepositoryOwner].Repositories[RepositoryName].IsWatching(), forceCacheInvalidation, response => IsWatched = response.Data).FireAndForget(); this.RequestModel(ApplicationService.Client.Users[RepositoryOwner].Repositories[RepositoryName].IsStarred(), forceCacheInvalidation, response => IsStarred = response.Data).FireAndForget(); this.RequestModel(ApplicationService.Client.Users[RepositoryOwner].Repositories[RepositoryName].GetContributors(), forceCacheInvalidation, response => Contributors = response.Data.Count).FireAndForget(); this.RequestModel(ApplicationService.Client.Users[RepositoryOwner].Repositories[RepositoryName].GetLanguages(), forceCacheInvalidation, response => Languages = response.Data.Count).FireAndForget(); this.RequestModel(ApplicationService.Client.Users[RepositoryOwner].Repositories[RepositoryName].GetReleases(), forceCacheInvalidation, response => Releases = response.Data.Count).FireAndForget(); return(t1); }); }