Example #1
0
        public async Task InitializeAsync(IConnection connection)
        {
            modelService = await modelServiceFactory.CreateAsync(connection);

            Title = string.Format(CultureInfo.CurrentCulture, Resources.CreateTitle, connection.HostAddress.Title);

            accounts = modelService.GetAccounts()
                       .ObserveOn(RxApp.MainThreadScheduler)
                       .ToProperty(this, vm => vm.Accounts, initialValue: new ReadOnlyCollection <IAccount>(new IAccount[] { }));

            this.WhenAny(x => x.Accounts, x => x.Value)
            .Select(accts => accts?.FirstOrDefault())
            .WhereNotNull()
            .Subscribe(a => SelectedAccount = a);

            GitIgnoreTemplates = TrackingCollection.CreateListenerCollectionAndRun(
                modelService.GetGitIgnoreTemplates(),
                new[] { GitIgnoreItem.None },
                OrderedComparer <GitIgnoreItem> .OrderByDescending(item => GitIgnoreItem.IsRecommended(item.Name)).Compare,
                x =>
            {
                if (x.Name.Equals("VisualStudio", StringComparison.OrdinalIgnoreCase))
                {
                    SelectedGitIgnoreTemplate = x;
                }
            });

            Licenses = TrackingCollection.CreateListenerCollectionAndRun(
                modelService.GetLicenses(),
                new[] { LicenseItem.None },
                OrderedComparer <LicenseItem> .OrderByDescending(item => LicenseItem.IsRecommended(item.Name)).Compare);
        }
        void CreatePullRequests()
        {
            PullRequests          = new TrackingCollection <IPullRequestModel>();
            pullRequests.Comparer = OrderedComparer <IPullRequestModel> .OrderByDescending(x => x.UpdatedAt).Compare;

            pullRequests.NewerComparer = OrderedComparer <IPullRequestModel> .OrderByDescending(x => x.UpdatedAt).Compare;
        }
Example #3
0
        public PullRequestListViewModel(
            IRepositoryHost repositoryHost,
            ILocalRepositoryModel repository,
            IPackageSettings settings)
        {
            this.repositoryHost = repositoryHost;
            this.repository     = repository;
            this.settings       = settings;

            Title = Resources.PullRequestsNavigationItemText;

            this.listSettings = settings.UIState
                                .GetOrCreateRepositoryState(repository.CloneUrl)
                                .PullRequests;

            States = new List <PullRequestState> {
                new PullRequestState {
                    IsOpen = true, Name = "Open"
                },
                new PullRequestState {
                    IsOpen = false, Name = "Closed"
                },
                new PullRequestState {
                    Name = "All"
                }
            };

            trackingAuthors = new TrackingCollection <IAccount>(Observable.Empty <IAccount>(),
                                                                OrderedComparer <IAccount> .OrderByDescending(x => x.Login).Compare);
            trackingAssignees = new TrackingCollection <IAccount>(Observable.Empty <IAccount>(),
                                                                  OrderedComparer <IAccount> .OrderByDescending(x => x.Login).Compare);
            trackingAuthors.Subscribe();
            trackingAssignees.Subscribe();

            Authors   = trackingAuthors.CreateListenerCollection(EmptyUser, this.WhenAnyValue(x => x.SelectedAuthor));
            Assignees = trackingAssignees.CreateListenerCollection(EmptyUser, this.WhenAnyValue(x => x.SelectedAssignee));

            PullRequests          = new TrackingCollection <IPullRequestModel>();
            pullRequests.Comparer = OrderedComparer <IPullRequestModel> .OrderByDescending(x => x.UpdatedAt).Compare;

            pullRequests.NewerComparer = OrderedComparer <IPullRequestModel> .OrderByDescending(x => x.UpdatedAt).Compare;

            this.WhenAny(x => x.SelectedState, x => x.Value)
            .Where(x => PullRequests != null)
            .Subscribe(s => UpdateFilter(s, SelectedAssignee, SelectedAuthor));

            this.WhenAny(x => x.SelectedAssignee, x => x.Value)
            .Where(x => PullRequests != null && x != EmptyUser && IsLoaded)
            .Subscribe(a => UpdateFilter(SelectedState, a, SelectedAuthor));

            this.WhenAny(x => x.SelectedAuthor, x => x.Value)
            .Where(x => PullRequests != null && x != EmptyUser && IsLoaded)
            .Subscribe(a => UpdateFilter(SelectedState, SelectedAssignee, a));

            SelectedState   = States.FirstOrDefault(x => x.Name == listSettings.SelectedState) ?? States[0];
            OpenPullRequest = ReactiveCommand.Create();
            OpenPullRequest.Subscribe(DoOpenPullRequest);
            CreatePullRequest = ReactiveCommand.Create();
            CreatePullRequest.Subscribe(_ => DoCreatePullRequest());
        }
