コード例 #1
0
        public override object GetField(Field field, SitecoreFieldConfiguration config, SitecoreDataMappingContext context)
        {
            var sitecoreGalleryField = new LinkField(field);
            var advancedGallery      = new AdvancedImageGalleryField();

            var stringValue = sitecoreGalleryField.Value.IsNullOrEmpty() ? "<gallery />" : sitecoreGalleryField.Value;

            var xml = new XmlDocument();

            xml.LoadXml(stringValue);
            var gallery       = xml.DocumentElement;
            var galleryImages = new List <AdvancedImageField>();

            if (gallery != null && gallery.HasChildNodes)
            {
                foreach (XmlElement galleryChildNode in gallery.ChildNodes)
                {
                    var img = AdvancedImageHelper.ConvertMediaItemToField(galleryChildNode, field.Database);
                    if (img == null)
                    {
                        continue;
                    }

                    galleryImages.Add(img);
                }
            }

            advancedGallery.GalleryItems = galleryImages;
            return(advancedGallery);
        }
        public override object GetField(Field field, SitecoreFieldConfiguration config, SitecoreDataMappingContext context)
        {
            var sitecoreImage = new ImageField(field);
            var defaultImage  = new AdvancedImageField();

            if (sitecoreImage.Value.IsEmptyOrNull())
            {
                return(defaultImage);
            }

            var xml = new XmlDocument();

            xml.LoadXml(sitecoreImage.Value);

            var resultImage = AdvancedImageHelper.ConvertMediaItemToField(xml.DocumentElement, field.Database);

            return(resultImage ?? defaultImage);
        }
コード例 #3
0
ファイル: ImageUrl.cs プロジェクト: Nelsjnjr/Emaarcommunities
        /// <summary>
        /// Computed field for image url
        /// </summary>
        /// <param name="indexable">IIndexable</param>
        /// <returns>object.</returns>
        public object ComputeFieldValue(IIndexable indexable)
        {
            Item item = null;

            try
            {
                item = indexable as SitecoreIndexableItem;
                if (item == null)
                {
                    return(null);
                }
                string formattedTemplateId = SearchHelper.FormatGuid(item.TemplateID.ToString());
                string imageUrl            = string.Empty;
                if (formattedTemplateId.Equals(SearchHelper.FormatGuid(CommonConstants.NewsTemplateID)) ||
                    formattedTemplateId.Equals(SearchHelper.FormatGuid(CommonConstants.ImageItemTemplateID)) ||
                    formattedTemplateId.Equals(SearchHelper.FormatGuid(CommonConstants.VideoItemTemplateID)) ||
                    formattedTemplateId.Equals(SearchHelper.FormatGuid(CommonConstants.DownloadItemTemplateID)))
                {
                    ImageField imageField = item.Fields["Image"];
                    if (SearchHelper.FormatGuid(item.TemplateID.ToString()).Equals(SearchHelper.FormatGuid(CommonConstants.NewsTemplateID)))
                    {
                        imageField = item.Fields["Banner"];
                    }


                    return(AdvancedImageHelper.GetImageFieldUrl(imageField, 0, 0).Replace("/sitecore/shell", ""));;
                }
            }

            catch (Exception ex)
            {
                string itemId = string.Empty;
                if (item != null)
                {
                    itemId = item.ID.ToString();
                }

                Sitecore.Diagnostics.Log.Error(GetType().Name + " - Item ID: " + itemId, ex, this);
            }

            return(null);
        }
