Beispiel #1
0
        /// <summary>
        /// Gets the iTunes object specified by an ObjectID.
        /// </summary>
        /// <param name="oid"></param>
        /// <returns></returns>
        public Playlist GetPlaylist(ObjectID oid)
        {
            return Invoke((Func<Playlist>)delegate
            {
                return new Playlist((IITPlaylist)itunes.GetITObjectByID(
                    oid.SourceID, oid.PlaylistID, oid.TrackID, oid.DatabaseID));

            });
        }
Beispiel #2
0
        /// <summary>
        /// Instantiate a new maintenance action only if the safe array describes a recognizable
        /// activity pattern.
        /// </summary>
        /// <param name="safeArray"></param>
        /// <returns></returns>

        public static MaintenanceAction Create(object safeArray)
        {
            Array array                = safeArray as Array;
            ObjectIDCollection list    = new ObjectIDCollection();
            StringBuilder      builder = new StringBuilder();
            ObjectID           oid;

            // convert the safe array to a collection and construct the pattern map

            int lower = array.GetLowerBound(0);
            int upper = array.GetUpperBound(0);

            for (int i = lower; i <= upper; i++)
            {
                oid = new ObjectID(
                    (int)array.GetValue(i, 0),                                  // source
                    (int)array.GetValue(i, 1),                                  // playlist
                    (int)array.GetValue(i, 2),                                  // trackid
                    (int)array.GetValue(i, 3));                                 // databaseid

                list.Add(oid);

                if (oid.IsPlaylist)
                {
                    builder.Append("P");
                }
                else if (oid.IsSource)
                {
                    builder.Append("S");
                }
                else if (oid.IsTrack)
                {
                    builder.Append("T");
                }
                else
                {
                    builder.Append("X");
                }
            }

            // recognize pattern to instantiate new MaintenanceAction

            string map = builder.ToString();

            if (Regex.IsMatch(map, AddPlaylistPattern))
            {
                return(new MaintenanceAction(ActionType.AddPlaylist, list));
            }
            else if (Regex.IsMatch(map, AddTracksPattern))
            {
                return(new MaintenanceAction(ActionType.AddTracksToPlaylist, list));
            }
            else if (Regex.IsMatch(map, RemovePlaylistPattern))
            {
                return(new MaintenanceAction(ActionType.RemovePlaylist, list));
            }
            else if (Regex.IsMatch(map, RemoveTracksPattern))
            {
                return(new MaintenanceAction(ActionType.RemoveTracksFromPlaylist, list));
            }

            // Not a recognizable pattern, return null

            list.Clear();
            return(null);
        }
Beispiel #3
0
        /// <summary>
        /// Gets the persisten ID of the iTunes object specified by an ObjectID.
        /// </summary>
        /// <param name="itunes"></param>
        /// <param name="oid"></param>
        /// <returns></returns>
        public PersistentID GetPersistentID(ObjectID oid)
        {
            return Invoke((Func<PersistentID>)delegate
            {
                IITObject obj = itunes.GetITObjectByID(
                    oid.SourceID, oid.PlaylistID, oid.TrackID, oid.DatabaseID);

                if (obj == null)
                {
                    return PersistentID.Empty;
                }

                PersistentID persistentID = GetPersistentID(obj);
                Release(obj);

                return persistentID;
            });
        }
        /// <summary>
        /// Instantiate a new maintenance action only if the safe array describes a recognizable
        /// activity pattern.
        /// </summary>
        /// <param name="safeArray"></param>
        /// <returns></returns>
        public static MaintenanceAction Create(object safeArray)
        {
            Array array = safeArray as Array;
            ObjectIDCollection list = new ObjectIDCollection();
            StringBuilder builder = new StringBuilder();
            ObjectID oid;

            // convert the safe array to a collection and construct the pattern map

            int lower = array.GetLowerBound(0);
            int upper = array.GetUpperBound(0);

            for (int i = lower; i <= upper; i++)
            {
                oid = new ObjectID(
                    (int)array.GetValue(i, 0),		// source
                    (int)array.GetValue(i, 1),		// playlist
                    (int)array.GetValue(i, 2),		// trackid
                    (int)array.GetValue(i, 3));		// databaseid

                list.Add(oid);

                if (oid.IsPlaylist)
                {
                    builder.Append("P");
                }
                else if (oid.IsSource)
                {
                    builder.Append("S");
                }
                else if (oid.IsTrack)
                {
                    builder.Append("T");
                }
                else
                {
                    builder.Append("X");
                }
            }

            // recognize pattern to instantiate new MaintenanceAction

            string map = builder.ToString();

            if (Regex.IsMatch(map, AddPlaylistPattern))
            {
                return new MaintenanceAction(ActionType.AddPlaylist, list);
            }
            else if (Regex.IsMatch(map, AddTracksPattern))
            {
                return new MaintenanceAction(ActionType.AddTracksToPlaylist, list);
            }
            else if (Regex.IsMatch(map, RemovePlaylistPattern))
            {
                return new MaintenanceAction(ActionType.RemovePlaylist, list);
            }
            else if (Regex.IsMatch(map, RemoveTracksPattern))
            {
                return new MaintenanceAction(ActionType.RemoveTracksFromPlaylist, list);
            }

            // Not a recognizable pattern, return null

            list.Clear();
            return null;
        }