Ejemplo n.º 1
0
        protected internal override void ReLoadItemsAndSubViewSpecifications(out IList <MediaItem> mediaItems, out IList <ViewSpecification> subViewSpecifications)
        {
            mediaItems            = new List <MediaItem>();
            subViewSpecifications = new List <ViewSpecification>();
            IServerConnectionManager scm = ServiceRegistration.Get <IServerConnectionManager>();
            IContentDirectory        cd  = scm.ContentDirectory;
            IServerController        sc  = scm.ServerController;

            if (cd == null || sc == null)
            {
                return;
            }
            ICollection <KeyValuePair <string, string> > systems = new List <KeyValuePair <string, string> >(
                sc.GetAttachedClients().Select(client => new KeyValuePair <string, string>(client.SystemId, client.LastClientName)))
            {
                new KeyValuePair <string, string>(scm.HomeServerSystemId, scm.LastHomeServerName) // Add the server too
            };

            foreach (KeyValuePair <string, string> kvp in BuildSystemsDictNames2Ids(systems))
            {
                var clientShares = cd.GetSharesAsync(kvp.Value, SharesFilter.All).Result;
                if (clientShares.Count == 0)
                {
                    continue;
                }

                // Check if we want to filter only for given MediaCategories
                if (_restrictedMediaCategories != null && !clientShares.Any(share => share.MediaCategories.Intersect(_restrictedMediaCategories).Any()))
                {
                    continue;
                }
                subViewSpecifications.Add(new SystemSharesViewSpecification(kvp.Value, kvp.Key, _necessaryMIATypeIds, _optionalMIATypeIds, _restrictedMediaCategories));
            }
        }
        public override async Task <ICollection <FilterValue> > GetAvailableValuesAsync(IEnumerable <Guid> necessaryMIATypeIds, IFilter selectAttributeFilter, IFilter filter)
        {
            IServerConnectionManager serverConnectionManager = ServiceRegistration.Get <IServerConnectionManager>();
            IServerController        serverController        = serverConnectionManager.ServerController;

            if (serverController == null)
            {
                throw new NotConnectedException("The MediaLibrary is not connected");
            }

            IDictionary <string, string> systemNames = new Dictionary <string, string>();

            foreach (MPClientMetadata client in serverController.GetAttachedClients())
            {
                systemNames.Add(client.SystemId, client.LastClientName);
            }
            systemNames.Add(serverConnectionManager.HomeServerSystemId, serverConnectionManager.LastHomeServerName);

            IContentDirectory cd = ServiceRegistration.Get <IServerConnectionManager>().ContentDirectory;

            if (cd == null)
            {
                return(new List <FilterValue>());
            }

            bool showVirtual = VirtualMediaHelper.ShowVirtualMedia(necessaryMIATypeIds);

            HomogenousMap valueGroups = await cd.GetValueGroupsAsync(ProviderResourceAspect.ATTR_SYSTEM_ID, null, ProjectionFunction.None, necessaryMIATypeIds, filter, true, showVirtual);

            IList <FilterValue> result = new List <FilterValue>(valueGroups.Count);
            int numEmptyEntries        = 0;

            foreach (KeyValuePair <object, object> group in valueGroups)
            {
                string name = group.Key as string ?? string.Empty;
                name = name.Trim();
                if (name == string.Empty)
                {
                    numEmptyEntries += (int)group.Value;
                }
                else
                {
                    string systemName;
                    if (systemNames.TryGetValue(name, out systemName) && !string.IsNullOrEmpty(systemName))
                    {
                        name = systemName;
                    }
                    result.Add(new FilterValue(name,
                                               new RelationalFilter(ProviderResourceAspect.ATTR_SYSTEM_ID, RelationalOperator.EQ, group.Key), null, (int)group.Value, this));
                }
            }
            if (numEmptyEntries > 0)
            {
                result.Insert(0, new FilterValue(Consts.RES_VALUE_EMPTY_TITLE, new EmptyFilter(ProviderResourceAspect.ATTR_SYSTEM_ID), null, numEmptyEntries, this));
            }
            return(result);
        }
Ejemplo n.º 3
0
        protected static bool IsSingleSeat(IServerConnectionManager serverConnectionManager)
        {
            SystemName             homeServerSystem      = serverConnectionManager.LastHomeServerSystem;
            bool                   isLocalHomeServer     = homeServerSystem != null && homeServerSystem.IsLocalSystem();
            IServerController      serverController      = serverConnectionManager.ServerController;
            ILocalSharesManagement localSharesManagement = ServiceRegistration.Get <ILocalSharesManagement>();
            ICollection <Share>    localClientShares     = localSharesManagement.Shares.Values;

            return(serverController != null && serverController.GetAttachedClients().Count == 1 && isLocalHomeServer && localClientShares.Count == 0);
        }
Ejemplo n.º 4
0
        public static MPClientMetadata GetClientMetadata(string systemId)
        {
            IServerConnectionManager scm = ServiceRegistration.Get <IServerConnectionManager>();

            if (scm == null)
            {
                return(null);
            }
            IServerController sc = scm.ServerController;

            if (sc == null)
            {
                return(null);
            }
            MPClientMetadata clientData = sc.GetAttachedClients().FirstOrDefault(client => client.SystemId == systemId);

            if (clientData != null)
            {
                return(clientData);
            }
            return(null);
        }
        protected internal override void ReLoadItemsAndSubViewSpecifications(out IList <MediaItem> mediaItems, out IList <ViewSpecification> subViewSpecifications)
        {
            mediaItems            = new List <MediaItem>();
            subViewSpecifications = new List <ViewSpecification>();
            IServerConnectionManager scm = ServiceRegistration.Get <IServerConnectionManager>();
            IContentDirectory        cd  = scm.ContentDirectory;
            IServerController        sc  = scm.ServerController;

            if (cd == null || sc == null)
            {
                return;
            }
            ICollection <KeyValuePair <string, string> > systems = new List <KeyValuePair <string, string> >(
                sc.GetAttachedClients().Select(client => new KeyValuePair <string, string>(client.SystemId, client.LastClientName)))
            {
                new KeyValuePair <string, string>(scm.HomeServerSystemId, scm.LastHomeServerName) // Add the server too
            };

            foreach (KeyValuePair <string, string> kvp in BuildSystemsDictNames2Ids(systems))
            {
                subViewSpecifications.Add(new SystemSharesViewSpecification(kvp.Value, kvp.Key, _necessaryMIATypeIds, _optionalMIATypeIds));
            }
        }