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;
            }
        }
Esempio n. 2
0
 public static Dynamic.OrganizationalItem BuildOrganizationalItem(TCM.Folder tcmFolder)
 {
     Dynamic.OrganizationalItem oi = new Dynamic.OrganizationalItem();
     oi.Title         = tcmFolder.Title;
     oi.Id            = tcmFolder.Id.ToString();
     oi.PublicationId = tcmFolder.ContextRepository.Id.ToString();
     return(oi);
 }
 public static Dynamic.OrganizationalItem BuildOrganizationalItem(TCM.Folder tcmFolder)
 {
     GeneralUtils.TimedLog("start BuildOrganizationalItem");
     Dynamic.OrganizationalItem oi = new Dynamic.OrganizationalItem();
     oi.Title         = tcmFolder.Title;
     oi.Id            = tcmFolder.Id.ToString();
     oi.PublicationId = tcmFolder.ContextRepository.Id.ToString();
     GeneralUtils.TimedLog("finished BuildOrganizationalItem");
     return(oi);
 }
        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;
            }
        }
Esempio n. 5
0
        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);
        }
Esempio n. 6
0
 public virtual Dynamic.OrganizationalItem BuildOrganizationalItem(TCM.Folder tcmFolder)
 {
     return(OrganizationalItemBuilder.BuildOrganizationalItem(tcmFolder));
 }
        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);
        }
Esempio n. 9
0
        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);
        }