コード例 #1
0
        private SiteLocalizationData GetPublicationDetails(Publication pub, bool isMaster = false)
        {
            SiteLocalizationData pubData = new SiteLocalizationData
            {
                Id       = pub.Id.ItemId.ToString(CultureInfo.InvariantCulture),
                Path     = pub.PublicationUrl,
                IsMaster = isMaster
            };

            if (_localizationConfigurationComponent != null)
            {
                TcmUri    localUri = new TcmUri(_localizationConfigurationComponent.Id.ItemId, ItemType.Component, pub.Id.ItemId);
                Component locComp  = (Component)Engine.GetObject(localUri);
                if (locComp != null)
                {
                    ItemFields fields = new ItemFields(locComp.Content, locComp.Schema);
                    foreach (ItemFields field in fields.GetEmbeddedFields("settings"))
                    {
                        if (field.GetTextValue("name") == "language")
                        {
                            pubData.Language = field.GetTextValue("value");
                            break;
                        }
                    }
                }
            }
            return(pubData);
        }
コード例 #2
0
        protected Dictionary <string, string> ExtractKeyValuePairs(Component component)
        {
            Dictionary <string, string> keyValuePairs = new Dictionary <string, string>();

            if (component.Content == null)
            {
                return(keyValuePairs);
            }

            ItemFields configComponentFields = new ItemFields(component.Content, component.Schema);

            ItemFields[] settingsFieldValues = configComponentFields.GetEmbeddedFields("settings").ToArray();
            if (settingsFieldValues.Any())
            {
                //either schema is a generic multival embedded name/value
                foreach (ItemFields setting in settingsFieldValues)
                {
                    string key = setting.GetTextValue("name");
                    if (!string.IsNullOrEmpty(key) && !keyValuePairs.ContainsKey(key))
                    {
                        keyValuePairs.Add(key, setting.GetTextValue("value"));
                    }
                    else
                    {
                        Logger.Warning(string.Format("Empty or duplicate key found ('{0}') in Component '{1}' ({2})",
                                                     key, component.Title, component.Id));
                    }
                }
            }
            else
            {
                //... or its a custom schema with individual fields
                foreach (ItemField field in configComponentFields)
                {
                    string key = field.Name;
                    keyValuePairs.Add(key, configComponentFields.GetSingleFieldValue(key));
                }
            }
            return(keyValuePairs);
        }
コード例 #3
0
        protected Dictionary <string, string> ReadComponentData(Component comp)
        {
            Dictionary <string, string> settings = new Dictionary <string, string>();

            if (comp.Content != null)
            {
                ItemFields fields = new ItemFields(comp.Content, comp.Schema);
                IEnumerable <ItemFields> configFields = fields.GetEmbeddedFields("settings");
                if (configFields.Any())
                {
                    //either schema is a generic multival embedded name/value
                    foreach (ItemFields setting in configFields)
                    {
                        string key = setting.GetTextValue("name");
                        if (!String.IsNullOrEmpty(key) && !settings.ContainsKey(key))
                        {
                            settings.Add(key, setting.GetTextValue("value"));
                        }
                        else
                        {
                            Logger.Warning(String.Format("Duplicate key found: '{0}' when processing component {1}", key, comp.Id));
                        }
                    }
                }
                else
                {
                    //... or its a custom schema with individual fields
                    foreach (ItemField field in fields)
                    {
                        //TODO - do we need to be smarter about date/number type fields?
                        string key = field.Name;
                        settings.Add(key, fields.GetSingleFieldValue(key));
                    }
                }
            }
            return(settings);
        }
 public static ItemFields GetEmbeddedField(this ItemFields fields, string fieldName)
 {
     return(fields.GetEmbeddedFields(fieldName).FirstOrDefault());
 }
コード例 #5
0
 private PublicationDetails GetPublicationDetails(Publication pub, bool isMaster = false)
 {
     PublicationDetails pubData = new PublicationDetails { Id = pub.Id.ItemId.ToString(CultureInfo.InvariantCulture), Path = pub.PublicationUrl, IsMaster = isMaster};
     if (_localizationConfigurationComponent != null)
     {
         TcmUri localUri = new TcmUri(_localizationConfigurationComponent.Id.ItemId,ItemType.Component,pub.Id.ItemId);
         Component locComp = (Component)Engine.GetObject(localUri);
         if (locComp != null)
         {
             ItemFields fields = new ItemFields(locComp.Content, locComp.Schema);
             foreach (ItemFields field in fields.GetEmbeddedFields("settings"))
             {
                 if (field.GetTextValue("name") == "language")
                 {
                     pubData.Language = field.GetTextValue("value");
                     break;
                 }
             }
         }
     }
     return pubData;
 }