コード例 #4
0
        /// <summary>
        /// Computed field for thumbnailimage url
        /// </summary>
        /// <param name="indexable">IIndexable</param>
        /// <returns>object.</returns>
        public object ComputeFieldValue(IIndexable indexable)
        {
            Item item = null;

            try
            {
                item = indexable as SitecoreIndexableItem;
                if (item == null)
                {
                    return(null);
                }
                string formattedTemplateId = SearchHelper.FormatGuid(item.TemplateID.ToString());

                if (formattedTemplateId.Equals(SearchHelper.FormatGuid(CommonConstants.NewsTemplateID)) ||
                    formattedTemplateId.Equals(SearchHelper.FormatGuid(CommonConstants.ImageItemTemplateID)) ||
                    formattedTemplateId.Equals(SearchHelper.FormatGuid(CommonConstants.VideoItemTemplateID)) ||
                    formattedTemplateId.Equals(SearchHelper.FormatGuid(CommonConstants.DownloadItemTemplateID)) ||
                    formattedTemplateId.Equals(SearchHelper.FormatGuid(CommonConstants.ImageAlbumPageTemplateID)) ||
                    formattedTemplateId.Equals(SearchHelper.FormatGuid(CommonConstants.VideoAlbumWithFiltersTemplateID)) ||
                    formattedTemplateId.Equals(SearchHelper.FormatGuid(CommonConstants.VideoAlbumWithoutFiltersTemplateID)))
                {
                    string[]   pixels     = null;
                    ImageField imageField = null;
                    switch (SearchHelper.FormatGuid(item.TemplateID.ToString()))
                    {
                    //For news thumbnail
                    case var templateId when templateId.Equals(SearchHelper.FormatGuid(CommonConstants.NewsTemplateID)):
                        imageField = item.Fields["Banner"];

                        if (imageField.MediaID.IsNull)
                        {
                            imageField = item.Database.GetItem(ID.Parse(CommonConstants.NoImageItemID)).Fields[CommonConstants.Image];
                        }
                        pixels = SitecoreSettings.NewsThumnailPixel.ToLower().Split('x');
                        return(AdvancedImageHelper.GetImageFieldUrl(imageField, System.Convert.ToInt32(pixels[0]), System.Convert.ToInt32(pixels[1])).Replace("/sitecore/shell", ""));

                    //For downloads thumbnail
                    case var templateId when templateId.Equals(SearchHelper.FormatGuid(CommonConstants.DownloadItemTemplateID)):
                        imageField = item.Fields["Image"];

                        if (imageField.MediaID.IsNull)
                        {
                            imageField = item.Database.GetItem(ID.Parse(CommonConstants.NoImageItemID)).Fields[CommonConstants.Image];
                        }
                        pixels = SitecoreSettings.DownloadThumnailPixel.ToLower().Split('x');
                        return(AdvancedImageHelper.GetImageFieldUrl(imageField, System.Convert.ToInt32(pixels[0]), System.Convert.ToInt32(pixels[1])).Replace("/sitecore/shell", ""));

                    //For image and video album thumbnail
                    case var templateId when templateId.Equals(SearchHelper.FormatGuid(CommonConstants.ImageAlbumPageTemplateID)) ||
                        templateId.Equals(SearchHelper.FormatGuid(CommonConstants.VideoAlbumWithFiltersTemplateID)) ||
                        templateId.Equals(SearchHelper.FormatGuid(CommonConstants.VideoAlbumWithoutFiltersTemplateID)):
                        imageField = item.Fields["ThumbnailImage"];

                        if (imageField.MediaID.IsNull)
                        {
                            imageField = item.Database.GetItem(ID.Parse(CommonConstants.NoImageItemID)).Fields[CommonConstants.Image];
                        }
                        pixels = SitecoreSettings.AlbumThumnailPixel.ToLower().Split('x');
                        return(AdvancedImageHelper.GetImageFieldUrl(imageField, System.Convert.ToInt32(pixels[0]), System.Convert.ToInt32(pixels[1])).Replace("/sitecore/shell", ""));

                    // This is for Video item and image item thumbnail
                    default:
                        imageField = item.Fields["Image"];
                        pixels     = SitecoreSettings.AlbumThumnailPixel.ToLower().Split('x');
                        return(AdvancedImageHelper.GetImageFieldUrl(imageField, System.Convert.ToInt32(pixels[0]), System.Convert.ToInt32(pixels[1])).Replace("/sitecore/shell", ""));
                    }
                }
            }

            catch (Exception ex)
            {
                string itemId = string.Empty;
                if (item != null)
                {
                    itemId = item.ID.ToString();
                }

                Sitecore.Diagnostics.Log.Error(GetType().Name + " - Item ID: " + itemId, ex, this);
            }

            return(null);
        }