public async Task <List <CollectionCategory> > GetAsync()
        {
            List <CollectionCategory> serviceCollections = new List <CollectionCategory>();
            var collections = await this._collectionQueries.GetAsync();

            if (collections != null)
            {
                foreach (var collection in collections)
                {
                    CollectionCategory currentCollection = new CollectionCategory(collection);
                    currentCollection.Tags = (await _tagQueries.GetByContainerIdAsync(currentCollection.Id)).Select(rec => new TagBO(rec)).ToList();

                    foreach (var childContainer in currentCollection.ChildContainers)
                    {
                        childContainer.Rules = await _ruleService.GetWithLogsByContainerIdAsync(childContainer.Id);

                        childContainer.AmountRules = childContainer.Rules != null ? childContainer.Rules.Count : 0;
                        childContainer.Tags        = (await _tagQueries.GetByContainerIdAsync(childContainer.Id)).Select(rec => new TagBO(rec)).ToList();

                        if (collection.RuleDetailsDestinationId != null && childContainer.Rules != null && childContainer.Rules.Any())
                        {
                            childContainer.Rules.ForEach(rec => rec.CollectionRuleDetailsDestinationId = collection.RuleDetailsDestinationId);
                        }
                    }
                    serviceCollections.Add(currentCollection);
                }
            }
            return(serviceCollections);
        }
        public async Task <CollectionCategory> GetAsync(Guid?containerId = null)
        {
            Container container = null;

            if (containerId == null)
            {
                container = await this._collectionQueries.GetDefaultAsync();
            }
            else
            {
                container = await this._collectionQueries.GetAsync(containerId.Value);
            }

            var collectionCategory = new CollectionCategory();

            collectionCategory.Id              = container.Id;
            collectionCategory.Name            = container.Name;
            collectionCategory.Description     = container.Description;
            collectionCategory.EnvironmentType = container.EnvironmentType;
            collectionCategory.ChildContainers = new List <CollectionCategory>();
            collectionCategory.Rules           = await _ruleService.GetWithLogsByContainerIdAsync(container.Id);

            collectionCategory.ValidRules      = collectionCategory.Rules.Count(m => m.LastStatus == 2);
            collectionCategory.LastStatus      = collectionCategory.Rules.Any(m => m.LastStatus == 2) ? 2 : 1;
            collectionCategory.ContainerTypeId = container.ContainerTypeId;
            //collectionCategory.CreatedByUserId = container.CreatedByUserId;
            collectionCategory.Tags = new List <TagBO>();
            collectionCategory.Tags = (await _tagQueries.GetByContainerIdAsync(collectionCategory.Id)).Select(rec => new TagBO(rec)).ToList();
            collectionCategory.RuleDetailsDestinationId = container.RuleDetailsDestinationId;

            foreach (var itemContainer in container.ChildContainers)
            {
                var category = new CollectionCategory
                {
                    Id    = itemContainer.Id,
                    Name  = itemContainer.Name,
                    Rules = new List <RuleBO>(),
                    Tags  = new List <TagBO>()
                };

                category.Tags  = (await _tagQueries.GetByContainerIdAsync(itemContainer.Id)).Select(rec => new TagBO(rec)).ToList();
                category.Rules = await _ruleService.GetWithLogsByContainerIdAsync(itemContainer.Id);

                category.ValidRules = category.Rules.Count(m => m.LastStatus == 2);
                category.LastStatus = category.Rules.Any(m => m.LastStatus == 2) ? 2 : 1;

                if (collectionCategory.RuleDetailsDestinationId != null && category.Rules != null && category.Rules.Any())
                {
                    category.Rules.ForEach(rec => rec.CollectionRuleDetailsDestinationId = collectionCategory.RuleDetailsDestinationId);
                }

                collectionCategory.ChildContainers.Add(category);
            }
            return(collectionCategory);
        }
Esempio n. 3
0
        public override uint Initialize(InitializeInfo info)
        {
            // Try to handle any immediately recognizable types (such as List<> or any direct interfaces).
            if (TryHandleDirectTypes(info, info.Type))
            {
                return(0);
            }

            // Work out what category this type falls under.
            CollectionCategory category = DetectCollectionType(info.Type.GetInterfaces(), out Type elementOrKeyType, out Type? valueType);

            SetStateFromCategory(info, category, elementOrKeyType, valueType);
            return(0);
        }
Esempio n. 4
0
        public async Task <UserCollection[]> GetCollection(int uid, CollectionCategory category, ResponseGroup responseGroup = ResponseGroup.Medium)
        {
            if (!Enum.IsDefined(typeof(CollectionCategory), category))
            {
                throw new ArgumentOutOfRangeException(nameof(category));
            }
            if (!Enum.IsDefined(typeof(ResponseGroup), responseGroup))
            {
                throw new ArgumentOutOfRangeException(nameof(responseGroup));
            }

            var url = $"/user/{uid}/collection?cat={(category == CollectionCategory.Watching ? "watching" : "all_watching")}&responseGroup={responseGroup.ToString().ToLowerInvariant()}";

            using (var client = new BangumiClient())
            {
                var json = await client.GetStringAsync(url);

                return(JsonConvert.DeserializeObject <UserCollection[]>(json));
            }
        }