当前位置: 首页>>代码示例>>C#>>正文


C# IReactiveCommand类代码示例

本文整理汇总了C#中IReactiveCommand的典型用法代码示例。如果您正苦于以下问题:C# IReactiveCommand类的具体用法?C# IReactiveCommand怎么用?C# IReactiveCommand使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


IReactiveCommand类属于命名空间,在下文中一共展示了IReactiveCommand类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: GistFileItemViewModel

 public GistFileItemViewModel(string name, string content)
 {
     Name = name;
     Content = content;
     EditCommand = ReactiveCommand.Create();
     DeleteCommand = ReactiveCommand.Create();
 }
开发者ID:runt18,项目名称:CodeHub,代码行数:7,代码来源:GistFileItemViewModel.cs

示例2: IssueEditViewModel

	    public IssueEditViewModel(IApplicationService applicationService)
	    {
	        _applicationService = applicationService;

            GoToDescriptionCommand = new ReactiveCommand(this.WhenAnyValue(x => x.Issue, x => x != null));
	        GoToDescriptionCommand.Subscribe(_ =>
	        {
	            var vm = CreateViewModel<ComposerViewModel>();
	            vm.Text = Issue.Body;
	            vm.SaveCommand.Subscribe(__ =>
	            {
	                Issue.Body = vm.Text;
                    vm.DismissCommand.ExecuteIfCan();
	            });
	            ShowViewModel(vm);
	        });

	        this.WhenAnyValue(x => x.Issue).Where(x => x != null).Subscribe(x =>
	        {
                Title = x.Title;
                AssignedTo = x.Assignee;
                Milestone = x.Milestone;
                Labels = x.Labels.ToArray();
                Content = x.Body;
                IsOpen = string.Equals(x.State, "open");
	        });
	    }
开发者ID:GSerjo,项目名称:CodeHub,代码行数:27,代码来源:IssueEditViewModel.cs

示例3: UserItemViewModel

 internal UserItemViewModel(string name, string avatarUrl, bool organization, Action gotoAction)
 {
     Name = name;
     Avatar = new GitHubAvatar(avatarUrl);
     IsOrganization = organization;
     GoToCommand = ReactiveCommand.Create().WithSubscription(_ => gotoAction());
 }
开发者ID:runt18,项目名称:CodeHub,代码行数:7,代码来源:UserItemViewModel.cs

示例4: ReadmeViewModel

        public ReadmeViewModel(
            ISessionService applicationService, 
            IActionMenuFactory actionMenuService)
        {
            Title = "Readme";

            var nonNullContentModel = this.WhenAnyValue(x => x.ContentModel).Select(x => x != null);

            ShareCommand = ReactiveCommand.Create(nonNullContentModel);
            ShareCommand.Subscribe(sender => actionMenuService.ShareUrl(sender, ContentModel.HtmlUrl));

            GoToGitHubCommand = ReactiveCommand.Create(nonNullContentModel);
            GoToGitHubCommand.Select(_ => ContentModel.HtmlUrl).Subscribe(GoToWebBrowser);

            GoToLinkCommand = ReactiveCommand.Create();
            GoToLinkCommand.OfType<string>().Subscribe(x => GoToWebBrowser(new Uri(x)));

            ShowMenuCommand = ReactiveCommand.CreateAsyncTask(nonNullContentModel, sender => {
                var menu = actionMenuService.Create();
                menu.AddButton("Share", ShareCommand);
                menu.AddButton("Show in GitHub", GoToGitHubCommand);
                return menu.Show(sender);
            });

            LoadCommand = ReactiveCommand.CreateAsyncTask(x => {
                var contentTask = applicationService.GitHubClient.Repository.Content.GetReadmeHtml(RepositoryOwner, RepositoryName)
                    .ContinueWith(t => ContentText = t.Result, TaskScheduler.FromCurrentSynchronizationContext());
                
                var modelTask = applicationService.GitHubClient.Repository.Content.GetReadme(RepositoryOwner, RepositoryName)
                    .ContinueWith(t => ContentModel = t.Result, TaskScheduler.FromCurrentSynchronizationContext());

                return Task.WhenAll(contentTask, modelTask);
            });
        }
开发者ID:crazypebble,项目名称:CodeHub,代码行数:34,代码来源:ReadmeViewModel.cs

