Esempio n. 1
0
        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());
        }
Esempio n. 2
0
        public CreateFileViewModel(ISessionService sessionService, 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    = 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());
        }
Esempio n. 3
0
        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 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());
        }
Esempio n. 5
0
        public EditFileViewModel(ISessionService sessionService, 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      = sessionService.Client.Users[RepositoryOwner].Repositories[RepositoryName].GetContentFile(path, Branch ?? "master");
                request.UseCache = false;
                var data         = await sessionService.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.TrimStart('/');
                var request = new Octokit.UpdateFileRequest(CommitMessage, Text, BlobSha)
                {
                    Branch = Branch
                };
                using (alertDialogFactory.Activate("Commiting..."))
                    return(await sessionService.GitHubClient.Repository.Content.UpdateFile(RepositoryOwner, RepositoryName, path, request));
            });
            SaveCommand.Subscribe(x => 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());
        }
Esempio n. 6
0
        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());
        }
Esempio n. 7
0
        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());
        }
        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());
        }
Esempio n. 9
0
        protected IssueModifyViewModel(
            ISessionService sessionService,
            IAlertDialogFactory alertDialogFactory)
        {
            GoToAssigneesCommand  = ReactiveCommand.Create();
            GoToLabelsCommand     = ReactiveCommand.Create();
            GoToMilestonesCommand = ReactiveCommand.Create();

            _assigneesCache = new Lazy <Task <IReadOnlyList <User> > >(() =>
                                                                       sessionService.GitHubClient.Issue.Assignee.GetAllForRepository(RepositoryOwner, RepositoryName));
            _milestonesCache = new Lazy <Task <IReadOnlyList <Milestone> > >(() =>
                                                                             sessionService.GitHubClient.Issue.Milestone.GetAllForRepository(RepositoryOwner, RepositoryName));
            _labelsCache = new Lazy <Task <IReadOnlyList <Label> > >(() =>
                                                                     sessionService.GitHubClient.Issue.Labels.GetAllForRepository(RepositoryOwner, RepositoryName));

            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 sessionService.GitHubClient.Repository.RepoCollaborators
                                     .IsCollaborator(RepositoryOwner, RepositoryName, sessionService.Account.Username);
                }
                catch
                {
                    IsCollaborator = false;
                }
            });

            DismissCommand = ReactiveCommand.CreateAsyncTask(t => Discard());
            DismissCommand.Where(x => x).Subscribe(_ => Dismiss());
        }
Esempio n. 10
0
        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());
        }
Esempio n. 11
0
        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());
        }
Esempio n. 12
0
        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());
	    }
Esempio n. 13
0
        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());
	    }