protected override void TransformPage(Dynamic.Page page)
        {
            Page tcmPage = this.GetTcmPage();
             StructureGroup tcmSG = (StructureGroup)tcmPage.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 (tcmSG.OrganizationalItem != null)
             {
            if (tcmSG.MetadataSchema != null)
            {
               TCM.Fields.ItemFields tcmFields = new TCM.Fields.ItemFields(tcmSG.Metadata, tcmSG.MetadataSchema);
               // change
               Builder.FieldsBuilder.AddFields(page.Metadata, tcmFields, 1, false, mergeAction, manager);
            }
            tcmSG = (StructureGroup)tcmSG.OrganizationalItem;
             }
        }
        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.Page page)
        {
            foreach (Dynamic.Field field in page.Metadata.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);
                    }
                }
            }

            // do not publish binaries in the components, because they should be handled
            // by the component templates!

            //foreach (Dynamic.ComponentPresentation cp in page.ComponentPresentations)
            //{
            //   Dynamic.Component component = cp.Component;
            //   if (component.ComponentType.Equals(Dynamic.ComponentType.Multimedia))
            //   {
            //      component.Multimedia.Url = binaryPublisher.PublishMultimediaComponent(component.Id);
            //   }
            //   foreach (Dynamic.Field field in component.Fields.Values)
            //   {
            //      if (field.FieldType == Dynamic.FieldType.ComponentLink || field.FieldType == Dynamic.FieldType.MultiMediaLink)
            //      {
            //         foreach (Dynamic.Component linkedComponent in field.LinkedComponentValues)
            //         {
            //            PublishAllBinaries(linkedComponent);
            //         }
            //      }
            //   }
            //}
        }
 private void PublishAllBinaries(Dynamic.Component component)
 {
     if (component.ComponentType.Equals(Dynamic.ComponentType.Multimedia))
     {
         component.Multimedia.Url = binaryPublisher.PublishMultimediaComponent(component.Id);
     }
     foreach (Dynamic.Field field in component.Fields.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);
             }
         }
     }
     foreach (Dynamic.Field 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);
             }
         }
     }
 }
Exemplo n.º 6
0
 protected override void TransformPage(Dynamic.Page page)
 {
     // do nothing, this is the basic operation
 }
 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);
Exemplo n.º 9
0
        public static void AddFields(Dynamic.SerializableDictionary<string, Field> fields, TCM.Fields.ItemFields tcmItemFields, int linkLevels, bool resolveWidthAndHeight, Dynamic.MergeAction mergeAction, BuildManager manager)
        {
            foreach (TCM.Fields.ItemField tcmItemField in tcmItemFields)
             {
            try
            {
               if (fields.ContainsKey(tcmItemField.Name))
               {
                  if (mergeAction.Equals(Dynamic.MergeAction.Skip))
                  {
                     continue;
                  }
                  Dynamic.Field f = manager.BuildField(tcmItemField, linkLevels, resolveWidthAndHeight);
                  if (mergeAction.Equals(Dynamic.MergeAction.Replace))
                  {
                     fields.Remove(f.Name);
                     fields.Add(f.Name, f);
                  }
                  else
                  {
                     Field existingField = fields[f.Name];
                     switch (existingField.FieldType)
                     {

                        case FieldType.ComponentLink:
                        case FieldType.MultiMediaLink:
                           foreach (Component linkedComponent in f.LinkedComponentValues)
                           {
                              bool valueExists = false;
                              foreach (Component existingLinkedComponent in existingField.LinkedComponentValues)
                              {
                                 if (linkedComponent.Id.Equals(existingLinkedComponent.Id))
                                 {
                                    // this value already exists
                                    valueExists = true;
                                    break;
                                 }
                              }
                              if (!valueExists)
                              {
                                 existingField.LinkedComponentValues.Add(linkedComponent);
                              }
                           }
                           break;
                        case FieldType.Date:
                           foreach (DateTime dateTime in f.DateTimeValues)
                           {
                              bool valueExists = false;
                              foreach (DateTime existingDateTime in existingField.DateTimeValues)
                              {
                                 if (dateTime.Equals(existingDateTime))
                                 {
                                    // this value already exists
                                    valueExists = true;
                                    break;
                                 }
                              }
                              if (!valueExists)
                              {
                                 existingField.DateTimeValues.Add(dateTime);
                              }
                           }
                           break;
                        case FieldType.Number:
                           foreach (int nr in f.NumericValues)
                           {
                              bool valueExists = false;
                              foreach (int existingNr in existingField.NumericValues)
                              {
                                 if (nr == existingNr)
                                 {
                                    // this value already exists
                                    valueExists = true;
                                    break;
                                 }
                              }
                              if (!valueExists)
                              {
                                 existingField.NumericValues.Add(nr);
                              }
                           }
                           break;
                        default:
                           foreach (string val in f.Values)
                           {
                              bool valueExists = false;
                              foreach (string existingVal in existingField.Values)
                              {
                                 if (val.Equals(existingVal))
                                 {
                                    // this value already exists
                                    valueExists = true;
                                    break;
                                 }
                              }
                              if (!valueExists)
                              {
                                 existingField.Values.Add(val);
                              }
                           }
                           break;
                     }
                  }
               }
               else
               {
                   Dynamic.Field f = manager.BuildField(tcmItemField, linkLevels, resolveWidthAndHeight);
                  fields.Add(f.Name, f);
               }
            }
            catch (FieldHasNoValueException)
            {
               // fail silently, field is not added to the list
            }
            catch (FieldTypeNotDefinedException)
            {
               // fail silently, field is not added to the list
            }
             }
        }
 /// <summary>
 /// Abstract method to be implemented by a subclass. The method takes a DynamicDelivery page and can add information to it (e.g. by searching in folders / structure groups / linked components, etc
 /// </summary>
 /// <param name="page">DynamicDelivery page</param>
 protected abstract void TransformPage(Dynamic.Page page);