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


C# IReactiveCommand.Where方法代码示例

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


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

示例1: CreateFileViewModel

        public CreateFileViewModel(ISessionService sessionService, IAlertDialogFactory alertDialogFactory)
        {
            Title = "Create File";

            this.WhenAnyValue(x => x.Name)
                .Subscribe(x => CommitMessage = "Created " + x);

            GoToCommitMessageCommand = ReactiveCommand.Create(
                this.WhenAnyValue(x => x.Name, x => !string.IsNullOrEmpty(x)));

            SaveCommand = ReactiveCommand.CreateAsyncTask(
                this.WhenAnyValue(x => x.Name).Select(x => !string.IsNullOrEmpty(x)), async _ => {
                    var content = Content ?? string.Empty;
                    var path = System.IO.Path.Combine(Path ?? string.Empty, Name);
                    var request = new Octokit.CreateFileRequest(CommitMessage, content) { Branch = Branch };
                    using (alertDialogFactory.Activate("Commiting..."))
                        return await sessionService.GitHubClient.Repository.Content.CreateFile(RepositoryOwner, RepositoryName, path, request);
                });
            SaveCommand.Subscribe(x => Dismiss());

            DismissCommand = ReactiveCommand.CreateAsyncTask(async t => {
                if (string.IsNullOrEmpty(Name) && string.IsNullOrEmpty(Content)) return true;
                return await alertDialogFactory.PromptYesNo("Discard File?", "Are you sure you want to discard this file?");
            });
            DismissCommand.Where(x => x).Subscribe(_ => Dismiss());
        }
开发者ID:runt18,项目名称:CodeHub,代码行数:26,代码来源:CreateFileViewModel.cs

示例2: CreateFileViewModel

        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());
        }
开发者ID:zdd910,项目名称:CodeHub,代码行数:32,代码来源:CreateFileViewModel.cs

示例3: FeedbackComposerViewModel

        public FeedbackComposerViewModel(ISessionService applicationService, IAlertDialogFactory alertDialogFactory)
        {
            this.WhenAnyValue(x => x.IsFeature).Subscribe(x => Title = x ? "New Feature" : "Bug Report");

            SubmitCommand = ReactiveCommand.CreateAsyncTask(
                this.WhenAnyValue(x => x.Subject).Select(x => !string.IsNullOrEmpty(x)),
                async _ =>
            {
                if (string.IsNullOrEmpty(Subject))
                    throw new ArgumentException(string.Format("You must provide a title for this {0}!", IsFeature ? "feature" : "bug"));

                var labels = await applicationService.GitHubClient.Issue.Labels.GetAllForRepository(CodeHubOwner, CodeHubName);
                var createLabels = labels.Where(x => string.Equals(x.Name, IsFeature ? "feature request" : "bug", StringComparison.OrdinalIgnoreCase)).Select(x => x.Name).Distinct();

                var createIssueRequest = new Octokit.NewIssue(Subject) { Body = Description };
                foreach (var label in createLabels)
                    createIssueRequest.Labels.Add(label);
                var createdIssue = await applicationService.GitHubClient.Issue.Create(CodeHubOwner, CodeHubName, createIssueRequest);

                _createdIssueSubject.OnNext(createdIssue);
                Dismiss();
            });

            DismissCommand = ReactiveCommand.CreateAsyncTask(async t =>
            {
                if (string.IsNullOrEmpty(Description) && string.IsNullOrEmpty(Subject))
                    return true;
                var itemType = IsFeature ? "feature" : "bug";
                return await alertDialogFactory.PromptYesNo("Discard " + itemType.Transform(To.TitleCase) + "?", "Are you sure you want to discard this " + itemType + "?");
            });
            DismissCommand.Where(x => x).Subscribe(_ => Dismiss());
        }
开发者ID:runt18,项目名称:CodeHub,代码行数:32,代码来源:FeedbackComposerViewModel.cs

示例4: ComposerViewModel

        public ComposerViewModel(string title, Func<string, Task> saveFunc, IAlertDialogFactory alertDialogFactory) 
        {
            Title = title;
            SaveCommand = ReactiveCommand.CreateAsyncTask(
                this.WhenAnyValue(x => x.Text).Select(x => !string.IsNullOrEmpty(x)),
                t => saveFunc(Text));
            SaveCommand.AlertExecuting(alertDialogFactory, "Saving...");
            SaveCommand.Subscribe(x => Dismiss());

            DismissCommand = ReactiveCommand.CreateAsyncTask(async t =>
                {
                    if (string.IsNullOrEmpty(Text))
                        return true;
                    return await alertDialogFactory.PromptYesNo("Discard Comment?", "Are you sure you want to discard this comment?");
                });
            DismissCommand.Where(x => x).Subscribe(_ => Dismiss());
        }
开发者ID:zdd910,项目名称:CodeHub,代码行数:17,代码来源:ComposerViewModel.cs

