/// <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); } } }
/// <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); }
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); }
/// <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)); }
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); }
/// <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); } }
/// <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); }
public static AttributeCache Read(Rock.Model.Attribute attributeModel, Dictionary <string, string> qualifiers) { return(Get(attributeModel, qualifiers)); }
public void CopyFromModel(Rock.Model.Attribute attribute, Dictionary <string, string> qualifiers) { this.SetFromEntity(attribute, qualifiers); }
/// <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 }); }
private AttributeCache(Rock.Model.Attribute model) : base(model) { }