示例5: EditSourceViewModel

	    public EditSourceViewModel(IApplicationService applicationService)
	    {
            SaveCommand = new ReactiveCommand();
	        SaveCommand.Subscribe(_ =>
	        {
	            var vm = CreateViewModel<CommitMessageViewModel>();
	            vm.SaveCommand.RegisterAsyncTask(async t =>
	            {
                    var request = applicationService.Client.Users[Username].Repositories[Repository]
                        .UpdateContentFile(Path, vm.Message, Text, BlobSha, Branch);
                    var response = await applicationService.Client.ExecuteAsync(request);
	                Content = response.Data;
                    DismissCommand.ExecuteIfCan();
	            });
                ShowViewModel(vm);
	        });

	        LoadCommand.RegisterAsyncTask(async t =>
	        {
	            var path = Path;
                if (!path.StartsWith("/", StringComparison.Ordinal))
                    path = "/" + path;

	            var request = applicationService.Client.Users[Username].Repositories[Repository].GetContentFile(path, Branch ?? "master");
			    request.UseCache = false;
			    var data = await applicationService.Client.ExecuteAsync(request);
			    BlobSha = data.Data.Sha;
			    Text = System.Text.Encoding.UTF8.GetString(Convert.FromBase64String(data.Data.Content));
	        });
	    }
开发者ID:GSerjo,项目名称:CodeHub,代码行数:30,代码来源:EditSourceViewModel.cs

示例6: IssueLabelsViewModel

        public IssueLabelsViewModel(Func<Task<IReadOnlyList<Label>>> loadLabels)
	    {
            var labels = new ReactiveList<Label>();
            Selected = new ReactiveList<Label>();
            Labels = labels.CreateDerivedCollection(x => 
            {
                var vm = new IssueLabelItemViewModel(x);
                vm.IsSelected = Selected.Any(y => string.Equals(y.Name, x.Name));
//                vm.GoToCommand
//                    .Select(_ => x)
//                    .Where(y => vm.IsSelected)
//                    .Where(y => Selected.All(l => l.Url != y.Url))
//                    .Subscribe(Selected.Add);
//                vm.GoToCommand
//                    .Select(_ => x)
//                    .Where(y => !vm.IsSelected)
//                    .Select(y => Selected.Where(l => l.Url == y.Url).ToArray())
//                    .Subscribe(Selected.RemoveAll);
                return vm;
            });

            SelectLabelsCommand = ReactiveCommand.CreateAsyncTask(t => {
                var selectedLabelsUrl = Selected.Select(x => x.Url).ToArray();
                var prevSelectedLabelsUrl = _previouslySelectedLabels.Select(x => x.Url).ToArray();
                var intersect = selectedLabelsUrl.Intersect(prevSelectedLabelsUrl).ToArray();
                var different = selectedLabelsUrl.Length != prevSelectedLabelsUrl.Length || intersect.Length != selectedLabelsUrl.Length;
                return Task.FromResult(0); //different ? updateIssue(new ReadOnlyCollection<Label>(Selected)) : Task.FromResult(0);
	        });

            LoadCommand = ReactiveCommand.CreateAsyncTask(async _ => {
                labels.Reset(await loadLabels());
            });
	    }
开发者ID:zdd910,项目名称:CodeHub,代码行数:33,代码来源:IssueLabelsViewModel.cs

示例7: IssueMilestonesViewModel

        public IssueMilestonesViewModel(
            Func<Task<IReadOnlyList<Milestone>>> loadMilestones,
            Func<Task<Milestone>> loadSelectedFunc,
            Func<Milestone, Task> saveFunc)
        {
            var milestones = new ReactiveList<Milestone>();
            Milestones = milestones.CreateDerivedCollection(x => CreateItemViewModel(x));

            this.WhenAnyValue(x => x.Selected)
                .Subscribe(x => {
                    foreach (var a in Milestones)
                        a.IsSelected = a.Number == x?.Number;
                });

            DismissCommand = ReactiveCommand.Create();

            SaveCommand = ReactiveCommand.CreateAsyncTask(_ => {
                DismissCommand.ExecuteIfCan();
                return _selected != _previouslySelected ? saveFunc(_selected) : Task.FromResult(0);
            });

            LoadCommand = ReactiveCommand.CreateAsyncTask(async _ => {
                _previouslySelected = Selected = await loadSelectedFunc();
                milestones.Reset(await loadMilestones());
            });
        }
开发者ID:runt18,项目名称:CodeHub,代码行数:26,代码来源:IssueMilestonesViewModel.cs

