public void TestSortByName()
        {
            var myCollection = new TrackCollection
            {
                new Track("test1.mp3", TestConstant.TestCheckSum),
                new Track("test3.mp3", TestConstant.TestCheckSum + "1"),
                new Track("test2.mp3", TestConstant.TestCheckSum + "2")
            };

            myCollection.SortByName();

            Assert.IsTrue(string.Compare(myCollection[0].Name, myCollection[1].Name, StringComparison.Ordinal) < 0);
            Assert.IsTrue(string.Compare(myCollection[1].Name, myCollection[2].Name, StringComparison.Ordinal) < 0);
        }
Пример #2
0
        public object LoadTracks(BackgroundWorker backgroundWorker, string[] fileNames)
        {
            var filesEnum           = fileNames.GetEnumerator();
            var tempTrackCollection = new TrackCollection();
            var count = 1;

            while (filesEnum.MoveNext() && !backgroundWorker.CancellationPending)
            {
                var filePath = (string)(filesEnum.Current);

                if (Directory.Exists(filePath))
                {
                    var filesInDirectoryEnum = Directory.GetFiles(filePath).GetEnumerator();

                    while (filesInDirectoryEnum.MoveNext() && !backgroundWorker.CancellationPending)
                    {
                        var filePathInDirectory = (string)(filesInDirectoryEnum.Current);

                        if (Utils.GetExtension(filePathInDirectory).Contains("mp3"))
                        {
                            var track = new Track(filePathInDirectory);
                            tempTrackCollection.SafeAdd(track);
                        }
                    }
                }

                else if (Utils.GetExtension(filePath).Contains("mp3"))
                {
                    var track = new Track(filePath);
                    tempTrackCollection.SafeAdd(track);
                }
                backgroundWorker.ReportProgress(250 * count++ / fileNames.Length);
            }

            _trackCollection.Concat(tempTrackCollection);
            _trackCollection.SortByName();
            backgroundWorker.ReportProgress(250);

            _dataExtractionEngine.ExtractData(backgroundWorker, tempTrackCollection);
            RetrieveControlOnCollection();

            _trackCollection.Purge();
            return(_trackCollection);
        }