Пример #1
0
        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));
        }
Пример #2
0
        public MediaLibraryShareContainer(string id) : base(id)
        {
            var split = id.IndexOf(':');

            BaseKey  = MediaLibraryHelper.GetBaseKey(id);
            ObjectId = MediaLibraryHelper.GetObjectId(id);
        }
        public override void Initialise(string sortCriteria, uint?offset = null, uint?count = null)
        {
            Logger.Debug("MediaServer initialise share containers");

            base.Initialise(sortCriteria, offset, count);
            IDictionary <Guid, Share> shares = GetShares();

            IMediaLibrary  library = ServiceRegistration.Get <IMediaLibrary>();
            BasicContainer parent  = new BasicContainer(Id, Client);
            var            items   = (from share in shares
                                      select new
            {
                Item = library.LoadItem(share.Value.SystemId,
                                        share.Value.BaseResourcePath,
                                        NECESSARY_SHARE_MIA_TYPE_IDS,
                                        OPTIONAL_SHARE_MIA_TYPE_IDS),
                ShareName = share.Value.Name
            }).ToList();

            foreach (var item in items.OrderBy(s => s.ShareName))
            {
                try
                {
                    if (item.Item != null)
                    {
                        Add((BasicObject)MediaLibraryHelper.InstansiateMediaLibraryObject(item.Item, parent, item.ShareName));
                    }
                }
                catch (Exception ex)
                {
                    Logger.Error("Media item '{0}' could not be added", ex, item.Item);
                }
            }
        }
        public override void Initialise(string sortCriteria, uint?offset = null, uint?count = null)
        {
            base.Initialise(sortCriteria, offset, count);

            if (offset == 0)
            {
                _initCache.Clear();
                _children.Clear();
            }
            if (!_initCache.Any(i => i != null))
            {
                _initCache = GetItems(sortCriteria);
                foreach (var item in _initCache)
                {
                    var title = item.MediaItemId.ToString();
                    if (MediaItemAspect.TryGetAspect(item.Aspects, MediaAspect.Metadata, out var mediaAspect))
                    {
                        title = mediaAspect.GetAttributeValue <string>(MediaAspect.ATTR_TITLE);
                    }

                    Add(new BasicItem(item.MediaItemId.ToString(), Client)
                    {
                        Title = $"{title} ({item.MediaItemId.ToString()})"
                    });
                }
            }

            uint?countStart = null;

            for (int i = 0; i < _initCache.Count; i++)
            {
                MediaItem item    = _initCache[i];
                bool      include = (!offset.HasValue || i >= offset) && (!count.HasValue || ((Convert.ToUInt32(i) - countStart) ?? 0) < count);
                if (include && !countStart.HasValue)
                {
                    countStart = Convert.ToUInt32(i);
                }
                if (item == null)
                {
                    continue;
                }

                try
                {
                    if (include || item.Aspects.ContainsKey(DirectoryAspect.ASPECT_ID))
                    {
                        _initCache[i] = null;
                        var child = (BasicObject)MediaLibraryHelper.InstansiateMediaLibraryObject(item, this);
                        if (child != null)
                        {
                            _children[i] = child;
                        }
                    }
                }
                catch (Exception ex)
                {
                    Logger.Error("Media item '{0}' could not be added", ex, item);
                }
            }
        }
        public override List <IDirectoryObject> Search(string filter, string sortCriteria)
        {
            var result = (from item in MediaLibraryBrowse()
                          select MediaLibraryHelper.InstansiateMediaLibraryObject(item, MediaLibraryHelper.GetBaseKey(Key), this)).ToList();

            return(result);
        }
        public override void InitialiseContainers()
        {
            base.InitialiseContainers();
            var items = GetItems(null);

            foreach (var item in items)
            {
                if (item.Aspects.ContainsKey(DirectoryAspect.ASPECT_ID))
                {
                    var child = (BasicObject)MediaLibraryHelper.InstansiateMediaLibraryObject(item, this);
                    if (child != null)
                    {
                        Add(child);
                    }
                }
                else
                {
                    Add(new BasicItem(item.MediaItemId.ToString(), Client, true));
                }
            }
        }
Пример #7
0
        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);
        }