Пример #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");
            }

            IUserManagement userProfileDataManagement = ServiceRegistration.Get <IUserManagement>();

            if (!userProfileDataManagement.IsValidUser)
            {
                return(new List <FilterValue>());
            }

            IFilter unwatchedFilter = new RelationalUserDataFilter(userProfileDataManagement.CurrentUser.ProfileId, UserDataKeysKnown.KEY_PLAY_PERCENTAGE, RelationalOperator.EQ, UserDataKeysKnown.GetSortablePlayPercentageString(0), true);
            IFilter watchedFilter   = new RelationalUserDataFilter(userProfileDataManagement.CurrentUser.ProfileId, UserDataKeysKnown.KEY_PLAY_PERCENTAGE, RelationalOperator.GT, UserDataKeysKnown.GetSortablePlayPercentageString(0));
            bool    showVirtual     = VirtualMediaHelper.ShowVirtualMedia(necessaryMIATypeIds);
            var     taskUnwatched   = cd.CountMediaItemsAsync(necessaryMIATypeIds, BooleanCombinationFilter.CombineFilters(BooleanOperator.And, filter, unwatchedFilter), true, showVirtual);
            var     taskWatched     = cd.CountMediaItemsAsync(necessaryMIATypeIds, BooleanCombinationFilter.CombineFilters(BooleanOperator.And, filter, watchedFilter), true, showVirtual);
            var     counts          = await Task.WhenAll(taskUnwatched, taskWatched);

            return(new List <FilterValue>(new FilterValue[]
            {
                new FilterValue(Consts.RES_VALUE_UNWATCHED, unwatchedFilter, null, counts[0], this),
                new FilterValue(Consts.RES_VALUE_WATCHED, watchedFilter, null, counts[1], this),
            }.Where(fv => !fv.NumItems.HasValue || fv.NumItems.Value > 0)));
        }
Пример #2
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);

            IFilter emptyFilter      = new EmptyFilter(AudioAlbumAspect.ATTR_COMPILATION);
            IFilter compiledFilter   = new RelationalFilter(AudioAlbumAspect.ATTR_COMPILATION, RelationalOperator.EQ, true);
            IFilter uncompiledFilter = new RelationalFilter(AudioAlbumAspect.ATTR_COMPILATION, RelationalOperator.EQ, false);
            var     taskEmpty        = cd.CountMediaItemsAsync(necessaryMIATypeIds, emptyFilter, true, showVirtual);
            var     taskCompiled     = cd.CountMediaItemsAsync(necessaryMIATypeIds, compiledFilter, true, showVirtual);
            var     taskUncompiled   = cd.CountMediaItemsAsync(necessaryMIATypeIds, uncompiledFilter, true, showVirtual);

            var counts = await Task.WhenAll(taskEmpty, taskCompiled, taskUncompiled);

            return(new List <FilterValue>(new FilterValue[]
            {
                new FilterValue(Consts.RES_VALUE_EMPTY_TITLE, emptyFilter, null, counts[0], this),
                new FilterValue(Consts.RES_COMPILATION_FILTER_COMPILED, compiledFilter, null, counts[1], this),
                new FilterValue(Consts.RES_COMPILATION_FILTER_UNCOMPILED, uncompiledFilter, null, counts[2], this),
            }.Where(fv => !fv.NumItems.HasValue || fv.NumItems.Value > 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");
            }
            IFilter emptyFilter = BooleanCombinationFilter.CombineFilters(BooleanOperator.Or,
                                                                          new EmptyFilter(ImageAspect.ATTR_WIDTH),
                                                                          new RelationalFilter(ImageAspect.ATTR_WIDTH, RelationalOperator.EQ, 0),
                                                                          new EmptyFilter(ImageAspect.ATTR_HEIGHT),
                                                                          new RelationalFilter(ImageAspect.ATTR_HEIGHT, RelationalOperator.EQ, 0));
            IFilter simpleSmallFilter = BooleanCombinationFilter.CombineFilters(BooleanOperator.And,
                                                                                new RelationalFilter(ImageAspect.ATTR_WIDTH, RelationalOperator.LT, Consts.SMALL_SIZE_THRESHOLD),
                                                                                new RelationalFilter(ImageAspect.ATTR_HEIGHT, RelationalOperator.LT, Consts.SMALL_SIZE_THRESHOLD));
            IFilter smallFilter = BooleanCombinationFilter.CombineFilters(BooleanOperator.And,
                                                                          simpleSmallFilter,
                                                                          new NotFilter(BooleanCombinationFilter.CombineFilters(BooleanOperator.Or,
                                                                                                                                new RelationalFilter(ImageAspect.ATTR_WIDTH, RelationalOperator.EQ, 0),
                                                                                                                                new RelationalFilter(ImageAspect.ATTR_HEIGHT, RelationalOperator.EQ, 0))));
            IFilter bigFilter = BooleanCombinationFilter.CombineFilters(BooleanOperator.Or,
                                                                        new RelationalFilter(ImageAspect.ATTR_WIDTH, RelationalOperator.GT, Consts.BIG_SIZE_THRESHOLD),
                                                                        new RelationalFilter(ImageAspect.ATTR_HEIGHT, RelationalOperator.GT, Consts.BIG_SIZE_THRESHOLD));
            IFilter mediumFilter = BooleanCombinationFilter.CombineFilters(BooleanOperator.And,
                                                                           new NotFilter(simpleSmallFilter),
                                                                           new NotFilter(bigFilter));

            bool showVirtual = VirtualMediaHelper.ShowVirtualMedia(necessaryMIATypeIds);

            var taskEmpty  = cd.CountMediaItemsAsync(necessaryMIATypeIds, emptyFilter, true, showVirtual);
            var taskSmall  = cd.CountMediaItemsAsync(necessaryMIATypeIds, smallFilter, true, showVirtual);
            var taskMedium = cd.CountMediaItemsAsync(necessaryMIATypeIds, mediumFilter, true, showVirtual);
            var taskBig    = cd.CountMediaItemsAsync(necessaryMIATypeIds, bigFilter, true, showVirtual);

            var counts = await Task.WhenAll(taskEmpty, taskSmall, taskMedium, taskBig);

            return(new List <FilterValue>(new FilterValue[]
            {
                new FilterValue(Consts.RES_VALUE_EMPTY_TITLE, emptyFilter, null, counts[0], this),
                new FilterValue(Consts.RES_IMAGE_FILTER_SMALL, smallFilter, null, counts[1], this),
                new FilterValue(Consts.RES_IMAGE_FILTER_MEDIUM, mediumFilter, null, counts[2], this),
                new FilterValue(Consts.RES_IMAGE_FILTER_BIG, bigFilter, null, counts[3], this),
            }.Where(fv => !fv.NumItems.HasValue || fv.NumItems.Value > 0)));
        }
Пример #4
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);
            }
        }