Пример #1
0
        /// <summary>
        /// Returns Block Type object from cache.  If block does not already exist in cache, it
        /// will be read and added to cache
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public static BlockTypeCache Read(int id)
        {
            string cacheKey = BlockTypeCache.CacheKey(id);

            ObjectCache    cache     = MemoryCache.Default;
            BlockTypeCache blockType = cache[cacheKey] as BlockTypeCache;

            if (blockType != null)
            {
                return(blockType);
            }
            else
            {
                Rock.Model.BlockTypeService blockTypeService = new Model.BlockTypeService();
                Rock.Model.BlockType        blockTypeModel   = blockTypeService.Get(id);
                if (blockTypeModel != null)
                {
                    blockType = new BlockTypeCache(blockTypeModel);

                    blockType.IsInstancePropertiesVerified = false;

                    blockTypeModel.LoadAttributes();

                    blockType.AttributeValues = blockTypeModel.AttributeValues;

                    if (blockTypeModel.Attributes != null)
                    {
                        foreach (var attribute in blockTypeModel.Attributes)
                        {
                            blockType.AttributeIds.Add(attribute.Value.Id);
                        }
                    }

                    // Block Type cache expiration monitors the actual block on the file system so that it is flushed from
                    // memory anytime the file contents change.  This is to force the cmsPage object to revalidate any
                    // BlockPropery attributes that may have been added or modified
                    string        physicalPath = System.Web.HttpContext.Current.Request.MapPath(blockType.Path);
                    List <string> filePaths    = new List <string>();
                    filePaths.Add(physicalPath);
                    filePaths.Add(physicalPath + ".cs");

                    CacheItemPolicy cacheItemPolicy = new CacheItemPolicy();
                    cacheItemPolicy.ChangeMonitors.Add(new HostFileChangeMonitor(filePaths));
                    cache.Set(cacheKey, blockType, cacheItemPolicy);

                    return(blockType);
                }
                else
                {
                    return(null);
                }
            }
        }
Пример #2
0
        /// <summary>
        /// Saves the attribute values.
        /// </summary>
        /// <param name="personId">The person id.</param>
        public void SaveAttributeValues(int?personId)
        {
            Rock.Model.BlockTypeService blockTypeService = new Model.BlockTypeService();
            Rock.Model.BlockType        blockTypeModel   = blockTypeService.Get(this.Id);

            if (blockTypeModel != null)
            {
                blockTypeModel.LoadAttributes();
                foreach (var attribute in blockTypeModel.Attributes)
                {
                    Rock.Attribute.Helper.SaveAttributeValues(blockTypeModel, attribute.Value, this.AttributeValues[attribute.Key], personId);
                }
            }
        }