/// <summary>
        /// Loads the content from Umbraco in the same way MCMS would have loaded it from its node cache.
        /// </summary>
        private void LoadContentFromUmbraco()
        {
            if (String.IsNullOrWhiteSpace(this.PlaceholderToBind))
            {
                return;
            }
            if (UmbracoContext.Current == null || !UmbracoContext.Current.PageId.HasValue)
            {
                return;
            }

            var content = UmbracoContext.Current.ContentCache.GetById(UmbracoContext.Current.PageId.Value);

            if (content == null)
            {
                return;
            }

            // Code from http://shazwazza.com/post/ultra-fast-media-performance-in-umbraco/

            // Unfortunately this hits the database, but the usual approach of content.GetPropertyValue<IPublishedContent>(property alias)
            // doesn't return the extra Description field. The next recommendation is using Examine but we know that doesn't work reliably on Azure.
            var mediaPicker = content.Properties.Single(prop => prop.PropertyTypeAlias == this.PlaceholderToBind + "_Content");

            if (mediaPicker != null && !String.IsNullOrEmpty(mediaPicker.DataValue.ToString()))
            {
                var media = umbraco.library.GetMedia(Int32.Parse(mediaPicker.DataValue.ToString(), CultureInfo.InvariantCulture), false);
                if (media != null && media.Current != null)
                {
                    media.MoveNext();
                    _value = new MediaValues(media.Current);
                }
            }
        }
示例#2
0
 /// <summary>
 /// Get the size (in kilobytes) of an item in the Resource Gallery
 /// </summary>
 /// <param name="res">The resource to return the size of</param>
 /// <returns>string with the size in kilobytes followed by a lowercase k, eg 123k</returns>
 public static string GetResourceFileSize(MediaValues res)
 {
     return(MediaHelper.GetFileSizeInKilobytes(res));
 }