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()); }
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 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; }
public static void String_EqualWorks(string a, string b) { IReadOnlyList<char> A = a.ToList(); IReadOnlyList<char> B = b.ToList(); OrderedComparer<char> comparer = new OrderedComparer<char>(); Assert.True(comparer.Compare(A, B) == 0); }
public static void String_EqualWorks(string a, string b) { IReadOnlyList <char> A = a.ToList(); IReadOnlyList <char> B = b.ToList(); OrderedComparer <char> comparer = new OrderedComparer <char>(); Assert.True(comparer.Compare(A, B) == 0); }
/// <summary> /// Gets a derived collection that contains all known repositories with the specified /// clone URL, ordered by name. /// </summary> /// <param name="repos">The local repositories object.</param> /// <param name="address">The address.</param> public static IReactiveDerivedList <LocalRepositoryModel> GetRepositoriesForAddress( this ILocalRepositories repos, HostAddress address) { return(repos.Repositories.CreateDerivedCollection( x => x, x => x.CloneUrl != null && address.Equals(HostAddress.Create(x.CloneUrl)), OrderedComparer <LocalRepositoryModel> .OrderBy(x => x.Name).Compare)); }
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; }
public void WorksWithAnonymousTypes() { var source = new List <string> { "abc", "bcd", "cde" }; var items = source.Select(x => new { FirstLetter = x[0], AllOfIt = x }).ToList(); items.Sort(OrderedComparer.For(items).OrderBy(x => x.FirstLetter)); Assert.True(items.Select(x => x.FirstLetter).SequenceEqual("abc")); }
public OrderedSortedSet([NotNull] IEnumerable <T> source, IComparer <T>?comparer) { if (source is null) { throw new ArgumentNullException(nameof(source)); } source = source.Materialize(); Inner = new OrderedComparer <T>(source, comparer); Set = new FixedSortedSet <T>(source, Inner); }
public int Compare( Func <string, int> keySelector, IComparer <int> keyComparer, bool descending, string x, string y) { var comparer = new OrderedComparer <string, int>( keySelector, keyComparer, descending); return(comparer.Compare(x, y)); }
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 })); }
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 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; }
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 void DerivedCollectionsSmokeTest() { var adam = new ReactiveEmployee { Name = "Adam", Age = 20, Salary = 100 }; var bob = new ReactiveEmployee { Name = "Bob", Age = 30, Salary = 150 }; var carol = new ReactiveEmployee { Name = "Carol", Age = 40, Salary = 200 }; var dan = new ReactiveEmployee { Name = "Dan", Age = 50, Salary = 250 }; var eve = new ReactiveEmployee { Name = "Eve", Age = 60, Salary = 300 }; var start = new[] { adam, bob, carol, dan, eve }; var employees = new ReactiveCollection <ReactiveEmployee>(start) { ChangeTrackingEnabled = true }; var employeesByName = DerivedCollectionTestContainer.Create( employees, selector: x => x, orderer: OrderedComparer <ReactiveEmployee> .OrderBy(x => x.Name) ); var employeesByAge = DerivedCollectionTestContainer.Create( employees, selector: x => x, orderer: OrderedComparer <ReactiveEmployee> .OrderBy(x => x.Age) ); var employeesBySalary = DerivedCollectionTestContainer.Create( employees, selector: x => x, orderer: OrderedComparer <ReactiveEmployee> .OrderBy(x => x.Salary) ); // special // filtered, ordered, reference var oldEmployeesByAge = DerivedCollectionTestContainer.Create( employees, selector: x => x, filter: x => x.Age >= 50, orderer: OrderedComparer <ReactiveEmployee> .OrderBy(x => x.Age) ); // ordered, not reference var employeeSalaries = DerivedCollectionTestContainer.Create( employees, selector: x => x.Salary, orderer: Comparer <int> .Default ); // not filtered (derived filter), not reference, not ordered (derived order) oldEmployeesByAge.Derived.ChangeTrackingEnabled = true; var oldEmployeesSalariesByAge = DerivedCollectionTestContainer.Create( oldEmployeesByAge.Derived, selector: x => x.Salary ); var containers = new List <DerivedCollectionTestContainer> { employeesByName, employeesByAge, employeesBySalary, oldEmployeesByAge, employeeSalaries, oldEmployeesSalariesByAge }; Action <Action> testAll = a => { a(); containers.ForEach(x => x.Test()); }; containers.ForEach(x => x.Test()); // if (isIncluded && !shouldBeIncluded) testAll(() => { dan.Age = 49; }); // else if (!isIncluded && shouldBeIncluded) testAll(() => { dan.Age = eve.Age + 1; }); // else if (isIncluded && shouldBeIncluded) testAll(() => { adam.Salary = 350; }); testAll(() => { dan.Age = 50; }); testAll(() => { dan.Age = 51; }); }
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; }
private void OnPlaylistsChanged() { PlaylistView = Playlists.CreateDerivedCollection(_ => _, orderer: OrderedComparer <Playlist> .OrderBy(_ => _.OrderNumber).Compare); ResetSelectedPlaylist(); }
public OrderedSortedSet(IComparer <T>?comparer) { Inner = new OrderedComparer <T>(comparer); Set = new FixedSortedSet <T>((IComparer <T>)Inner); }
public IComparer <T> OrderByDescending <TValue>(Func <T, TValue> selector, IComparer <TValue> comparer) => OrderedComparer <T> .OrderByDescending(selector, comparer);
protected void Refresh(IConnection connection) { if (connection == null) { LoggedIn = false; IsVisible = false; SectionConnection = null; if (Repositories != null) { Repositories.CollectionChanged -= UpdateRepositoryList; } Repositories = null; settings = null; if (sectionIndex == 0 && TEServiceProvider != null) { var section = GetSection(TeamExplorerInvitationBase.TeamExplorerInvitationSectionGuid); IsVisible = !(section?.IsVisible ?? true); // only show this when the invitation section is hidden. When in doubt, don't show it. if (section != null) { section.PropertyChanged += (s, p) => { if (p.PropertyName == "IsVisible") { IsVisible = LoggedIn || !((ITeamExplorerSection)s).IsVisible; } } } ; } } else { if (connection != SectionConnection) { SectionConnection = connection; Repositories = SectionConnection.Repositories.CreateDerivedCollection(x => x, orderer: OrderedComparer <ILocalRepositoryModel> .OrderBy(x => x.Name).Compare); Repositories.CollectionChanged += UpdateRepositoryList; Title = connection.HostAddress.Title; IsVisible = true; LoggedIn = true; settings = packageSettings.UIState.GetOrCreateConnectSection(Title); IsExpanded = settings.IsExpanded; } if (TEServiceProvider != null) { RefreshRepositories().Forget(); } } }
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)); }
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; }
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; }
public IComparer <T> OrderBy <TValue>(Func <T, TValue> selector, IComparer <TValue> comparer) => OrderedComparer <T> .OrderBy(selector, comparer);