Exemplo n.º 1
0
        /// <summary>
        /// Returns Attribute object from cache.  If attribute does not already exist in cache, it
        /// will be read and added to cache
        /// </summary>
        /// <param name="id">The id of the Attribute to read</param>
        /// <returns></returns>
        public static AttributeCache Read(int id)
        {
            string cacheKey = AttributeCache.CacheKey(id);

            ObjectCache    cache     = MemoryCache.Default;
            AttributeCache attribute = cache[cacheKey] as AttributeCache;

            if (attribute != null)
            {
                return(attribute);
            }
            else
            {
                Rock.Model.AttributeService attributeService = new Rock.Model.AttributeService();
                Rock.Model.Attribute        attributeModel   = attributeService.Get(id);
                if (attributeModel != null)
                {
                    attribute = AttributeCache.CopyModel(attributeModel);

                    cache.Set(cacheKey, attribute, new CacheItemPolicy());

                    return(attribute);
                }
                else
                {
                    return(null);
                }
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// Adds Attribute model to cache, and returns cached object.
        /// </summary>
        /// <param name="attributeModel">The attribute model.</param>
        /// <param name="qualifiers">The qualifiers.</param>
        /// <returns></returns>
        public static AttributeCache Read(Rock.Model.Attribute attributeModel, Dictionary <string, string> qualifiers)
        {
            AttributeCache attribute = AttributeCache.CopyModel(attributeModel, qualifiers);

            string      cacheKey = AttributeCache.CacheKey(attributeModel.Id);
            ObjectCache cache    = MemoryCache.Default;

            cache.Set(cacheKey, attribute, new CacheItemPolicy());

            return(attribute);
        }
Exemplo n.º 3
0
        private static AttributeCache CopyModel(Rock.Model.Attribute attributeModel, Dictionary <string, string> qualifiers)
        {
            var attribute = new AttributeCache(attributeModel);

            attribute.QualifierValues = new Dictionary <string, ConfigurationValue>();
            foreach (var qualifier in qualifiers)
            {
                attribute.QualifierValues.Add(qualifier.Key, new ConfigurationValue(qualifier.Value));
            }

            return(attribute);
        }
Exemplo n.º 4
0
        /// <summary>
        /// Copies the properties of a <see cref="Rock.Model.Attribute"/> object to a <see cref="AttributeCache"/> object/>
        /// </summary>
        /// <param name="attributeModel">The attribute model.</param>
        /// <returns></returns>
        public static AttributeCache CopyModel(Rock.Model.Attribute attributeModel)
        {
            var qualifiers = new Dictionary <string, string>();

            if (attributeModel.AttributeQualifiers != null)
            {
                foreach (Rock.Model.AttributeQualifier qualifier in attributeModel.AttributeQualifiers)
                {
                    qualifiers.Add(qualifier.Key, qualifier.Value);
                }
            }

            return(CopyModel(attributeModel, qualifiers));
        }
Exemplo n.º 5
0
        public static AttributeField GetAttributeFieldForEntityAttribute(Rock.Model.Attribute attribute)
        {
            AttributeField boundField = new AttributeField();

            boundField.DataField      = attribute.Key;
            boundField.HeaderText     = attribute.Name;
            boundField.SortExpression = string.Empty;

            var attributeCache = Rock.Web.Cache.AttributeCache.Read(attribute.Id);

            //if ( attributeCache != null )
            //          {
            boundField.ItemStyle.HorizontalAlign = attributeCache.FieldType.Field.AlignValue;
            //        }

            return(boundField);
        }
Exemplo n.º 6
0
        /// <summary>
        /// Adds Attribute model to cache, and returns cached object
        /// </summary>
        /// <param name="attributeModel">The attributeModel to cache</param>
        /// <returns></returns>
        public static AttributeCache Read(Rock.Model.Attribute attributeModel)
        {
            string cacheKey = AttributeCache.CacheKey(attributeModel.Id);

            ObjectCache    cache     = MemoryCache.Default;
            AttributeCache attribute = cache[cacheKey] as AttributeCache;

            if (attribute != null)
            {
                return(attribute);
            }
            else
            {
                attribute = AttributeCache.CopyModel(attributeModel);
                cache.Set(cacheKey, attribute, new CacheItemPolicy());

                return(attribute);
            }
        }
Exemplo n.º 7
0
 /// <summary>
 /// Updates the <see cref="EntityAttributesCache" /> based on the attribute and entityState
 /// </summary>
 /// <param name="attribute">The attribute.</param>
 /// <param name="entityState">State of the entity.</param>
 internal static void UpdateCacheEntityAttributes(Rock.Model.Attribute attribute, EntityState entityState)
 {
     EntityAttributesCache.UpdateCacheEntityAttributes(attribute, entityState);
 }
Exemplo n.º 8
0
 public static AttributeCache Read(Rock.Model.Attribute attributeModel, Dictionary <string, string> qualifiers)
 {
     return(Get(attributeModel, qualifiers));
 }
Exemplo n.º 9
0
 public void CopyFromModel(Rock.Model.Attribute attribute, Dictionary <string, string> qualifiers)
 {
     this.SetFromEntity(attribute, qualifiers);
 }
Exemplo n.º 10
0
        /// <summary>
        /// Gets the public editable attribute view model. This contains all the
        /// information required for the individual to make changes to the attribute.
        /// </summary>
        /// <remarks>This is for editing the attribute itself, not the attribute value.</remarks>
        /// <param name="attribute">The attribute that will be represented.</param>
        /// <returns>A <see cref="PublicEditableAttributeViewModel"/> that represents the attribute.</returns>
        internal static PublicEditableAttributeViewModel GetPublicEditableAttributeViewModel(Rock.Model.Attribute attribute)
        {
            var fieldTypeCache      = FieldTypeCache.Get(attribute.FieldTypeId);
            var configurationValues = attribute.AttributeQualifiers.ToDictionary(q => q.Key, q => q.Value);

            return(new PublicEditableAttributeViewModel
            {
                Guid = attribute.Guid,
                Name = attribute.Name,
                Key = attribute.Key,
                AbbreviatedName = attribute.AbbreviatedName,
                Description = attribute.Description,
                IsActive = attribute.IsActive,
                IsAnalytic = attribute.IsAnalytic,
                IsAnalyticHistory = attribute.IsAnalyticHistory,
                PreHtml = attribute.PreHtml,
                PostHtml = attribute.PostHtml,
                IsAllowSearch = attribute.AllowSearch,
                IsEnableHistory = attribute.EnableHistory,
                IsIndexEnabled = attribute.IsIndexEnabled,
                IsPublic = attribute.IsPublic,
                IsRequired = attribute.IsRequired,
                IsSystem = attribute.IsSystem,
                IsShowInGrid = attribute.IsGridColumn,
                IsShowOnBulk = attribute.ShowOnBulk,
                FieldTypeGuid = fieldTypeCache.Guid,
                Categories = attribute.Categories
                             .Select(c => new ListItemViewModel
                {
                    Value = c.Guid.ToString(),
                    Text = c.Name
                })
                             .ToList(),
                ConfigurationValues = fieldTypeCache.Field?.GetPublicConfigurationValues(configurationValues, Field.ConfigurationValueUsage.Configure, null) ?? new Dictionary <string, string>(),
                DefaultValue = fieldTypeCache.Field?.GetPublicEditValue(attribute.DefaultValue, configurationValues) ?? string.Empty
            });
        }
Exemplo n.º 11
0
 private AttributeCache(Rock.Model.Attribute model) : base(model)
 {
 }