Example #4
0
        public PullRequestListViewModel(
            IRepositoryHost repositoryHost,
            ILocalRepositoryModel repository,
            IPackageSettings settings)
        {
            this.repositoryHost = repositoryHost;
            this.repository     = repository;
            this.settings       = settings;

            this.listSettings = settings.UIState
                                .GetOrCreateRepositoryState(repository.CloneUrl)
                                .PullRequests;

            openPullRequestCommand = ReactiveCommand.Create();
            openPullRequestCommand.Subscribe(_ =>
            {
                VisualStudio.Services.DefaultExportProvider.GetExportedValue <IVisualStudioBrowser>().OpenUrl(repositoryHost.Address.WebUri);
            });

            States = new List <PullRequestState> {
                new PullRequestState {
                    IsOpen = true, Name = "Open"
                },
                new PullRequestState {
                    IsOpen = false, Name = "Closed"
                },
                new PullRequestState {
                    Name = "All"
                }
            };

            trackingAuthors = new TrackingCollection <IAccount>(Observable.Empty <IAccount>(),
                                                                OrderedComparer <IAccount> .OrderByDescending(x => x.Login).Compare);
            trackingAssignees = new TrackingCollection <IAccount>(Observable.Empty <IAccount>(),
                                                                  OrderedComparer <IAccount> .OrderByDescending(x => x.Login).Compare);
            trackingAuthors.Subscribe();
            trackingAssignees.Subscribe();

            Authors   = trackingAuthors.CreateListenerCollection(EmptyUser, this.WhenAnyValue(x => x.SelectedAuthor));
            Assignees = trackingAssignees.CreateListenerCollection(EmptyUser, this.WhenAnyValue(x => x.SelectedAssignee));

            PullRequests          = new TrackingCollection <IPullRequestModel>();
            pullRequests.Comparer = OrderedComparer <IPullRequestModel> .OrderByDescending(x => x.UpdatedAt).Compare;

            pullRequests.NewerComparer = OrderedComparer <IPullRequestModel> .OrderByDescending(x => x.UpdatedAt).Compare;

            this.WhenAny(x => x.SelectedState, x => x.Value)
            .Where(x => PullRequests != null)
            .Subscribe(s => UpdateFilter(s, SelectedAssignee, SelectedAuthor));

            this.WhenAny(x => x.SelectedAssignee, x => x.Value)
            .Where(x => PullRequests != null && x != EmptyUser && IsLoaded)
            .Subscribe(a => UpdateFilter(SelectedState, a, SelectedAuthor));

            this.WhenAny(x => x.SelectedAuthor, x => x.Value)
            .Where(x => PullRequests != null && x != EmptyUser && IsLoaded)
            .Subscribe(a => UpdateFilter(SelectedState, SelectedAssignee, a));

            SelectedState = States.FirstOrDefault(x => x.Name == listSettings.SelectedState) ?? States[0];
        }
        public PullRequestListViewModel(IRepositoryHost repositoryHost, ISimpleRepositoryModel repository)
        {
            this.repositoryHost = repositoryHost;
            this.repository     = repository;

            openPullRequestCommand = ReactiveCommand.Create();
            openPullRequestCommand.Subscribe(_ =>
            {
                VisualStudio.Services.DefaultExportProvider.GetExportedValue <IVisualStudioBrowser>().OpenUrl(repositoryHost.Address.WebUri);
            });

            States = new List <PullRequestState> {
                new PullRequestState {
                    IsOpen = true, Name = "Open"
                },
                new PullRequestState {
                    IsOpen = false, Name = "Closed"
                },
                new PullRequestState {
                    Name = "All"
                }
            };
            SelectedState = States[0];

            this.WhenAny(x => x.SelectedState, x => x.Value)
            .Where(x => PullRequests != null)
            .Subscribe(s => UpdateFilter(s, SelectedAssignee, SelectedAuthor));

            this.WhenAny(x => x.SelectedAssignee, x => x.Value)
            .Where(x => PullRequests != null)
            .Subscribe(a => UpdateFilter(SelectedState, a, SelectedAuthor));

            this.WhenAny(x => x.SelectedAuthor, x => x.Value)
            .Where(x => PullRequests != null)
            .Subscribe(a => UpdateFilter(SelectedState, SelectedAssignee, a));

            trackingAuthors = new TrackingCollection <IAccount>(Observable.Empty <IAccount>(),
                                                                OrderedComparer <IAccount> .OrderByDescending(x => x.Login).Compare);
            trackingAssignees = new TrackingCollection <IAccount>(Observable.Empty <IAccount>(),
                                                                  OrderedComparer <IAccount> .OrderByDescending(x => x.Login).Compare);
            trackingAuthors.Subscribe();
            trackingAssignees.Subscribe();

            Authors = trackingAuthors.CreateListenerCollection(new List <IAccount> {
                EmptyUser
            });
            Assignees = trackingAssignees.CreateListenerCollection(new List <IAccount> {
                EmptyUser
            });

            PullRequests          = new TrackingCollection <IPullRequestModel>();
            pullRequests.Comparer = OrderedComparer <IPullRequestModel> .OrderByDescending(x => x.UpdatedAt).Compare;

            pullRequests.Filter        = (pr, i, l) => pr.IsOpen;
            pullRequests.NewerComparer = OrderedComparer <IPullRequestModel> .OrderByDescending(x => x.UpdatedAt).Compare;
        }
