protected override void TransformComponent(Dynamic.Component component) { TCM.Component tcmComponent = this.GetTcmComponent(); TCM.Folder tcmFolder = (TCM.Folder)tcmComponent.OrganizationalItem; String mergeActionStr = Package.GetValue("MergeAction"); Dynamic.MergeAction mergeAction; if (string.IsNullOrEmpty(mergeActionStr)) { mergeAction = defaultMergeAction; } else { mergeAction = (Dynamic.MergeAction)Enum.Parse(typeof(Dynamic.MergeAction), mergeActionStr); } while (tcmFolder.OrganizationalItem != null) { if (tcmFolder.MetadataSchema != null) { TCM.Fields.ItemFields tcmFields = new TCM.Fields.ItemFields(tcmFolder.Metadata, tcmFolder.MetadataSchema); // change FieldsBuilder.AddFields(component.MetadataFields, tcmFields, 1, false, false, mergeAction, Manager); } tcmFolder = (TCM.Folder)tcmFolder.OrganizationalItem; } }
/// <summary> /// Publishes the Binary Data of a Multimedia Component and sets it Multimedia URL (and ExtensionData for ECL). /// </summary> /// <param name="mmComponent">The (DD4T) Multimedia Component to Publish.</param> /// <param name="buildProperties">The DD4T Build Properties</param> public void PublishMultimediaComponent(Dynamic.Component mmComponent, BuildProperties buildProperties) { Dynamic.Multimedia multimedia = mmComponent.Multimedia; if (multimedia == null) { log.Warning("PublishMultimediaComponent called with a non-Multimedia Component: " + mmComponent.Id); return; } if (multimedia.MimeType == EclMimeType && buildProperties.ECLEnabled && mmComponent.EclId == null) { using (EclProcessor eclProcessor = new EclProcessor(engine, targetStructureGroupUri)) { eclProcessor.ProcessEclStubComponent(mmComponent); } } else if (mmComponent.EclId != null) { log.Debug(string.Format("ECL Stub Component '{0}' has already been processed (ECL ID: '{1}') ", mmComponent.Id, mmComponent.EclId)); } else { multimedia.Url = PublishMultimediaComponent(mmComponent.Id, buildProperties); } }
private Dynamic.ComponentPresentation GetDynamicComponentPresentation() { Template template = Engine.PublishingContext.ResolvedItem.Template; if (!(template is ComponentTemplate)) { Log.Error("no component template found (is this a page template?)"); return(null); } ComponentTemplate tcmComponentTemplate = (ComponentTemplate)template; Item item = Package.GetByName(Package.ComponentName); if (item == null) { Log.Error("no component found (is this a page template?)"); return(null); } Component tcmComponent = (Component)Engine.GetObject(item); Dynamic.Component component = Manager.BuildComponent(tcmComponent); EnsureExtraProperties(component, tcmComponent); Dynamic.ComponentTemplate componentTemplate = Manager.BuildComponentTemplate(tcmComponentTemplate); Dynamic.ComponentPresentation componentPresentation = new Dynamic.ComponentPresentation() { Component = component, ComponentTemplate = componentTemplate, IsDynamic = tcmComponentTemplate.IsRepositoryPublishable }; return(componentPresentation); }
protected void PublishAllBinaries(Dynamic.Component component) { if (component.ComponentType.Equals(Dynamic.ComponentType.Multimedia)) { BinaryPublisher.PublishMultimediaComponent(component, Manager.BuildProperties); } PublishAllBinaries(component.Fields); PublishAllBinaries(component.MetadataFields); }
protected void PublishAllBinaries(Dynamic.Component component) { if (component.ComponentType.Equals(Dynamic.ComponentType.Multimedia)) { component.Multimedia.Url = BinaryPublisher.PublishMultimediaComponent(component.Id); } PublishAllBinaries(component.Fields); PublishAllBinaries(component.MetadataFields); }
protected override void TransformComponent(Dynamic.Component component) { // persist the ComponentPresentationRenderStyle in the package so that the next TBB in the chain is able to read it if (Package != null) { Item renderStyle = Package.CreateStringItem(ContentType.Text, ComponentPresentationRenderStyle.ToString()); Package.PushItem("render-style", renderStyle); } }
protected override void TransformComponent(Dynamic.Component component) { // call helper function to publish all relevant multimedia components // that could be: // - the current component // - any component linked to the current component // - any component linked to that (the number of levels is configurable in a parameter) PublishAllBinaries(component); }
private Dynamic.Component GetDynamicComponent(BuildManager manager) { GeneralUtils.TimedLog("start getting component from package"); Item item = Package.GetByName(Package.ComponentName); GeneralUtils.TimedLog("finished getting component from package"); if (item == null) { Log.Error("no component found (is this a page template?)"); return(null); } Component tcmComponent = (Component)Engine.GetObject(item.GetAsSource().GetValue("ID")); int linkLevels; if (HasPackageValue(Package, "LinkLevels")) { linkLevels = Convert.ToInt32(Package.GetValue("LinkLevels")); } else { GeneralUtils.TimedLog("no link levels configured, using default level " + this.DefaultLinkLevels); linkLevels = this.DefaultLinkLevels; } bool resolveWidthAndHeight; if (HasPackageValue(Package, "ResolveWidthAndHeight")) { resolveWidthAndHeight = Package.GetValue("ResolveWidthAndHeight").ToLower().Equals("yes"); } else { GeneralUtils.TimedLog("no ResolveWidthAndHeight configured, using default value " + this.DefaultResolveWidthAndHeight); resolveWidthAndHeight = this.DefaultResolveWidthAndHeight; } bool publishEmptyFields; if (HasPackageValue(Package, "PublishEmptyFields")) { publishEmptyFields = Package.GetValue("PublishEmptyFields").ToLower().Equals("yes"); } else { GeneralUtils.TimedLog("no PublishEmptyFields configured, using default value " + this.DefaultResolveWidthAndHeight); publishEmptyFields = this.DefaultPublishEmptyFields; } GeneralUtils.TimedLog("found component with title " + tcmComponent.Title + " and id " + tcmComponent.Id); GeneralUtils.TimedLog("constructing dynamic component, links are followed to level " + linkLevels + ", width and height are " + (resolveWidthAndHeight ? "" : "not ") + "resolved"); GeneralUtils.TimedLog("start building dynamic component"); Dynamic.Component component = manager.BuildComponent(tcmComponent, linkLevels, resolveWidthAndHeight, publishEmptyFields); GeneralUtils.TimedLog("finished building dynamic component"); return(component); }
private void PublishAllBinaries(Dynamic.Component component) { if (component.ComponentType.Equals(Dynamic.ComponentType.Multimedia)) { BinaryPublisher.PublishMultimediaComponent(component, Manager.BuildProperties); } foreach (var field in component.Fields.Values) { if (field.FieldType == Dynamic.FieldType.ComponentLink || field.FieldType == Dynamic.FieldType.MultiMediaLink) { foreach (IComponent linkedComponent in field.LinkedComponentValues) { PublishAllBinaries(linkedComponent as Component); } } if (field.FieldType == Dynamic.FieldType.Embedded) { foreach (Dynamic.FieldSet embeddedFields in field.EmbeddedValues) { PublishAllBinaries(embeddedFields); } } if (field.FieldType == Dynamic.FieldType.Xhtml) { for (int i = 0; i < field.Values.Count; i++) { string xhtml = field.Values[i]; field.Values[i] = BinaryPublisher.PublishBinariesInRichTextField(xhtml, Manager.BuildProperties); } } } foreach (var field in component.MetadataFields.Values) { if (field.FieldType == Dynamic.FieldType.ComponentLink || field.FieldType == Dynamic.FieldType.MultiMediaLink) { foreach (Dynamic.Component linkedComponent in field.LinkedComponentValues) { PublishAllBinaries(linkedComponent); } } if (field.FieldType == Dynamic.FieldType.Xhtml) { for (int i = 0; i < field.Values.Count; i++) { string xhtml = field.Values[i]; field.Values[i] = BinaryPublisher.PublishBinariesInRichTextField(xhtml, Manager.BuildProperties); } } } }
protected override void TransformComponent(Dynamic.Component component) { TCM.Component tcmComponent = this.GetTcmComponent(); TCM.Folder tcmFolder = (TCM.Folder)tcmComponent.OrganizationalItem; while (tcmFolder.OrganizationalItem != null) { if (tcmFolder.MetadataSchema != null) { TCM.Fields.ItemFields tcmFields = new TCM.Fields.ItemFields(tcmFolder.Metadata, tcmFolder.MetadataSchema); FieldsBuilder.AddFields(component.MetadataFields, tcmFields, Manager); } tcmFolder = (TCM.Folder)tcmFolder.OrganizationalItem; } }
private Dynamic.Component GetDynamicComponent() { Item item = Package.GetByName(Package.ComponentName); if (item == null) { Log.Error("no component found (is this a page template?)"); return(null); } Component tcmComponent = (Component)Engine.GetObject(item); Dynamic.Component component = Manager.BuildComponent(tcmComponent); EnsureExtraProperties(component, tcmComponent); return(component); }
private void EnsureExtraProperties(Dynamic.Component component, Component tcmComponent) { // make sure that the Publication, Folder and OwningPublication are always available on the top level if (component.Publication == null) { component.Publication = Manager.BuildPublication(tcmComponent.ContextRepository); } if (component.OwningPublication == null) { component.OwningPublication = Manager.BuildPublication(tcmComponent.OwningRepository); } if (component.Folder == null) { component.Folder = Manager.BuildOrganizationalItem((Folder)tcmComponent.OrganizationalItem); } }
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 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 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.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; }
/// <summary> /// Abstract method to be implemented by a subclass. The method takes a DynamicDelivery component and can add information to it (e.g. by searching in folders / structure groups / linked components, etc /// </summary> /// <param name="component">DynamicDelivery component </param> protected abstract void TransformComponent(Dynamic.Component component);
protected override void TransformComponent(Dynamic.Component component) { }
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); }
private void ProcessRegions(IList <IRegion> regions, Dynamic.Page dd4tPage, int fieldCounter) { int i = fieldCounter; Log.Debug($"ProcessRegions {regions.Count()}, {dd4tPage.ComponentPresentations.Count()}, {fieldCounter}"); foreach (var region in regions) { if (region.ComponentPresentations != null && region.ComponentPresentations.Any()) { foreach (var cp in region.ComponentPresentations) { Dynamic.Component component = Manager.BuildComponent(cp.Component); Dynamic.ComponentTemplate componentTemplate = Manager.BuildComponentTemplate(cp.ComponentTemplate); Dynamic.ComponentPresentation componentPresentation = new Dynamic.ComponentPresentation() { Component = component, ComponentTemplate = componentTemplate, IsDynamic = cp.ComponentTemplate.IsRepositoryPublishable }; dd4tPage.ComponentPresentations.Add(componentPresentation); if (componentTemplate.MetadataFields == null) { componentTemplate.MetadataFields = new Dynamic.FieldSet(); } if (componentTemplate.MetadataFields.ContainsKey("region")) { componentTemplate.MetadataFields["region"].Values.Clear(); componentTemplate.MetadataFields["region"].Values.Add(region.RegionSchema.Title); } else { componentTemplate.MetadataFields.Add("region", new Dynamic.Field() { Name = "region", FieldType = Dynamic.FieldType.Text, Values = new List <string>() { region.RegionName } }); } // remove regionView metadata field, because it is no longer possible to manage this information in Tridion 9 with Regions if (componentTemplate.MetadataFields.ContainsKey("regionView")) { componentTemplate.MetadataFields.Remove("regionView"); } // copy all other metadata fields from the region to the entity if (region.Metadata != null) { ItemFields regionMetadataFields = new ItemFields(region.Metadata, region.RegionSchema); try { foreach (var regionMeta in regionMetadataFields) { componentTemplate.MetadataFields.Add(regionMeta.Name, Manager.BuildField(regionMeta, 1)); } } catch (Exception e) { Log.Warning("error while trying to copy metadata from region to component template\r\n" + e.Message + "\r\n" + e.StackTrace); } } if (region.Regions != null && region.RegionName.Any()) { ProcessRegions(region.Regions, dd4tPage, i); } } } } }
protected override void TransformComponent(Dynamic.Component component) { // do nothing, this is the basic operation }