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); }
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; }
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); } } }
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; }
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); }
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); }
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); }
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); }
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); }
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; }
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; } } }
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; }