Example #6
0
        public void CustomComparerTest()
        {
            var items = new List <string> {
                "aaa", "AAA", "abb", "aaaa"
            };

            items.Sort(OrderedComparer <string> .OrderBy(x => x, StringComparer.Ordinal));
            Assert.True(items.SequenceEqual(new[] { "AAA", "aaa", "aaaa", "abb" }));

            items.Sort(OrderedComparer <string> .OrderByDescending(x => x.Length).ThenBy(x => x, StringComparer.Ordinal));
            Assert.True(items.SequenceEqual(new[] { "aaaa", "AAA", "aaa", "abb" }));

            items.Sort(OrderedComparer <string> .OrderBy(x => x.Length).ThenBy(x => x, StringComparer.Ordinal));
            Assert.True(items.SequenceEqual(new[] { "AAA", "aaa", "abb", "aaaa" }));

            items.Sort(OrderedComparer <string> .OrderBy(x => x.Length).ThenBy(x => x, StringComparer.OrdinalIgnoreCase));
            Assert.True(items.SequenceEqual(new[] { "AAA", "AAA", "abb", "aaaa" }, StringComparer.OrdinalIgnoreCase));
        }
        public void SmokeTest()
        {
            var adam = new Employee {
                Name = "Adam", Age = 50, Salary = 125
            };
            var alice = new Employee {
                Name = "Alice", Age = 25, Salary = 100
            };
            var bob = new Employee {
                Name = "Bob", Age = 30, Salary = 75
            };
            var carol = new Employee {
                Name = "Carol", Age = 35, Salary = 100
            };
            var xavier = new Employee {
                Name = "Xavier", Age = 35, Salary = 100
            };

            var employees = new List <Employee> {
                adam, alice, bob, carol, xavier
            };

            employees.Sort(OrderedComparer <Employee> .OrderBy(x => x.Name));
            Assert.True(employees.SequenceEqual(new[] { adam, alice, bob, carol, xavier }));

            employees.Sort(OrderedComparer <Employee>
                           .OrderByDescending(x => x.Age)
                           .ThenBy(x => x.Name)
                           );
            Assert.True(employees.SequenceEqual(new[] { adam, carol, xavier, bob, alice }));

            employees.Sort(OrderedComparer <Employee>
                           .OrderByDescending(x => x.Salary)
                           .ThenBy(x => x.Name, StringComparer.OrdinalIgnoreCase)
                           );
            Assert.True(employees.SequenceEqual(new[] { adam, alice, carol, xavier, bob }));

            employees.Sort(OrderedComparer <Employee>
                           .OrderByDescending(x => x.Age)
                           .ThenByDescending(x => x.Salary)
                           .ThenBy(x => x.Name)
                           );
            Assert.True(employees.SequenceEqual(new[] { adam, carol, xavier, bob, alice }));
        }
