ContainsUri() 공개 정적인 메소드

public static ContainsUri ( SafeUri uri, int primary_sources ) : bool
uri Hyena.SafeUri
primary_sources int
리턴 bool
        public DatabaseTrackInfo ImportTrack(SafeUri uri)
        {
            if (!IsWhiteListedFile(uri.LocalPath))
            {
                return(null);
            }

            if (DatabaseTrackInfo.ContainsUri(uri, PrimarySourceIds))
            {
                // TODO add DatabaseTrackInfo.SyncedStamp property, and if the file has been
                // updated since the last sync, fetch its metadata into the db.
                return(null);
            }

            DatabaseTrackInfo track = null;

            // TODO note, there is deadlock potential here b/c of locking of shared commands and blocking
            // because of transactions.  Needs to be fixed in HyenaDatabaseConnection.
            ServiceManager.DbConnection.BeginTransaction();
            try {
                track     = new DatabaseTrackInfo();
                track.Uri = uri;
                StreamTagger.TrackInfoMerge(track, StreamTagger.ProcessUri(uri));

                track.PrimarySource = trackPrimarySourceChooser(track);

                bool save_track = true;
                if (track.PrimarySource is Banshee.Library.LibrarySource)
                {
                    save_track = track.CopyToLibraryIfAppropriate(force_copy);
                }

                if (save_track)
                {
                    track.Save(false);
                }

                ServiceManager.DbConnection.CommitTransaction();
            } catch (Exception) {
                ServiceManager.DbConnection.RollbackTransaction();
                throw;
            }

            counts[track.PrimarySourceId] = counts.ContainsKey(track.PrimarySourceId) ? counts[track.PrimarySourceId] + 1 : 1;

            // Reload every 20% or every 250 tracks, whatever is more (eg at most reload 5 times during an import)
            if (counts[track.PrimarySourceId] >= Math.Max(TotalCount / 5, 250))
            {
                counts[track.PrimarySourceId] = 0;
                track.PrimarySource.NotifyTracksAdded();
            }

            return(track);
        }
예제 #2
0
        public DatabaseTrackInfo ImportTrack(SafeUri uri)
        {
            if (!IsWhiteListedFile(uri.AbsoluteUri))
            {
                return(null);
            }

            if (DatabaseTrackInfo.ContainsUri(uri, PrimarySourceIds))
            {
                // TODO add DatabaseTrackInfo.SyncedStamp property, and if the file has been
                // updated since the last sync, fetch its metadata into the db.
                return(null);
            }

            if (!Banshee.IO.File.GetPermissions(uri).IsReadable)
            {
                throw new InvalidFileException(String.Format(
                                                   Catalog.GetString("File is not readable so it could not be imported: {0}"),
                                                   Path.GetFileName(uri.LocalPath)));
            }

            if (Banshee.IO.File.GetSize(uri) == 0)
            {
                throw new InvalidFileException(String.Format(
                                                   Catalog.GetString("File is empty so it could not be imported: {0}"),
                                                   Path.GetFileName(uri.LocalPath)));
            }

            DatabaseTrackInfo track = new DatabaseTrackInfo()
            {
                Uri = uri
            };

            using (var file = StreamTagger.ProcessUri(uri)) {
                StreamTagger.TrackInfoMerge(track, file, false, true, true);
            }

            track.Uri = uri;

            if (FindOutdatedDupe(track))
            {
                return(null);
            }

            track.PrimarySource = trackPrimarySourceChooser(track);

            // TODO note, there is deadlock potential here b/c of locking of shared commands and blocking
            // because of transactions.  Needs to be fixed in HyenaDatabaseConnection.
            ServiceManager.DbConnection.BeginTransaction();
            try {
                bool save_track = true;
                if (track.PrimarySource is Banshee.Library.LibrarySource)
                {
                    save_track = track.CopyToLibraryIfAppropriate(force_copy);
                }

                if (save_track)
                {
                    track.Save(false);
                }

                ServiceManager.DbConnection.CommitTransaction();
            } catch (Exception) {
                ServiceManager.DbConnection.RollbackTransaction();
                throw;
            }

            counts[track.PrimarySourceId] = counts.ContainsKey(track.PrimarySourceId) ? counts[track.PrimarySourceId] + 1 : 1;

            // Reload every 20% or every 250 tracks, whatever is more (eg at most reload 5 times during an import)
            if (counts[track.PrimarySourceId] >= Math.Max(TotalCount / 5, 250))
            {
                counts[track.PrimarySourceId] = 0;
                track.PrimarySource.NotifyTracksAdded();
            }

            return(track);
        }