private void CustomizeCompomentForKeywordField(Component component) { component.Schema.RootElementName = "hasKeyword"; Field headingField = new Field() { Name = "heading", Values = new List <string> { "some heading" } }; FieldSet metadataFields = new FieldSet(); metadataFields.Add(headingField.Name, headingField); Field keywordField = new Field() { Name = "keyword", KeywordValues = new List <Keyword>() { new Keyword() { MetadataFields = metadataFields, Id = Randomizer.AnyUri(1024), Title = Randomizer.AnyString(33), Description = Randomizer.AnyString(33) } } }; component.Fields.Add(keywordField.Name, keywordField); }
private void CustomizeCompomentForComponentLinkIgnoreCase(Component component) { component.Schema.RootElementName = "RootA"; Field headingField = new Field() { Name = "Heading", Values = new List <string> { "some heading" } }; FieldSet fieldsForLinkedComponent = new FieldSet(); fieldsForLinkedComponent.Add(headingField.Name, headingField); Field linkField = new Field() { Name = "Link", LinkedComponentValues = new List <Component> { new Component() { Title = Randomizer.AnyString(16), Id = Randomizer.AnyUri(16), Schema = new Schema() { Title = Randomizer.AnyString(10), RootElementName = "RootB" }, Fields = fieldsForLinkedComponent } } }; component.Fields.Add(linkField.Name, linkField); }
private void CustomizeCompomentForEmbeddedField(Component component) { component.Schema.RootElementName = "rootEmbedding"; Field headingField = new Field() { Name = "heading", Values = new List <string> { "some heading" } }; FieldSet embeddedFields = new FieldSet(); embeddedFields.Add(headingField.Name, headingField); Field embeddedField = new Field() { Name = "embedded", EmbeddedSchema = new Schema() { Title = "EmbeddedSchema", RootElementName = "embeddedRoot", Id = Randomizer.AnyUri(8) }, EmbeddedValues = new List <FieldSet>() { embeddedFields } }; component.Fields.Add(embeddedField.Name, embeddedField); }
/// <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; page.ComponentPresentations = new List <ComponentPresentation>(); string cpString = ComponentPresentationProvider.GetContent(""); page.ComponentPresentations.Add(SerializerService.Deserialize <ComponentPresentation>(cpString)); FieldSet metadataFields = new FieldSet(); page.MetadataFields = metadataFields; return(SerializerService.Serialize <Page>(page)); }
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 (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)); }
/// <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) { if (ThrowPageNotFound) { return(string.Empty); } Page page = new Page(); page.Title = Randomizer.AnyString(15); page.Id = Randomizer.AnyUri(64); page.Filename = Randomizer.AnySafeString(8) + ".html"; PageTemplate pt = new PageTemplate(); if (url.ToLower().Contains("model")) { pt.Title = "Standard"; } else { 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; page.ComponentPresentations = new List <ComponentPresentation>(); string cpString = ComponentPresentationProvider.GetContent(""); page.ComponentPresentations.Add(SerializerService.Deserialize <ComponentPresentation>(cpString)); FieldSet metadataFields = new FieldSet(); page.MetadataFields = metadataFields; return(SerializerService.Serialize <Page>(page)); }
/// <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); }