Read() private static method

Returns Global Attributes from cache. If they are not already in cache, they will be read and added to cache
private static Read ( ) : SystemSettings
return SystemSettings
Example #1
0
        /// <summary>
        /// Gets the RockInstanceId for this particular installation.
        /// </summary>
        /// <returns>the Guid of this Rock instance</returns>
        public static Guid GetRockInstanceId()
        {
            var settings       = SystemSettings.Read();
            var attributeCache = settings.Attributes.FirstOrDefault(a => a.Key.Equals(SystemSettingKeys.ROCK_INSTANCE_ID, StringComparison.OrdinalIgnoreCase));

            if (attributeCache != null)
            {
                return(attributeCache.Guid);
            }

            return(new Guid()); // 0000-0000-0000...
        }
Example #2
0
        /// <summary>
        /// Gets the Global Attribute values for the specified key.
        /// </summary>
        /// <param name="key">The key.</param>
        /// <returns></returns>
        public static string GetValue(string key)
        {
            var settings       = SystemSettings.Read();
            var attributeCache = settings.Attributes.FirstOrDefault(a => a.Key.Equals(key, StringComparison.OrdinalIgnoreCase));

            if (attributeCache != null)
            {
                return(attributeCache.DefaultValue);
            }

            return(string.Empty);
        }
Example #3
0
        /// <summary>
        /// Sets the value.
        /// </summary>
        /// <param name="key">The key.</param>
        /// <param name="value">The value.</param>
        public static void SetValue(string key, string value)
        {
            var rockContext      = new Rock.Data.RockContext();
            var attributeService = new AttributeService(rockContext);
            var attribute        = attributeService.GetSystemSetting(key);

            bool isNew = false;

            if (attribute == null)
            {
                attribute             = new Rock.Model.Attribute();
                attribute.FieldTypeId = FieldTypeCache.Read(new Guid(SystemGuid.FieldType.TEXT)).Id;
                attribute.EntityTypeQualifierColumn = Rock.Model.Attribute.SYSTEM_SETTING_QUALIFIER;
                attribute.EntityTypeQualifierValue  = string.Empty;
                attribute.Key          = key;
                attribute.Name         = key.SplitCase();
                attribute.DefaultValue = value;
                attributeService.Add(attribute);
                isNew = true;
            }
            else
            {
                attribute.DefaultValue = value;
            }

            rockContext.SaveChanges();

            AttributeCache.Flush(attribute.Id);
            if (isNew)
            {
                AttributeCache.FlushEntityAttributes();
            }

            var settings       = SystemSettings.Read();
            var attributeCache = settings.Attributes.FirstOrDefault(a => a.Key.Equals(key, StringComparison.OrdinalIgnoreCase));

            if (attributeCache != null)
            {
                attributeCache.DefaultValue = value;
            }
            else
            {
                settings.Attributes.Add(AttributeCache.Read(attribute.Id));
            }
        }