public ImportPlaylistWorker(string name, string [] uris, PrimarySource source, DatabaseImportManager importer)
 {
     this.name     = name;
     this.uris     = uris;
     this.source   = source;
     this.importer = importer;
 }
示例#2
0
        public static void RegisterDependencies()
        {
            var builder = new ContainerBuilder();

            var storageCredentials = GetPrimaryStorageCredentials();
            var batchCredentials   = GetBatchCredentials();

            builder.Register(c => new Microsoft.Azure.Batch.Blast.Configuration.BlastConfigurationManager(
                                 storageCredentials, batchCredentials).GetConfiguration())
            .As <BlastConfiguration>();

            builder.Register(c => new SystemDatabaseProvider(
                                 c.Resolve <BlastConfiguration>(),
                                 SystemDatabaseProvider.DefaultContainerName))
            .As <IDatabaseProvider>();

            builder.Register(c =>
            {
                var databaseRepoManager = new ExternalRepositoryManager(
                    c.Resolve <BlastConfiguration>());
                databaseRepoManager.AddRepository(ExternalRepositoryManager.GetNCBIRepository());
                return(databaseRepoManager);
            }).As <IExternalRepositoryManager>().SingleInstance();

            builder.Register(c =>
            {
                var importManager = new DatabaseImportManager(
                    c.Resolve <BlastConfiguration>());
                return(importManager);
            })
            .As <IDatabaseImportManager>().SingleInstance();

            builder.Register(c => new AzureSearchProvider(
                                 c.Resolve <BlastConfiguration>(),
                                 c.Resolve <IDatabaseProvider>()))
            .As <ISearchProvider>();

            // autowire
            builder.RegisterAssemblyTypes(Assembly.GetExecutingAssembly())
            .As <IDatabaseRepository>()
            .AsImplementedInterfaces()
            .InstancePerDependency();

            builder.RegisterAssemblyTypes(Assembly.GetExecutingAssembly())
            .As <ISearchProvider>()
            .AsImplementedInterfaces()
            .InstancePerRequest();

            // make controllers use constructor injection
            builder.RegisterControllers(Assembly.GetExecutingAssembly());
            builder.RegisterApiControllers(Assembly.GetExecutingAssembly()).InstancePerRequest();

            var container = builder.Build();

            DependencyResolver.SetResolver(new AutofacDependencyResolver(container));
            GlobalConfiguration.Configuration.DependencyResolver = new AutofacWebApiDependencyResolver(container);
        }
示例#3
0
        // WARNING: This will be called from a thread!
        protected override void LoadFromDevice()
        {
            importer = new DatabaseImportManager(this);
            importer.KeepUserJobHidden = true;
            importer.Threaded          = false; // We are already threaded
            importer.Finished         += OnImportFinished;

            foreach (string audio_folder in BaseDirectories)
            {
                importer.Enqueue(audio_folder);
            }
        }
 public void Import()
 {
     try {
         if (importer == null)
         {
             importer = new Banshee.Library.LibraryImportManager();
         }
         finished           = false;
         importer.Finished += CreatePlaylist;
         importer.Enqueue(uris);
     } catch (PlaylistImportCanceledException e) {
         Hyena.Log.Exception(e);
     }
 }
示例#5
0
 private string GetMetadataHash(QueueItem item)
 {
     if (item.ChangeType == WatcherChangeTypes.Created && item.MetadataHash == null)
     {
         var uri = new SafeUri(item.FullPath);
         if (DatabaseImportManager.IsWhiteListedFile(item.FullPath) && Banshee.IO.File.Exists(uri))
         {
             var track = new TrackInfo();
             using (var file = StreamTagger.ProcessUri(uri)) {
                 StreamTagger.TrackInfoMerge(track, file);
             }
             item.MetadataHash = track.MetadataHash;
         }
     }
     return(item.MetadataHash);
 }