Example #8
0
            public void DerivedCollectionShouldHandleRemovesOfFilteredItems()
            {
                var a = new ReactiveVisibilityItem <string>("A", true);
                var b = new ReactiveVisibilityItem <string>("B", true);
                var c = new ReactiveVisibilityItem <string>("C", true);
                var d = new ReactiveVisibilityItem <string>("D", false);
                var e = new ReactiveVisibilityItem <string>("E", true);

                var items = new ReactiveCollection <ReactiveVisibilityItem <string> >(new[] { a, b, c, d, e })
                {
                    ChangeTrackingEnabled = true
                };

                var onlyVisible = items.CreateDerivedCollection(
                    x => x.Value,
                    x => x.IsVisible,
                    OrderedComparer <string> .OrderByDescending(x => x).Compare
                    );

                Assert.True(onlyVisible.SequenceEqual(new[] { "E", "C", "B", "A" }, StringComparer.Ordinal));
                Assert.Equal(4, onlyVisible.Count);

                // Removal of an item from the source collection that's filtered in the derived collection should
                // have no effect on the derived.
                items.Remove(d);

                Assert.True(onlyVisible.SequenceEqual(new[] { "E", "C", "B", "A" }, StringComparer.Ordinal));
                Assert.Equal(4, onlyVisible.Count);

                c.IsVisible = false;
                Assert.Equal(3, onlyVisible.Count);
                Assert.True(onlyVisible.SequenceEqual(new[] { "E", "B", "A" }, StringComparer.Ordinal));

                items.Remove(c);
                Assert.Equal(3, onlyVisible.Count);
                Assert.True(onlyVisible.SequenceEqual(new[] { "E", "B", "A" }, StringComparer.Ordinal));

                items.Remove(b);
                Assert.Equal(2, onlyVisible.Count);
                Assert.True(onlyVisible.SequenceEqual(new[] { "E", "A" }, StringComparer.Ordinal));
            }
        public RepositoryCreationViewModel(
            IConnection connection,
            IModelServiceFactory modelServiceFactory,
            IOperatingSystem operatingSystem,
            IRepositoryCreationService repositoryCreationService,
            IUsageTracker usageTracker)
        {
            Guard.ArgumentNotNull(connection, nameof(connection));
            Guard.ArgumentNotNull(modelServiceFactory, nameof(modelServiceFactory));
            Guard.ArgumentNotNull(operatingSystem, nameof(operatingSystem));
            Guard.ArgumentNotNull(repositoryCreationService, nameof(repositoryCreationService));
            Guard.ArgumentNotNull(usageTracker, nameof(usageTracker));

            this.operatingSystem           = operatingSystem;
            this.repositoryCreationService = repositoryCreationService;
            this.usageTracker = usageTracker;

            Title = string.Format(CultureInfo.CurrentCulture, Resources.CreateTitle, connection.HostAddress.Title);
            SelectedGitIgnoreTemplate = GitIgnoreItem.None;
            SelectedLicense           = LicenseItem.None;

            modelService = modelServiceFactory.CreateBlocking(connection);

            accounts = modelService.GetAccounts()
                       .ObserveOn(RxApp.MainThreadScheduler)
                       .ToProperty(this, vm => vm.Accounts, initialValue: new ReadOnlyCollection <IAccount>(new IAccount[] {}));

            this.WhenAny(x => x.Accounts, x => x.Value)
            .Select(accts => accts?.FirstOrDefault())
            .WhereNotNull()
            .Subscribe(a => SelectedAccount = a);

            browseForDirectoryCommand.Subscribe(_ => ShowBrowseForDirectoryDialog());

            BaseRepositoryPathValidator = ReactivePropertyValidator.ForObservable(this.WhenAny(x => x.BaseRepositoryPath, x => x.Value))
                                          .IfNullOrEmpty(Resources.RepositoryCreationClonePathEmpty)
                                          .IfTrue(x => x.Length > 200, Resources.RepositoryCreationClonePathTooLong)
                                          .IfContainsInvalidPathChars(Resources.RepositoryCreationClonePathInvalidCharacters)
                                          .IfPathNotRooted(Resources.RepositoryCreationClonePathInvalid);

            var nonNullRepositoryName = this.WhenAny(
                x => x.RepositoryName,
                x => x.BaseRepositoryPath,
                (x, y) => x.Value)
                                        .WhereNotNull();

            RepositoryNameValidator = ReactivePropertyValidator.ForObservable(nonNullRepositoryName)
                                      .IfNullOrEmpty(Resources.RepositoryNameValidatorEmpty)
                                      .IfTrue(x => x.Length > 100, Resources.RepositoryNameValidatorTooLong)
                                      .IfTrue(IsAlreadyRepoAtPath, Resources.RepositoryNameValidatorAlreadyExists);

            SafeRepositoryNameWarningValidator = ReactivePropertyValidator.ForObservable(nonNullRepositoryName)
                                                 .Add(repoName =>
            {
                var parsedReference = GetSafeRepositoryName(repoName);
                return(parsedReference != repoName ? String.Format(CultureInfo.CurrentCulture, Resources.SafeRepositoryNameWarning, parsedReference) : null);
            });

            this.WhenAny(x => x.BaseRepositoryPathValidator.ValidationResult, x => x.Value)
            .Subscribe();

            CreateRepository = InitializeCreateRepositoryCommand();

            canKeepPrivate = CanKeepPrivateObservable.CombineLatest(CreateRepository.IsExecuting,
                                                                    (canKeep, publishing) => canKeep && !publishing)
                             .ToProperty(this, x => x.CanKeepPrivate);

            isCreating = CreateRepository.IsExecuting
                         .ToProperty(this, x => x.IsCreating);

            GitIgnoreTemplates = TrackingCollection.CreateListenerCollectionAndRun(
                modelService.GetGitIgnoreTemplates(),
                new[] { GitIgnoreItem.None },
                OrderedComparer <GitIgnoreItem> .OrderByDescending(item => GitIgnoreItem.IsRecommended(item.Name)).Compare,
                x =>
            {
                if (x.Name.Equals("VisualStudio", StringComparison.OrdinalIgnoreCase))
                {
                    SelectedGitIgnoreTemplate = x;
                }
            });

            Licenses = TrackingCollection.CreateListenerCollectionAndRun(
                modelService.GetLicenses(),
                new[] { LicenseItem.None },
                OrderedComparer <LicenseItem> .OrderByDescending(item => LicenseItem.IsRecommended(item.Name)).Compare);

            BaseRepositoryPath = repositoryCreationService.DefaultClonePath;
        }
