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 Builder.FieldsBuilder.AddFields(component.MetadataFields, tcmFields, 1, false, mergeAction, manager); } tcmFolder = (TCM.Folder)tcmFolder.OrganizationalItem; } }
protected override void TransformComponent(Dynamic.Component component) { binaryPublisher = new BinaryPublisher(Package, Engine); // 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 void PublishAllBinaries(Dynamic.Component component) { if (component.ComponentType.Equals(Dynamic.ComponentType.Multimedia)) { component.Multimedia.Url = binaryPublisher.PublishMultimediaComponent(component.Id); } foreach (var field in component.Fields.Values) { if (field.FieldType == Dynamic.FieldType.ComponentLink || field.FieldType == Dynamic.FieldType.MultiMediaLink) { foreach (var 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); } } } 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); } } } }
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; } 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); GeneralUtils.TimedLog("finished building dynamic component"); return(component); }
public static Dynamic.Component BuildComponent(TCM.Component tcmComponent, int linkLevels, bool resolveWidthAndHeight, BuildManager manager) { GeneralUtils.TimedLog("start BuildComponent"); Dynamic.Component c = new Dynamic.Component(); c.Title = tcmComponent.Title; c.Id = tcmComponent.Id.ToString(); GeneralUtils.TimedLog("component title = " + c.Title); 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" multimedia.FileExtension = System.IO.Path.GetExtension(multimedia.FileName).Substring(1); if (resolveWidthAndHeight) { 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; } else { multimedia.Width = 0; multimedia.Height = 0; } c.Multimedia = multimedia; GeneralUtils.TimedLog("finished building multimedia"); } else { c.Multimedia = null; } c.Fields = new Dynamic.SerializableDictionary <string, Field>(); c.MetadataFields = new Dynamic.SerializableDictionary <string, Field>(); 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); GeneralUtils.TimedLog("finished retrieving tcm fields"); GeneralUtils.TimedLog("start building fields"); c.Fields = manager.BuildFields(tcmFields, linkLevels, resolveWidthAndHeight); 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); GeneralUtils.TimedLog("finished building metadata fields"); } } GeneralUtils.TimedLog("start retrieving tcm publication"); TCM.Repository pub = tcmComponent.ContextRepository; GeneralUtils.TimedLog("finished retrieving tcm publication"); GeneralUtils.TimedLog("start building publication"); c.Publication = manager.BuildPublication(pub); GeneralUtils.TimedLog("finished building publication"); GeneralUtils.TimedLog("start retrieving tcm folder"); TCM.Folder folder = (TCM.Folder)tcmComponent.OrganizationalItem; GeneralUtils.TimedLog("finished retrieving tcm folder"); GeneralUtils.TimedLog("start building folder"); c.Folder = manager.BuildOrganizationalItem(folder); GeneralUtils.TimedLog("finished building folder"); GeneralUtils.TimedLog("start building categories"); c.Categories = manager.BuildCategories(tcmComponent); GeneralUtils.TimedLog("finished building categories"); GeneralUtils.TimedLog("finished BuildComponent " + c.Title); return(c); }
public static Dynamic.Component BuildComponent(TCM.Component tcmComponent, int linkLevels, bool resolveWidthAndHeight, BuildManager manager) { GeneralUtils.TimedLog("start BuildComponent"); Dynamic.Component c = new Dynamic.Component(); c.Title = tcmComponent.Title; c.Id = tcmComponent.Id.ToString(); GeneralUtils.TimedLog("component title = " + c.Title); 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" multimedia.FileExtension = System.IO.Path.GetExtension(multimedia.FileName).Substring(1); if (resolveWidthAndHeight) { 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; } else { multimedia.Width = 0; multimedia.Height = 0; } c.Multimedia = multimedia; GeneralUtils.TimedLog("finished building multimedia"); } else { c.Multimedia = null; } c.Fields = new Dynamic.SerializableDictionary<string,Field>(); c.MetadataFields = new Dynamic.SerializableDictionary<string, Field>(); 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); GeneralUtils.TimedLog("finished retrieving tcm fields"); GeneralUtils.TimedLog("start building fields"); c.Fields = manager.BuildFields(tcmFields, linkLevels, resolveWidthAndHeight); 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); GeneralUtils.TimedLog("finished building metadata fields"); } } GeneralUtils.TimedLog("start retrieving tcm publication"); TCM.Repository pub = tcmComponent.ContextRepository; GeneralUtils.TimedLog("finished retrieving tcm publication"); GeneralUtils.TimedLog("start building publication"); c.Publication = manager.BuildPublication(pub); GeneralUtils.TimedLog("finished building publication"); GeneralUtils.TimedLog("start retrieving tcm folder"); TCM.Folder folder = (TCM.Folder) tcmComponent.OrganizationalItem; GeneralUtils.TimedLog("finished retrieving tcm folder"); GeneralUtils.TimedLog("start building folder"); c.Folder = manager.BuildOrganizationalItem(folder); GeneralUtils.TimedLog("finished building folder"); GeneralUtils.TimedLog("start building categories"); c.Categories = manager.BuildCategories(tcmComponent); GeneralUtils.TimedLog("finished building categories"); GeneralUtils.TimedLog("finished BuildComponent " + c.Title); return c; }
protected override void TransformComponent(Dynamic.Component component) { // do nothing, this is the basic operation }
/// <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);