コード例 #6
0
        protected override string Render()
        {
            // Each ItemField derived type has the .HasValue() extension method
            // that can be used to check whether such field has a value.

            ItemFields fields = this.Model.GetFields();

            /* *******************************************************************************
            * TextField, XhtmlField, SingleLineTextField, MultiLineTextField, ExternalLinkField
            * ***************************************************************************** */

            bool hasValue = fields.GetField <TextField>("name").HasValue();

            // Alternatives.

            hasValue = fields.GetTexts("name").Count > 0;
            hasValue = fields.GetText("name") != null;

            /* *******************************************************************************
            * ComponentLinkField, MultimediaLinkField
            * ***************************************************************************** */

            hasValue = fields.GetField <ComponentLinkField>("link").HasValue();

            // Alternatives.

            hasValue = fields.GetComponents("link").Count > 0;
            hasValue = fields.GetComponent("link") != null;

            /* *******************************************************************************
            * EmbeddedSchemaField.
            * ***************************************************************************** */

            hasValue = fields.GetField <EmbeddedSchemaField>("paragraphs").HasValue();

            // Alternatives.

            hasValue = fields.GetEmbeddedFields("paragraphs").Count > 0;
            hasValue = fields.GetEmbeddedField("paragraphs") != null;

            /* *******************************************************************************
            * Accessing DateField.
            * ***************************************************************************** */

            hasValue = fields.GetField <DateField>("publish_date").HasValue();

            // Alternatives.

            hasValue = fields.GetDates("publish_date").Count > 0;
            hasValue = fields.GetDate("publish_date") != DateTime.MinValue;

            /* *******************************************************************************
            * NumberField.
            * ***************************************************************************** */

            hasValue = fields.GetField <NumberField>("age").HasValue();

            // Alternatives.

            hasValue = fields.GetNumbers("age").Count > 0;
            hasValue = fields.GetNumber("age") != double.MinValue;

            /* *******************************************************************************
            * Accessing KeywordField.
            * ***************************************************************************** */

            hasValue = fields.GetField <KeywordField>("tag").HasValue();

            // Alternatives.

            hasValue = fields.GetKeywords("tag").Count > 0;
            hasValue = fields.GetKeyword("tag") != null;

            return(string.Empty);
        }