Example #10
0
        public void CopyFromDoesNotLoseAvatar()
        {
            var userImage = AvatarProvider.CreateBitmapImage("pack://application:,,,/GitHub.App;component/Images/default_user_avatar.png");
            var orgImage  = AvatarProvider.CreateBitmapImage("pack://application:,,,/GitHub.App;component/Images/default_org_avatar.png");

            var initialBitmapImageSubject = new Subject <BitmapImage>();

            var collectionEvent     = new ManualResetEvent(false);
            var avatarPropertyEvent = new ManualResetEvent(false);

            //Creating an initial account with an observable that returns immediately
            const string login = "******";
            const int    initialOwnedPrivateRepositoryCount = 1;

            var initialAccount = new Account(login, true, false, initialOwnedPrivateRepositoryCount, 0, initialBitmapImageSubject);

            //Creating the test collection
            var col = new TrackingCollection <IAccount>(Observable.Empty <IAccount>(), OrderedComparer <IAccount> .OrderByDescending(x => x.Login).Compare);

            col.Subscribe(account =>
            {
                collectionEvent.Set();
            }, () => { });

            //Adding that account to the TrackingCollection
            col.AddItem(initialAccount);

            //Waiting for the collection add the item
            collectionEvent.WaitOne();
            collectionEvent.Reset();

            //Checking some initial properties
            Assert.That(login, Is.EqualTo(col[0].Login));
            Assert.That(initialOwnedPrivateRepositoryCount, Is.EqualTo(col[0].OwnedPrivateRepos));

            //Demonstrating that the avatar is not yet present
            Assert.That(col[0].Avatar, Is.Null);

            //Adding a listener to check for the changing of the Avatar property
            initialAccount.Changed.Subscribe(args =>
            {
                if (args.PropertyName == "Avatar")
                {
                    avatarPropertyEvent.Set();
                }
            });

            //Providing the first avatar
            initialBitmapImageSubject.OnNext(userImage);
            initialBitmapImageSubject.OnCompleted();

            //Waiting for the avatar to be added
            avatarPropertyEvent.WaitOne();
            avatarPropertyEvent.Reset();

            //Demonstrating that the avatar is present
            Assert.That(col[0].Avatar, Is.Not.Null);
            Assert.True(BitmapSourcesAreEqual(col[0].Avatar, userImage));
            Assert.False(BitmapSourcesAreEqual(col[0].Avatar, orgImage));

            //Creating an account update
            const int updatedOwnedPrivateRepositoryCount = 2;
            var       updatedBitmapImageSubject          = new Subject <BitmapImage>();
            var       updatedAccount = new Account(login, true, false, updatedOwnedPrivateRepositoryCount, 0, updatedBitmapImageSubject);

            //Updating the account in the collection
            col.AddItem(updatedAccount);

            //Waiting for the collection to process the update
            collectionEvent.WaitOne();
            collectionEvent.Reset();

            //Providing the second avatar
            updatedBitmapImageSubject.OnNext(orgImage);
            updatedBitmapImageSubject.OnCompleted();

            //Waiting for the delayed bitmap image observable
            avatarPropertyEvent.WaitOne();
            avatarPropertyEvent.Reset();

            //Login is the id, so that should be the same
            Assert.That(login, Is.EqualTo(col[0].Login));

            //CopyFrom() should have updated this field
            Assert.That(updatedOwnedPrivateRepositoryCount, Is.EqualTo(col[0].OwnedPrivateRepos));

            //CopyFrom() should not cause a race condition here
            Assert.That(col[0].Avatar, Is.Not.Null);
            Assert.True(BitmapSourcesAreEqual(col[0].Avatar, orgImage));
            Assert.False(BitmapSourcesAreEqual(col[0].Avatar, userImage));
        }
