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)); }); }
public ReadmeViewModel(IApplicationService applicationService, IShareService shareService, IActionMenuService actionMenuService) { Title = "Readme"; var nonNullContentModel = this.WhenAnyValue(x => x.ContentModel).Select(x => x != null); ShareCommand = ReactiveCommand.Create(nonNullContentModel); ShareCommand.Subscribe(_ => shareService.ShareUrl(ContentModel.HtmlUrl)); GoToGitHubCommand = ReactiveCommand.Create(nonNullContentModel); GoToGitHubCommand.Select(_ => ContentModel.HtmlUrl).Subscribe(this.ShowWebBrowser); GoToLinkCommand = ReactiveCommand.Create(); GoToLinkCommand.OfType <string>().Subscribe(this.ShowWebBrowser); ShowMenuCommand = ReactiveCommand.CreateAsyncTask(nonNullContentModel, _ => { var menu = actionMenuService.Create(Title); menu.AddButton("Share", ShareCommand); menu.AddButton("Show in GitHub", GoToGitHubCommand); return(menu.Show()); }); LoadCommand = ReactiveCommand.CreateAsyncTask(async x => { var repository = applicationService.Client.Users[RepositoryOwner].Repositories[RepositoryName]; ContentText = await repository.GetReadmeRendered(); ContentModel = (await applicationService.Client.ExecuteAsync(repository.GetReadme())).Data; }); }
public ReleaseViewModel(IApplicationService applicationService, IShareService shareService, IUrlRouterService urlRouterService, IActionMenuService actionMenuService) { this.WhenAnyValue(x => x.ReleaseModel) .Select(x => x == null ? "Release" : x.Name).Subscribe(x => Title = x); ShareCommand = ReactiveCommand.Create(this.WhenAnyValue(x => x.ReleaseModel).Select(x => x != null)); ShareCommand.Subscribe(_ => shareService.ShareUrl(ReleaseModel.HtmlUrl)); var gotoUrlCommand = this.CreateUrlCommand(); GoToGitHubCommand = ReactiveCommand.Create(this.WhenAnyValue(x => x.ReleaseModel).Select(x => x != null)); GoToGitHubCommand.Select(_ => ReleaseModel.HtmlUrl).Subscribe(gotoUrlCommand.ExecuteIfCan); GoToLinkCommand = ReactiveCommand.Create(); GoToLinkCommand.OfType <string>().Subscribe(x => { var handledViewModel = urlRouterService.Handle(x); if (handledViewModel != null && applicationService.Account.OpenUrlsInApp) { ShowViewModel(handledViewModel); } else { gotoUrlCommand.ExecuteIfCan(x); } }); ShowMenuCommand = ReactiveCommand.CreateAsyncTask( this.WhenAnyValue(x => x.ReleaseModel).Select(x => x != null), _ => { var menu = actionMenuService.Create(Title); menu.AddButton("Share", ShowMenuCommand); menu.AddButton("Show in GitHub", GoToGitHubCommand); return(menu.Show()); }); _contentText = this.WhenAnyValue(x => x.ReleaseModel).IsNotNull() .Select(x => x.BodyHtml).ToProperty(this, x => x.ContentText); LoadCommand = ReactiveCommand.CreateAsyncTask(x => this.RequestModel(applicationService.Client.Users[RepositoryOwner].Repositories[RepositoryName].GetRelease(ReleaseId), x as bool?, r => ReleaseModel = r.Data)); }
public ReleaseViewModel(IApplicationService applicationService, IMarkdownService markdownService, IShareService shareService) { ShareCommand = ReactiveCommand.Create(this.WhenAnyValue(x => x.ReleaseModel).Select(x => x != null)); ShareCommand.Subscribe(_ => shareService.ShareUrl(ReleaseModel.HtmlUrl)); GoToGitHubCommand = ReactiveCommand.Create(this.WhenAnyValue(x => x.ReleaseModel).Select(x => x != null)); GoToGitHubCommand.Subscribe(_ => GoToUrlCommand.ExecuteIfCan(ReleaseModel.HtmlUrl)); GoToLinkCommand = ReactiveCommand.Create(); GoToLinkCommand.OfType <string>().Subscribe(x => GoToUrlCommand.ExecuteIfCan(x)); _contentText = this.WhenAnyValue(x => x.ReleaseModel).IsNotNull() .Select(x => markdownService.Convert(x.Body)).ToProperty(this, x => x.ContentText); LoadCommand = ReactiveCommand.CreateAsyncTask(x => this.RequestModel(applicationService.Client.Users[RepositoryOwner].Repositories[RepositoryName].GetRelease(ReleaseId), x as bool?, r => ReleaseModel = r.Data)); }
public ReadmeViewModel(IApplicationService applicationService, IMarkdownService markdownService, IShareService shareService) { ShareCommand = ReactiveCommand.Create(this.WhenAnyValue(x => x.ContentModel).Select(x => x != null)); ShareCommand.Subscribe(_ => shareService.ShareUrl(ContentModel.HtmlUrl)); GoToGitHubCommand = ReactiveCommand.Create(this.WhenAnyValue(x => x.ContentModel).Select(x => x != null)); GoToGitHubCommand.Subscribe(_ => GoToUrlCommand.ExecuteIfCan(ContentModel.HtmlUrl)); GoToLinkCommand = ReactiveCommand.Create(); GoToLinkCommand.OfType <string>().Subscribe(x => GoToUrlCommand.ExecuteIfCan(x)); LoadCommand = ReactiveCommand.CreateAsyncTask(x => this.RequestModel(applicationService.Client.Users[RepositoryOwner].Repositories[RepositoryName].GetReadme(), x as bool?, r => { ContentModel = r.Data; var content = Convert.FromBase64String(ContentModel.Content); ContentText = markdownService.Convert(Encoding.UTF8.GetString(content, 0, content.Length)); })); }
public ReadmeViewModel(IApplicationService applicationService, IShareService shareService) { Title = "Readme"; ShareCommand = ReactiveCommand.Create(this.WhenAnyValue(x => x.ContentModel).Select(x => x != null)); ShareCommand.Subscribe(_ => shareService.ShareUrl(ContentModel.HtmlUrl)); GoToGitHubCommand = ReactiveCommand.Create(this.WhenAnyValue(x => x.ContentModel).Select(x => x != null)); GoToGitHubCommand.Subscribe(_ => GoToUrlCommand.ExecuteIfCan(ContentModel.HtmlUrl)); GoToLinkCommand = ReactiveCommand.Create(); GoToLinkCommand.OfType <string>().Subscribe(x => GoToUrlCommand.ExecuteIfCan(x)); LoadCommand = ReactiveCommand.CreateAsyncTask(async x => { var repository = applicationService.Client.Users[RepositoryOwner].Repositories[RepositoryName]; ContentText = await repository.GetReadmeRendered(); ContentModel = (await applicationService.Client.ExecuteAsync(repository.GetReadme())).Data; }); }
protected BaseRepositoryViewModel(IApplicationService applicationService, INetworkActivityService networkActivity) { LikeCommand = ReactiveCommand.Create(); LikeCommand.Subscribe(_ => { if (StumbledRepository == null) { var repo = CreateStumbledRepository(); repo.Liked = true; applicationService.Account.StumbledRepositories.Insert(repo); StumbledRepository = repo; } else { StumbledRepository.Liked = true; StumbledRepository.Description = Repository.Description; StumbledRepository.Forks = Repository.ForksCount; StumbledRepository.Stars = Repository.WatchersCount; StumbledRepository.ImageUrl = Repository.Owner.AvatarUrl; applicationService.Account.StumbledRepositories.Update(StumbledRepository); } if (applicationService.Account.SyncWithGitHub) { applicationService.Client.Activity.Starring.StarRepo(Repository.Owner.Login, Repository.Name); } Liked = true; }); DislikeCommand = ReactiveCommand.Create(); DislikeCommand.Subscribe(_ => { if (StumbledRepository == null) { var repo = CreateStumbledRepository(); repo.Liked = false; applicationService.Account.StumbledRepositories.Insert(repo); StumbledRepository = repo; } else { StumbledRepository.Liked = false; StumbledRepository.Description = Repository.Description; StumbledRepository.Forks = Repository.ForksCount; StumbledRepository.Stars = Repository.WatchersCount; StumbledRepository.ImageUrl = Repository.Owner.AvatarUrl; applicationService.Account.StumbledRepositories.Update(StumbledRepository); } if (applicationService.Account.SyncWithGitHub) { applicationService.Client.Activity.Starring.RemoveStarFromRepo(Repository.Owner.Login, Repository.Name); } Liked = false; }); this.WhenAnyValue(x => x.RepositoryIdentifier) .Where(x => x != null) .Subscribe(x => { StumbledRepository = applicationService.Account.StumbledRepositories.FindByFullname(x.Owner, x.Name); }); this.WhenAnyValue(x => x.StumbledRepository) .Where(x => x != null) .Subscribe(x => Liked = x.Liked); GoToGitHubCommand = ReactiveCommand.Create(this.WhenAnyValue(x => x.Repository).Select(x => x != null)); GoToGitHubCommand.Subscribe(_ => GoToUrlCommand.ExecuteIfCan(Repository.HtmlUrl)); LoadCommand = ReactiveCommand.CreateAsyncTask(this.WhenAnyValue(x => x.RepositoryIdentifier).Select(x => x != null), async t => { Repository = (await applicationService.Client.Repository.Get(RepositoryIdentifier.Owner, RepositoryIdentifier.Name)); ContributorCount = (await applicationService.Client.Repository.GetAllContributors(RepositoryIdentifier.Owner, RepositoryIdentifier.Name)).Count; try { Readme = await applicationService.Client.Repository.GetReadmeHtml(RepositoryIdentifier.Owner, RepositoryIdentifier.Name); } catch (Exception e) { Readme = "<center>There is no readme for this repository :(</center>"; Debug.WriteLine(e.Message + " for " + RepositoryIdentifier.Owner + "/" + RepositoryIdentifier.Name); } }); LoadCommand.TriggerNetworkActivity(networkActivity); }