GetUmbracoHelper() public static méthode

Gets an UmbracoHelper.
public static GetUmbracoHelper ( ) : UmbracoHelper
Résultat UmbracoHelper
Exemple #1
0
        /// <summary>
        /// Converts the given object to the type of this converter, using the specified context and culture information.
        /// </summary>
        /// <param name="context">An <see cref="T:System.ComponentModel.ITypeDescriptorContext" /> that provides a format context.</param>
        /// <param name="culture">The <see cref="T:System.Globalization.CultureInfo" /> to use as the current culture.</param>
        /// <param name="value">The <see cref="T:System.Object" /> to convert.</param>
        /// <returns>
        /// An <see cref="T:System.Object" /> that represents the converted value.
        /// </returns>
        public override object ConvertFrom(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value)
        {
            if (value != null)
            {
                int mediaId;
                if (int.TryParse(value.ToString(), out mediaId))
                {
                    if (mediaId > 0)
                    {
                        UmbracoHelper umbracoHelper = ConverterHelper.GetUmbracoHelper();

                        IPublishedContent media = umbracoHelper.TypedMedia(mediaId);

                        if (media != null)
                        {
                            return(media.Url);
                        }

                        IMediaService mediaService = ConverterHelper.GetMediaService();
                        IMedia        media2       = mediaService.GetById(mediaId);

                        if (media2 != null)
                        {
                            return(media2.GetValue("umbracoFile"));
                        }
                    }
                }
            }

            // Always call base, even if you can't convert.
            return(base.ConvertFrom(context, culture, value));
        }
Exemple #2
0
        /// <summary>
        /// Converts the given object to the type of this converter, using the specified context and culture information.
        /// </summary>
        /// <param name="context">An <see cref="T:System.ComponentModel.ITypeDescriptorContext" /> that provides a format context.</param>
        /// <param name="culture">The <see cref="T:System.Globalization.CultureInfo" /> to use as the current culture.</param>
        /// <param name="value">The <see cref="T:System.Object" /> to convert.</param>
        /// <returns>
        /// An <see cref="T:System.Object" /> that represents the converted value.
        /// </returns>
        public override object ConvertFrom(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value)
        {
            if (value != null)
            {
                string[] mediaIdArray  = value.ToString().Split(',');
                string[] mediaUrlArray = new string[mediaIdArray.Length];

                for (int i = 0; i < mediaIdArray.Length; i++)
                {
                    int mediaId;

                    if (int.TryParse(mediaIdArray[i], out mediaId))
                    {
                        if (mediaId > 0)
                        {
                            UmbracoHelper     umbracoHelper = ConverterHelper.GetUmbracoHelper();
                            IPublishedContent media         = umbracoHelper.TypedMedia(mediaId);
                            mediaUrlArray[i] = media.Url;
                        }
                    }
                }

                return(mediaUrlArray);
            }

            // Always call base, even if you can't convert.
            return(base.ConvertFrom(context, culture, null));
        }