public CenteredAlbumViewModel(IList<IAlbum> iAlbums, IMusicSession isession)
        {
            Albums = iAlbums;

            AlbumDistanceComparerFactory adcf = new AlbumDistanceComparerFactory(isession);
            _OrderByAfinity = new AfinityCollection<IAlbum>(this.Albums, al => adcf.GetComparer(al), 50);
            AffinityOrderedCollection = _OrderByAfinity.Collection;

            //CenterAlbum = Albums.MaxBy(isession.AlbumSorter.Sorter);
            _OrderByAfinity.Reference = Albums.MaxBy(isession.AlbumSorter.Sorter);

            ChangeArtist = RelayCommand.Instanciate(DoChangeArtist);
            ChangeGenre = RelayCommand.Instanciate(DoChangeGenre);
            Random = RelayCommand.Instanciate(DoRandom);
            ChangeAlbum = RelayCommand.Instanciate(DoChangeAlbum);
            Center = RelayCommand.Instanciate<IAlbum>(al => CenterAlbum = al);
        }
        public void TestPef()
        {

            _IMusicSession.AllAlbums.Should().HaveCount(2860);


            for (int k = 0; k < 10; k++)
            {
                AlbumDistanceComparerFactory adcf = new AlbumDistanceComparerFactory(_IMusicSession);
   
                TimeTracer tr2 = TimeTracer.TimeTrack("100 Building Comparator Cache");
                List<IUpdatableComparer<IAlbum>> cts = new List<IUpdatableComparer<IAlbum>>();
                using (tr2)
                {
                    for (int i = 0; i < 100; i++)
                    {
                        IUpdatableComparer<IAlbum> ct = adcf.GetComparer(_IMusicSession.AllAlbums[10]);
                        cts.Add(ct);
                    }
                }
            }
        }
        public void Test_functional_AfinityAlbumComparer()
        {
            _IMusicSession.AllAlbums.Should().HaveCount(3377);
            _IMusicSession.AllTracks.Should().HaveCount(23996);

            var first = _IMusicSession.AllAlbums.First();
            first.Artists.Should().HaveCount(3);

            //AfinityAlbumComparer target = new AfinityAlbumComparer(_IMusicSession, first);
            IUpdatableComparer<IAlbum> target = new AlbumDistanceComparerFactory(_IMusicSession).GetComparer(first);

            _IMusicSession.AllAlbums.MinBy(target).Should().Be(first);

            var second = _IMusicSession.AllAlbums.Skip(1).MinBy(target);

            second.Artists.Apply(a => first.Artists.Should().Contain(a));
            first.Artists.Apply(a => second.Artists.Should().Contain(a));

            target.MonitorEvents();

            using (var mod = second.GetModifiableAlbum())
            {
                mod.Artists.Clear();
                mod.Artists.Add(_IMusicSession.CreateArtist("Teste Artist"));
                mod.Commit();
            }

            second.Artists.Should().HaveCount(1);
            second.Artists.First().Name.Should().Be("Teste Artist");

            target.ShouldRaise("OnElementChanged").WithSender(target).WithArgs<ElementChangedArgs<IAlbum>>(a => a.Element == second);

            var newsecond = _IMusicSession.AllAlbums.Skip(1).MinBy(target);

            newsecond.Should().NotBe(second);
        }
        private void OrderTotalFastParellel(IAlbum ial)
        {
            Console.WriteLine("Album Reference {0}", ial);
            //AfinityAlbumComparer ct = new AfinityAlbumComparer(_IMusicSession, ial);
            IUpdatableComparer<IAlbum> ct = new AlbumDistanceComparerFactory(_IMusicSession).GetComparer(ial);

            for (int k = 0; k < 5; k++)
            {
                TimeTracer tr2 = TimeTracer.TimeTrack(string.Format("50 odering parcial(50) with album {0}", ial));

                using (tr2)
                {
                    List<List<IAlbum>> ll = new List<List<IAlbum>>();
                    for (int i = 0; i < 50; i++)
                    {
                        var myres = _IMusicSession.AllAlbums.SortFirstParallel(50, ct);
                        ll.Add(myres.ToList());
                    }
                }
            }
        }