public override void SetValue(global::Sitecore.Data.Items.Item item, object value, ISitecoreService service)
        {
            Image img = value as Image;

            Field itemField = base.GetField(item);

            if (itemField == null)
            {
                return;
            }

            ImageField scImg = new ImageField(itemField);

            if (img == null)
            {
                scImg.Clear();
                return;
            }

            if (scImg.MediaID.Guid != img.MediaId)
            {
                //this only handles empty guids, but do we need to remove the link before adding a new one?
                if (img.MediaId == Guid.Empty)
                {
                    ItemLink link = new ItemLink(item.Database.Name, item.ID, scImg.InnerField.ID, scImg.MediaItem.Database.Name, scImg.MediaID, scImg.MediaPath);
                    scImg.RemoveLink(link);
                }
                else
                {
                    ID   newId  = new ID(img.MediaId);
                    Item target = item.Database.GetItem(newId);
                    if (target != null)
                    {
                        scImg.MediaID = newId;
                        ItemLink link = new ItemLink(item.Database.Name, item.ID, scImg.InnerField.ID, target.Database.Name, target.ID, target.Paths.FullPath);
                        scImg.UpdateLink(link);
                    }
                    else
                    {
                        throw new MapperException("No item with ID {0}. Can not update Media Item field".Formatted(newId));
                    }
                }
            }

            scImg.Height = img.Height.ToString();
            scImg.Width  = img.Width.ToString();
            scImg.HSpace = img.HSpace.ToString();
            scImg.VSpace = img.VSpace.ToString();
            scImg.Alt    = img.Alt;
            scImg.Border = img.Border;
            scImg.Class  = img.Class;
        }
        public override void SetValue( global::Sitecore.Data.Items.Item item, object value,  ISitecoreService service)
        {

            Image img = value as Image;

            Field itemField = base.GetField(item);

            if (itemField == null) return;

            ImageField scImg = new ImageField(itemField);

            if (img == null)
            {
                scImg.Clear();
                return;
            }

            if (scImg.MediaID.Guid != img.MediaId)
            {
                //this only handles empty guids, but do we need to remove the link before adding a new one?
                if (img.MediaId == Guid.Empty)
                {
                    ItemLink link = new ItemLink(item.Database.Name, item.ID, scImg.InnerField.ID, scImg.MediaItem.Database.Name, scImg.MediaID, scImg.MediaPath);
                    scImg.RemoveLink(link);
                }
                else
                {
                    ID newId = new ID(img.MediaId);
                    Item target = item.Database.GetItem(newId);
                    if (target != null)
                    {
                        scImg.MediaID = newId;
                        ItemLink link = new ItemLink(item.Database.Name, item.ID, scImg.InnerField.ID, target.Database.Name, target.ID, target.Paths.FullPath);
                        scImg.UpdateLink(link);
                    }
                    else throw new MapperException("No item with ID {0}. Can not update Media Item field".Formatted(newId));
                }
            }

            scImg.Height = img.Height.ToString();
            scImg.Width = img.Width.ToString();
            scImg.HSpace = img.HSpace.ToString();
            scImg.VSpace = img.VSpace.ToString();
            scImg.Alt = img.Alt;
            scImg.Border = img.Border;
            scImg.Class = img.Class;
          
           

        }
Ejemplo n.º 3
0
        public static bool AttachImageToItem(BaseDataMap map, object importRow, Item newItem, string newItemField, MediaItem imageItem, ref LevelLogger logger, string height = null, string width = null)
        {
            var attachImageLogger = logger.CreateLevelLogger();

            if (imageItem != null)
            {
                if (string.IsNullOrEmpty(newItemField))
                {
                    {
                        attachImageLogger.AddError(NewItemFieldIsNotDefinedForMediaitem, String.Format("NewItemField is not defined for mediaitem: {0}.",
                                                                                                       map.GetImportRowDebugInfo(importRow)));
                        return(false);
                    }
                }
                if (!newItem.Editing.IsEditing)
                {
                    newItem.Editing.BeginEdit();
                }
                ImageField imageField = newItem.Fields[newItemField];
                if (imageField.MediaID != imageItem.ID)
                {
                    imageField.Clear();
                    imageField.MediaID = imageItem.ID;
                    if (!String.IsNullOrEmpty(height))
                    {
                        imageField.Height = height;
                    }
                    if (!String.IsNullOrEmpty(width))
                    {
                        imageField.Width = width;
                    }

                    if (!String.IsNullOrEmpty(imageItem.Alt))
                    {
                        imageField.Alt = imageItem.Alt;
                    }
                    else
                    {
                        imageField.Alt = imageItem.DisplayName;
                    }
                    return(true);
                }
            }
            return(false);
        }
