示例#1
0
        private MetaDataProperty GetProperty(string name, CultureInfo culture, bool ensureExist)
        {
            MetaDataPropertyDefinition propertyDefinition = GetPropertyDefinition(name);

            if (propertyDefinition == null)
            {
                throw new CmsException("MetaData property '" + name + "' does not exist.");
            }

            MetaDataProperty property;

            if (propertyDefinition.IsLocalized)
            {
                CultureInfo cul = LocalizationManager.CurrentContentCulture;
                if (cul.Name.ToString() == "sr")
                {
                    CultureInfo cult = new CultureInfo("sr-Cyrl-CS");
                    culture = cult;
                }
                else
                {
                    if (culture == null)
                    {
                        culture = LocalizationManager.CurrentContentCulture; //Sauti.FrameCore.Localization.CurrentContentCulture;
                    }
                }


                property = Properties
                           .SingleOrDefault(x => x.Name.Equals(name, StringComparison.OrdinalIgnoreCase) &&
                                            x.CultureID.Equals(culture.LCID));
            }
            else
            {
                if (culture == null)
                {
                    culture = CultureInfo.InvariantCulture;
                }

                property = Properties.FirstOrDefault(x => x.Name.Equals(name, StringComparison.OrdinalIgnoreCase));

                // HACK: Preserves backward compatibility with old databases,
                // and forces non-localized properties to have invariant culture id (0).
                if (property != null && property.CultureID != culture.LCID)
                {
                    property.CultureID = culture.LCID;
                }
            }

            if (property == null && ensureExist)
            {
                property = new MetaDataProperty {
                    CultureID = culture.LCID, Name = name
                };
                Properties.Add(property);
            }

            return(property);
        }
示例#2
0
        /// <summary>
        /// Gets the strongly typed value of the metadata property with the given name and culture.
        /// </summary>
        /// <typeparam name="T">Type of the value to retrieve.</typeparam>
        /// <param name="name">Name of the property to retrieve the value for.</param>
        /// <param name="culture">Culture version to retrieve.</param>
        /// <returns>A metadata property value.</returns>
        public virtual T GetValueCulture <T>(string name, CultureInfo culture)
        {
            MetaDataProperty property = GetProperty(name, culture, true);

            return(property == null
                       ? default(T)
                       : ObjectBuilder.BuildObjectValue(property.Value, default(T)));
        }
示例#3
0
        /// <summary>
        /// Gets the strongly typed value of the metadata property with the given name and culture.
        /// </summary>
        /// <typeparam name="T">Type of the value to retrieve.</typeparam>
        /// <param name="name">Name of the property to retrieve the value for.</param>
        /// <param name="culture">Culture version to retrieve.</param>
        /// <returns>A metadata property value.</returns>
        public virtual T GetValue <T>(string name, CultureInfo culture = null)
        {
            //if (culture = "sr")
            //    culture = "sr-Cyrl-CS";
            MetaDataProperty property = GetProperty(name, culture, true);

            return(property == null
                       ? default(T)
                       : ObjectBuilder.BuildObjectValue(property.Value, default(T)));
        }
示例#4
0
        public virtual void SetValueNull <T>(string name, T value, CultureInfo culture = null)
        {
            if (!IsPropertyDefined(name))
            {
                throw new Exception(String.Format(
                                        "Type '{0}' does not contains definition for name '{1}'", _type, name));
            }

            MetaDataProperty property = GetProperty(name, culture, true);
            object           oldValue = property.Value;
            var newValue = ObjectBuilder.BuildObjectValue <T>(value);

            property.Value = newValue;

            // ReSharper disable CompareNonConstrainedGenericWithNull
            bool changed = oldValue == null
                               ? newValue != null
                               : !oldValue.Equals(newValue);

            // ReSharper restore CompareNonConstrainedGenericWithNull

            IsChanged = IsChanged || changed;
        }