public override TrackCollection Sort(BackgroundWorker backgroundWorker, TrackCollection trackCollection, TrackCollection fixedTracks)
        {
            var nbCollections    = fixedTracks.Count;
            var resultCollection = new TrackCollection();
            var collections      = new List <TrackCollection>();
            int numCollection    = 0;

            fixedTracks.ForEach(delegate(Track track)
            {
                collections.Add(new TrackCollection());
                int pos = trackCollection.IndexOf(track);
                if (pos != -1)
                {
                    for (int i = 0; i < pos; i++)
                    {
                        collections[numCollection].Add(trackCollection[i]);
                    }
                    numCollection++;

                    collections.Add(new TrackCollection());
                    collections[numCollection].Add(trackCollection[pos]); // add the fixed Track
                    numCollection++;

                    trackCollection.RemoveRange(0, pos + 1);
                }
            });

            collections.Add(new TrackCollection());
            for (int i = 0; i < trackCollection.Count; i++)
            {
                collections[numCollection].Add(trackCollection[i]);
            }
            numCollection++;
            trackCollection.Clear();

            for (int i = 0; i < collections.Count; i++)
            {
                TrackCollection newCollection;
                newCollection = Sort(backgroundWorker, collections[i]);

                if (!newCollection.Equals(collections[i]))
                {
                    var pos = collections.IndexOf(collections[i]);
                    collections[pos] = newCollection;
                }
            }

            collections.ForEach(delegate(TrackCollection collection)
            {
                resultCollection.Concat(collection);
            });

            return(resultCollection);
        }
Пример #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);
        }