示例#6
0
        // WARNING: This will be called from a thread!
        protected override void LoadFromDevice()
        {
            import_reset_event = new System.Threading.ManualResetEvent(false);

            importer = new DatabaseImportManager(this)
            {
                KeepUserJobHidden  = true,
                SkipHiddenChildren = false
            };
            importer.Finished += OnImportFinished;

            foreach (string audio_folder in BaseDirectories)
            {
                importer.Enqueue(audio_folder);
            }

            import_reset_event.WaitOne();
        }
        public static void ImportPlaylistToLibrary(string path, PrimarySource source, DatabaseImportManager importer)
        {
            try {
                Log.InformationFormat("Importing playlist {0} to library", path);
                SafeUri        uri          = new SafeUri(path);
                PlaylistParser parser       = new PlaylistParser();
                string         relative_dir = System.IO.Path.GetDirectoryName(uri.LocalPath);
                if (relative_dir[relative_dir.Length - 1] != System.IO.Path.DirectorySeparatorChar)
                {
                    relative_dir = relative_dir + System.IO.Path.DirectorySeparatorChar;
                }
                parser.BaseUri = new Uri(relative_dir);
                if (parser.Parse(uri))
                {
                    List <string> uris = new List <string> ();
                    foreach (Dictionary <string, object> element in parser.Elements)
                    {
                        Uri elt = (Uri)element["uri"];
                        if (elt.IsFile)
                        {
                            uris.Add(elt.LocalPath);
                        }
                        else
                        {
                            Log.InformationFormat("Ignoring invalid playlist element: {0}", elt.OriginalString);
                        }
                    }

                    if (source == null)
                    {
                        if (uris.Count > 0)
                        {
                            // Get the media attribute of the 1st Uri in Playlist
                            // and then determine whether the playlist belongs to Video or Music
                            SafeUri uri1  = new SafeUri(uris[0]);
                            var     track = new TrackInfo();
                            StreamTagger.TrackInfoMerge(track, uri1);

                            if (track.HasAttribute(TrackMediaAttributes.VideoStream))
                            {
                                source = ServiceManager.SourceManager.VideoLibrary;
                            }
                            else
                            {
                                source = ServiceManager.SourceManager.MusicLibrary;
                            }
                        }
                    }

                    // Give source a fallback value - MusicLibrary when it's null
                    if (source == null)
                    {
                        source = ServiceManager.SourceManager.MusicLibrary;
                    }

                    // Only import an non-empty playlist
                    if (uris.Count > 0)
                    {
                        ImportPlaylistWorker worker = new ImportPlaylistWorker(
                            parser.Title,
                            uris.ToArray(), source, importer);
                        worker.Import();
                    }
                }
            } catch (Exception e) {
                Hyena.Log.Exception(e);
            }
        }
        public void Enqueue(string path)
        {
            try {
                SafeUri uri = new SafeUri(path);
                if (uri.IsLocalPath && !String.IsNullOrEmpty(uri.LocalPath))
                {
                    path = uri.LocalPath;
                }
            } catch {
            }

            lock (this) {
                if (importer == null)
                {
                    importer = new DatabaseImportManager(this);
                    importer.KeepUserJobHidden = true;
                    importer.ImportResult     += delegate(object o, DatabaseImportResultArgs args) {
                        Banshee.ServiceStack.Application.Invoke(delegate {
                            if (args.Error != null || path_to_play != null)
                            {
                                return;
                            }

                            path_to_play = args.Path;
                            if (args.Track == null)
                            {
                                // Play immediately if the track is already in the source,
                                // otherwise the call will be deferred until the track has
                                // been imported and loaded into the cache
                                PlayEnqueued();
                            }
                        });
                    };

                    importer.Finished += delegate {
                        if (visible)
                        {
                            Banshee.Base.ThreadAssist.ProxyToMain(delegate {
                                TrackInfo current_track = ServiceManager.PlaybackController.CurrentTrack;
                                // Don't switch to FSQ if the current item is a video
                                if (current_track == null || !current_track.HasAttribute(TrackMediaAttributes.VideoStream))
                                {
                                    ServiceManager.SourceManager.SetActiveSource(this);
                                }
                            });
                        }
                    };
                }

                if (PlaylistFileUtil.PathHasPlaylistExtension(path))
                {
                    Banshee.Kernel.Scheduler.Schedule(new DelegateJob(delegate {
                        // If it's in /tmp it probably came from Firefox - just play it
                        if (path.StartsWith(Paths.SystemTempDir))
                        {
                            Banshee.Streaming.RadioTrackInfo.OpenPlay(path);
                        }
                        else
                        {
                            PlaylistFileUtil.ImportPlaylistToLibrary(path, this, importer);
                        }
                    }));
                }
                else
                {
                    importer.Enqueue(path);
                }
            }
        }
