private IList <PageZone> CreateMaster(string oldTemplate, string template, string fileName) { template = ChangeHead(template); template = AddForm(template); IList <object> oldFragments = SplitPageTemplate(oldTemplate); IList <object> fragments = SplitPageTemplate(template); IList <PageZone> oldZoneList = new List <PageZone>(); for (int i = 0; i < oldFragments.Count; i++) { if (oldFragments[i] is PageZone) { PageZone oldZone = oldFragments[i] as PageZone; oldZoneList.Add(oldZone); } } IList <PageZone> zoneList = new List <PageZone>(); StringBuilder master = new StringBuilder(); master.Append(MASTERHEADER); for (int i = 0; i < fragments.Count; i++) { if (fragments[i] is PageZone) { PageZone zone = fragments[i] as PageZone; master.AppendFormat(PLACEHOLDER, zone.Name); zoneList.Add(zone); } else if (fragments[i] is PageEdit) { PageEdit edit = fragments[i] as PageEdit; master.AppendFormat(PAGEEDIT, edit.Name); } else if (fragments[i] is PageCatalog) { // do nothing } else { master.Append((string)fragments[i]); } } _isZoneChange = ZoneChanged(oldZoneList, zoneList); // MasterPages will be generated next to PageTemplates with appropriate extension and content type. // SaveMasterPage(string.Concat(fileName, MASTER), Repository.PageTemplatesFolderPath, master.ToString()); var parentPath = RepositoryPath.GetParentPath(this.PageTemplateNode.Path); SaveMasterPage(string.Concat(fileName, MASTER), parentPath, master.ToString()); return(zoneList); }
public async Task <IActionResult> ReadPageZone(long tenantId, long pageId, long pageZoneId) { PageZone pageZone = await _pageService.ReadPageZoneAsync(tenantId, pageId, pageZoneId); if (pageZone == null) { return(NotFound()); } return(Ok(pageZone)); }
private static bool ExistPageZone(PageZone pageZone, IList <PageZone> pageZoneList) { foreach (PageZone pz in pageZoneList) { if (pageZone.Name == pz.Name && pageZone.AttrListText == pz.AttrListText && pageZone.InnerText == pz.InnerText) { return(true); } } return(false); }
public void WhenInstantiatingClassWithDefaultConstructor_Succeeds() { // Arrange PageZone model; // Act model = new PageZone(); // Assert Assert.NotNull(model); }
public async Task <PageZone> ReadPageZoneAsync(long tenantId, long pageId, long pageZoneId) { using (SqlConnection connection = new SqlConnection(_options.Value.SqlConnectionString)) { connection.Open(); PageZone pageZone = await connection.QueryFirstOrDefaultAsync <PageZone>( @"SELECT TenantId, PageId, PageZoneId, MasterPageId, MasterPageZoneId FROM cms.PageZone WHERE TenantId = @TenantId AND PageId = @PageId AND PageZoneId = @PageZoneId", new { TenantId = tenantId, PageId = pageId, PageZoneId = pageZoneId } ); return(pageZone); } }
public BinaryData GetASPXBinaryByPageTemplate(Page page, PageTemplate pageTemplate) { if (page == null) { throw new ArgumentNullException("page"); } if (pageTemplate == null) { throw new ArgumentNullException("pageTemplate"); } BinaryData binaryData = new BinaryData(); if (page.Binary != null) { binaryData = page.Binary; } string pageTmp = RepositoryTools.GetStreamString(pageTemplate.Binary.GetStream()); IList <object> fragments = SplitPageTemplate(pageTmp); StringBuilder aspx = new StringBuilder(); // MasterPage is inside the PageTemplates folder. var parentPath = RepositoryPath.GetParentPath(pageTemplate.Path); aspx.AppendFormat(ASPXHEADER, string.Concat("/", GetFileNameWithoutExt(pageTemplate.Name), MASTER), parentPath); for (int i = 0; i < fragments.Count; i++) { if (fragments[i] is PageZone) { PageZone zone = fragments[i] as PageZone; aspx.AppendFormat(WEBPARTZONE, zone.Name, zone.InnerText, zone.AttrListText); } } binaryData.SetStream(RepositoryTools.GetStreamFromString(aspx.ToString())); binaryData.FileName = new BinaryFileName(ASPX); binaryData.ContentType = ASPXCONTENTTYPE; return(binaryData); }
public Form GetForm(string context) { // Check permissions _authorizationService.AuthorizeUserForFunction(Functions.UpdatePageElements); // Get tenant, page and page zone identifiers string[] parts = context.Split('|'); long pageId = Convert.ToInt64(parts[0]); long pageZoneId = Convert.ToInt64(parts[1]); long tenantId = _authenticationService.TenantId; // Get page and master page zones Page page = _pageService.Read(tenantId, pageId); MasterPage masterPage = _masterPageService.Read(tenantId, page.MasterPageId); PageZone pageZone = page.PageZones.Where(pz => pz.PageZoneId == pageZoneId).First(); MasterPageZone masterPageZone = masterPage.MasterPageZones.Where(mpz => mpz.MasterPageZoneId == pageZone.MasterPageZoneId).First(); // Get all element types List <IElementSettings> elements = new List <IElementSettings>(); IEnumerable <ElementType> elementTypes = _elementService.ListTypes(); Dictionary <Guid, ElementType> elementTypesById = elementTypes.GroupBy(t => t.ElementTypeId).ToDictionary(t => t.Key, t => t.First()); // Construct form Form form = new Form { Fields = new Dictionary <string, IFormField>(), Id = FormId.ToString(), Context = context }; List <ElementType> availableElementTypes = new List <ElementType>(); foreach (MasterPageZoneElementType masterPageZoneElementType in masterPageZone.MasterPageZoneElementTypes) { ElementType elementType = elementTypesById[masterPageZoneElementType.ElementTypeId]; availableElementTypes.Add(elementType); } form.FieldSets = GetFieldSets(elementTypesById, pageZone); form.NamedFieldSets = GetNamedFieldSets(availableElementTypes); form.SubmitLabel = PageResource.PageZoneAdminButtonLabel; // Return result return(form); }
private IList <FormFieldSet> GetFieldSets(Dictionary <Guid, ElementType> elementTypesById, PageZone pageZone) { List <FormFieldSet> fieldSets = new List <FormFieldSet>(); foreach (PageZoneElement pageZoneElement in pageZone.PageZoneElements) { FormFieldSet fieldSet = new FormFieldSet { Fields = new Dictionary <string, IFormField>() }; IElementSettings element = _elementService.Read(pageZoneElement.TenantId, pageZoneElement.ElementTypeId, pageZoneElement.ElementId); fieldSet.Fields.Add("name", GetNameTextField(pageZoneElement.PageZoneElementId, element.Name)); fieldSet.Fields.Add("elementType", GetElementTypeSelectListField(pageZoneElement.PageZoneElementId, pageZoneElement.ElementTypeId, elementTypesById, null)); fieldSets.Add(fieldSet); } return(fieldSets); }