示例5: GistModifyViewModel

        protected GistModifyViewModel()
        {
            Files = InternalFiles.CreateDerivedCollection(x => 
            {
                var item = new GistFileItemViewModel(x.Item1, x.Item2);
                item.EditCommand.Subscribe(_ => NavigateTo(new GistFileEditViewModel(y =>
                {
                    var i = InternalFiles.IndexOf(x);
                    InternalFiles.Remove(x);
                    InternalFiles.Insert(i, Tuple.Create(y.Item1.Trim(), y.Item2));
                    return Task.FromResult(0);
                })
                {
                    Filename = x.Item1,
                    Description = x.Item2
                }));
                item.DeleteCommand.Subscribe(_ => InternalFiles.Remove(x));
                return item;
            });

            var canSave = new BehaviorSubject<bool>(false);
            Files.IsEmptyChanged.Select(x => !x).Subscribe(canSave.OnNext);

            SaveCommand = ReactiveCommand.CreateAsyncTask(canSave, _ => SaveGist());
            SaveCommand.Subscribe(_ => Dismiss());

            AddGistFileCommand = ReactiveCommand.Create();
            AddGistFileCommand.Subscribe(_ => NavigateTo(new GistFileAddViewModel(x =>
            {
                if (Files.Any(y => y.Name == x.Item1))
                    throw new Exception("Gist already contains a file with that name!");
                InternalFiles.Add(Tuple.Create(x.Item1.Trim(), x.Item2));
                return Task.FromResult(0);
            })));

            DismissCommand = ReactiveCommand.CreateAsyncTask(t => Discard());
            DismissCommand.Where(x => x).Subscribe(_ => Dismiss());
        }
开发者ID:zdd910,项目名称:CodeHub,代码行数:38,代码来源:GistModifyViewModel.cs

示例6: EditFileViewModel

        public EditFileViewModel(ISessionService applicationService, IAlertDialogFactory alertDialogFactory)
	    {
            Title = "Edit";

            this.WhenAnyValue(x => x.Path)
                .IsNotNull()
                .Subscribe(x => CommitMessage = "Updated " + x.Substring(x.LastIndexOf('/') + 1));

            this.WhenAnyValue(x => x.Text)
                .Subscribe(x => _lastEdit = DateTime.Now);

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

    	            var request = applicationService.Client.Users[RepositoryOwner].Repositories[RepositoryName].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) ?? string.Empty;
                    _lastLoad = DateTime.Now;
    	        });

            SaveCommand = ReactiveCommand.CreateAsyncTask(
                this.WhenAnyValue(x => x.CommitMessage).Select(x => !string.IsNullOrEmpty(x)),
                async _ =>
            {
                var path = Path.StartsWith("/", StringComparison.Ordinal) ? Path : string.Concat("/", Path);
                var request = applicationService.Client.Users[RepositoryOwner].Repositories[RepositoryName]
                    .UpdateContentFile(path, CommitMessage, Text, BlobSha, Branch);

                using (alertDialogFactory.Activate("Commiting..."))
                {
                    var response = await applicationService.Client.ExecuteAsync(request);
                    _sourceChangedSubject.OnNext(response.Data);
                }

                Dismiss();
            });

            DismissCommand = ReactiveCommand.CreateAsyncTask(async t =>
            {
                if (string.IsNullOrEmpty(Text)) return true;
                if (_lastEdit <= _lastLoad) return true;
                return await alertDialogFactory.PromptYesNo("Discard Edit?", "Are you sure you want to discard these changes?");
            });
            DismissCommand.Where(x => x).Subscribe(_ => Dismiss());
	    }
开发者ID:zdd910,项目名称:CodeHub,代码行数:51,代码来源:EditFileViewModel.cs

示例7: IssueModifyViewModel

        protected IssueModifyViewModel(
            ISessionService applicationService, 
            IAlertDialogFactory alertDialogFactory)
	    {
            GoToAssigneesCommand = ReactiveCommand.Create();
            GoToLabelsCommand = ReactiveCommand.Create();
            GoToMilestonesCommand = ReactiveCommand.Create();

            // Make sure repeated access is cached with Lazy
            var getAssignees = new Lazy<Task<IReadOnlyList<User>>>(() => applicationService.GitHubClient.Issue.Assignee.GetAllForRepository(RepositoryOwner, RepositoryName));
            var getMilestones = new Lazy<Task<IReadOnlyList<Milestone>>>(() => applicationService.GitHubClient.Issue.Milestone.GetAllForRepository(RepositoryOwner, RepositoryName));
            var getLables = new Lazy<Task<IReadOnlyList<Label>>>(() => applicationService.GitHubClient.Issue.Labels.GetAllForRepository(RepositoryOwner, RepositoryName));

            Assignees = new IssueAssigneeViewModel(() => getAssignees.Value);
            Milestones = new IssueMilestonesViewModel(() => getMilestones.Value);
            Labels = new IssueLabelsViewModel(() => getLables.Value);

            var canSave = this.WhenAnyValue(x => x.Subject).Select(x => !string.IsNullOrEmpty(x));
            SaveCommand = ReactiveCommand.CreateAsyncTask(canSave, _ => {
                using (alertDialogFactory.Activate("Saving..."))
                    return Save();
            });

            // This is because the stupid ReactiveUI issue with the tableview :(
            SaveCommand.Subscribe(_ => Dismiss());

            LoadCommand = ReactiveCommand.CreateAsyncTask(async t =>
            {
                try
                {
                    IsCollaborator = await applicationService.GitHubClient.Repository.RepoCollaborators
                        .IsCollaborator(RepositoryOwner, RepositoryName, applicationService.Account.Username);
                }
                catch
                {
                    IsCollaborator = false;
                }
            });

            DismissCommand = ReactiveCommand.CreateAsyncTask(t => Discard());
            DismissCommand.Where(x => x).Subscribe(_ => Dismiss());
	    }
开发者ID:zdd910,项目名称:CodeHub,代码行数:42,代码来源:IssueModifyViewModel.cs


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