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;
        }
Esempio n. 3
0
        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.Schema BuildSchema(TCM.Schema tcmSchema, BuildManager manager)
        {
			if (tcmSchema == null) {
				return null;
			}
			Dynamic.Schema s = new Dynamic.Schema();
			s.Title = tcmSchema.Title;
			s.Id = tcmSchema.Id.ToString();

            if (!manager.BuildProperties.OmitContextPublications)
                s.Publication = manager.BuildPublication(tcmSchema.ContextRepository);
            if (!manager.BuildProperties.OmitFolders)
                s.Folder = manager.BuildOrganizationalItem((TCM.Folder)tcmSchema.OrganizationalItem);

            if (!String.IsNullOrEmpty(tcmSchema.RootElementName))
            {
                s.RootElementName = tcmSchema.RootElementName;
            }
            // note that non-webschemas and multimedia schema's lack a root element. In order not
            // to break deserialization, setting it to undefined will do
            else
            {
                s.RootElementName = "undefined";
            }

			return s;
		}
        public static Dynamic.Schema BuildSchema(TCM.Schema tcmSchema, BuildManager manager)
        {
            if (tcmSchema == null)
            {
                return(null);
            }
            Dynamic.Schema s = new Dynamic.Schema();
            s.Title = tcmSchema.Title;
            s.Id    = tcmSchema.Id.ToString();

            if (!manager.BuildProperties.OmitContextPublications)
            {
                s.Publication = manager.BuildPublication(tcmSchema.ContextRepository);
            }
            if (!manager.BuildProperties.OmitFolders)
            {
                s.Folder = manager.BuildOrganizationalItem((TCM.Folder)tcmSchema.OrganizationalItem);
            }

            if (!String.IsNullOrEmpty(tcmSchema.RootElementName))
            {
                s.RootElementName = tcmSchema.RootElementName;
            }
            // note that non-webschemas and multimedia schema's lack a root element. In order not
            // to break deserialization, setting it to undefined will do
            else
            {
                s.RootElementName = "undefined";
            }

            return(s);
        }
        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.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;
		}
Esempio n. 9
0
 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.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 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. 15
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);
        }