Example #11
0
        public RepositoryCloneViewModel(
            IConnection connection,
            IModelServiceFactory modelServiceFactory,
            IRepositoryCloneService cloneService,
            IOperatingSystem operatingSystem)
        {
            Guard.ArgumentNotNull(connection, nameof(connection));
            Guard.ArgumentNotNull(modelServiceFactory, nameof(modelServiceFactory));
            Guard.ArgumentNotNull(cloneService, nameof(cloneService));
            Guard.ArgumentNotNull(operatingSystem, nameof(operatingSystem));

            this.connection          = connection;
            this.modelServiceFactory = modelServiceFactory;
            this.operatingSystem     = operatingSystem;

            Title = string.Format(CultureInfo.CurrentCulture, Resources.CloneTitle, connection.HostAddress.Title);

            Repositories = new TrackingCollection <IRemoteRepositoryModel>();
            repositories.ProcessingDelay = TimeSpan.Zero;
            repositories.Comparer        = OrderedComparer <IRemoteRepositoryModel> .OrderBy(x => x.Owner).ThenBy(x => x.Name).Compare;

            repositories.Filter        = FilterRepository;
            repositories.NewerComparer = OrderedComparer <IRemoteRepositoryModel> .OrderByDescending(x => x.UpdatedAt).Compare;

            filterTextIsEnabled = this.WhenAny(x => x.IsBusy,
                                               loading => loading.Value || repositories.UnfilteredCount > 0 && !LoadingFailed)
                                  .ToProperty(this, x => x.FilterTextIsEnabled);

            this.WhenAny(
                x => x.repositories.UnfilteredCount,
                x => x.IsBusy,
                x => x.LoadingFailed,
                (unfilteredCount, loading, failed) =>
            {
                if (loading.Value)
                {
                    return(false);
                }

                if (failed.Value)
                {
                    return(false);
                }

                return(unfilteredCount.Value == 0);
            })
            .Subscribe(x =>
            {
                NoRepositoriesFound = x;
            });

            this.WhenAny(x => x.FilterText, x => x.Value)
            .DistinctUntilChanged(StringComparer.OrdinalIgnoreCase)
            .Throttle(TimeSpan.FromMilliseconds(100), RxApp.MainThreadScheduler)
            .Subscribe(_ => repositories.Filter = FilterRepository);

            var baseRepositoryPath = this.WhenAny(
                x => x.BaseRepositoryPath,
                x => x.SelectedRepository,
                (x, y) => x.Value);

            BaseRepositoryPathValidator = ReactivePropertyValidator.ForObservable(baseRepositoryPath)
                                          .IfNullOrEmpty(Resources.RepositoryCreationClonePathEmpty)
                                          .IfTrue(x => x.Length > 200, Resources.RepositoryCreationClonePathTooLong)
                                          .IfContainsInvalidPathChars(Resources.RepositoryCreationClonePathInvalidCharacters)
                                          .IfPathNotRooted(Resources.RepositoryCreationClonePathInvalid)
                                          .IfTrue(IsAlreadyRepoAtPath, Resources.RepositoryNameValidatorAlreadyExists);

            var canCloneObservable = this.WhenAny(
                x => x.SelectedRepository,
                x => x.BaseRepositoryPathValidator.ValidationResult.IsValid,
                (x, y) => x.Value != null && y.Value);

            canClone     = canCloneObservable.ToProperty(this, x => x.CanClone);
            CloneCommand = ReactiveCommand.Create(canCloneObservable);

            browseForDirectoryCommand.Subscribe(_ => ShowBrowseForDirectoryDialog());
            this.WhenAny(x => x.BaseRepositoryPathValidator.ValidationResult, x => x.Value)
            .Subscribe();
            BaseRepositoryPath  = cloneService.DefaultClonePath;
            NoRepositoriesFound = true;
        }
        public PullRequestListViewModel(
            IModelServiceFactory modelServiceFactory,
            IPackageSettings settings,
            IVisualStudioBrowser visualStudioBrowser)
        {
            Guard.ArgumentNotNull(modelServiceFactory, nameof(modelServiceFactory));
            Guard.ArgumentNotNull(settings, nameof(settings));
            Guard.ArgumentNotNull(visualStudioBrowser, nameof(visualStudioBrowser));

            constructing             = true;
            this.modelServiceFactory = modelServiceFactory;
            this.settings            = settings;
            this.visualStudioBrowser = visualStudioBrowser;

            Title = Resources.PullRequestsNavigationItemText;

            States = new List <PullRequestState> {
                new PullRequestState {
                    IsOpen = true, Name = "Open"
                },
                new PullRequestState {
                    IsOpen = false, Name = "Closed"
                },
                new PullRequestState {
                    Name = "All"
                }
            };

            trackingAuthors = new TrackingCollection <IAccount>(Observable.Empty <IAccount>(),
                                                                OrderedComparer <IAccount> .OrderByDescending(x => x.Login).Compare);
            trackingAssignees = new TrackingCollection <IAccount>(Observable.Empty <IAccount>(),
                                                                  OrderedComparer <IAccount> .OrderByDescending(x => x.Login).Compare);
            trackingAuthors.Subscribe();
            trackingAssignees.Subscribe();

            Authors   = trackingAuthors.CreateListenerCollection(EmptyUser, this.WhenAnyValue(x => x.SelectedAuthor));
            Assignees = trackingAssignees.CreateListenerCollection(EmptyUser, this.WhenAnyValue(x => x.SelectedAssignee));

            CreatePullRequests();

            this.WhenAny(x => x.SelectedState, x => x.Value)
            .Where(x => PullRequests != null)
            .Subscribe(s => UpdateFilter(s, SelectedAssignee, SelectedAuthor, SearchQuery));

            this.WhenAny(x => x.SelectedAssignee, x => x.Value)
            .Where(x => PullRequests != null && x != EmptyUser)
            .Subscribe(a => UpdateFilter(SelectedState, a, SelectedAuthor, SearchQuery));

            this.WhenAny(x => x.SelectedAuthor, x => x.Value)
            .Where(x => PullRequests != null && x != EmptyUser)
            .Subscribe(a => UpdateFilter(SelectedState, SelectedAssignee, a, SearchQuery));

            this.WhenAny(x => x.SearchQuery, x => x.Value)
            .Where(x => PullRequests != null)
            .Subscribe(f => UpdateFilter(SelectedState, SelectedAssignee, SelectedAuthor, f));

            this.WhenAnyValue(x => x.SelectedRepository)
            .Skip(1)
            .Subscribe(_ => ResetAndLoad());

            OpenPullRequest = ReactiveCommand.Create();
            OpenPullRequest.Subscribe(DoOpenPullRequest);
            CreatePullRequest = ReactiveCommand.Create();
            CreatePullRequest.Subscribe(_ => DoCreatePullRequest());

            OpenPullRequestOnGitHub = ReactiveCommand.Create();
            OpenPullRequestOnGitHub.Subscribe(x => DoOpenPullRequestOnGitHub((int)x));

            constructing = false;
        }