コード例 #7
0
        protected override string Render()
        {
            // Model is a Component.

            // Get ItemFields from Component. Then access individual fields from the ItemFields object.

            ItemFields fields = this.Model.GetFields();

            // Alternatively, it's possible to access individual fields directly from a
            // Component. This is made possible for cases in which only one field is needed
            // from a Component.

            // In case you need to access more than one fields from a Component you should
            // get the ItemFields (as above) then access the individual fields from the
            // ItemFields object. This will make your code to execute faster.

            string title = this.Model.GetText("title");

            // Below are sample codes for accessing different ItemField types from ItemFields.

            /* *******************************************************************************
            * Accessing TextField, XhtmlField, SingleLineTextField, MultiLineTextField, ExternalLinkField
            * ***************************************************************************** */

            // IMPORTANT NOTE: when a handler for the TridionExtensions.XhtmlResolver delegate
            // is assigned .GetText() will automatically resolve xhtml content from an XhtmlField.
            // See IntranetController how the TridionExtensions.XhtmlResolver is assigned.

            string         text  = fields.GetText("text");
            IList <string> texts = fields.GetTexts("texts");

            text  = fields.GetField <TextField>("text").Value;
            texts = fields.GetField <TextField>("texts").Values;

            /* *******************************************************************************
            * Accessing ComponentLinkField, MultimediaLinkField
            * ***************************************************************************** */

            Component         component  = fields.GetComponent("link");
            IList <Component> components = fields.GetComponents("links");

            // Alternatives.

            component  = fields.GetField <ComponentLinkField>("link").Value;
            components = fields.GetField <ComponentLinkField>("links").Values;

            /* *******************************************************************************
            * Accessing EmbeddedSchemaField.
            * ***************************************************************************** */

            ItemFields         embeddedField  = fields.GetEmbeddedField("paragraphs");
            IList <ItemFields> embeddedFields = fields.GetEmbeddedFields("paragraphs");

            // Alternatives.

            embeddedField  = fields.GetField <EmbeddedSchemaField>("paragraphs").Value;
            embeddedFields = fields.GetField <EmbeddedSchemaField>("paragraphs").Values;

            /* *******************************************************************************
            * Accessing DateField.
            * ***************************************************************************** */

            DateTime         publishDate  = fields.GetDate("publish_date");
            IList <DateTime> publishDates = fields.GetDates("pubish_date");

            // Alternatives.

            publishDate  = fields.GetField <DateField>("publish_date").Value;
            publishDates = fields.GetField <DateField>("publish_date").Values;

            /* *******************************************************************************
            * Accessing NumberField.
            * ***************************************************************************** */

            double         height  = fields.GetNumber("height");
            IList <double> heights = fields.GetNumbers("height");

            // Alternatives.

            height  = fields.GetField <NumberField>("height").Value;
            heights = fields.GetField <NumberField>("height").Values;

            /* *******************************************************************************
            * Accessing KeywordField.
            * ***************************************************************************** */

            Keyword         tag  = fields.GetKeyword("tag");
            IList <Keyword> tags = fields.GetKeywords("tag");

            // Alternatives.

            tag  = fields.GetField <KeywordField>("tag").Value;
            tags = fields.GetField <KeywordField>("tag").Values;

            return(string.Empty);
        }
コード例 #8
0
 protected Dictionary<string, string> ReadComponentData(Component comp)
 {
     Dictionary<string, string> settings = new Dictionary<string, string>();
     if (comp.Content!=null)
     {
         ItemFields fields = new ItemFields(comp.Content, comp.Schema);
         IEnumerable<ItemFields> configFields = fields.GetEmbeddedFields("settings");
         if (configFields.Any())
         {
             //either schema is a generic multival embedded name/value
             foreach (ItemFields setting in configFields)
             {
                 string key = setting.GetTextValue("name");
                 if (!String.IsNullOrEmpty(key) && !settings.ContainsKey(key))
                 {
                     settings.Add(key, setting.GetTextValue("value"));
                 }
                 else
                 {
                     Logger.Warning(String.Format("Duplicate key found: '{0}' when processing component {1}", key, comp.Id));
                 }
             }
         }
         else
         {
             //... or its a custom schema with individual fields
             foreach (ItemField field in fields)
             {
                 //TODO - do we need to be smarter about date/number type fields?
                 string key = field.Name;
                 settings.Add(key, fields.GetSingleFieldValue(key));
             }
         }
     }
     return settings;
 }
コード例 #9
0
        protected Dictionary<string, string> ExtractKeyValuePairs(Component component)
        {
            Dictionary<string, string> keyValuePairs = new Dictionary<string, string>();
            if (component.Content == null)
            {
                return keyValuePairs;
            }

            ItemFields configComponentFields = new ItemFields(component.Content, component.Schema);
            ItemFields[] settingsFieldValues = configComponentFields.GetEmbeddedFields("settings").ToArray();
            if (settingsFieldValues.Any())
            {
                //either schema is a generic multival embedded name/value
                foreach (ItemFields setting in settingsFieldValues)
                {
                    string key = setting.GetTextValue("name");
                    if (!string.IsNullOrEmpty(key) && !keyValuePairs.ContainsKey(key))
                    {
                        keyValuePairs.Add(key, setting.GetTextValue("value"));
                    }
                    else
                    {
                        Logger.Warning(string.Format("Empty or duplicate key found ('{0}') in Component '{1}' ({2})",
                            key, component.Title, component.Id));
                    }
                }
            }
            else
            {
                //... or its a custom schema with individual fields
                foreach (ItemField field in configComponentFields)
                {
                    string key = field.Name;
                    keyValuePairs.Add(key, configComponentFields.GetSingleFieldValue(key));
                }
            }
            return keyValuePairs;
        }