public async Task Generate(PlanTemplateCM planTemplate, string fr8AccountId)
        {
            var storage = await _tagGenerator.GetTags(planTemplate, fr8AccountId);

            foreach (var tag in storage.WebServiceTemplateTags)
            {
                var tags           = tag.TagsWithIcons.Select(x => x.Key).ToArray();
                var pageName       = GeneratePageNameFromTags(tags);
                var pageDefinition = _pageDefinitionService.Get(x => x.PageName == pageName && x.Type == PageType).FirstOrDefault() ?? new PageDefinitionDO
                {
                    PageName = pageName,
                    Tags     = tags,
                    Type     = PageType,
                    Title    = tag.Title
                };
                if (!pageDefinition.PlanTemplatesIds.Contains(planTemplate.ParentPlanId))
                {
                    pageDefinition.PlanTemplatesIds.Add(planTemplate.ParentPlanId);
                }
                pageDefinition.Url = new Uri($"{_templateGenerator.BaseUrl}/{pageName}");
                _pageDefinitionService.CreateOrUpdate(pageDefinition);
                var relatedPageDefinitions = _pageDefinitionService.GetAll().Where(x => x.PlanTemplatesIds.Contains(planTemplate.ParentPlanId));
                var curPageDefinition      = relatedPageDefinitions.FirstOrDefault(x => x.PageName == pageName);
                var curRelatedPlans        = new List <PublishPlanTemplateDTO>();
                foreach (var planTemplateId in curPageDefinition.PlanTemplatesIds)
                {
                    var planDto = _planTemplateService.GetPlanTemplateDTO(fr8AccountId, Guid.Parse(planTemplateId)).Result;
                    if (planDto != null)
                    {
                        curRelatedPlans.Add(planDto);
                    }
                }
                var relatedPlans = new List <Tuple <string, string, string> >();
                foreach (var publishPlanTemplateDTO in curRelatedPlans)
                {
                    relatedPlans.Add(new
                                     Tuple <string, string, string>(
                                         publishPlanTemplateDTO.Name,
                                         publishPlanTemplateDTO.Description ?? publishPlanTemplateDTO.Name,
                                         CloudConfigurationManager.GetSetting("HubApiUrl") +
                                         "plan_templates/createplan/?id=" + publishPlanTemplateDTO.ParentPlanId));
                }
                await _templateGenerator.Generate(new PlanCategoryTemplate(), pageName, new Dictionary <string, object>
                {
                    ["Name"]         = pageName,
                    ["Tags"]         = tag.TagsWithIcons,
                    ["RelatedPlans"] = relatedPlans
                });
            }
        }
        public async Task <Uri> Generate(string manifestName, GenerateMode generateMode)
        {
            if (string.IsNullOrWhiteSpace(manifestName))
            {
                throw new ArgumentException("Value can't be empty", nameof(manifestName));
            }
            var normalizedManifestName = manifestName.ToLower();
            var pageName       = manifestName;
            var fileName       = $"{normalizedManifestName}{PageExtension}";
            var pageDefinition = _pageDefinitionService.Get(x => x.Type == PageType && x.PageName == pageName).FirstOrDefault();

            switch (generateMode)
            {
            case GenerateMode.RetrieveExisting:
                if (pageDefinition == null)
                {
                    throw new ManifestPageNotFoundException(manifestName);
                }
                return(pageDefinition.Url);

            case GenerateMode.GenerateIfNotExists:
                if (pageDefinition != null)
                {
                    return(pageDefinition.Url);
                }
                break;
            }
            var systemUser = _fr8AccountService.GetSystemUser()?.EmailAddress?.Address;

            if (string.IsNullOrEmpty(systemUser))
            {
                throw new ManifestGenerationException("Failed to generate manifest description page. System user doesn't exist or not configured properly");
            }
            using (var uow = _uowFactory.Create())
            {
                var manifests = uow.MultiTenantObjectRepository.Query <ManifestDescriptionCM>(systemUser, x => x.Name.ToLower() == normalizedManifestName);
                if (manifests.Count == 0)
                {
                    throw new ManifestNotFoundException(manifestName);
                }
                manifests.Sort((x, y) => int.Parse(y.Version).CompareTo(int.Parse(x.Version)));
                if (pageDefinition == null)
                {
                    pageDefinition = new PageDefinitionDO
                    {
                        Type     = PageType,
                        PageName = pageName,
                    };
                }
                pageDefinition.Title       = $"Manifest description - {manifestName}";
                pageDefinition.Description = $"Basic information and sample JSON of all registered version of '{manifestName}' manifest";
                pageDefinition.Url         = new Uri($"{_templateGenerator.BaseUrl}/{fileName}");
                await _templateGenerator.Generate(new ManifestDescriptionTemplate(), fileName, new Dictionary <string, object>
                {
                    ["Manifests"] = manifests
                });

                _pageDefinitionService.CreateOrUpdate(pageDefinition);
                return(pageDefinition.Url);
            }
        }
示例#3
0
        public PageDefinitionDTO Get(int id)
        {
            var pageDefinition = _pageDefinition.Get(id);

            return(Mapper.Map <PageDefinitionDTO>(pageDefinition));
        }