Example #13
0
        public PullRequestListViewModel(
            IModelServiceFactory modelServiceFactory,
            IPackageSettings settings,
            IPullRequestSessionManager sessionManager,
            IVisualStudioBrowser visualStudioBrowser)
        {
            Guard.ArgumentNotNull(modelServiceFactory, nameof(modelServiceFactory));
            Guard.ArgumentNotNull(settings, nameof(settings));
            Guard.ArgumentNotNull(sessionManager, nameof(sessionManager));
            Guard.ArgumentNotNull(visualStudioBrowser, nameof(visualStudioBrowser));

            constructing             = true;
            this.modelServiceFactory = modelServiceFactory;
            this.settings            = settings;
            this.visualStudioBrowser = visualStudioBrowser;

            Title = Resources.PullRequestsNavigationItemText;

            States = new List <PullRequestState> {
                new PullRequestState {
                    IsOpen = true, Name = "Open"
                },
                new PullRequestState {
                    IsOpen = false, Name = "Closed"
                },
                new PullRequestState {
                    Name = "All"
                }
            };

            trackingAuthors = new TrackingCollection <IAccount>(Observable.Empty <IAccount>(),
                                                                OrderedComparer <IAccount> .OrderByDescending(x => x.Login).Compare);
            trackingAssignees = new TrackingCollection <IAccount>(Observable.Empty <IAccount>(),
                                                                  OrderedComparer <IAccount> .OrderByDescending(x => x.Login).Compare);
            trackingAuthors.Subscribe();
            trackingAssignees.Subscribe();

            Authors   = trackingAuthors.CreateListenerCollection(EmptyUser, this.WhenAnyValue(x => x.SelectedAuthor));
            Assignees = trackingAssignees.CreateListenerCollection(EmptyUser, this.WhenAnyValue(x => x.SelectedAssignee));

            CreatePullRequests();

            this.WhenAny(x => x.SelectedState, x => x.Value)
            .Where(x => PullRequests != null)
            .Subscribe(s => UpdateFilter(s, SelectedAssignee, SelectedAuthor, SearchQuery));

            this.WhenAny(x => x.SelectedAssignee, x => x.Value)
            .Where(x => PullRequests != null && x != EmptyUser)
            .Subscribe(a => UpdateFilter(SelectedState, a, SelectedAuthor, SearchQuery));

            this.WhenAny(x => x.SelectedAuthor, x => x.Value)
            .Where(x => PullRequests != null && x != EmptyUser)
            .Subscribe(a => UpdateFilter(SelectedState, SelectedAssignee, a, SearchQuery));

            this.WhenAny(x => x.SearchQuery, x => x.Value)
            .Where(x => PullRequests != null)
            .Subscribe(f => UpdateFilter(SelectedState, SelectedAssignee, SelectedAuthor, f));

            this.WhenAnyValue(x => x.SelectedRepository)
            .Skip(1)
            .Subscribe(_ => ResetAndLoad());

            OpenPullRequest = ReactiveCommand.Create();
            OpenPullRequest.Subscribe(DoOpenPullRequest);
            CreatePullRequest = ReactiveCommand.Create();
            CreatePullRequest.Subscribe(_ => DoCreatePullRequest());

            OpenPullRequestOnGitHub = ReactiveCommand.Create();
            OpenPullRequestOnGitHub.Subscribe(x => DoOpenPullRequestOnGitHub((int)x));

            // Get the current pull request session and the selected repository. When the session's
            // repository is the same as our selected repository set CheckedOutPullRequest to the
            // current session's model, so that the checked out PR can be highlighted.
            Observable.CombineLatest(
                sessionManager.WhenAnyValue(x => x.CurrentSession),
                this.WhenAnyValue(x => x.SelectedRepository),
                (s, r) => new { Session = s, Repository = r })
            .Subscribe(x =>
            {
                CheckedOutPullRequest = x.Session?.RepositoryOwner == x.Repository?.Owner ?
                                        x.Session?.PullRequest : null;
            });

            constructing = false;
        }
