private static void InitialiseContainerTree()
 {
     RootContainer = new BasicContainer("0") { Title = "MediaPortal Media Library" };
     var audioContainer = new BasicContainer("A") { Title = "Audio" };
     RootContainer.Add(audioContainer);
     var pictureContainer = new BasicContainer("P") { Title = "Picture" };
     RootContainer.Add(pictureContainer);
     var videoContainer = new BasicContainer("V") { Title = "Video" };
     RootContainer.Add(videoContainer);
         videoContainer.Add(new MediaLibraryGenreContainer("VG") { Title = "Genres" });
     RootContainer.Add(new MediaLibraryShareContainer("S") { Title = "Shares" });
 }
        public static IDirectoryObject InstansiateMediaLibraryObject(MediaItem item, string baseKey, BasicContainer parent, string title)
        {
            IDirectoryObject obj;
            // Choose the appropiate MediaLibrary* object for the media item
            if (item.Aspects.ContainsKey(DirectoryAspect.ASPECT_ID))
            {
                obj = new MediaLibraryContainer(baseKey, item);
            }
            else if (item.Aspects.ContainsKey(AudioAspect.ASPECT_ID))
            {
                obj = new MediaLibraryMusicTrack(baseKey, item);
            }
            else if (item.Aspects.ContainsKey(ImageAspect.ASPECT_ID))
            {
                obj = new MediaLibraryImageItem(baseKey, item);
            }
            else if (item.Aspects.ContainsKey(VideoAspect.ASPECT_ID))
            {
                obj = new MediaLibraryVideoItem(baseKey, item);
            }
            else
            {
                obj = null;
            }

            // Assign the parent
            if (parent != null && obj != null)
            {
                parent.Add((TreeNode<object>)obj);
            }

            // Initialise the object
            if (obj is MediaLibraryContainer)
            {
                ((MediaLibraryContainer)obj).Initialise();
            }
            else if (obj is MediaLibraryItem)
            {
                ((MediaLibraryItem)obj).Initialise();
            }
            if (obj != null)
            {
                ServiceRegistration.Get<ILogger>().Info("Created object of type {0} for MediaItem {1}", obj.GetType().Name, item.MediaItemId);
                if (title != null)
                {
                    obj.Title = title;
                }
            }

            return obj;
        }
        public override TreeNode<object> FindNode(string key)
        {
            if (!key.StartsWith(Key)) return null;
            if (key == Key) return this;

            var item = MediaLibraryHelper.GetMediaItem(MediaLibraryHelper.GetObjectId(key));
            var parentId = new Guid(item.Aspects[ProviderResourceAspect.ASPECT_ID].GetAttributeValue(
                ProviderResourceAspect.ATTR_PARENT_DIRECTORY_ID).ToString());

            BasicContainer parent;
            if (parentId == Guid.Empty)
            {
                parent = new BasicContainer(MediaLibraryHelper.GetBaseKey(key));
            }
            else
            {
                parent = new BasicContainer(MediaLibraryHelper.GetBaseKey(key) + ":" + parentId.ToString());
            }

            return (TreeNode<object>)MediaLibraryHelper.InstansiateMediaLibraryObject(item, MediaLibraryHelper.GetBaseKey(key), parent);
        }
 public static IDirectoryObject InstansiateMediaLibraryObject(MediaItem item, string baseKey, BasicContainer parent)
 {
     return InstansiateMediaLibraryObject(item, baseKey, parent, null);
 }
        public override List<IDirectoryObject> Search(string filter, string sortCriteria)
        {
            var shares = MediaLibraryShares();

            var necessaryMiaTypeIDs = new Guid[]
            {
                ProviderResourceAspect.ASPECT_ID,
                MediaAspect.ASPECT_ID,
            };
            var optionalMiaTypeIDs = new Guid[]
            {
                DirectoryAspect.ASPECT_ID,
            };

            var library = ServiceRegistration.Get<IMediaLibrary>();

            var parent = new BasicContainer(Id);
            var result = (from share in shares
                          let item = library.LoadItem(share.Value.SystemId, share.Value.BaseResourcePath, necessaryMiaTypeIDs, optionalMiaTypeIDs)
                          select MediaLibraryHelper.InstansiateMediaLibraryObject(item, Key, parent, share.Value.Name)).ToList();
            return result;
        }