Ejemplo n.º 4
0
        public static void MapToField(ImageField field, Image image, Item item)
        {
            if (image == null)
            {
                field.Clear();
                return;
            }

            if (field.MediaID.Guid != image.MediaId)
            {
                //this only handles empty guids, but do we need to remove the link before adding a new one?
                if (image.MediaId == Guid.Empty)
                {
                    ItemLink link = new ItemLink(item.Database.Name, item.ID, field.InnerField.ID, field.MediaItem.Database.Name, field.MediaID, field.MediaItem.Paths.Path);
                    field.RemoveLink(link);
                }
                else
                {
                    ID   newId  = new ID(image.MediaId);
                    Item target = item.Database.GetItem(newId);
                    if (target != null)
                    {
                        field.MediaID = newId;
                        ItemLink link = new ItemLink(item.Database.Name, item.ID, field.InnerField.ID, target.Database.Name, target.ID, target.Paths.FullPath);
                        field.UpdateLink(link);
                    }
                    else
                    {
                        throw new MapperException("No item with ID {0}. Can not update Media Item field".Formatted(newId));
                    }
                }
            }

            field.Height = image.Height.ToString();
            field.Width  = image.Width.ToString();
            field.HSpace = image.HSpace.ToString();
            field.VSpace = image.VSpace.ToString();
            field.Alt    = image.Alt;
            field.Border = image.Border;
            field.Class  = image.Class;
        }
        public static void MapToField(ImageField field, Image image, Item item)
        {
            if (image == null)
            {
                field.Clear();
                return;
            }

            if (field.MediaID.Guid != image.MediaId)
            {
                //this only handles empty guids, but do we need to remove the link before adding a new one?
                if (image.MediaId == Guid.Empty)
                {
                    ItemLink link = new ItemLink(item.Database.Name, item.ID, field.InnerField.ID, field.MediaItem.Database.Name, field.MediaID, field.MediaItem.Paths.Path);
                    field.RemoveLink(link);
                }
                else
                {
                    ID newId = new ID(image.MediaId);
                    Item target = item.Database.GetItem(newId);
                    if (target != null)
                    {
                        field.MediaID = newId;
                        ItemLink link = new ItemLink(item.Database.Name, item.ID, field.InnerField.ID, target.Database.Name, target.ID, target.Paths.FullPath);
                        field.UpdateLink(link);

                    }
                    else throw new MapperException("No item with ID {0}. Can not update Media Item field".Formatted(newId));
                }
            }

            if (image.Height > 0)
                field.Height = image.Height.ToString();
            if (image.Width > 0)
                field.Width = image.Width.ToString();
            if (image.HSpace > 0)
                field.HSpace = image.HSpace.ToString();
            if (image.VSpace > 0)
                field.VSpace = image.VSpace.ToString();

            if (field.Alt.IsNotNullOrEmpty() || image.Alt.IsNotNullOrEmpty())
                field.Alt = image.Alt ?? string.Empty;
            if (field.Border.IsNotNullOrEmpty() || image.Border.IsNotNullOrEmpty())
                field.Border = image.Border ?? string.Empty;
            if (field.Class.IsNotNullOrEmpty() || image.Class.IsNotNullOrEmpty())
                field.Class = image.Class ?? string.Empty;
        }
Ejemplo n.º 6
0
 public void EditImageField(string imagepath)
 {
     ImageField.Clear();
     ImageField.SendKeys(imagepath);
 }