示例8: IssueMilestonesViewModel

        public IssueMilestonesViewModel(IApplicationService applicationService)
        {
            Milestones = new ReactiveCollection<MilestoneModel>();

            SelectMilestoneCommand = new ReactiveCommand();
            SelectMilestoneCommand.RegisterAsyncTask(async t =>
            {
                var milestone = t as MilestoneModel;
                if (milestone != null)
                    SelectedMilestone = milestone;

                if (SaveOnSelect)
                {
                    try
                    {
                        int? milestoneNumber = null;
                        if (SelectedMilestone != null) milestoneNumber = SelectedMilestone.Number;
                        var updateReq = applicationService.Client.Users[RepositoryOwner].Repositories[RepositoryName].Issues[IssueId].UpdateMilestone(milestoneNumber);
                        await applicationService.Client.ExecuteAsync(updateReq);
                    }
                    catch (Exception e)
                    {
                        throw new Exception("Unable to to save milestone! Please try again.", e);
                    }
                }

                DismissCommand.ExecuteIfCan();
            });

            LoadCommand.RegisterAsyncTask(t =>
                Milestones.SimpleCollectionLoad(
                    applicationService.Client.Users[RepositoryOwner].Repositories[RepositoryName].Milestones.GetAll(),
                    t as bool?));
        }
开发者ID:GSerjo,项目名称:CodeHub,代码行数:34,代码来源:IssueMilestonesViewModel.cs

示例9: ReleaseItemViewModel

 internal ReleaseItemViewModel(Octokit.Release release)
 {
     Id = release.Id;
     Created = ((release.PublishedAt.HasValue ? release.PublishedAt.Value : release.CreatedAt).LocalDateTime).Humanize();
     Name = string.IsNullOrEmpty(release.Name) ? release.TagName : release.Name;
     GoToCommand = ReactiveCommand.Create();
 }
开发者ID:runt18,项目名称:CodeHub,代码行数:7,代码来源:ReleaseItemViewModel.cs

示例10: MarkdownAccessoryViewModel

        public MarkdownAccessoryViewModel(
            IImgurService imgurService, 
            IMediaPickerFactory mediaPicker, 
            IAlertDialogFactory alertDialogFactory,
            IDefaultValueService defaultValueService)
        {
            PostToImgurCommand = ReactiveCommand.CreateAsyncTask(async _ => {
                if (!defaultValueService.GetOrDefault(IMGUR_UPLOAD_WARN, false))
                {
                    defaultValueService.Set(IMGUR_UPLOAD_WARN, true);
                    await alertDialogFactory.Alert("Please Read!", IMGUR_UPLOAD_WARN_MESSAGE);
                }

                var photo = await mediaPicker.PickPhoto();
                var memoryStream = new MemoryStream();
                await photo.Save(Splat.CompressedBitmapFormat.Jpeg, 0.8f, memoryStream);
                using (alertDialogFactory.Activate("Uploading..."))
                {
                    var model = await imgurService.SendImage(memoryStream.ToArray());
                    if (model == null || model.Data == null || model.Data.Link == null)
                        throw new InvalidOperationException("Unable to upload to Imgur. Please try again later.");
                    return model.Data.Link;
                }
            });

            PostToImgurCommand.ThrownExceptions
                .Where(x => !(x is TaskCanceledException))
                .Subscribe(x => alertDialogFactory.Alert("Upload Error", x.Message));
        }
开发者ID:runt18,项目名称:CodeHub,代码行数:29,代码来源:MarkdownAccessoryViewModel.cs

示例11: GistViewableFileViewModel

        public GistViewableFileViewModel(IApplicationService applicationService, IFilesystemService filesystemService)
        {
            GoToFileSourceCommand = ReactiveCommand.Create();

            LoadCommand = ReactiveCommand.CreateAsyncTask(async t =>
            {
                string data;
                using (var ms = new System.IO.MemoryStream())
                {
                    await applicationService.Client.DownloadRawResource(GistFile.RawUrl, ms);
                    ms.Position = 0;
                    var sr = new System.IO.StreamReader(ms);
                    data = sr.ReadToEnd();
                }
                if (GistFile.Language.Equals("Markdown"))
                    data = await applicationService.Client.Markdown.GetMarkdown(data);

                string path;
                using (var stream = filesystemService.CreateTempFile(out path, "gist.html"))
                {
                    using (var fs = new System.IO.StreamWriter(stream))
                    {
                        fs.Write(data);
                    }
                }

                FilePath = path;
            });
        }
开发者ID:nelsonnan,项目名称:CodeHub,代码行数:29,代码来源:GistViewableFileViewModel.cs

示例12: MyIssuesViewModel

        public MyIssuesViewModel(ISessionService sessionService)
            : base(sessionService)
        {
            _sessionService = sessionService;

            Title = "My Issues";
            Filter = MyIssuesFilterModel.CreateOpenFilter();

            _selectedFilter = this.WhenAnyValue(x => x.Filter)
                .Select(x =>
                {
                    if (x == null || _openFilter.Equals(x))
                        return 0;
                    return _closedFilter.Equals(x) ? 1 : -1;
                })
                .ToProperty(this, x => x.SelectedFilter);

            this.WhenAnyValue(x => x.Filter).Skip(1).Subscribe(filter => {
                InternalItems.Clear();
                LoadCommand.ExecuteIfCan();
                CustomFilterEnabled = !(filter == _closedFilter || filter == _openFilter);
            });

            GoToFilterCommand = ReactiveCommand.Create();
            GoToFilterCommand.Subscribe(_ => {
                var vm = this.CreateViewModel<MyIssuesFilterViewModel>();
                vm.Init(Filter);
                vm.SaveCommand.Subscribe(filter => Filter = filter);
                NavigateTo(vm);
            });
        }