Example #14
0
        public RepositoryCloneViewModel(
            IRepositoryHost repositoryHost,
            IRepositoryCloneService cloneService,
            IOperatingSystem operatingSystem,
            INotificationService notificationService,
            IUsageTracker usageTracker)
        {
            this.repositoryHost      = repositoryHost;
            this.cloneService        = cloneService;
            this.operatingSystem     = operatingSystem;
            this.notificationService = notificationService;
            this.usageTracker        = usageTracker;

            Title = string.Format(CultureInfo.CurrentCulture, Resources.CloneTitle, repositoryHost.Title);

            Repositories = new TrackingCollection <IRepositoryModel>();
            repositories.ProcessingDelay = TimeSpan.Zero;
            repositories.Comparer        = OrderedComparer <IRepositoryModel> .OrderBy(x => x.Owner).ThenBy(x => x.Name).Compare;

            repositories.Filter        = FilterRepository;
            repositories.NewerComparer = OrderedComparer <IRepositoryModel> .OrderByDescending(x => x.UpdatedAt).Compare;

            filterTextIsEnabled = this.WhenAny(x => x.IsLoading, x => x.Value)
                                  .Select(x => !x && repositories.UnfilteredCount > 0)
                                  .ToProperty(this, x => x.FilterTextIsEnabled);

            this.WhenAny(x => x.FilterTextIsEnabled, x => x.IsLoading, x => x.LoadingFailed
                         , (any, loading, failed) => !any.Value && !loading.Value && !failed.Value)
            .Subscribe(x => NoRepositoriesFound = x);

            this.WhenAny(x => x.FilterText, x => x.Value)
            .DistinctUntilChanged(StringComparer.OrdinalIgnoreCase)
            .Throttle(TimeSpan.FromMilliseconds(100), RxApp.MainThreadScheduler)
            .Subscribe(_ => repositories.Filter = FilterRepository);

            var baseRepositoryPath = this.WhenAny(
                x => x.BaseRepositoryPath,
                x => x.SelectedRepository,
                (x, y) => x.Value);

            BaseRepositoryPathValidator = ReactivePropertyValidator.ForObservable(baseRepositoryPath)
                                          .IfNullOrEmpty(Resources.RepositoryCreationClonePathEmpty)
                                          .IfTrue(x => x.Length > 200, Resources.RepositoryCreationClonePathTooLong)
                                          .IfContainsInvalidPathChars(Resources.RepositoryCreationClonePathInvalidCharacters)
                                          .IfPathNotRooted(Resources.RepositoryCreationClonePathInvalid)
                                          .IfTrue(IsAlreadyRepoAtPath, Resources.RepositoryNameValidatorAlreadyExists);

            var canCloneObservable = this.WhenAny(
                x => x.SelectedRepository,
                x => x.BaseRepositoryPathValidator.ValidationResult.IsValid,
                (x, y) => x.Value != null && y.Value);

            canClone     = canCloneObservable.ToProperty(this, x => x.CanClone);
            CloneCommand = ReactiveCommand.CreateAsyncObservable(canCloneObservable, OnCloneRepository);

            browseForDirectoryCommand.Subscribe(_ => ShowBrowseForDirectoryDialog());
            this.WhenAny(x => x.BaseRepositoryPathValidator.ValidationResult, x => x.Value)
            .Subscribe();
            BaseRepositoryPath  = cloneService.DefaultClonePath;
            NoRepositoriesFound = true;
        }
Example #15
0
 public IComparer <T> OrderByDescending <TValue>(Func <T, TValue> selector, IComparer <TValue> comparer) => OrderedComparer <T> .OrderByDescending(selector, comparer);