public static Dynamic.PageTemplate BuildPageTemplate(TComm.PageTemplate tcmPageTemplate, BuildManager manager) { Dynamic.PageTemplate pt = new Dynamic.PageTemplate(); pt.Title = tcmPageTemplate.Title; pt.Id = tcmPageTemplate.Id.ToString(); pt.FileExtension = tcmPageTemplate.FileExtension; pt.RevisionDate = tcmPageTemplate.RevisionDate; if (tcmPageTemplate.Metadata != null && tcmPageTemplate.MetadataSchema != null) { pt.MetadataFields = new Dynamic.FieldSet(); TCM.Fields.ItemFields tcmMetadataFields = new TCM.Fields.ItemFields(tcmPageTemplate.Metadata, tcmPageTemplate.MetadataSchema); pt.MetadataFields = manager.BuildFields(tcmMetadataFields); } else { pt.MetadataFields = null; } if (!manager.BuildProperties.OmitContextPublications) pt.Publication = manager.BuildPublication(tcmPageTemplate.ContextRepository); if (!manager.BuildProperties.OmitOwningPublications) pt.OwningPublication = manager.BuildPublication(tcmPageTemplate.OwningRepository); if (!manager.BuildProperties.OmitFolders) pt.Folder = manager.BuildOrganizationalItem((TCM.Folder)tcmPageTemplate.OrganizationalItem); return pt; }
public static Dynamic.ComponentTemplate BuildComponentTemplate(TComm.ComponentTemplate tcmComponentTemplate, BuildManager manager) { Dynamic.ComponentTemplate ct = new Dynamic.ComponentTemplate(); ct.Title = tcmComponentTemplate.Title; ct.Id = tcmComponentTemplate.Id.ToString(); ct.OutputFormat = tcmComponentTemplate.OutputFormat; ct.RevisionDate = tcmComponentTemplate.RevisionDate; if (tcmComponentTemplate.Metadata != null && tcmComponentTemplate.MetadataSchema != null) { ct.MetadataFields = new Dynamic.FieldSet(); TCM.Fields.ItemFields tcmMetadataFields = new TCM.Fields.ItemFields(tcmComponentTemplate.Metadata, tcmComponentTemplate.MetadataSchema); ct.MetadataFields = manager.BuildFields(tcmMetadataFields); } else { ct.MetadataFields = null; } if (!manager.BuildProperties.OmitContextPublications) ct.Publication = manager.BuildPublication(tcmComponentTemplate.ContextRepository); if (!manager.BuildProperties.OmitOwningPublications) ct.OwningPublication = manager.BuildPublication(tcmComponentTemplate.OwningRepository); if (!manager.BuildProperties.OmitFolders) ct.Folder = manager.BuildOrganizationalItem((TCM.Folder)tcmComponentTemplate.OrganizationalItem); return ct; }
public static Dynamic.Page BuildPage(TCM.Page tcmPage, Engine engine, BuildManager manager, int linkLevels, bool resolveWidthAndHeight, bool publishEmptyFields) { Dynamic.Page p = new Dynamic.Page { Title = tcmPage.Title, Id = tcmPage.Id.ToString(), Filename = tcmPage.FileName, PageTemplate = manager.BuildPageTemplate(tcmPage.PageTemplate), Schema = manager.BuildSchema(tcmPage.MetadataSchema), Version = tcmPage.Version, RevisionDate = tcmPage.RevisionDate, MetadataFields = new Dynamic.FieldSet() }; if (linkLevels > 0) { try { if (tcmPage.Metadata != null && tcmPage.MetadataSchema != null) { var tcmMetadataFields = new Tridion.ContentManager.ContentManagement.Fields.ItemFields(tcmPage.Metadata, tcmPage.MetadataSchema); p.MetadataFields = manager.BuildFields(tcmMetadataFields); } } catch (Exception) { // fail silently if there is no metadata schema } } p.ComponentPresentations = new List <Dynamic.ComponentPresentation>(); foreach (TCM.ComponentPresentation cp in tcmPage.ComponentPresentations) { Dynamic.ComponentPresentation dynCp = manager.BuildComponentPresentation(cp, engine, linkLevels - 1, resolveWidthAndHeight); p.ComponentPresentations.Add(dynCp); } p.StructureGroup = manager.BuildOrganizationalItem((TCM.StructureGroup)tcmPage.OrganizationalItem); if (!manager.BuildProperties.OmitContextPublications) { p.Publication = manager.BuildPublication(tcmPage.ContextRepository); } if (!manager.BuildProperties.OmitOwningPublications) { p.OwningPublication = manager.BuildPublication(tcmPage.OwningRepository); } if (!manager.BuildProperties.OmitCategories) { p.Categories = manager.BuildCategories(tcmPage); } manager.AddXpathToFields(p.MetadataFields, "Metadata"); return(p); }
public static Dynamic.Page BuildPage(TCM.Page tcmPage, Engine engine, BuildManager manager, int linkLevels, bool resolveWidthAndHeight,bool publishEmptyFields) { Dynamic.Page p = new Dynamic.Page { Title = tcmPage.Title, Id = tcmPage.Id.ToString(), Filename = tcmPage.FileName, PageTemplate = manager.BuildPageTemplate(tcmPage.PageTemplate), Schema = manager.BuildSchema(tcmPage.MetadataSchema), Version = tcmPage.Version, RevisionDate = tcmPage.RevisionDate, MetadataFields = new Dynamic.FieldSet() }; if (linkLevels > 0) { try { if (tcmPage.Metadata != null && tcmPage.MetadataSchema != null) { var tcmMetadataFields = new Tridion.ContentManager.ContentManagement.Fields.ItemFields(tcmPage.Metadata, tcmPage.MetadataSchema); p.MetadataFields = manager.BuildFields(tcmMetadataFields); } } catch (Exception) { // fail silently if there is no metadata schema } } p.ComponentPresentations = new List<Dynamic.ComponentPresentation>(); foreach (TCM.ComponentPresentation cp in tcmPage.ComponentPresentations) { Dynamic.ComponentPresentation dynCp = manager.BuildComponentPresentation(cp, engine, linkLevels - 1, resolveWidthAndHeight); p.ComponentPresentations.Add(dynCp); } p.StructureGroup = manager.BuildOrganizationalItem((TCM.StructureGroup)tcmPage.OrganizationalItem); if (!manager.BuildProperties.OmitContextPublications) { p.Publication = manager.BuildPublication(tcmPage.ContextRepository); } if (!manager.BuildProperties.OmitOwningPublications) { p.OwningPublication = manager.BuildPublication(tcmPage.OwningRepository); } if (!manager.BuildProperties.OmitCategories) { p.Categories = manager.BuildCategories(tcmPage); } manager.AddXpathToFields(p.MetadataFields, "Metadata"); return p; }
public static Dynamic.Region BuildRegion(TCM.Regions.IRegion tcmRegion, Engine engine, BuildManager manager, int linkLevels, bool resolveWidthAndHeight, bool publishEmptyFields) { Dynamic.Region r = new Dynamic.Region { Name = tcmRegion.RegionName, Schema = manager.BuildSchema(tcmRegion.RegionSchema), MetadataFields = new Dynamic.FieldSet() }; if (linkLevels > 0) { try { if (tcmRegion.Metadata != null && tcmRegion.RegionSchema != null) { var tcmMetadataFields = new Tridion.ContentManager.ContentManagement.Fields.ItemFields(tcmRegion.Metadata, tcmRegion.RegionSchema); r.MetadataFields = manager.BuildFields(tcmMetadataFields); } } catch (Exception) { // fail silently if there is no metadata schema } } r.ComponentPresentations = new List <Dynamic.ComponentPresentation>(); foreach (TCM.ComponentPresentation cp in tcmRegion.ComponentPresentations) { Dynamic.ComponentPresentation dynCp = manager.BuildComponentPresentation(cp, engine, linkLevels - 1, resolveWidthAndHeight); r.ComponentPresentations.Add(dynCp); } manager.AddXpathToFields(r.MetadataFields, "Metadata"); // adding nested regions r.Regions = new List <Dynamic.Region>(); foreach (TCM.Regions.IRegion nestedTcmRegion in tcmRegion.Regions) { Dynamic.Region nestedRegion = manager.BuildRegion(nestedTcmRegion, engine); r.Regions.Add(nestedRegion); } return(r); }
public static Dynamic.Keyword BuildKeyword(Keyword keyword, int currentLinkLevel, BuildManager buildManager) { Dynamic.Keyword dk = new Dynamic.Keyword(); dk.Id = keyword.Id; dk.Title = keyword.Title; dk.Path = FindKeywordPath(keyword); dk.Description = keyword.Description; dk.Key = keyword.Key; dk.TaxonomyId = keyword.OrganizationalItem.Id; if (currentLinkLevel > 0) { if (keyword.Metadata != null && keyword.MetadataSchema != null) { var tcmMetadataFields = new Tridion.ContentManager.ContentManagement.Fields.ItemFields(keyword.Metadata, keyword.MetadataSchema); dk.MetadataFields = buildManager.BuildFields(tcmMetadataFields, currentLinkLevel); } } return(dk); }
public static Dynamic.ComponentTemplate BuildComponentTemplate(TComm.ComponentTemplate tcmComponentTemplate, BuildManager manager) { Dynamic.ComponentTemplate ct = new Dynamic.ComponentTemplate(); ct.Title = tcmComponentTemplate.Title; ct.Id = tcmComponentTemplate.Id.ToString(); ct.OutputFormat = tcmComponentTemplate.OutputFormat; ct.RevisionDate = tcmComponentTemplate.RevisionDate; if (tcmComponentTemplate.Metadata != null && tcmComponentTemplate.MetadataSchema != null) { ct.MetadataFields = new Dynamic.FieldSet(); TCM.Fields.ItemFields tcmMetadataFields = new TCM.Fields.ItemFields(tcmComponentTemplate.Metadata, tcmComponentTemplate.MetadataSchema); ct.MetadataFields = manager.BuildFields(tcmMetadataFields, 0, false,false); // never follow links to components from component templates, never resolve binary widht/height } else { ct.MetadataFields = null; } ct.Folder = manager.BuildOrganizationalItem((TCM.Folder)tcmComponentTemplate.OrganizationalItem); ct.Publication = manager.BuildPublication(tcmComponentTemplate.ContextRepository); return ct; }
public static Dynamic.ComponentTemplate BuildComponentTemplate(TComm.ComponentTemplate tcmComponentTemplate, BuildManager manager) { Dynamic.ComponentTemplate ct = new Dynamic.ComponentTemplate(); ct.Title = tcmComponentTemplate.Title; ct.Id = tcmComponentTemplate.Id.ToString(); ct.OutputFormat = tcmComponentTemplate.OutputFormat; ct.RevisionDate = tcmComponentTemplate.RevisionDate; if (tcmComponentTemplate.Metadata != null && tcmComponentTemplate.MetadataSchema != null) { ct.MetadataFields = new Dynamic.FieldSet(); TCM.Fields.ItemFields tcmMetadataFields = new TCM.Fields.ItemFields(tcmComponentTemplate.Metadata, tcmComponentTemplate.MetadataSchema); ct.MetadataFields = manager.BuildFields(tcmMetadataFields, 0, false, false); // never follow links to components from component templates, never resolve binary widht/height } else { ct.MetadataFields = null; } ct.Folder = manager.BuildOrganizationalItem((TCM.Folder)tcmComponentTemplate.OrganizationalItem); ct.Publication = manager.BuildPublication(tcmComponentTemplate.ContextRepository); return(ct); }
public static Dynamic.ComponentTemplate BuildComponentTemplate(TComm.ComponentTemplate tcmComponentTemplate, BuildManager manager) { Dynamic.ComponentTemplate ct = new Dynamic.ComponentTemplate(); ct.Title = tcmComponentTemplate.Title; ct.Id = tcmComponentTemplate.Id.ToString(); ct.OutputFormat = tcmComponentTemplate.OutputFormat; ct.RevisionDate = tcmComponentTemplate.RevisionDate; if (tcmComponentTemplate.Metadata != null && tcmComponentTemplate.MetadataSchema != null) { ct.MetadataFields = new Dynamic.FieldSet(); TCM.Fields.ItemFields tcmMetadataFields = new TCM.Fields.ItemFields(tcmComponentTemplate.Metadata, tcmComponentTemplate.MetadataSchema); ct.MetadataFields = manager.BuildFields(tcmMetadataFields); } else { ct.MetadataFields = null; } if (!manager.BuildProperties.OmitContextPublications) { ct.Publication = manager.BuildPublication(tcmComponentTemplate.ContextRepository); } if (!manager.BuildProperties.OmitOwningPublications) { ct.OwningPublication = manager.BuildPublication(tcmComponentTemplate.OwningRepository); } if (!manager.BuildProperties.OmitFolders) { ct.Folder = manager.BuildOrganizationalItem((TCM.Folder)tcmComponentTemplate.OrganizationalItem); } return(ct); }
public static Dynamic.Component BuildComponent(TCM.Component tcmComponent, int linkLevels, bool resolveWidthAndHeight, bool publishEmptyFields, BuildManager manager) { GeneralUtils.TimedLog("start BuildComponent"); Dynamic.Component c = new Dynamic.Component(); c.Title = tcmComponent.Title; c.Id = tcmComponent.Id.ToString(); c.RevisionDate = tcmComponent.RevisionDate; GeneralUtils.TimedLog("component title = " + c.Title); c.Version = tcmComponent.Version; GeneralUtils.TimedLog("start building schema"); c.Schema = manager.BuildSchema(tcmComponent.Schema); GeneralUtils.TimedLog("finished building schema"); c.ComponentType = (ComponentType)Enum.Parse(typeof(ComponentType), tcmComponent.ComponentType.ToString()); if (tcmComponent.ComponentType.Equals(TCM.ComponentType.Multimedia)) { GeneralUtils.TimedLog("start building multimedia"); Multimedia multimedia = new Multimedia(); multimedia.MimeType = tcmComponent.BinaryContent.MultimediaType.MimeType; multimedia.Size = tcmComponent.BinaryContent.FileSize; multimedia.FileName = tcmComponent.BinaryContent.Filename; // remove leading dot from extension because microsoft returns this as ".gif" string extension = System.IO.Path.GetExtension(multimedia.FileName); if (string.IsNullOrEmpty(extension)) { multimedia.FileExtension = ""; } else { multimedia.FileExtension = extension.Substring(1); } if (resolveWidthAndHeight) { try { MemoryStream memstream = new MemoryStream(); tcmComponent.BinaryContent.WriteToStream(memstream); Image image = Image.FromStream(memstream); memstream.Close(); multimedia.Width = image.Size.Width; multimedia.Height = image.Size.Height; } catch (Exception e) { log.Warning("error retrieving width and height of image: " + e.Message); multimedia.Width = 0; multimedia.Height = 0; } } else { multimedia.Width = 0; multimedia.Height = 0; } c.Multimedia = multimedia; GeneralUtils.TimedLog("finished building multimedia"); } else { c.Multimedia = null; } c.Fields = new Dynamic.FieldSet(); c.MetadataFields = new Dynamic.FieldSet(); if (linkLevels > 0) { if (tcmComponent.Content != null) { GeneralUtils.TimedLog("start retrieving tcm fields"); TCM.Fields.ItemFields tcmFields = new TCM.Fields.ItemFields(tcmComponent.Content, tcmComponent.Schema); log.Debug("TCM fields" + tcmFields.ToXml()); GeneralUtils.TimedLog("finished retrieving tcm fields"); GeneralUtils.TimedLog("start building fields"); c.Fields = manager.BuildFields(tcmFields, linkLevels, resolveWidthAndHeight, publishEmptyFields); GeneralUtils.TimedLog("finished building fields"); } if (tcmComponent.Metadata != null) { GeneralUtils.TimedLog("start retrieving tcm metadata fields"); TCM.Fields.ItemFields tcmMetadataFields = new TCM.Fields.ItemFields(tcmComponent.Metadata, tcmComponent.MetadataSchema); GeneralUtils.TimedLog("finished retrieving tcm metadata fields"); GeneralUtils.TimedLog("start building metadata fields"); c.MetadataFields = manager.BuildFields(tcmMetadataFields, linkLevels, resolveWidthAndHeight, publishEmptyFields); GeneralUtils.TimedLog("finished building metadata fields"); } } c.Publication = manager.BuildPublication(tcmComponent.ContextRepository); c.OwningPublication = manager.BuildPublication(tcmComponent.OwningRepository); TCM.Folder folder = (TCM.Folder)tcmComponent.OrganizationalItem; c.Folder = manager.BuildOrganizationalItem(folder); c.Categories = manager.BuildCategories(tcmComponent); manager.AddXpathToFields(c.Fields, "tcm:Content/custom:" + tcmComponent.Schema.RootElementName); // TODO: check if the first part of the XPath is really the root element name, or simply always 'Content' manager.AddXpathToFields(c.MetadataFields, "tcm:Metadata/custom:Metadata"); return(c); }
public static Dynamic.Component BuildComponent(TCM.Component tcmComponent, int currentLinkLevel, BuildManager manager) { log.Debug(string.Format("start BuildComponent with component {0} ({1}) and link level {2}", tcmComponent.Title, tcmComponent.Id, currentLinkLevel)); Dynamic.Component c = new Dynamic.Component(); c.Title = tcmComponent.Title; c.Id = tcmComponent.Id.ToString(); c.RevisionDate = tcmComponent.RevisionDate; c.Version = tcmComponent.Version; c.Schema = manager.BuildSchema(tcmComponent.Schema); c.ComponentType = (ComponentType)Enum.Parse(typeof(ComponentType), tcmComponent.ComponentType.ToString()); if (tcmComponent.ComponentType.Equals(TCM.ComponentType.Multimedia)) { Multimedia multimedia = new Multimedia(); multimedia.MimeType = tcmComponent.BinaryContent.MultimediaType.MimeType; multimedia.Size = tcmComponent.BinaryContent.Size; multimedia.FileName = tcmComponent.BinaryContent.Filename; string extension = System.IO.Path.GetExtension(multimedia.FileName); if (string.IsNullOrEmpty(extension)) { multimedia.FileExtension = ""; } else { // remove leading dot from extension because microsoft returns this as ".gif" multimedia.FileExtension = extension.Substring(1); } if (manager.BuildProperties.ResolveWidthAndHeight) { try { MemoryStream memstream = new MemoryStream(); tcmComponent.BinaryContent.WriteToStream(memstream); Image image = Image.FromStream(memstream); memstream.Close(); multimedia.Width = image.Size.Width; multimedia.Height = image.Size.Height; } catch (Exception e) { log.Warning(string.Format("error retrieving width and height of image: is component with ID {0} really an image? Error message: {1}", c.Id, e.Message)); multimedia.Width = 0; multimedia.Height = 0; } } else { multimedia.Width = 0; multimedia.Height = 0; } c.Multimedia = multimedia; c.Multimedia.Url = manager.PublishMultimediaComponent(c); } else { c.Multimedia = null; } c.Fields = new Dynamic.FieldSet(); c.MetadataFields = new Dynamic.FieldSet(); if (currentLinkLevel > 0) { if (tcmComponent.Content != null) { TCM.Fields.ItemFields tcmFields = new TCM.Fields.ItemFields(tcmComponent.Content, tcmComponent.Schema); c.Fields = manager.BuildFields(tcmFields, currentLinkLevel); } if (tcmComponent.Metadata != null) { TCM.Fields.ItemFields tcmMetadataFields = new TCM.Fields.ItemFields(tcmComponent.Metadata, tcmComponent.MetadataSchema); c.MetadataFields = manager.BuildFields(tcmMetadataFields, currentLinkLevel); } } if (!manager.BuildProperties.OmitContextPublications) { c.Publication = manager.BuildPublication(tcmComponent.ContextRepository); } if (!manager.BuildProperties.OmitOwningPublications) { c.OwningPublication = manager.BuildPublication(tcmComponent.OwningRepository); } if (!manager.BuildProperties.OmitFolders) { TCM.Folder folder = (TCM.Folder)tcmComponent.OrganizationalItem; c.Folder = manager.BuildOrganizationalItem(folder); } if (!manager.BuildProperties.OmitCategories) { c.Categories = manager.BuildCategories(tcmComponent); } manager.AddXpathToFields(c.Fields, "tcm:Content/custom:" + tcmComponent.Schema.RootElementName); manager.AddXpathToFields(c.MetadataFields, "tcm:Metadata/custom:Metadata"); return(c); }
public static Dynamic.Field BuildField(TCM.Fields.ItemField tcmItemField, int currentLinkLevel, BuildManager manager) { Dynamic.Field f = new Dynamic.Field(); if (tcmItemField == null && manager.BuildProperties.PublishEmptyFields) { f.Values.Add(""); return f; } else if (tcmItemField == null && !manager.BuildProperties.PublishEmptyFields) { throw new FieldHasNoValueException(); } f.Name = tcmItemField.Name; if (tcmItemField is TCM.Fields.XhtmlField) { TCM.Fields.XhtmlField sField = (TCM.Fields.XhtmlField)tcmItemField; if (sField.Values.Count == 0 && manager.BuildProperties.PublishEmptyFields) { f.Values.Add(""); } else if (sField.Values.Count == 0 && !manager.BuildProperties.PublishEmptyFields) { throw new FieldHasNoValueException(); } else { foreach (string v in sField.Values) { f.Values.Add(manager.PublishBinariesInRichTextField(v)); } } f.FieldType = FieldType.Xhtml; return f; } if (tcmItemField is TCM.Fields.MultiLineTextField) { TCM.Fields.TextField sField = (TCM.Fields.MultiLineTextField)tcmItemField; if (sField.Values.Count == 0 && manager.BuildProperties.PublishEmptyFields) { f.Values.Add(""); } else if (sField.Values.Count == 0 && !manager.BuildProperties.PublishEmptyFields) { throw new FieldHasNoValueException(); } else { foreach (string v in sField.Values) { f.Values.Add(v); } } f.FieldType = FieldType.MultiLineText; return f; } if (tcmItemField is TCM.Fields.TextField) { TCM.Fields.TextField sField = (TCM.Fields.TextField)tcmItemField; if (sField.Values.Count == 0 && manager.BuildProperties.PublishEmptyFields) { f.Values.Add(""); } else if (sField.Values.Count == 0 && !manager.BuildProperties.PublishEmptyFields) { throw new FieldHasNoValueException(); } else { foreach (string v in sField.Values) { f.Values.Add(v); } } f.FieldType = FieldType.Text; return f; } if (tcmItemField is TCM.Fields.KeywordField) { TCM.Fields.KeywordField sField = (TCM.Fields.KeywordField)tcmItemField; if (sField.Values.Count == 0 && manager.BuildProperties.PublishEmptyFields) { f.Values.Add(""); } else if (sField.Values.Count == 0 && !manager.BuildProperties.PublishEmptyFields) { throw new FieldHasNoValueException(); } else { // add keyword values f.Keywords = new List<Keyword>(); // we will wrap each linked component in a ContentModel component foreach (TCM.Keyword kw in sField.Values) { f.Keywords.Add(manager.BuildKeyword(kw)); } if (!manager.BuildProperties.OmitValueLists) { f.Values = new List<string>(); foreach (TCM.Keyword kw in sField.Values) { f.Values.Add(kw.Title); } } KeywordFieldDefinition fieldDef = (KeywordFieldDefinition)sField.Definition; f.CategoryId = fieldDef.Category.Id; f.CategoryName = fieldDef.Category.Title; } f.FieldType = FieldType.Keyword; return f; } if (tcmItemField is TCM.Fields.NumberField) { TCM.Fields.NumberField sField = (TCM.Fields.NumberField)tcmItemField; if (sField.Values.Count == 0 && manager.BuildProperties.PublishEmptyFields) { f.Values.Add(""); } else if (sField.Values.Count == 0 && !manager.BuildProperties.PublishEmptyFields) { throw new FieldHasNoValueException(); } else { f.NumericValues = (List<double>)sField.Values; if (!manager.BuildProperties.OmitValueLists) { f.Values = new List<string>(); foreach (double d in f.NumericValues) { f.Values.Add(Convert.ToString(d)); } } } f.FieldType = FieldType.Number; return f; } if (tcmItemField is TCM.Fields.DateField) { TCM.Fields.DateField sField = (TCM.Fields.DateField)tcmItemField; if (sField.Values.Count == 0 && manager.BuildProperties.PublishEmptyFields) { f.Values.Add(""); } else if (sField.Values.Count == 0 && !manager.BuildProperties.PublishEmptyFields) { throw new FieldHasNoValueException(); } else { f.DateTimeValues = (List<DateTime>)sField.Values; if (!manager.BuildProperties.OmitValueLists) { f.Values = new List<string>(); foreach (DateTime dt in f.DateTimeValues) { f.Values.Add(Convert.ToString(dt)); } } } f.FieldType = FieldType.Date; return f; } if (tcmItemField is TCM.Fields.MultimediaLinkField) { TCM.Fields.MultimediaLinkField sField = (TCM.Fields.MultimediaLinkField)tcmItemField; if (sField.Values.Count == 0 && manager.BuildProperties.PublishEmptyFields) { f.Values.Add(tcmItemField.Name); } else if (sField.Values.Count == 0 && !manager.BuildProperties.PublishEmptyFields) { throw new FieldHasNoValueException(); } else { // we will wrap each linked component in a ContentModel component f.LinkedComponentValues = new List<Dynamic.Component>(); int nextLinkLevel = currentLinkLevel - 1; if (MustFollowField(sField, manager)) { log.Debug(string.Format("found component link field named {0} with global followLinksPerField property set to false OR followLink set to true for this field", sField.Name)); } else { log.Debug(string.Format("found component link field named {0} with followLink set to false for this field", sField.Name)); nextLinkLevel = 0; } foreach (TCM.Component comp in sField.Values) { f.LinkedComponentValues.Add(manager.BuildComponent(comp, nextLinkLevel)); } if (!manager.BuildProperties.OmitValueLists) { f.Values = new List<string>(); foreach (Dynamic.Component c in f.LinkedComponentValues) { f.Values.Add(c.Id); } } } f.FieldType = FieldType.MultiMediaLink; return f; } if (tcmItemField is TCM.Fields.ComponentLinkField) { TCM.Fields.ComponentLinkField sField = (TCM.Fields.ComponentLinkField)tcmItemField; if (sField.Values.Count == 0 && manager.BuildProperties.PublishEmptyFields) { f.Values.Add(tcmItemField.Name); } else if (sField.Values.Count == 0 && !manager.BuildProperties.PublishEmptyFields) { throw new FieldHasNoValueException(); } else { // we will wrap each linked component in a ContentModel component f.LinkedComponentValues = new List<Dynamic.Component>(); int nextLinkLevel = currentLinkLevel - 1; if (MustFollowField(sField, manager)) { log.Debug(string.Format("found component link field named {0} with global followLinksPerField property set to false OR followLink set to true for this field", sField.Name)); } else { log.Debug(string.Format("found component link field named {0} with followLink set to false for this field", sField.Name)); nextLinkLevel = 0; } foreach (TCM.Component comp in sField.Values) { f.LinkedComponentValues.Add(manager.BuildComponent(comp, nextLinkLevel)); } if (!manager.BuildProperties.OmitValueLists) { f.Values = new List<string>(); foreach (Dynamic.Component c in f.LinkedComponentValues) { f.Values.Add(c.Id); } } } f.FieldType = FieldType.ComponentLink; return f; } if (tcmItemField is TCM.Fields.EmbeddedSchemaField) { TCM.Fields.EmbeddedSchemaField sField = (TCM.Fields.EmbeddedSchemaField)tcmItemField; f.FieldType = FieldType.Embedded; f.EmbeddedValues = new List<Dynamic.FieldSet>(); bool hasValues = CheckIfEmbeddedFieldHasValues(sField); if (!hasValues && manager.BuildProperties.PublishEmptyFields) { Dynamic.FieldSet fields = new FieldSet(); Dynamic.Field fe = new Dynamic.Field(); f.EmbeddedSchema = manager.BuildSchema(((EmbeddedSchemaFieldDefinition)sField.Definition).EmbeddedSchema); EmbeddedSchemaFieldDefinition linksFieldDefinition = sField.Definition as EmbeddedSchemaFieldDefinition; ItemFields newItemField = new ItemFields(linksFieldDefinition.EmbeddedSchema); for (int i = 0; i < newItemField.Count; i++) { if (newItemField[i] is TCM.Fields.EmbeddedSchemaField) { TCM.Fields.EmbeddedSchemaField innerField = (TCM.Fields.EmbeddedSchemaField)newItemField[i]; if (innerField.Values.Count == 0) { Dynamic.FieldSet fieldsinner = new FieldSet(); Dynamic.Field fin = new Dynamic.Field(); fe.EmbeddedSchema = manager.BuildSchema(((EmbeddedSchemaFieldDefinition)innerField.Definition).EmbeddedSchema); EmbeddedSchemaFieldDefinition inlinksFieldDefinition = innerField.Definition as EmbeddedSchemaFieldDefinition; ItemFields newinItemField = new ItemFields(inlinksFieldDefinition.EmbeddedSchema); for (int n = 0; n < newinItemField.Count; n++) { fin.Name = newItemField[n].Name; fieldsinner.Add(newinItemField[n].Name, fin); } fe.EmbeddedValues.Add(fieldsinner); fe.Values.Add(""); } fe.Name = newItemField[i].Name; fields.Add(newItemField[i].Name, fe); } else { Dynamic.Field fein = manager.BuildField(newItemField[i], currentLinkLevel); fein.Values.Clear(); fields.Add(newItemField[i].Name, fein); } } f.EmbeddedValues.Add(fields); f.Values.Add(""); } else if (!hasValues && !manager.BuildProperties.PublishEmptyFields) { throw new FieldHasNoValueException(); } else { // we will wrap each linked component in a ContentModel component f.EmbeddedValues = new List<Dynamic.FieldSet>(); f.EmbeddedSchema = manager.BuildSchema(((EmbeddedSchemaFieldDefinition)sField.Definition).EmbeddedSchema); foreach (TCM.Fields.ItemFields embeddedFields in sField.Values) { f.EmbeddedValues.Add(manager.BuildFields(embeddedFields, currentLinkLevel)); } } return f; } throw new FieldTypeNotDefinedException(); }
public static Dynamic.Field BuildField(TCM.Fields.ItemField tcmItemField, int linkLevels, bool resolveWidthAndHeight, bool publishEmptyFields, BuildManager manager) { Dynamic.Field f = new Dynamic.Field(); if (tcmItemField == null && publishEmptyFields) { GeneralUtils.TimedLog("item field is null"); //throw new FieldHasNoValueException(); f.Values.Add(""); return(f); } else if (tcmItemField == null && !publishEmptyFields) { throw new FieldHasNoValueException(); } f.Name = tcmItemField.Name; if (tcmItemField is TCM.Fields.XhtmlField) { TCM.Fields.XhtmlField sField = (TCM.Fields.XhtmlField)tcmItemField; GeneralUtils.TimedLog(string.Format("item field {0} has {1} values", tcmItemField.Name, sField.Values.Count)); if (sField.Values.Count == 0 && publishEmptyFields) { //throw new FieldHasNoValueException(); f.Values.Add(""); } else if (sField.Values.Count == 0 && !publishEmptyFields) { throw new FieldHasNoValueException(); } else { foreach (string v in sField.Values) { f.Values.Add(v); } } f.FieldType = FieldType.Xhtml; return(f); } if (tcmItemField is TCM.Fields.MultiLineTextField) { TCM.Fields.TextField sField = (TCM.Fields.MultiLineTextField)tcmItemField; GeneralUtils.TimedLog(string.Format("item field {0} has {1} values", tcmItemField.Name, sField.Values.Count)); //if (sField.Values.Count == 0) // throw new FieldHasNoValueException(); if (sField.Values.Count == 0 && publishEmptyFields) { //throw new FieldHasNoValueException(); f.Values.Add(""); } else if (sField.Values.Count == 0 && !publishEmptyFields) { throw new FieldHasNoValueException(); } else { foreach (string v in sField.Values) { f.Values.Add(v); } } f.FieldType = FieldType.MultiLineText; return(f); } if (tcmItemField is TCM.Fields.TextField) { TCM.Fields.TextField sField = (TCM.Fields.TextField)tcmItemField; GeneralUtils.TimedLog(string.Format("item field {0} has {1} values", tcmItemField.Name, sField.Values.Count)); //if (sField.Values.Count == 0) // throw new FieldHasNoValueException(); if (sField.Values.Count == 0 && publishEmptyFields) { //throw new FieldHasNoValueException(); f.Values.Add(""); } else if (sField.Values.Count == 0 && !publishEmptyFields) { throw new FieldHasNoValueException(); } else { foreach (string v in sField.Values) { f.Values.Add(v); } } f.FieldType = FieldType.Text; return(f); } if (tcmItemField is TCM.Fields.KeywordField) { TCM.Fields.KeywordField sField = (TCM.Fields.KeywordField)tcmItemField; GeneralUtils.TimedLog(string.Format("item field {0} has {1} values", tcmItemField.Name, sField.Values.Count)); //if (sField.Values.Count == 0) // throw new FieldHasNoValueException(); if (sField.Values.Count == 0 && publishEmptyFields) { //throw new FieldHasNoValueException(); f.Values.Add(""); } else if (sField.Values.Count == 0 && !publishEmptyFields) { throw new FieldHasNoValueException(); } else { // add keyword values f.Keywords = new List <Keyword>(); // we will wrap each linked component in a ContentModel component f.Values = new List <string>(); foreach (TCM.Keyword kw in sField.Values) { // todo: add binary to package, and add BinaryUrl property to the component f.Values.Add(kw.Title); f.Keywords.Add(manager.BuildKeyword(kw)); } KeywordFieldDefinition fieldDef = (KeywordFieldDefinition)sField.Definition; f.CategoryId = fieldDef.Category.Id; f.CategoryName = fieldDef.Category.Title; } f.FieldType = FieldType.Keyword; return(f); } if (tcmItemField is TCM.Fields.NumberField) { TCM.Fields.NumberField sField = (TCM.Fields.NumberField)tcmItemField; GeneralUtils.TimedLog(string.Format("item field {0} has {1} values", tcmItemField.Name, sField.Values.Count)); //if (sField.Values.Count == 0) // throw new FieldHasNoValueException(); if (sField.Values.Count == 0 && publishEmptyFields) { //throw new FieldHasNoValueException(); f.Values.Add(""); } else if (sField.Values.Count == 0 && !publishEmptyFields) { throw new FieldHasNoValueException(); } else { f.NumericValues = (List <double>)sField.Values; f.Values = new List <string>(); foreach (double d in f.NumericValues) { f.Values.Add(Convert.ToString(d)); } } f.FieldType = FieldType.Number; return(f); } if (tcmItemField is TCM.Fields.DateField) { TCM.Fields.DateField sField = (TCM.Fields.DateField)tcmItemField; GeneralUtils.TimedLog(string.Format("item field {0} has {1} values", tcmItemField.Name, sField.Values.Count)); //if (sField.Values.Count == 0) // throw new FieldHasNoValueException(); if (sField.Values.Count == 0 && publishEmptyFields) { //throw new FieldHasNoValueException(); f.Values.Add(""); } else if (sField.Values.Count == 0 && !publishEmptyFields) { throw new FieldHasNoValueException(); } else { f.DateTimeValues = (List <DateTime>)sField.Values; f.Values = new List <string>(); foreach (DateTime dt in f.DateTimeValues) { f.Values.Add(Convert.ToString(dt)); } } f.FieldType = FieldType.Date; return(f); } if (tcmItemField is TCM.Fields.MultimediaLinkField) { TCM.Fields.MultimediaLinkField sField = (TCM.Fields.MultimediaLinkField)tcmItemField; GeneralUtils.TimedLog(string.Format("item field {0} has {1} values", tcmItemField.Name, sField.Values.Count)); if (sField.Values.Count == 0 && publishEmptyFields) { f.Values.Add(tcmItemField.Name); } else if (sField.Values.Count == 0 && !publishEmptyFields) { throw new FieldHasNoValueException(); } else { // we will wrap each linked component in a ContentModel component f.LinkedComponentValues = new List <Dynamic.Component>(); foreach (TCM.Component comp in sField.Values) { // todo: add binary to package, and add BinaryUrl property to the component f.LinkedComponentValues.Add(manager.BuildComponent(comp, linkLevels - 1, resolveWidthAndHeight, publishEmptyFields)); } f.Values = new List <string>(); foreach (Dynamic.Component c in f.LinkedComponentValues) { f.Values.Add(c.Id); } } f.FieldType = FieldType.MultiMediaLink; return(f); } if (tcmItemField is TCM.Fields.ComponentLinkField) { TCM.Fields.ComponentLinkField sField = (TCM.Fields.ComponentLinkField)tcmItemField; GeneralUtils.TimedLog(string.Format("item field {0} has {1} values", tcmItemField.Name, sField.Values.Count)); //if (sField.Values.Count == 0) // throw new FieldHasNoValueException(); if (sField.Values.Count == 0 && publishEmptyFields) { f.Values.Add(tcmItemField.Name); } else if (sField.Values.Count == 0 && !publishEmptyFields) { throw new FieldHasNoValueException(); } else { // we will wrap each linked component in a ContentModel component f.LinkedComponentValues = new List <Dynamic.Component>(); foreach (TCM.Component comp in sField.Values) { f.LinkedComponentValues.Add(manager.BuildComponent(comp, linkLevels - 1, resolveWidthAndHeight, publishEmptyFields)); } f.Values = new List <string>(); foreach (Dynamic.Component c in f.LinkedComponentValues) { f.Values.Add(c.Id); } } f.FieldType = FieldType.ComponentLink; return(f); } if (tcmItemField is TCM.Fields.EmbeddedSchemaField) { TCM.Fields.EmbeddedSchemaField sField = (TCM.Fields.EmbeddedSchemaField)tcmItemField; GeneralUtils.TimedLog(string.Format("item field {0} has {1} values", tcmItemField.Name, sField.Values.Count)); //if (sField.Values.Count == 0) //throw new FieldHasNoValueException(); f.FieldType = FieldType.Embedded; f.EmbeddedValues = new List <Dynamic.FieldSet>(); if (sField.Values.Count == 0 && publishEmptyFields) { Dynamic.FieldSet fields = new FieldSet(); Dynamic.Field fe = new Dynamic.Field(); f.EmbeddedSchema = manager.BuildSchema(((EmbeddedSchemaFieldDefinition)sField.Definition).EmbeddedSchema); EmbeddedSchemaFieldDefinition linksFieldDefinition = sField.Definition as EmbeddedSchemaFieldDefinition; ItemFields newItemField = new ItemFields(linksFieldDefinition.EmbeddedSchema); for (int i = 0; i < newItemField.Count; i++) { if (newItemField[i] is TCM.Fields.EmbeddedSchemaField) { TCM.Fields.EmbeddedSchemaField innerField = (TCM.Fields.EmbeddedSchemaField)newItemField[i]; if (innerField.Values.Count == 0) { Dynamic.FieldSet fieldsinner = new FieldSet(); Dynamic.Field fin = new Dynamic.Field(); fe.EmbeddedSchema = manager.BuildSchema(((EmbeddedSchemaFieldDefinition)innerField.Definition).EmbeddedSchema); EmbeddedSchemaFieldDefinition inlinksFieldDefinition = innerField.Definition as EmbeddedSchemaFieldDefinition; ItemFields newinItemField = new ItemFields(inlinksFieldDefinition.EmbeddedSchema); for (int n = 0; n < newinItemField.Count; n++) { fin.Name = newItemField[n].Name; fieldsinner.Add(newinItemField[n].Name, fin); } fe.EmbeddedValues.Add(fieldsinner); fe.Values.Add(""); } fe.Name = newItemField[i].Name; fields.Add(newItemField[i].Name, fe); } else { Dynamic.Field fein = manager.BuildField(newItemField[i], linkLevels, resolveWidthAndHeight, publishEmptyFields); fein.Values.Clear(); fields.Add(newItemField[i].Name, fein); } } f.EmbeddedValues.Add(fields); f.Values.Add(""); } else if (sField.Values.Count == 0 && !publishEmptyFields) { throw new FieldHasNoValueException(); } else { // we will wrap each linked component in a ContentModel component f.EmbeddedValues = new List <Dynamic.FieldSet>(); f.EmbeddedSchema = manager.BuildSchema(((EmbeddedSchemaFieldDefinition)sField.Definition).EmbeddedSchema); foreach (TCM.Fields.ItemFields embeddedFields in sField.Values) { f.EmbeddedValues.Add(manager.BuildFields(embeddedFields, linkLevels, resolveWidthAndHeight, publishEmptyFields)); } } return(f); } throw new FieldTypeNotDefinedException(); }
public static Dynamic.Field BuildField(TCM.Fields.ItemField tcmItemField, int currentLinkLevel, BuildManager manager) { Dynamic.Field f = new Dynamic.Field(); if (tcmItemField == null && manager.BuildProperties.PublishEmptyFields) { f.Values.Add(""); return(f); } else if (tcmItemField == null && !manager.BuildProperties.PublishEmptyFields) { throw new FieldHasNoValueException(); } f.Name = tcmItemField.Name; if (tcmItemField is TCM.Fields.XhtmlField) { TCM.Fields.XhtmlField sField = (TCM.Fields.XhtmlField)tcmItemField; if (sField.Values.Count == 0 && manager.BuildProperties.PublishEmptyFields) { f.Values.Add(""); } else if (sField.Values.Count == 0 && !manager.BuildProperties.PublishEmptyFields) { throw new FieldHasNoValueException(); } else { foreach (string v in sField.Values) { f.Values.Add(manager.PublishBinariesInRichTextField(v)); } } f.FieldType = FieldType.Xhtml; return(f); } if (tcmItemField is TCM.Fields.MultiLineTextField) { TCM.Fields.TextField sField = (TCM.Fields.MultiLineTextField)tcmItemField; if (sField.Values.Count == 0 && manager.BuildProperties.PublishEmptyFields) { f.Values.Add(""); } else if (sField.Values.Count == 0 && !manager.BuildProperties.PublishEmptyFields) { throw new FieldHasNoValueException(); } else { foreach (string v in sField.Values) { f.Values.Add(v); } } f.FieldType = FieldType.MultiLineText; return(f); } if (tcmItemField is TCM.Fields.TextField) { TCM.Fields.TextField sField = (TCM.Fields.TextField)tcmItemField; if (sField.Values.Count == 0 && manager.BuildProperties.PublishEmptyFields) { f.Values.Add(""); } else if (sField.Values.Count == 0 && !manager.BuildProperties.PublishEmptyFields) { throw new FieldHasNoValueException(); } else { foreach (string v in sField.Values) { f.Values.Add(v); } } f.FieldType = FieldType.Text; return(f); } if (tcmItemField is TCM.Fields.KeywordField) { TCM.Fields.KeywordField sField = (TCM.Fields.KeywordField)tcmItemField; if (sField.Values.Count == 0 && manager.BuildProperties.PublishEmptyFields) { f.Values.Add(""); } else if (sField.Values.Count == 0 && !manager.BuildProperties.PublishEmptyFields) { throw new FieldHasNoValueException(); } else { // add keyword values f.Keywords = new List <Keyword>(); // we will wrap each linked component in a ContentModel component foreach (TCM.Keyword kw in sField.Values) { f.Keywords.Add(manager.BuildKeyword(kw)); } if (!manager.BuildProperties.OmitValueLists) { f.Values = new List <string>(); foreach (TCM.Keyword kw in sField.Values) { f.Values.Add(kw.Title); } } KeywordFieldDefinition fieldDef = (KeywordFieldDefinition)sField.Definition; f.CategoryId = fieldDef.Category.Id; f.CategoryName = fieldDef.Category.Title; } f.FieldType = FieldType.Keyword; return(f); } if (tcmItemField is TCM.Fields.NumberField) { TCM.Fields.NumberField sField = (TCM.Fields.NumberField)tcmItemField; if (sField.Values.Count == 0 && manager.BuildProperties.PublishEmptyFields) { f.Values.Add(""); } else if (sField.Values.Count == 0 && !manager.BuildProperties.PublishEmptyFields) { throw new FieldHasNoValueException(); } else { f.NumericValues = (List <double>)sField.Values; if (!manager.BuildProperties.OmitValueLists) { f.Values = new List <string>(); foreach (double d in f.NumericValues) { f.Values.Add(Convert.ToString(d)); } } } f.FieldType = FieldType.Number; return(f); } if (tcmItemField is TCM.Fields.DateField) { TCM.Fields.DateField sField = (TCM.Fields.DateField)tcmItemField; if (sField.Values.Count == 0 && manager.BuildProperties.PublishEmptyFields) { f.Values.Add(""); } else if (sField.Values.Count == 0 && !manager.BuildProperties.PublishEmptyFields) { throw new FieldHasNoValueException(); } else { f.DateTimeValues = (List <DateTime>)sField.Values; if (!manager.BuildProperties.OmitValueLists) { f.Values = new List <string>(); foreach (DateTime dt in f.DateTimeValues) { f.Values.Add(Convert.ToString(dt)); } } } f.FieldType = FieldType.Date; return(f); } if (tcmItemField is TCM.Fields.MultimediaLinkField) { TCM.Fields.MultimediaLinkField sField = (TCM.Fields.MultimediaLinkField)tcmItemField; if (sField.Values.Count == 0 && manager.BuildProperties.PublishEmptyFields) { f.Values.Add(tcmItemField.Name); } else if (sField.Values.Count == 0 && !manager.BuildProperties.PublishEmptyFields) { throw new FieldHasNoValueException(); } else { // we will wrap each linked component in a ContentModel component f.LinkedComponentValues = new List <Dynamic.Component>(); int nextLinkLevel = currentLinkLevel - 1; if (MustFollowField(sField, manager)) { log.Debug(string.Format("found component link field named {0} with global followLinksPerField property set to false OR followLink set to true for this field", sField.Name)); } else { log.Debug(string.Format("found component link field named {0} with followLink set to false for this field", sField.Name)); nextLinkLevel = 0; } foreach (TCM.Component comp in sField.Values) { f.LinkedComponentValues.Add(manager.BuildComponent(comp, nextLinkLevel)); } if (!manager.BuildProperties.OmitValueLists) { f.Values = new List <string>(); foreach (Dynamic.Component c in f.LinkedComponentValues) { f.Values.Add(c.Id); } } } f.FieldType = FieldType.MultiMediaLink; return(f); } if (tcmItemField is TCM.Fields.ComponentLinkField) { TCM.Fields.ComponentLinkField sField = (TCM.Fields.ComponentLinkField)tcmItemField; if (sField.Values.Count == 0 && manager.BuildProperties.PublishEmptyFields) { f.Values.Add(tcmItemField.Name); } else if (sField.Values.Count == 0 && !manager.BuildProperties.PublishEmptyFields) { throw new FieldHasNoValueException(); } else { // we will wrap each linked component in a ContentModel component f.LinkedComponentValues = new List <Dynamic.Component>(); int nextLinkLevel = currentLinkLevel - 1; if (MustFollowField(sField, manager)) { log.Debug(string.Format("found component link field named {0} with global followLinksPerField property set to false OR followLink set to true for this field", sField.Name)); } else { log.Debug(string.Format("found component link field named {0} with followLink set to false for this field", sField.Name)); nextLinkLevel = 0; } foreach (TCM.Component comp in sField.Values) { f.LinkedComponentValues.Add(manager.BuildComponent(comp, nextLinkLevel)); } if (!manager.BuildProperties.OmitValueLists) { f.Values = new List <string>(); foreach (Dynamic.Component c in f.LinkedComponentValues) { f.Values.Add(c.Id); } } } f.FieldType = FieldType.ComponentLink; return(f); } if (tcmItemField is TCM.Fields.EmbeddedSchemaField) { TCM.Fields.EmbeddedSchemaField sField = (TCM.Fields.EmbeddedSchemaField)tcmItemField; f.FieldType = FieldType.Embedded; f.EmbeddedValues = new List <Dynamic.FieldSet>(); bool hasValues = CheckIfEmbeddedFieldHasValues(sField); if (!hasValues && manager.BuildProperties.PublishEmptyFields) { Dynamic.FieldSet fields = new FieldSet(); Dynamic.Field fe = new Dynamic.Field(); f.EmbeddedSchema = manager.BuildSchema(((EmbeddedSchemaFieldDefinition)sField.Definition).EmbeddedSchema); EmbeddedSchemaFieldDefinition linksFieldDefinition = sField.Definition as EmbeddedSchemaFieldDefinition; ItemFields newItemField = new ItemFields(linksFieldDefinition.EmbeddedSchema); for (int i = 0; i < newItemField.Count; i++) { if (newItemField[i] is TCM.Fields.EmbeddedSchemaField) { TCM.Fields.EmbeddedSchemaField innerField = (TCM.Fields.EmbeddedSchemaField)newItemField[i]; if (innerField.Values.Count == 0) { Dynamic.FieldSet fieldsinner = new FieldSet(); Dynamic.Field fin = new Dynamic.Field(); fe.EmbeddedSchema = manager.BuildSchema(((EmbeddedSchemaFieldDefinition)innerField.Definition).EmbeddedSchema); EmbeddedSchemaFieldDefinition inlinksFieldDefinition = innerField.Definition as EmbeddedSchemaFieldDefinition; ItemFields newinItemField = new ItemFields(inlinksFieldDefinition.EmbeddedSchema); for (int n = 0; n < newinItemField.Count; n++) { fin.Name = newItemField[n].Name; fieldsinner.Add(newinItemField[n].Name, fin); } fe.EmbeddedValues.Add(fieldsinner); fe.Values.Add(""); } fe.Name = newItemField[i].Name; fields.Add(newItemField[i].Name, fe); } else { Dynamic.Field fein = manager.BuildField(newItemField[i], currentLinkLevel); fein.Values.Clear(); fields.Add(newItemField[i].Name, fein); } } f.EmbeddedValues.Add(fields); f.Values.Add(""); } else if (!hasValues && !manager.BuildProperties.PublishEmptyFields) { throw new FieldHasNoValueException(); } else { // we will wrap each linked component in a ContentModel component f.EmbeddedValues = new List <Dynamic.FieldSet>(); f.EmbeddedSchema = manager.BuildSchema(((EmbeddedSchemaFieldDefinition)sField.Definition).EmbeddedSchema); foreach (TCM.Fields.ItemFields embeddedFields in sField.Values) { f.EmbeddedValues.Add(manager.BuildFields(embeddedFields, currentLinkLevel)); } } return(f); } throw new FieldTypeNotDefinedException(); }
public static Dynamic.Component BuildComponent(TCM.Component tcmComponent, int currentLinkLevel, BuildManager manager) { log.Debug(string.Format("start BuildComponent with component {0} ({1}) and link level {2}", tcmComponent.Title, tcmComponent.Id, currentLinkLevel)); Dynamic.Component c = new Dynamic.Component(); c.Title = tcmComponent.Title; c.Id = tcmComponent.Id.ToString(); c.RevisionDate = tcmComponent.RevisionDate; c.Version = tcmComponent.Version; c.Schema = manager.BuildSchema(tcmComponent.Schema); c.ComponentType = (ComponentType)Enum.Parse(typeof(ComponentType), tcmComponent.ComponentType.ToString()); if (tcmComponent.ComponentType.Equals(TCM.ComponentType.Multimedia)) { Multimedia multimedia = new Multimedia(); multimedia.MimeType = tcmComponent.BinaryContent.MultimediaType.MimeType; // PLEASE NOTE: this weird way to set the size of the multimedia is needed because of a difference between Tridion 2011 and 2013 // The property in Tridion's BinaryContent class changed its name AND its type (int FileSize became long Size) // This way, we can use preprocessing to choose the right property // Thijs Borst and Quirijn Slings, 9 April 2015 #if Legacy PropertyInfo prop = tcmComponent.BinaryContent.GetType().GetProperty("FileSize", BindingFlags.Public | BindingFlags.Instance); multimedia.Size = Convert.ToInt64(prop.GetValue(tcmComponent.BinaryContent,null)); #else PropertyInfo prop = tcmComponent.BinaryContent.GetType().GetProperty("Size", BindingFlags.Public | BindingFlags.Instance); multimedia.Size = (long) prop.GetValue(tcmComponent.BinaryContent,null); #endif multimedia.FileName = tcmComponent.BinaryContent.Filename; string extension = System.IO.Path.GetExtension(multimedia.FileName); if (string.IsNullOrEmpty(extension)) { multimedia.FileExtension = ""; } else { // remove leading dot from extension because microsoft returns this as ".gif" multimedia.FileExtension = extension.Substring(1); } if (manager.BuildProperties.ResolveWidthAndHeight) { try { MemoryStream memstream = new MemoryStream(); tcmComponent.BinaryContent.WriteToStream(memstream); Image image = Image.FromStream(memstream); memstream.Close(); multimedia.Width = image.Size.Width; multimedia.Height = image.Size.Height; } catch (Exception e) { log.Warning(string.Format("error retrieving width and height of image: is component with ID {0} really an image? Error message: {1}", c.Id, e.Message)); multimedia.Width = 0; multimedia.Height = 0; } } else { multimedia.Width = 0; multimedia.Height = 0; } c.Multimedia = multimedia; c.Multimedia.Url = manager.PublishMultimediaComponent(c); } else { c.Multimedia = null; } c.Fields = new Dynamic.FieldSet(); c.MetadataFields = new Dynamic.FieldSet(); if (currentLinkLevel > 0) { if (tcmComponent.Content != null) { TCM.Fields.ItemFields tcmFields = new TCM.Fields.ItemFields(tcmComponent.Content, tcmComponent.Schema); c.Fields = manager.BuildFields(tcmFields, currentLinkLevel); } if (tcmComponent.Metadata != null) { TCM.Fields.ItemFields tcmMetadataFields = new TCM.Fields.ItemFields(tcmComponent.Metadata, tcmComponent.MetadataSchema); c.MetadataFields = manager.BuildFields(tcmMetadataFields, currentLinkLevel); } } if (!manager.BuildProperties.OmitContextPublications) { c.Publication = manager.BuildPublication(tcmComponent.ContextRepository); } if (!manager.BuildProperties.OmitOwningPublications) { c.OwningPublication = manager.BuildPublication(tcmComponent.OwningRepository); } if (!manager.BuildProperties.OmitFolders) { TCM.Folder folder = (TCM.Folder)tcmComponent.OrganizationalItem; c.Folder = manager.BuildOrganizationalItem(folder); } if (!manager.BuildProperties.OmitCategories) { c.Categories = manager.BuildCategories(tcmComponent); } manager.AddXpathToFields(c.Fields, "tcm:Content/custom:" + tcmComponent.Schema.RootElementName); manager.AddXpathToFields(c.MetadataFields, "tcm:Metadata/custom:Metadata"); return c; }
public static Dynamic.Component BuildComponent(TCM.Component tcmComponent, int currentLinkLevel, BuildManager manager) { log.Debug(string.Format("start BuildComponent with component {0} ({1}) and link level {2}", tcmComponent.Title, tcmComponent.Id, currentLinkLevel)); Dynamic.Component c = new Dynamic.Component(); c.Title = tcmComponent.Title; c.Id = tcmComponent.Id.ToString(); c.RevisionDate = tcmComponent.RevisionDate; c.Version = tcmComponent.Version; c.Schema = manager.BuildSchema(tcmComponent.Schema); c.ComponentType = (ComponentType)Enum.Parse(typeof(ComponentType), tcmComponent.ComponentType.ToString()); if (tcmComponent.ComponentType.Equals(TCM.ComponentType.Multimedia)) { Multimedia multimedia = new Multimedia(); multimedia.MimeType = tcmComponent.BinaryContent.MultimediaType.MimeType; multimedia.Size = tcmComponent.BinaryContent.Size; multimedia.FileName = tcmComponent.BinaryContent.Filename; string extension = System.IO.Path.GetExtension(multimedia.FileName); if (string.IsNullOrEmpty(extension)) { multimedia.FileExtension = ""; } else { // remove leading dot from extension because microsoft returns this as ".gif" multimedia.FileExtension = extension.Substring(1); } if (manager.BuildProperties.ResolveWidthAndHeight) { try { MemoryStream memstream = new MemoryStream(); tcmComponent.BinaryContent.WriteToStream(memstream); Image image = Image.FromStream(memstream); memstream.Close(); multimedia.Width = image.Size.Width; multimedia.Height = image.Size.Height; } catch (Exception e) { log.Warning(string.Format("error retrieving width and height of image: is component with ID {0} really an image? Error message: {1}", c.Id, e.Message)); multimedia.Width = 0; multimedia.Height = 0; } } else { multimedia.Width = 0; multimedia.Height = 0; } c.Multimedia = multimedia; c.Multimedia.Url = manager.PublishMultimediaComponent(c); } else { c.Multimedia = null; } c.Fields = new Dynamic.FieldSet(); c.MetadataFields = new Dynamic.FieldSet(); if (currentLinkLevel > 0) { if (tcmComponent.Content != null) { TCM.Fields.ItemFields tcmFields = new TCM.Fields.ItemFields(tcmComponent.Content, tcmComponent.Schema); c.Fields = manager.BuildFields(tcmFields, currentLinkLevel); } if (tcmComponent.Metadata != null) { TCM.Fields.ItemFields tcmMetadataFields = new TCM.Fields.ItemFields(tcmComponent.Metadata, tcmComponent.MetadataSchema); c.MetadataFields = manager.BuildFields(tcmMetadataFields, currentLinkLevel); } } if (!manager.BuildProperties.OmitContextPublications) { c.Publication = manager.BuildPublication(tcmComponent.ContextRepository); } if (!manager.BuildProperties.OmitOwningPublications) { c.OwningPublication = manager.BuildPublication(tcmComponent.OwningRepository); } if (!manager.BuildProperties.OmitFolders) { TCM.Folder folder = (TCM.Folder)tcmComponent.OrganizationalItem; c.Folder = manager.BuildOrganizationalItem(folder); } if (!manager.BuildProperties.OmitCategories) { c.Categories = manager.BuildCategories(tcmComponent); } manager.AddXpathToFields(c.Fields, "tcm:Content/custom:" + tcmComponent.Schema.RootElementName); manager.AddXpathToFields(c.MetadataFields, "tcm:Metadata/custom:Metadata"); return c; }
public static Dynamic.Component BuildComponent(TCM.Component tcmComponent, int linkLevels, bool resolveWidthAndHeight, bool publishEmptyFields, BuildManager manager) { GeneralUtils.TimedLog("start BuildComponent"); Dynamic.Component c = new Dynamic.Component(); c.Title = tcmComponent.Title; c.Id = tcmComponent.Id.ToString(); c.RevisionDate = tcmComponent.RevisionDate; GeneralUtils.TimedLog("component title = " + c.Title); c.Version = tcmComponent.Version; GeneralUtils.TimedLog("start building schema"); c.Schema = manager.BuildSchema(tcmComponent.Schema); GeneralUtils.TimedLog("finished building schema"); c.ComponentType = (ComponentType)Enum.Parse(typeof(ComponentType), tcmComponent.ComponentType.ToString()); if (tcmComponent.ComponentType.Equals(TCM.ComponentType.Multimedia)) { GeneralUtils.TimedLog("start building multimedia"); Multimedia multimedia = new Multimedia(); multimedia.MimeType = tcmComponent.BinaryContent.MultimediaType.MimeType; multimedia.Size = tcmComponent.BinaryContent.FileSize; multimedia.FileName = tcmComponent.BinaryContent.Filename; // remove leading dot from extension because microsoft returns this as ".gif" string extension = System.IO.Path.GetExtension(multimedia.FileName); if (string.IsNullOrEmpty(extension)) multimedia.FileExtension = ""; else multimedia.FileExtension = extension.Substring(1); if (resolveWidthAndHeight) { try { MemoryStream memstream = new MemoryStream(); tcmComponent.BinaryContent.WriteToStream(memstream); Image image = Image.FromStream(memstream); memstream.Close(); multimedia.Width = image.Size.Width; multimedia.Height = image.Size.Height; } catch (Exception e) { log.Warning("error retrieving width and height of image: " + e.Message); multimedia.Width = 0; multimedia.Height = 0; } } else { multimedia.Width = 0; multimedia.Height = 0; } c.Multimedia = multimedia; GeneralUtils.TimedLog("finished building multimedia"); } else { c.Multimedia = null; } c.Fields = new Dynamic.FieldSet(); c.MetadataFields = new Dynamic.FieldSet(); if (linkLevels > 0) { if (tcmComponent.Content != null) { GeneralUtils.TimedLog("start retrieving tcm fields"); TCM.Fields.ItemFields tcmFields = new TCM.Fields.ItemFields(tcmComponent.Content, tcmComponent.Schema); log.Debug("TCM fields" +tcmFields.ToXml()); GeneralUtils.TimedLog("finished retrieving tcm fields"); GeneralUtils.TimedLog("start building fields"); c.Fields = manager.BuildFields(tcmFields, linkLevels, resolveWidthAndHeight,publishEmptyFields); GeneralUtils.TimedLog("finished building fields"); } if (tcmComponent.Metadata != null) { GeneralUtils.TimedLog("start retrieving tcm metadata fields"); TCM.Fields.ItemFields tcmMetadataFields = new TCM.Fields.ItemFields(tcmComponent.Metadata, tcmComponent.MetadataSchema); GeneralUtils.TimedLog("finished retrieving tcm metadata fields"); GeneralUtils.TimedLog("start building metadata fields"); c.MetadataFields = manager.BuildFields(tcmMetadataFields, linkLevels, resolveWidthAndHeight,publishEmptyFields); GeneralUtils.TimedLog("finished building metadata fields"); } } c.Publication = manager.BuildPublication(tcmComponent.ContextRepository); c.OwningPublication = manager.BuildPublication(tcmComponent.OwningRepository); TCM.Folder folder = (TCM.Folder)tcmComponent.OrganizationalItem; c.Folder = manager.BuildOrganizationalItem(folder); c.Categories = manager.BuildCategories(tcmComponent); manager.AddXpathToFields(c.Fields, "tcm:Content/custom:" + tcmComponent.Schema.RootElementName); // TODO: check if the first part of the XPath is really the root element name, or simply always 'Content' manager.AddXpathToFields(c.MetadataFields, "tcm:Metadata/custom:Metadata"); return c; }
public static Dynamic.Component BuildComponent(TCM.Component tcmComponent, int currentLinkLevel, BuildManager manager) { log.Debug(string.Format("start BuildComponent with component {0} ({1}) and link level {2}", tcmComponent.Title, tcmComponent.Id, currentLinkLevel)); Dynamic.Component c = new Dynamic.Component(); c.Title = tcmComponent.Title; c.Id = tcmComponent.Id.ToString(); c.RevisionDate = tcmComponent.RevisionDate; c.Version = tcmComponent.Version; c.Schema = manager.BuildSchema(tcmComponent.Schema); c.ComponentType = (ComponentType)Enum.Parse(typeof(ComponentType), tcmComponent.ComponentType.ToString()); if (tcmComponent.ComponentType.Equals(TCM.ComponentType.Multimedia)) { Multimedia multimedia = new Multimedia(); multimedia.MimeType = tcmComponent.BinaryContent.MultimediaType.MimeType; // PLEASE NOTE: this weird way to set the size of the multimedia is needed because of a difference between Tridion 2011 and 2013 // The property in Tridion's BinaryContent class changed its name AND its type (int FileSize became long Size) // This way, we can use preprocessing to choose the right property // Thijs Borst and Quirijn Slings, 9 April 2015 #if Legacy PropertyInfo prop = tcmComponent.BinaryContent.GetType().GetProperty("FileSize", BindingFlags.Public | BindingFlags.Instance); multimedia.Size = Convert.ToInt64(prop.GetValue(tcmComponent.BinaryContent, null)); #else PropertyInfo prop = tcmComponent.BinaryContent.GetType().GetProperty("Size", BindingFlags.Public | BindingFlags.Instance); multimedia.Size = (long)prop.GetValue(tcmComponent.BinaryContent, null); #endif multimedia.FileName = tcmComponent.BinaryContent.Filename; string extension = System.IO.Path.GetExtension(multimedia.FileName); if (string.IsNullOrEmpty(extension)) { multimedia.FileExtension = ""; } else { // remove leading dot from extension because microsoft returns this as ".gif" multimedia.FileExtension = extension.Substring(1); } if (manager.BuildProperties.ResolveWidthAndHeight) { try { MemoryStream memstream = new MemoryStream(); tcmComponent.BinaryContent.WriteToStream(memstream); Image image = Image.FromStream(memstream); memstream.Close(); multimedia.Width = image.Size.Width; multimedia.Height = image.Size.Height; } catch (Exception e) { log.Warning(string.Format("error retrieving width and height of image: is component with ID {0} really an image? Error message: {1}", c.Id, e.Message)); multimedia.Width = 0; multimedia.Height = 0; } } else { multimedia.Width = 0; multimedia.Height = 0; } c.Multimedia = multimedia; manager.PublishMultimediaComponent(c); } else { c.Multimedia = null; } c.Fields = new Dynamic.FieldSet(); c.MetadataFields = new Dynamic.FieldSet(); if (currentLinkLevel > 0) { if (tcmComponent.Content != null) { TCM.Fields.ItemFields tcmFields = new TCM.Fields.ItemFields(tcmComponent.Content, tcmComponent.Schema); c.Fields = manager.BuildFields(tcmFields, currentLinkLevel); } if (tcmComponent.Metadata != null) { TCM.Fields.ItemFields tcmMetadataFields = new TCM.Fields.ItemFields(tcmComponent.Metadata, tcmComponent.MetadataSchema); c.MetadataFields = manager.BuildFields(tcmMetadataFields, currentLinkLevel); } } if (!manager.BuildProperties.OmitContextPublications) { c.Publication = manager.BuildPublication(tcmComponent.ContextRepository); } if (!manager.BuildProperties.OmitOwningPublications) { c.OwningPublication = manager.BuildPublication(tcmComponent.OwningRepository); } if (!manager.BuildProperties.OmitFolders) { TCM.Folder folder = (TCM.Folder)tcmComponent.OrganizationalItem; c.Folder = manager.BuildOrganizationalItem(folder); } if (!manager.BuildProperties.OmitCategories) { c.Categories = manager.BuildCategories(tcmComponent); } manager.AddXpathToFields(c.Fields, "tcm:Content/custom:" + tcmComponent.Schema.RootElementName); manager.AddXpathToFields(c.MetadataFields, "tcm:Metadata/custom:Metadata"); return(c); }
public static Dynamic.Field BuildField(TCM.Fields.ItemField tcmItemField, int linkLevels, bool resolveWidthAndHeight, bool publishEmptyFields, BuildManager manager) { Dynamic.Field f = new Dynamic.Field(); if (tcmItemField == null&&publishEmptyFields) { GeneralUtils.TimedLog("item field is null"); //throw new FieldHasNoValueException(); f.Values.Add(""); return f; } else if (tcmItemField == null && !publishEmptyFields) { throw new FieldHasNoValueException(); } f.Name = tcmItemField.Name; if (tcmItemField is TCM.Fields.XhtmlField) { TCM.Fields.XhtmlField sField = (TCM.Fields.XhtmlField)tcmItemField; GeneralUtils.TimedLog(string.Format("item field {0} has {1} values", tcmItemField.Name, sField.Values.Count)); if (sField.Values.Count == 0 && publishEmptyFields) { //throw new FieldHasNoValueException(); f.Values.Add(""); } else if (sField.Values.Count == 0 && !publishEmptyFields) { throw new FieldHasNoValueException(); } else { foreach (string v in sField.Values) { f.Values.Add(v); } } f.FieldType = FieldType.Xhtml; return f; } if (tcmItemField is TCM.Fields.MultiLineTextField) { TCM.Fields.TextField sField = (TCM.Fields.MultiLineTextField)tcmItemField; GeneralUtils.TimedLog(string.Format("item field {0} has {1} values", tcmItemField.Name, sField.Values.Count)); //if (sField.Values.Count == 0) // throw new FieldHasNoValueException(); if (sField.Values.Count == 0 && publishEmptyFields) { //throw new FieldHasNoValueException(); f.Values.Add(""); } else if (sField.Values.Count == 0 && !publishEmptyFields) { throw new FieldHasNoValueException(); } else { foreach (string v in sField.Values) { f.Values.Add(v); } } f.FieldType = FieldType.MultiLineText; return f; } if (tcmItemField is TCM.Fields.TextField) { TCM.Fields.TextField sField = (TCM.Fields.TextField)tcmItemField; GeneralUtils.TimedLog(string.Format("item field {0} has {1} values", tcmItemField.Name, sField.Values.Count)); //if (sField.Values.Count == 0) // throw new FieldHasNoValueException(); if (sField.Values.Count == 0 && publishEmptyFields) { //throw new FieldHasNoValueException(); f.Values.Add(""); } else if (sField.Values.Count == 0 && !publishEmptyFields) { throw new FieldHasNoValueException(); } else { foreach (string v in sField.Values) { f.Values.Add(v); } } f.FieldType = FieldType.Text; return f; } if (tcmItemField is TCM.Fields.KeywordField) { TCM.Fields.KeywordField sField = (TCM.Fields.KeywordField)tcmItemField; GeneralUtils.TimedLog(string.Format("item field {0} has {1} values", tcmItemField.Name, sField.Values.Count)); //if (sField.Values.Count == 0) // throw new FieldHasNoValueException(); if (sField.Values.Count == 0 && publishEmptyFields) { //throw new FieldHasNoValueException(); f.Values.Add(""); } else if (sField.Values.Count == 0 && !publishEmptyFields) { throw new FieldHasNoValueException(); } else { // add keyword values f.Keywords = new List<Keyword>(); // we will wrap each linked component in a ContentModel component f.Values = new List<string>(); foreach (TCM.Keyword kw in sField.Values) { // todo: add binary to package, and add BinaryUrl property to the component f.Values.Add(kw.Title); f.Keywords.Add(manager.BuildKeyword(kw)); } KeywordFieldDefinition fieldDef = (KeywordFieldDefinition)sField.Definition; f.CategoryId = fieldDef.Category.Id; f.CategoryName = fieldDef.Category.Title; } f.FieldType = FieldType.Keyword; return f; } if (tcmItemField is TCM.Fields.NumberField) { TCM.Fields.NumberField sField = (TCM.Fields.NumberField)tcmItemField; GeneralUtils.TimedLog(string.Format("item field {0} has {1} values", tcmItemField.Name, sField.Values.Count)); //if (sField.Values.Count == 0) // throw new FieldHasNoValueException(); if (sField.Values.Count == 0 && publishEmptyFields) { //throw new FieldHasNoValueException(); f.Values.Add(""); } else if (sField.Values.Count == 0 && !publishEmptyFields) { throw new FieldHasNoValueException(); } else { f.NumericValues = (List<double>)sField.Values; f.Values = new List<string>(); foreach (double d in f.NumericValues) { f.Values.Add(Convert.ToString(d)); } } f.FieldType = FieldType.Number; return f; } if (tcmItemField is TCM.Fields.DateField) { TCM.Fields.DateField sField = (TCM.Fields.DateField)tcmItemField; GeneralUtils.TimedLog(string.Format("item field {0} has {1} values", tcmItemField.Name, sField.Values.Count)); //if (sField.Values.Count == 0) // throw new FieldHasNoValueException(); if (sField.Values.Count == 0 && publishEmptyFields) { //throw new FieldHasNoValueException(); f.Values.Add(""); } else if (sField.Values.Count == 0 && !publishEmptyFields) { throw new FieldHasNoValueException(); } else { f.DateTimeValues = (List<DateTime>)sField.Values; f.Values = new List<string>(); foreach (DateTime dt in f.DateTimeValues) { f.Values.Add(Convert.ToString(dt)); } } f.FieldType = FieldType.Date; return f; } if (tcmItemField is TCM.Fields.MultimediaLinkField) { TCM.Fields.MultimediaLinkField sField = (TCM.Fields.MultimediaLinkField)tcmItemField; GeneralUtils.TimedLog(string.Format("item field {0} has {1} values", tcmItemField.Name, sField.Values.Count)); if (sField.Values.Count == 0 && publishEmptyFields) { f.Values.Add(tcmItemField.Name); } else if (sField.Values.Count == 0 && !publishEmptyFields) { throw new FieldHasNoValueException(); } else { // we will wrap each linked component in a ContentModel component f.LinkedComponentValues = new List<Dynamic.Component>(); foreach (TCM.Component comp in sField.Values) { // todo: add binary to package, and add BinaryUrl property to the component f.LinkedComponentValues.Add(manager.BuildComponent(comp, linkLevels - 1, resolveWidthAndHeight, publishEmptyFields)); } f.Values = new List<string>(); foreach (Dynamic.Component c in f.LinkedComponentValues) { f.Values.Add(c.Id); } } f.FieldType = FieldType.MultiMediaLink; return f; } if (tcmItemField is TCM.Fields.ComponentLinkField) { TCM.Fields.ComponentLinkField sField = (TCM.Fields.ComponentLinkField)tcmItemField; GeneralUtils.TimedLog(string.Format("item field {0} has {1} values", tcmItemField.Name, sField.Values.Count)); //if (sField.Values.Count == 0) // throw new FieldHasNoValueException(); if (sField.Values.Count == 0 && publishEmptyFields) { f.Values.Add(tcmItemField.Name); } else if (sField.Values.Count == 0 && !publishEmptyFields) { throw new FieldHasNoValueException(); } else { // we will wrap each linked component in a ContentModel component f.LinkedComponentValues = new List<Dynamic.Component>(); foreach (TCM.Component comp in sField.Values) { f.LinkedComponentValues.Add(manager.BuildComponent(comp, linkLevels - 1, resolveWidthAndHeight, publishEmptyFields)); } f.Values = new List<string>(); foreach (Dynamic.Component c in f.LinkedComponentValues) { f.Values.Add(c.Id); } } f.FieldType = FieldType.ComponentLink; return f; } if (tcmItemField is TCM.Fields.EmbeddedSchemaField) { TCM.Fields.EmbeddedSchemaField sField = (TCM.Fields.EmbeddedSchemaField)tcmItemField; GeneralUtils.TimedLog(string.Format("item field {0} has {1} values", tcmItemField.Name, sField.Values.Count)); //if (sField.Values.Count == 0) //throw new FieldHasNoValueException(); f.FieldType = FieldType.Embedded; f.EmbeddedValues = new List<Dynamic.FieldSet>(); if (sField.Values.Count == 0 && publishEmptyFields) { Dynamic.FieldSet fields = new FieldSet(); Dynamic.Field fe = new Dynamic.Field(); f.EmbeddedSchema = manager.BuildSchema(((EmbeddedSchemaFieldDefinition)sField.Definition).EmbeddedSchema); EmbeddedSchemaFieldDefinition linksFieldDefinition = sField.Definition as EmbeddedSchemaFieldDefinition; ItemFields newItemField = new ItemFields(linksFieldDefinition.EmbeddedSchema); for (int i = 0; i < newItemField.Count; i++) { if (newItemField[i] is TCM.Fields.EmbeddedSchemaField) { TCM.Fields.EmbeddedSchemaField innerField = (TCM.Fields.EmbeddedSchemaField)newItemField[i]; if (innerField.Values.Count == 0) { Dynamic.FieldSet fieldsinner = new FieldSet(); Dynamic.Field fin = new Dynamic.Field(); fe.EmbeddedSchema = manager.BuildSchema(((EmbeddedSchemaFieldDefinition)innerField.Definition).EmbeddedSchema); EmbeddedSchemaFieldDefinition inlinksFieldDefinition = innerField.Definition as EmbeddedSchemaFieldDefinition; ItemFields newinItemField = new ItemFields(inlinksFieldDefinition.EmbeddedSchema); for (int n = 0; n < newinItemField.Count; n++) { fin.Name = newItemField[n].Name; fieldsinner.Add(newinItemField[n].Name, fin); } fe.EmbeddedValues.Add(fieldsinner); fe.Values.Add(""); } fe.Name = newItemField[i].Name; fields.Add(newItemField[i].Name, fe); } else { Dynamic.Field fein = manager.BuildField(newItemField[i], linkLevels, resolveWidthAndHeight, publishEmptyFields); fein.Values.Clear(); fields.Add(newItemField[i].Name, fein); } } f.EmbeddedValues.Add(fields); f.Values.Add(""); } else if (sField.Values.Count == 0 && !publishEmptyFields) { throw new FieldHasNoValueException(); } else { // we will wrap each linked component in a ContentModel component f.EmbeddedValues = new List<Dynamic.FieldSet>(); f.EmbeddedSchema = manager.BuildSchema(((EmbeddedSchemaFieldDefinition)sField.Definition).EmbeddedSchema); foreach (TCM.Fields.ItemFields embeddedFields in sField.Values) { f.EmbeddedValues.Add(manager.BuildFields(embeddedFields, linkLevels, resolveWidthAndHeight, publishEmptyFields)); } } return f; } throw new FieldTypeNotDefinedException(); }