コード例 #1
0
        public async Task <ContainerBO> GetToCommunityAsync(Guid containerId)
        {
            Container container = await this._collectionQueries.GetAsync(containerId);

            var collectionCategory = new ContainerBO();

            collectionCategory.Id              = container.Id;
            collectionCategory.Name            = container.Name;
            collectionCategory.Description     = container.Description;
            collectionCategory.EnvironmentType = container.EnvironmentType;
            collectionCategory.ChildContainers = new List <ContainerBO>();
            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;

            var environmentCatalog = await _catalogQueries.GetAsync(container.EnvironmentType);

            if (environmentCatalog != null)
            {
                collectionCategory.CatalogEnvironmentType = new CatalogBO
                {
                    CatalogType = environmentCatalog.CatalogType,
                    Description = environmentCatalog.Description,
                    Name        = environmentCatalog.Name
                }
            }
            ;

            if (collectionCategory.Tags.Any())
            {
                collectionCategory.Tags = collectionCategory.Tags.Where(rec => rec.IsPublic).ToList();
            }

            if (collectionCategory.RuleDetailsDestinationId != null)
            {
                var existCatalog = await _catalogQueries.GetAsync(collectionCategory.RuleDetailsDestinationId.Value);

                if (existCatalog != null)
                {
                    var listColumns = await _edFiRuleExecutionLogDetailQueries.GetColumnsByTableAsync(existCatalog.Name, "destination");

                    if (listColumns != null)
                    {
                        collectionCategory.ContainerDestination = new ContainerDestinationBO
                        {
                            CatalogId            = existCatalog.Id,
                            ContainerId          = collectionCategory.Id,
                            DestinationName      = existCatalog.Name,
                            DestinationStructure = JsonConvert.SerializeObject(listColumns)
                        };
                    }
                }
            }

            foreach (var itemContainer in container.ChildContainers)
            {
                var category = new ContainerBO
                {
                    Id                = itemContainer.Id,
                    Name              = itemContainer.Name,
                    Description       = itemContainer.Description,
                    ParentContainerId = itemContainer.ParentContainerId,
                    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.GetByContainerIdAsync(itemContainer.Id);

                if (category.Tags.Any())
                {
                    category.Tags = category.Tags.Where(rec => rec.IsPublic).ToList();
                }

                if (category.Rules.Any())
                {
                    category.Rules.ForEach(rec =>
                    {
                        if (rec.Tags != null && rec.Tags.Any())
                        {
                            rec.Tags = rec.Tags.Where(recTags => recTags.IsPublic).ToList();
                        }
                    });
                }

                collectionCategory.ChildContainers.Add(category);
            }
            return(collectionCategory);
        }