public void Transform_NativeRegionAddComponentTemplateAndSchemaConstraint_Success() { Schema regionSchema = null; Schema constraintSchema = null; ComponentTemplate constraintComponentTemplate = null; try { constraintSchema = GetNewSchema(SchemaPurpose.Component); constraintSchema.Save(true); constraintComponentTemplate = GetNewComponentTemaplate(constraintSchema); constraintComponentTemplate.Save(true); regionSchema = GetNewSchema(SchemaPurpose.Region); AddTypeConstraint(regionSchema.RegionDefinition, constraintSchema, constraintComponentTemplate); regionSchema.Save(true); string regionId = regionSchema.Id.ItemId.ToString(); var definedRegions = GetRenderedRegionDefinitions(); var region = definedRegions.FirstOrDefault(r => r.Region == regionId); Assert.IsNotNull(region, $"Region with Id {regionId} was not found"); Assert.AreEqual(1, region.ComponentTypes.Count); Assert.AreEqual(constraintSchema.Id, region.ComponentTypes[0].Schema); Assert.AreEqual(constraintComponentTemplate.Id, region.ComponentTypes[0].Template); } finally { //Cleanup Remove(regionSchema); Remove(constraintComponentTemplate); Remove(constraintSchema); } }
/// <summary> /// Gets the raw string (xml) from the broker db by URL /// </summary> /// <param name="Url">URL of the page</param> /// <returns>String with page xml or empty string if no page was found</returns> public string GetContentByUrl(string Url) { Page page = new Page(); page.Title = Randomizer.AnyString(15); page.Id = Randomizer.AnyUri(64); page.Filename = Randomizer.AnySafeString(8) + ".html"; PageTemplate pt = new PageTemplate(); pt.Title = Randomizer.AnyString(20); Field ptfieldView = new Field(); ptfieldView.Name = "view"; ptfieldView.Values.Add("Standard"); pt.MetadataFields = new FieldSet(); pt.MetadataFields.Add(ptfieldView.Name, ptfieldView); page.PageTemplate = pt; Schema schema = new Schema(); schema.Title = Randomizer.AnyString(10); Component component = new Component(); component.Title = Randomizer.AnyString(30); component.Id = Randomizer.AnyUri(16); component.Schema = schema; Field field1 = Randomizer.AnyTextField(6, 120, true); Field field2 = Randomizer.AnyTextField(8, 40, false); FieldSet fieldSet = new FieldSet(); fieldSet.Add(field1.Name, field1); fieldSet.Add(field2.Name, field2); component.Fields = fieldSet; ComponentTemplate ct = new ComponentTemplate(); ct.Title = Randomizer.AnyString(20); Field fieldView = new Field(); fieldView.Name = "view"; fieldView.Values.Add("DefaultComponentView"); ct.MetadataFields = new FieldSet(); ct.MetadataFields.Add(fieldView.Name, fieldView); ComponentPresentation cp = new ComponentPresentation(); cp.Component = component; cp.ComponentTemplate = ct; page.ComponentPresentations = new List<ComponentPresentation>(); page.ComponentPresentations.Add(cp); FieldSet metadataFields = new FieldSet(); page.MetadataFields = metadataFields; var serializer = new XmlSerializer(typeof(Page)); StringBuilder builder = new StringBuilder(); StringWriter writer = new StringWriter(builder); //XmlTextWriter writer = new XmlTextWriter(page.Filename, Encoding.UTF8); //serializer.Serialize(writer, page); serializer.Serialize(writer, page); string pageAsString = builder.ToString(); return pageAsString; }
public void ProcessRequest(HttpContext context) { string id = context.Request["id"]; ComponentTemplate componentTemplate = bll.GetByKey <ComponentTemplate>("AutoId", id); if (componentTemplate == null) { apiResp.code = (int)APIErrCode.IsNotFound; apiResp.msg = "模板未找到"; bll.ContextResponse(context, apiResp); return; } apiResp.status = true; string cate_name = ""; ArticleCategory cate = bllCate.GetArticleCategory(componentTemplate.CateId); if (cate != null) { cate_name = cate.CategoryName; } apiResp.result = new { id = componentTemplate.AutoId, name = componentTemplate.Name, img = componentTemplate.ThumbnailsPath, config = componentTemplate.Config, data = componentTemplate.Data, cate = componentTemplate.CateId, cate_name = cate_name, }; apiResp.msg = "获取模板设置成功"; apiResp.code = (int)APIErrCode.IsSuccess; bll.ContextResponse(context, apiResp); }
private ComponentTemplate ParseNode(ComponentTemplate rootTemplate, string containerScope, XmlNode node, string[] namespaces) { var componentType = componentTypeResolver.FindComponentType(node.Name, namespaces); var template = new ComponentTemplate(containerScope, node.Name, componentType); ParsePropertiesSetters(template, node); if (componentType == typeof(ComponentPlaceholderComponent)) { rootTemplate.Placeholders.Add(template); } foreach (XmlNode childNode in node.ChildNodes) { if (IsScopeTemplate(childNode, out string scopeName)) { foreach (XmlNode scopeChildNode in childNode.ChildNodes) { var childTemplate = ParseNode(rootTemplate, scopeName, scopeChildNode, namespaces); template.Templates.Add(childTemplate); } } else { var childTemplate = ParseNode(rootTemplate, "default", childNode, namespaces); template.Templates.Add(childTemplate); } } return(template); }
/// <summary> /// Constructs a new instance of the view model for the /// component catalog, which will be assigned to an instance /// of the plug-in catalog user control. /// </summary> /// <param name="catalog"></param> public AfxComponentCatalogViewModel(IAfxComponentCatalog catalog) { foreach (var package in catalog) { var packageModel = new ComponentPackage() { Title = package.Title, Items = new ObservableCollection<ComponentTemplate>() }; foreach (var template in package) { var templateModel = new ComponentTemplate() { Id = template.Id, Name = template.Name, Image = GetComponentBitmap(template, catalog) }; packageModel.Items.Add(templateModel); } this._items.Add(packageModel); } }
public string GetContent(string uri, string templateUri = "") { Schema schema = new Schema(); schema.Title = Randomizer.AnyString(10); Component component = new Component(); component.Title = Randomizer.AnyString(30); component.Id = Randomizer.AnyUri(16); component.Schema = schema; Field field1 = Randomizer.AnyTextField(6, 120, true); Field field2 = Randomizer.AnyTextField(8, 40, false); FieldSet fieldSet = new FieldSet(); fieldSet.Add(field1.Name, field1); fieldSet.Add(field2.Name, field2); component.Fields = fieldSet; if (templateUri == "componentlink") { CustomizeCompomentForComponentLink(component); } if (templateUri == "embedded") { CustomizeCompomentForEmbeddedField(component); } if (templateUri == "keyword") { CustomizeCompomentForKeywordField(component); } if(templateUri == "componentIgnoreCase") { CustomizeCompomentForComponentLinkIgnoreCase(component); } if (uri == "component") { return SerializerService.Serialize<Component>(component); } ComponentTemplate ct = new ComponentTemplate(); ct.Title = Randomizer.AnyString(20); Field fieldView = new Field(); fieldView.Name = "view"; fieldView.Values.Add("DefaultComponentView"); ct.MetadataFields = new FieldSet(); ct.MetadataFields.Add(fieldView.Name, fieldView); ComponentPresentation cp = new ComponentPresentation(); cp.Component = component; cp.ComponentTemplate = ct; Condition condition = new KeywordCondition() { Keyword = new Keyword() { Id = "tcm:2-123-1024", Key = "test", Title = "Test" }, Operator = NumericalConditionOperator.Equals, Value = 1 }; cp.Conditions = new List<Condition>() { condition }; return SerializerService.Serialize<ComponentPresentation>(cp); }
private void AddTypeConstraint(dynamic regionDefinition, Schema schema, ComponentTemplate ct) { Type typeConstraintType = GetType( "Tridion.ContentManager.CommunicationManagement.Regions.TypeConstraint"); dynamic typeConstraint = Activator.CreateInstance(typeConstraintType, TestSession); typeConstraint.BasedOnComponentTemplate = ct; typeConstraint.BasedOnSchema = schema; regionDefinition.ComponentPresentationConstraints.Add(typeConstraint); }
public ComponentPresentationModel(Engine engine, Component component, ComponentTemplate template, int index) { _engine = engine; _component = new ComponentModel(engine, component); _template = new ComponentTemplateModel(engine, template); _componentID = component.Id; _templateID = template.Id; Index = index; }
public static MvcHtmlString SiteEditComponentPresentation(this HtmlHelper helper, IComponent component, string componentTemplateId, bool queryBased, string region) { ComponentTemplate ct = new ComponentTemplate(); ct.Id = componentTemplateId; ComponentPresentation cp = new ComponentPresentation(); cp.Component = component as Component; cp.ComponentTemplate = ct; cp.OrderOnPage = -1; return SiteEditComponentPresentation(helper, cp, queryBased, region); }
/// <summary> /// Gets a ComponentTemplateModel object. /// </summary> /// <param name="itemUriOrWebDavUrl"></param> /// <returns></returns> public dynamic GetComponentTemplate(string itemUriOrWebDavUrl) { ComponentTemplate ct = _engine.GetObject(itemUriOrWebDavUrl) as ComponentTemplate; if (ct == null) { Logger.Error(String.Format("Unable to GetComponentTemplate With '{0}'", itemUriOrWebDavUrl)); return(null); } return(new ComponentTemplateModel(_engine, ct)); }
private Component GetInnerRegion(ComponentTemplate template) { Component innerRegion = null; ItemFields metadata = this.GetMetaData(template); ComponentLinkField innerRegionField = (ComponentLinkField) metadata["innerRegion"]; if (innerRegionField != null) { innerRegion = innerRegionField.Value; } return innerRegion; }
private InnerRegion GetInnerRegion(Page page, ComponentTemplate template) { if (Region.ExtractRegionIndex(template.Id) == -1 && template.Metadata != null) { ItemFields metadata = new ItemFields(template.Metadata, template.MetadataSchema); if (metadata != null && metadata.Contains("innerRegion") && metadata["innerRegion"] != null) { ComponentLinkField innerRegionField = (ComponentLinkField) metadata["innerRegion"]; return new InnerRegion(page, innerRegionField.Value, ComponentPresentation.Component); } } return null; }
/// <summary> /// Returns grouped components from the current <see cref="T:Tridion.ContentManager.CommunicationManagement.Page" /> /// list of <see cref="T:Tridion.ContentManager.CommunicationManagement.ComponentPresentation" /> /// </summary> /// <param name="component"><see cref="T:Tridion.ContentManager.ContentManagement.Component"/></param> /// <param name="template"><see cref="T:Tridion.ContentManager.CommunicationManagement.ComponentTemplate"/></param> /// <param name="page"><see cref="T:Tridion.ContentManager.CommunicationManagement.Page"/></param> /// <returns>List of <see cref="T:Tridion.ContentManager.ContentManagement.Component"/></returns> public static IList<Component> ComponentGroup(this Component component, ComponentTemplate template, Page page) { bool isLocated = false; List<Component> result = new List<Component>(); ComponentPresentation previous = null; if (component != null && page != null) { foreach (ComponentPresentation cp in page.ComponentPresentations) { // Locate the first component presentation matching our current component // Also ensure its the first matching component in a "block" if (!isLocated && cp.Component.Id.ItemId == component.Id.ItemId && cp.ComponentTemplate.Id.ItemId == template.Id.ItemId && (previous == null || (previous.Component.Schema.Id.ItemId != component.Schema.Id.ItemId && previous.ComponentTemplate.Id.ItemId != template.Id.ItemId))) { isLocated = true; result.Add(cp.Component); continue; } // Now find any following components in the same "block" based on the same schema and using the same component template if (isLocated) { if (cp.Component.Schema.Id.ItemId == component.Schema.Id.ItemId && cp.ComponentTemplate.Id.ItemId == template.Id.ItemId) { result.Add(cp.Component); } else { break; } } previous = cp; } } return result; }
public Region(Component regionComponent, ComponentTemplate regionTemplate) { this.regionComponent = regionComponent; this.regionTemplate = regionTemplate; this.fields = new ItemFields(regionComponent.Content, regionComponent.Schema); this.componentTypes = new List<ComponentType>(); EmbeddedSchemaField componentTypeESField = (EmbeddedSchemaField) fields["componentTypes"]; foreach (ItemFields componentTypeFields in componentTypeESField.Values) { this.componentTypes.Add(new ComponentType(componentTypeFields, this.regionComponent.Id.PublicationId)); } }
public static string GetKeyFromTemplate(ComponentTemplate template) { string key = Regex.Replace(template.Title, @"[\[\]\s\.]", ""); return key.Substring(0, 1).ToLower() + key.Substring(1); }
protected static string GetRegionName(ComponentTemplate template) { // check CT metadata if (template.MetadataSchema != null && template.Metadata != null) { ItemFields meta = new ItemFields(template.Metadata, template.MetadataSchema); string regionName = meta.GetTextValue("regionName"); if (!String.IsNullOrEmpty(regionName)) { return regionName; } string regionViewName = meta.GetTextValue("regionView"); if (!String.IsNullOrEmpty(regionViewName)) { // strip module from fully qualified name // since we need just the region name here as the web application can't deal with fully qualified region names yet return StripModuleFromName(regionViewName); } } // fallback use template title Match match = Regex.Match(template.Title, @".*?\[(.+?)\]"); if (match.Success) { // strip module from fully qualified name // since we need just the region name here as the web application can't deal with fully qualified region names yet return StripModuleFromName(match.Groups[1].Value); } // default region name return "Main"; }
public ComponentPresentationModel(Engine engine, Component component, ComponentTemplate template) : this(engine, component, template, 0) { }
private void OutputRegions(StringBuilder sb) { sb.Append("<regions>\n"); IComponentPresentationList componentPresentations = this.GetComponentPresentations(); Region region = null; Region innerRegion = null; int index = 0; foreach (Tridion.ContentManager.Templating.ComponentPresentation componentPresentation in componentPresentations) { Component component = new Component(componentPresentation.ComponentUri, Engine.GetSession()); ComponentTemplate template = new ComponentTemplate(componentPresentation.TemplateUri, Engine.GetSession()); Log.Debug("Checking component of type: " + component.Schema.Title); // TODO: How to handle region schemas?? What pattern to look for??? Find a more generic approach than looking on the schema title if (component.Schema.Title.Equals("DD4T Lite Region")) { if (region != null) { sb.Append(this.RenderRegion(region)); } region = new Region(component, template); innerRegion = null; } else if ( innerRegion != null && innerRegion.Accept(component, template) ) { innerRegion.AddComponentPresentation(new ComponentPresentationInfo(component, template)); } else if (region != null) { innerRegion = null; // Clear inner region Log.Debug("Adding component: " + component.Title + " to region: " + region.Name); ComponentPresentationInfo cpInfo = new ComponentPresentationInfo(component, template); region.AddComponentPresentation(cpInfo); if (this.IsContainerComponent(template)) { innerRegion = new Region(this.GetInnerRegion(template), index); cpInfo.InnerRegion = innerRegion; } } index++; } if (region != null) { Log.Debug("Outputting region: " + region.Name); sb.Append(this.RenderRegion(region)); } sb.Append("</regions>\n"); }
private bool IsContainerComponent(ComponentTemplate template) { ItemFields metadata = this.GetMetaData(template); return metadata != null && metadata.Contains("innerRegion") && metadata["innerRegion"] != null; }
public ComponentPresentationInfo(Component component, ComponentTemplate template) { this.component = component; this.template = template; }
public bool Accept(Component component, ComponentTemplate template) { foreach (ComponentType type in this.componentTypes) { if (type.SchemaId == component.Schema.Id.ItemId && type.TemplateId == template.Id.ItemId) { return true; } } return false; }
protected static string GetRegionFromTemplate(ComponentTemplate template) { var match = Regex.Match(template.Title, @".*?\[(.*?)\]"); if (match.Success) { return match.Groups[1].Value; } //default region name return "Main"; }