Inheritance: ICloneable
Exemplo n.º 1
0
 private static string FromDaap(Database database, Track track)
 {
     return string.Format(
         ExternalIdFormat,
         database.Id,
         track.Id,
         track.Format);
 }
Exemplo n.º 2
0
        public BeaglePlugin()
        {
            server = Daemon.Server;
            db = Daemon.DefaultDatabase;
            log = Daemon.Log;

            query = new Query ();
            query.AddDomain (QueryDomain.Neighborhood);
            query.MaxHits = 10000;

            QueryPart_Property filePart = new QueryPart_Property ();
            filePart.Type = PropertyType.Keyword;
            filePart.Key = "beagle:HitType";
            filePart.Value = "File";
            query.AddPart (filePart);

            QueryPart_Or queryUnion = new QueryPart_Or ();

            foreach (string mt in supportedMimeTypes) {
                QueryPart_Property part = new QueryPart_Property ();
                part.Type = PropertyType.Keyword;
                part.Key = "beagle:MimeType";
                part.Value = mt;
                queryUnion.Add (part);
            }

            query.AddPart (queryUnion);
            query.HitsAddedEvent += OnHitsAdded;
            query.HitsSubtractedEvent += OnHitsSubtracted;
            query.FinishedEvent += OnFinished;

            int attempts = 0;
            while (true) {
                try {
                    query.SendAsync ();
                    break;
                } catch (Exception e) {
                    if (attempts++ >= 5) {
                        log.Warn ("Failed to initialize beagle plugin");
                        query = null;
                        break;
                    }

                    // something bad happened, wait a sec and try again
                    log.Debug ("Sending query failed: " + e.Message);
                    log.Debug ("Waiting 3 seconds...");
                    Thread.Sleep (3000);
                }
            }
        }
Exemplo n.º 3
0
        public IPodPlugin()
        {
            server = Daemon.Server;
            db = Daemon.DefaultDatabase;
            log = Daemon.Log;

            listener = new IPod.DeviceEventListener ();

            AddDevices ();

            listener.DeviceAdded += OnDeviceAdded;
            listener.DeviceRemoved += OnDeviceRemoved;

            log.Info ("Finished adding iPod devices");
        }
Exemplo n.º 4
0
        private Playlist ClonePlaylist(Database db, Playlist pl)
        {
            Playlist clonePl = new Playlist (pl.Name);
            clonePl.Id = pl.Id;

            IList<Track> pltracks = pl.Tracks;
            for (int i = 0; i < pltracks.Count; i++) {
                clonePl.AddTrack (db.LookupTrackById (pltracks[i].Id), pl.GetContainerId (i));
            }

            return clonePl;
        }
Exemplo n.º 5
0
        public object Clone()
        {
            Database db = new Database (this.name);
            db.id = id;
            db.persistentId = persistentId;

            List<Track> cloneTracks = new List<Track> ();
            foreach (Track track in tracks) {
                cloneTracks.Add ((Track) track.Clone ());
            }

            db.tracks = cloneTracks;

            List<Playlist> clonePlaylists = new List<Playlist> ();
            foreach (Playlist pl in playlists) {
                clonePlaylists.Add (ClonePlaylist (db, pl));
            }

            db.playlists = clonePlaylists;
            db.basePlaylist = ClonePlaylist (db, basePlaylist);
            return db;
        }
Exemplo n.º 6
0
        public static void Run()
        {
            InitializeLogging ();

            if (!File.Exists (ConfigPath)) {
                log.WarnFormat ("Config file '{0}' was not found, using defaults", ConfigPath);
            }

            AppDomain.CurrentDomain.UnhandledException += OnUnhandledException;

            #if LINUX || MACOSX
            UnixSignal.RegisterHandler (Signum.SIGTERM, OnSignal);
            UnixSignal.RegisterHandler (Signum.SIGINT, OnSignal);
            UnixSignal.Start ();
            #else
            Application.EnableVisualStyles ();
            Application.SetCompatibleTextRenderingDefault (false);
            #endif

            server = new Server (Name);
            server.UserLogin += OnUserLogin;
            server.UserLogout += OnUserLogout;
            server.Port = Port;
            server.IsPublished = IsPublished;
            server.Collision += OnCollision;
            db = new Database (Name);
            server.AddDatabase (db);
            server.MaxUsers = MaxUsers;

            server.TrackRequested += OnTrackRequested;

            log.Info ("Server name: " + Name);

            PluginManager.LoadPlugins (PluginNames);

            #if LINUX
            if (Inotify.Enabled) {
                Inotify.Start ();
            }
            #endif

            AddUsers ();

            try {
                lock (server) {
                    server.Commit ();
                    server.Start ();
                }
            } catch (Exception e) {
                LogError ("Failed to start server", e);
                Shutdown ();
            }

            RunLoop ();
            Shutdown ();
        }
Exemplo n.º 7
0
        private void FetchDatabases()
        {
            ContentNode dbnode = ContentParser.Parse (bag, fetcher.Fetch ("/databases"));

            foreach (ContentNode child in (ContentNode[]) dbnode.Value) {
                if (child.Name != "dmap.listing")
                    continue;

                foreach (ContentNode item in (ContentNode[]) child.Value) {
                    Database db = new Database (this, item);
                    databases.Add (db);
                }
            }
        }
Exemplo n.º 8
0
 public TrackRequestedArgs(string user, IPAddress host, Database db, Track track)
 {
     this.user = user;
     this.host = host;
     this.db = db;
     this.track = track;
 }
Exemplo n.º 9
0
 public void RemoveDatabase(Database db)
 {
     databases.Remove (db);
 }
Exemplo n.º 10
0
 public void AddDatabase(Database db)
 {
     databases.Add (db);
 }
Exemplo n.º 11
0
        internal static void FromPlaylistNode(Database db, ContentNode node, out Track track, out int containerId)
        {
            track = null;
            containerId = 0;

            foreach (ContentNode field in (ContentNode[]) node.Value) {
                switch (field.Name) {
                case "dmap.itemid":
                    track = db.LookupTrackById ((int) field.Value);
                    break;
                case "dmap.containeritemid":
                    containerId = (int) field.Value;
                    break;
                default:
                    break;
                }
            }
        }