示例#9
0
        protected override string ProcessItem(string file_path)
        {
            if (!DatabaseImportManager.IsWhiteListedFile(file_path))
            {
                return(null);
            }

            // Hack to ignore Podcast files
            if (file_path.Contains("Podcasts"))
            {
                return(null);
            }

            //Hyena.Log.DebugFormat ("Rescanning item {0}", file_path);
            try {
                SafeUri uri = new SafeUri(file_path);

                using (var reader = ServiceManager.DbConnection.Query(fetch_command, psource.DbId, uri.AbsoluteUri)) {
                    if (reader.Read())
                    {
                        //Hyena.Log.DebugFormat ("Found it in the db!");
                        DatabaseTrackInfo track = DatabaseTrackInfo.Provider.Load(reader);

                        MergeIfModified(track);

                        // Either way, update the LastSyncStamp
                        track.LastSyncedStamp = DateTime.Now;
                        track.Save(false);
                        status = String.Format("{0} - {1}", track.DisplayArtistName, track.DisplayTrackTitle);
                    }
                    else
                    {
                        // This URI is not in the database - try to find it based on MetadataHash in case it was simply moved
                        DatabaseTrackInfo track = new DatabaseTrackInfo();
                        Banshee.Streaming.StreamTagger.TrackInfoMerge(track, uri);

                        using (var similar_reader = ServiceManager.DbConnection.Query(
                                   fetch_similar_command, psource.DbId, scan_started, track.MetadataHash)) {
                            DatabaseTrackInfo similar_track = null;
                            while (similar_reader.Read())
                            {
                                similar_track = DatabaseTrackInfo.Provider.Load(similar_reader);
                                if (!Banshee.IO.File.Exists(similar_track.Uri))
                                {
                                    //Hyena.Log.DebugFormat ("Apparently {0} was moved to {1}", similar_track.Uri, file_path);
                                    similar_track.Uri = uri;
                                    MergeIfModified(similar_track);
                                    similar_track.LastSyncedStamp = DateTime.Now;
                                    similar_track.Save(false);
                                    status = String.Format("{0} - {1}", similar_track.DisplayArtistName, similar_track.DisplayTrackTitle);
                                    break;
                                }
                                similar_track = null;
                            }

                            // If we still couldn't find it, try to import it
                            if (similar_track == null)
                            {
                                //Hyena.Log.DebugFormat ("Couldn't find it, so queueing to import it");
                                status = System.IO.Path.GetFileNameWithoutExtension(file_path);
                                ServiceManager.Get <Banshee.Library.LibraryImportManager> ().ImportTrack(uri);
                            }
                        }
                    }
                }
            } catch (Exception e) {
                Hyena.Log.Exception(e);
            }
            return(null);
        }
示例#10
0
        public static void ImportPlaylistToLibrary(string path, PrimarySource source, DatabaseImportManager importer)
        {
            try {
                SafeUri        uri          = new SafeUri(path);
                PlaylistParser parser       = new PlaylistParser();
                string         relative_dir = System.IO.Path.GetDirectoryName(uri.LocalPath);
                if (relative_dir[relative_dir.Length - 1] != System.IO.Path.DirectorySeparatorChar)
                {
                    relative_dir = relative_dir + System.IO.Path.DirectorySeparatorChar;
                }
                parser.BaseUri = new Uri(relative_dir);
                if (parser.Parse(uri))
                {
                    List <string> uris = new List <string> ();
                    foreach (Dictionary <string, object> element in parser.Elements)
                    {
                        uris.Add(((Uri)element["uri"]).LocalPath);
                    }

                    ImportPlaylistWorker worker = new ImportPlaylistWorker(
                        parser.Title,
                        uris.ToArray(), source, importer);
                    worker.Import();
                }
            } catch (Exception e) {
                Hyena.Log.Exception(e);
            }
        }