Exemple #1
0
        public string GetCVLValue(string cvlId, object key)
        {
            if (key == null)
            {
                return(string.Empty);
            }

            CVLValue cv = CVLValues.FirstOrDefault(cvl => cvl.CVLId.Equals(cvlId) && cvl.Key.Equals(key));

            if (cv == null)
            {
                return(string.Empty);
            }

            return(cv.Value.ToString());
        }
Exemple #2
0
        public List <XElement> GetCVLValues(Field field, Configuration configuration)
        {
            List <XElement> elemets = new List <XElement>();

            if (field == null || field.IsEmpty())
            {
                if (field != null)
                {
                    CVL cvl = CvLs.FirstOrDefault(c => c.Id.Equals(field.FieldType.CVLId));
                    if (cvl == null)
                    {
                        return(elemets);
                    }

                    if (cvl.DataType == DataType.LocaleString)
                    {
                        Dictionary <string, XElement> valuesPerLanguage = new Dictionary <string, XElement>
                        {
                            {
                                configuration.ChannelDefaultLanguage.Name,
                                new XElement("Data", new XAttribute("language", configuration.ChannelDefaultLanguage.Name.ToLower()))
                            }
                        };
                        if (!configuration.ActiveCVLDataMode.Equals(CVLDataMode.Keys))
                        {
                            foreach (KeyValuePair <CultureInfo, CultureInfo> keyValuePair in configuration.LanguageMapping)
                            {
                                if (!valuesPerLanguage.ContainsKey(keyValuePair.Key.Name))
                                {
                                    valuesPerLanguage.Add(
                                        keyValuePair.Key.Name,
                                        new XElement("Data", new XAttribute("language", keyValuePair.Key.Name.ToLower())));
                                }
                            }

                            if (valuesPerLanguage.Count > 0)
                            {
                                foreach (string key in valuesPerLanguage.Keys)
                                {
                                    elemets.Add(valuesPerLanguage[key]);
                                }
                            }
                        }
                    }
                    else
                    {
                        XElement dataElement = new XElement(
                            "Data",
                            new XAttribute("language", configuration.ChannelDefaultLanguage.Name.ToLower()));

                        elemets.Add(dataElement);
                    }
                }

                return(elemets);
            }

            if (configuration.ActiveCVLDataMode.Equals(CVLDataMode.Keys) ||
                (field.FieldType.Settings.ContainsKey("EPiMetaFieldName") && field.FieldType.Settings["EPiMetaFieldName"].Equals("_ExcludedCatalogEntryMarkets")))
            {
                XElement dataElement = new XElement(
                    "Data",
                    new XAttribute("language", configuration.ChannelDefaultLanguage.Name.ToLower()));
                if (field.FieldType.Multivalue)
                {
                    foreach (string cvlKey in field.Data.ToString().Split(';'))
                    {
                        dataElement.Add(new XElement("Item", new XAttribute("value", cvlKey)));
                    }
                }
                else
                {
                    dataElement.Add(new XAttribute("value", field.Data));
                }

                elemets.Add(dataElement);
            }
            else
            {
                CVL cvl = CvLs.FirstOrDefault(c => c.Id.Equals(field.FieldType.CVLId));
                if (cvl == null)
                {
                    return(elemets);
                }

                string[] keys = field.FieldType.Multivalue
                                    ? field.Data.ToString().Split(';')
                                    : new[] { field.Data.ToString() };

                Dictionary <string, XElement> valuesPerLanguage = new Dictionary <string, XElement>
                {
                    {
                        configuration.ChannelDefaultLanguage.Name,
                        new XElement("Data", new XAttribute("language", configuration.ChannelDefaultLanguage.Name.ToLower()))
                    }
                };

                foreach (string key in keys)
                {
                    CVLValue cvlValue = CVLValues.FirstOrDefault(cv => cv.CVLId.Equals(cvl.Id) && cv.Key.Equals(key));
                    if (cvlValue == null || cvlValue.Value == null)
                    {
                        continue;
                    }

                    if (cvl.DataType.Equals(DataType.LocaleString))
                    {
                        LocaleString ls = (LocaleString)cvlValue.Value;
                        foreach (KeyValuePair <CultureInfo, CultureInfo> keyValuePair in configuration.LanguageMapping)
                        {
                            if (!valuesPerLanguage.ContainsKey(keyValuePair.Key.Name))
                            {
                                valuesPerLanguage.Add(
                                    keyValuePair.Key.Name,
                                    new XElement("Data", new XAttribute("language", keyValuePair.Key.Name.ToLower())));
                            }

                            string value = ls[keyValuePair.Value];
                            if (configuration.ActiveCVLDataMode.Equals(CVLDataMode.KeysAndValues))
                            {
                                value = key + Configuration.CVLKeyDelimiter + value;
                            }

                            // MultiValue uses <Item> elements, SingleValue stores the value in the <Data> element.
                            if (field.FieldType.Multivalue)
                            {
                                valuesPerLanguage[keyValuePair.Key.Name].Add(
                                    new XElement("Item", new XAttribute("value", value)));
                            }
                            else
                            {
                                valuesPerLanguage[keyValuePair.Key.Name].Add(new XAttribute("value", value));
                            }
                        }
                    }
                    else
                    {
                        string value = cvlValue.Value.ToString();
                        if (configuration.ActiveCVLDataMode.Equals(CVLDataMode.KeysAndValues))
                        {
                            value = key + Configuration.CVLKeyDelimiter + value;
                        }

                        // MultiValue uses <Item> elements, SingleValue stores the value in the <Data> element.
                        if (field.FieldType.Multivalue)
                        {
                            valuesPerLanguage[configuration.ChannelDefaultLanguage.Name].Add(
                                new XElement("Item", new XAttribute("value", value)));
                        }
                        else
                        {
                            valuesPerLanguage[configuration.ChannelDefaultLanguage.Name].Add(new XAttribute("value", value));
                        }
                    }
                }

                if (valuesPerLanguage.Count > 0)
                {
                    foreach (string key in valuesPerLanguage.Keys)
                    {
                        elemets.Add(valuesPerLanguage[key]);
                    }
                }
            }

            return(elemets);
        }