Ejemplo n.º 1
0
        public override async Task <ICollection <FilterValue> > GetAvailableValuesAsync(IEnumerable <Guid> necessaryMIATypeIds, IFilter selectAttributeFilter, IFilter filter)
        {
            IContentDirectory cd = ServiceRegistration.Get <IServerConnectionManager>().ContentDirectory;

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

            bool showVirtual = VirtualMediaHelper.ShowVirtualMedia(necessaryMIATypeIds);

            if (string.IsNullOrEmpty(CertificationHelper.DisplayMovieCertificationCountry))
            {
                HomogenousMap valueGroups = await cd.GetValueGroupsAsync(MovieAspect.ATTR_CERTIFICATION, 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 certification = (string)group.Key;
                    if (!string.IsNullOrEmpty(certification))
                    {
                        CertificationMapping cert;
                        if (CertificationMapper.TryFindMovieCertification(certification, out cert))
                        {
                            result.Add(new FilterValue(cert.CertificationId, cert.Name,
                                                       new RelationalFilter(MovieAspect.ATTR_CERTIFICATION, RelationalOperator.EQ, certification), null, (int)group.Value, this));
                        }
                    }
                    else
                    {
                        numEmptyEntries += (int)group.Value;
                    }
                }
                if (numEmptyEntries > 0)
                {
                    result.Insert(0, new FilterValue("UR", Consts.RES_VALUE_UNRATED_TITLE, new EmptyFilter(MovieAspect.ATTR_CERTIFICATION), null, numEmptyEntries, this));
                }
                return(result);
            }
            else
            {
                IList <FilterValue> result      = new List <FilterValue>();
                IFilter             emptyFilter = new EmptyFilter(MovieAspect.ATTR_CERTIFICATION);
                int numEmptyItems = await cd.CountMediaItemsAsync(necessaryMIATypeIds, BooleanCombinationFilter.CombineFilters(BooleanOperator.And, filter, emptyFilter), true, showVirtual);

                if (numEmptyItems > 0)
                {
                    result.Add(new FilterValue("UR", Consts.RES_VALUE_UNRATED_TITLE, emptyFilter, null, numEmptyItems, this));
                }
                List <string> usedFilters = new List <string>();
                foreach (var cert in CertificationMapper.GetMovieCertificationsForCountry(CertificationHelper.DisplayMovieCertificationCountry))
                {
                    IEnumerable <CertificationMapping> certs = CertificationMapper.FindAllAllowedMovieCertifications(cert.CertificationId);
                    if (certs.Count() > 0)
                    {
                        List <string> certList = new List <string>(certs.Select(c => c.CertificationId).Except(usedFilters));
                        usedFilters.AddRange(certList);
                        IFilter certFilter = new InFilter(MovieAspect.ATTR_CERTIFICATION, certList);
                        int     numItems   = await cd.CountMediaItemsAsync(necessaryMIATypeIds, BooleanCombinationFilter.CombineFilters(BooleanOperator.And, filter, certFilter), true, showVirtual);

                        result.Add(new FilterValue(cert.CertificationId, cert.Name, certFilter, null, numItems, this));
                    }
                }
                return(result);
            }
        }