Esempio n. 1
0
 protected void PublishAllBinaries(Dynamic.FieldSet fieldSet)
 {
     foreach (Dynamic.Field field in fieldSet.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.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);
             }
         }
     }
 }
Esempio n. 2
0
        public void AddExtensionProperty(string sectionName, string propertyName, object value)
        {
            if (value == null)
            {
                // For a null value we just don't do anything rather than creating a field with a null value (or add a null value to existing field).
                return;
            }

            if (ExtensionData == null)
            {
                ExtensionData = new SerializableDictionary <string, IFieldSet, FieldSet>();
            }

            IFieldSet sectionFieldSet;

            if (!ExtensionData.TryGetValue(sectionName, out sectionFieldSet))
            {
                sectionFieldSet = new FieldSet();
                ExtensionData.Add(sectionName, sectionFieldSet);
            }

            IField propertyField;

            if (!sectionFieldSet.TryGetValue(propertyName, out propertyField))
            {
                propertyField = new Field(propertyName, value);
                sectionFieldSet.Add(propertyName, propertyField);
            }
            else
            {
                ((Field)propertyField).AddFieldValue(value);
            }
        }
        public static void AddXpathToFields(Dynamic.FieldSet fieldSet, string baseXpath)
        {
            // add XPath properties to all fields

            if (fieldSet == null)
            {
                log.Error("fieldSet == null");
                return;
            }
            if (fieldSet.Values == null)
            {
                log.Error("fieldSet.Values == null");
                return;
            }
            try
            {
                foreach (Field f in fieldSet.Values)
                {
                    f.XPath = string.Format("{0}/custom:{1}", baseXpath, f.Name);
                    int i = 1;
                    if (f.EmbeddedValues != null)
                    {
                        foreach (FieldSet subFields in f.EmbeddedValues)
                        {
                            AddXpathToFields(subFields, string.Format("{0}/custom:{1}[{2}]", baseXpath, f.Name, i++));
                        }
                    }
                }
            }
            catch (Exception e)
            {
                log.Error("Exception adding xpath to fields", e);
            }
        }
Esempio n. 4
0
        public static void AddXpathToFields(Dynamic.FieldSet fieldSet, string baseXpath)
        {
            // add XPath properties to all fields

            if (fieldSet == null)
            {
                GeneralUtils.TimedLog("Error: fieldSet = null");
            }
            if (fieldSet.Values == null)
            {
                GeneralUtils.TimedLog("Error: fieldSet.Values = null");
            }
            try
            {
                foreach (Field f in fieldSet.Values)
                {
                    if (f == null)
                    {
                        GeneralUtils.TimedLog("Error: field = null");
                    }
                    f.XPath = string.Format("{0}/custom:{1}", baseXpath, f.Name);
                    int i = 1;
                    if (f.EmbeddedValues != null)
                    {
                        foreach (FieldSet subFields in f.EmbeddedValues)
                        {
                            AddXpathToFields(subFields, string.Format("{0}/custom:{1}[{2}]", baseXpath, f.Name, i++));
                        }
                    }
                }
            }
            catch (Exception e)
            {
                GeneralUtils.TimedLog("Caught exception: " + e.Message);
            }
        }
Esempio n. 5
0
 public virtual void AddXpathToFields(Dynamic.FieldSet fieldSet, string baseXpath)
 {
     FieldsBuilder.AddXpathToFields(fieldSet, baseXpath);
 }
Esempio n. 6
0
        public static void AddFields(Dynamic.FieldSet fields, TCM.Fields.ItemFields tcmItemFields, int linkLevels, bool resolveWidthAndHeight, bool publishEmptyFields, Dynamic.MergeAction mergeAction, BuildManager manager)
        {
            GeneralUtils.TimedLog(string.Format("add fields: found {0} fields", tcmItemFields.Count));


            foreach (TCM.Fields.ItemField tcmItemField in tcmItemFields)
            {
                GeneralUtils.TimedLog("add fields: found " + tcmItemField.Name);
                try
                {
                    if (fields.ContainsKey(tcmItemField.Name))
                    {
                        GeneralUtils.TimedLog("field exists already, with " + fields[tcmItemField.Name].Values.Count + " values");
                        if (mergeAction.Equals(Dynamic.MergeAction.Skip) || (mergeAction.Equals(Dynamic.MergeAction.MergeMultiValueSkipSingleValue) && tcmItemField.Definition.MaxOccurs == 1))
                        {
                            GeneralUtils.TimedLog(string.Format("skipping field (merge action {0}, maxoccurs {1}", mergeAction.ToString(), tcmItemField.Definition.MaxOccurs));
                            continue;
                        }
                        Dynamic.Field f = manager.BuildField(tcmItemField, linkLevels, resolveWidthAndHeight, publishEmptyFields);
                        if (mergeAction.Equals(Dynamic.MergeAction.Replace) || (mergeAction.Equals(Dynamic.MergeAction.MergeMultiValueReplaceSingleValue) && tcmItemField.Definition.MaxOccurs == 1))
                        {
                            GeneralUtils.TimedLog(string.Format("replacing field (merge action {0}, maxoccurs {1}", mergeAction.ToString(), tcmItemField.Definition.MaxOccurs));
                            fields.Remove(f.Name);
                            fields.Add(f.Name, f);
                        }
                        else
                        {
                            IField 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;
                                        }
                                    }
                                    GeneralUtils.TimedLog(string.Format("found value {0}, valueExists: {1}", val, valueExists));
                                    if (!valueExists)
                                    {
                                        existingField.Values.Add(val);
                                    }
                                }
                                break;
                            }
                        }
                    }
                    else
                    {
                        Dynamic.Field f = manager.BuildField(tcmItemField, linkLevels, resolveWidthAndHeight, publishEmptyFields);
                        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
                }
            }
        }
 public static void AddFields(Dynamic.FieldSet fields, TCM.Fields.ItemFields tcmItemFields, BuildManager manager)
 {
     AddFields(fields, tcmItemFields, manager.BuildProperties.LinkLevels, manager);
 }