开发者ID:runt18,项目名称:CodeHub,代码行数:31,代码来源:MyIssuesViewModel.cs

示例13: AccountsViewModel

        public AccountsViewModel(ISessionService sessionService, IAccountsRepository accountsRepository)
        {
            _accountsRepository = accountsRepository;
            _sessionService = sessionService;

            Title = "Accounts";

            Accounts = _accounts.CreateDerivedCollection(CreateAccountItem);

            this.WhenAnyValue(x => x.ActiveAccount)
                .Select(x => x == null ? string.Empty : x.Key)
                .Subscribe(x =>
                {
                    foreach (var account in Accounts)
                        account.Selected = account.Id == x;
                });

            var canDismiss = this.WhenAnyValue(x => x.ActiveAccount).Select(x => x != null);
            DismissCommand = ReactiveCommand.Create(canDismiss).WithSubscription(x => Dismiss());

            GoToAddAccountCommand = ReactiveCommand.Create()
                .WithSubscription(_ => NavigateTo(this.CreateViewModel<NewAccountViewModel>()));

            // Activate immediately since WhenActivated triggers off Did* instead of Will* in iOS
            UpdateAccounts();
            this.WhenActivated(d => UpdateAccounts());
        }
开发者ID:jianwoo,项目名称:CodeHub,代码行数:27,代码来源:AccountsViewModel.cs

示例14: PullRequestsViewModel

        public PullRequestsViewModel(IApplicationService applicationService)
		{
            PullRequests = new ReactiveList<PullRequestModel>();

            GoToPullRequestCommand = ReactiveCommand.Create();
		    GoToPullRequestCommand.OfType<PullRequestModel>().Subscribe(pullRequest =>
		    {
		        var vm = CreateViewModel<PullRequestViewModel>();
		        vm.RepositoryOwner = RepositoryOwner;
		        vm.RepositoryName = RepositoryName;
		        vm.PullRequestId = pullRequest.Number;
		        vm.PullRequest = pullRequest;
		        vm.WhenAnyValue(x => x.PullRequest).Skip(1).Subscribe(x =>
		        {
                    var index = PullRequests.IndexOf(pullRequest);
                    if (index < 0) return;
                    PullRequests[index] = x;
                    PullRequests.Reset();
		        });
                ShowViewModel(vm);
		    });

		    this.WhenAnyValue(x => x.SelectedFilter).Skip(1).Subscribe(_ => LoadCommand.ExecuteIfCan());

            LoadCommand = ReactiveCommand.CreateAsyncTask(t =>
            {
                var state = SelectedFilter == 0 ? "open" : "closed";
			    var request = applicationService.Client.Users[RepositoryOwner].Repositories[RepositoryName].PullRequests.GetAll(state: state);
                return PullRequests.SimpleCollectionLoad(request, t as bool?);
            });
		}
开发者ID:nelsonnan,项目名称:CodeHub,代码行数:31,代码来源:PullRequestsViewModel.cs

示例15: IssueAssignedToViewModel

        public IssueAssignedToViewModel(IApplicationService applicationService)
        {
            _applicationService = applicationService;
            Users = new ReactiveCollection<BasicUserModel>();

            SelectUserCommand = new ReactiveCommand();
            SelectUserCommand.RegisterAsyncTask(async t =>
            {
                var selectedUser = t as BasicUserModel;
                if (selectedUser != null)
                    SelectedUser = selectedUser;

                if (SaveOnSelect)
                {
                    var assignee = SelectedUser != null ? SelectedUser.Login : null;
                    var updateReq = _applicationService.Client.Users[RepositoryOwner].Repositories[RepositoryName].Issues[IssueId].UpdateAssignee(assignee);
                    await _applicationService.Client.ExecuteAsync(updateReq);
                }

                DismissCommand.ExecuteIfCan();
            });

            LoadCommand.RegisterAsyncTask(t => 
                Users.SimpleCollectionLoad(applicationService.Client.Users[RepositoryOwner].Repositories[RepositoryName].GetAssignees(), t as bool?));
        }
开发者ID:GSerjo,项目名称:CodeHub,代码行数:25,代码来源:IssueAssignedToViewModel.cs


注:本文中的IReactiveCommand类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。