Esempio n. 1
0
        public bool SetThumbnailReference(Image thumbnailImage)
        {
            // if image is already set either as reference or binarydata, do nothing
            if (this.ImageMode != ImageRequestMode.None)
            {
                return(false);
            }

            var data = new ImageFieldData(this, thumbnailImage, null);

            this.SetData(data);
            return(true);
        }
Esempio n. 2
0
        protected override object[] ConvertFrom(object value)
        {
            _data = value as ImageFieldData;

            var data = value as ImageFieldData;
            if (data == null)
                throw new NotSupportedException("Field value is null or not a ImageFieldData. FieldName: " + this.Name);

            object[] result = new object[2];

            result[0] = data.ImgRef == null ? new List<Node>() : new List<Node>() { data.ImgRef };
            result[1] = data.ImgData == null ? new BinaryData() : data.ImgData;

            return result;
        }
Esempio n. 3
0
 public static ImageRequestMode GetImageMode(ImageFieldData data)
 {
     if (data != null && data.ImgData != null && !data.ImgData.IsEmpty && data.ImgData.Size > 0)
     {
         return(ImageRequestMode.BinaryData);
     }
     else
     {
         if (data != null && data.ImgRef != null)
         {
             return(ImageRequestMode.Reference);
         }
         else
         {
             return(ImageRequestMode.None);
         }
     }
 }
Esempio n. 4
0
        protected override object ConvertTo(object[] handlerValues)
        {
            var result = new ImageFieldData();

            if (handlerValues[0] != null)
            {
                var nodeList = handlerValues[0] as IEnumerable<Node>;
                if (nodeList != null)
                {
                    result.ImgRef = nodeList.FirstOrDefault() as Image;
                }
            }

            if (handlerValues[1] != null)
                result.ImgData = handlerValues[1] as BinaryData;

            _data = result;
            return result;
        }
Esempio n. 5
0
        public static string GetImageUrl(ImageRequestMode imageMode, ImageFieldData data, int contentId, string binaryPropertyName)
        {
            var imageUrl = string.Empty;

            switch (imageMode)
            {
            case ImageRequestMode.Reference:
                imageUrl = data.ImgRef.Path;
                break;

            case ImageRequestMode.BinaryData:
                if (contentId > 0)
                {
                    imageUrl = BinaryField.GetBinaryUrl(contentId, binaryPropertyName, data.ImgData.Timestamp);
                }
                break;
            }

            return(imageUrl);
        }
Esempio n. 6
0
        protected override object ConvertTo(object[] handlerValues)
        {
            var result = new ImageFieldData(this);

            if (handlerValues[0] != null)
            {
                var nodeList = handlerValues[0] as IEnumerable <Node>;
                if (nodeList != null)
                {
                    result.ImgRef = nodeList.FirstOrDefault() as Image;
                }
            }

            if (handlerValues[1] != null)
            {
                result.ImgData = handlerValues[1] as BinaryData;
            }

            _data = result;
            return(result);
        }
Esempio n. 7
0
        protected override object[] ConvertFrom(object value)
        {
            _data = value as ImageFieldData;

            var data = value as ImageFieldData;

            if (data == null)
            {
                throw new NotSupportedException("Field value is null or not a ImageFieldData. FieldName: " + this.Name);
            }

            object[] result = new object[2];

            result[0] = data.ImgRef == null ? new List <Node>() : new List <Node>()
            {
                data.ImgRef
            };
            result[1] = data.ImgData == null ? new BinaryData() : data.ImgData;

            return(result);
        }
Esempio n. 8
0
        public static string GetImageUrl(ImageRequestMode imageMode, ImageFieldData data, int contentId, string binaryPropertyName)
        {
            var imageUrl = string.Empty;

            switch (imageMode)
            {
            case ImageRequestMode.Reference:
                imageUrl = data.ImgRef.Path;
                break;

            case ImageRequestMode.BinaryData:
                if (contentId > 0)
                {
                    imageUrl = string.Format("/binaryhandler.ashx?nodeid={0}&propertyname={1}&checksum={2}", contentId, binaryPropertyName, HttpUtility.UrlEncode(data.ImgData.Timestamp.ToString()));
                }
                break;

            default:
                break;
            }

            return(imageUrl);
        }
Esempio n. 9
0
        protected override object[] ConvertFrom(object value)
        {
            ImageFieldData data = null;

            if (value is int intValue)
            {
                if (Node.LoadNode(intValue) is Image refImage)
                {
                    data = new ImageFieldData(this, refImage, null);
                }
            }
            else if (value is string stringValue)
            {
                try
                {
                    if (Node.LoadNode(stringValue) is Image refImage)
                    {
                        data = new ImageFieldData(this, refImage, null);
                    }
                }
                catch
                {
                    // ignored
                }
            }
            else if (value is long longValue)
            {
                try
                {
                    var id = Convert.ToInt32(longValue);
                    if (Node.LoadNode(id) is Image refImage)
                    {
                        data = new ImageFieldData(this, refImage, null);
                    }
                }
                catch
                {
                    // ignored
                }
            }
            else
            {
                data = value as ImageFieldData;
            }

            if (data == null)
            {
                throw new NotSupportedException("Field value is null or not a valid ImageFieldData or content id or path. FieldName: " + this.Name);
            }
            _data = data;

            var result = new object[2];

            result[0] = data.ImgRef == null ? new List <Node>() : new List <Node>()
            {
                data.ImgRef
            };
            result[1] = data.ImgData ?? new BinaryData();

            return(result);
        }
Esempio n. 10
0
        public static string GetImageUrl(ImageRequestMode imageMode, ImageFieldData data, int contentId, string binaryPropertyName)
        {
            var imageUrl = string.Empty;

            switch (imageMode)
            {
                case ImageRequestMode.Reference:
                    imageUrl = data.ImgRef.Path;
                    break;
                case ImageRequestMode.BinaryData:
                    if (contentId > 0)
                        imageUrl = string.Format("/binaryhandler.ashx?nodeid={0}&propertyname={1}", contentId, binaryPropertyName);
                    break;
                default:
                    break;
            }

            return imageUrl;
        }
Esempio n. 11
0
 public static ImageRequestMode GetImageMode(ImageFieldData data)
 {
     if (data != null && data.ImgData != null && !data.ImgData.IsEmpty && data.ImgData.Size > 0)
     {
         return ImageRequestMode.BinaryData;
     }
     else
     {
         if (data != null && data.ImgRef != null)
         {
             return ImageRequestMode.Reference;
         }
         else
         {
             return ImageRequestMode.None;
         }
     }
 }
Esempio n. 12
0
        public bool SetThumbnailReference(Image thumbnailImage)
        {
            // if image is already set either as reference or binarydata, do nothing
            if (this.ImageMode != ImageRequestMode.None)
                return false;

            var data = new ImageFieldData(thumbnailImage, null);
            this.SetData(data);
            return true;
        }