private static void SetProperties(IContentBase content, IImagingAutoFillUploadField autoFillConfig, Size?size, long length, string extension, string culture, string segment) { if (content == null) { throw new ArgumentNullException(nameof(content)); } if (autoFillConfig == null) { throw new ArgumentNullException(nameof(autoFillConfig)); } if (content.Properties.Contains(autoFillConfig.WidthFieldAlias)) { content.Properties[autoFillConfig.WidthFieldAlias].SetValue(size.HasValue ? size.Value.Width.ToInvariantString() : string.Empty, culture, segment); } if (content.Properties.Contains(autoFillConfig.HeightFieldAlias)) { content.Properties[autoFillConfig.HeightFieldAlias].SetValue(size.HasValue ? size.Value.Height.ToInvariantString() : string.Empty, culture, segment); } if (content.Properties.Contains(autoFillConfig.LengthFieldAlias)) { content.Properties[autoFillConfig.LengthFieldAlias].SetValue(length, culture, segment); } if (content.Properties.Contains(autoFillConfig.ExtensionFieldAlias)) { content.Properties[autoFillConfig.ExtensionFieldAlias].SetValue(extension, culture, segment); } }
private void FillProperties(IImagingAutoFillUploadField uploadFieldConfigNode, Content content, UmbracoFile um) { var prop = content.getProperty(uploadFieldConfigNode.WidthFieldAlias); if (prop != null) { prop.Value = um.SupportsResizing ? um.GetDimensions().Item1.ToString() : string.Empty; } prop = content.getProperty(uploadFieldConfigNode.HeightFieldAlias); if (prop != null) { prop.Value = um.SupportsResizing ? um.GetDimensions().Item2.ToString() : string.Empty; } prop = content.getProperty(uploadFieldConfigNode.LengthFieldAlias); if (prop != null) { prop.Value = um.Length; } prop = content.getProperty(uploadFieldConfigNode.ExtensionFieldAlias); if (prop != null) { prop.Value = um.Extension; } }
private static void ResetProperties(IContentBase content, IImagingAutoFillUploadField autoFillConfig) { if (content == null) { throw new ArgumentNullException("content"); } if (autoFillConfig == null) { throw new ArgumentNullException("autoFillConfig"); } if (content.Properties.Contains(autoFillConfig.WidthFieldAlias)) { content.Properties[autoFillConfig.WidthFieldAlias].Value = string.Empty; } if (content.Properties.Contains(autoFillConfig.HeightFieldAlias)) { content.Properties[autoFillConfig.HeightFieldAlias].Value = string.Empty; } if (content.Properties.Contains(autoFillConfig.LengthFieldAlias)) { content.Properties[autoFillConfig.LengthFieldAlias].Value = string.Empty; } if (content.Properties.Contains(autoFillConfig.ExtensionFieldAlias)) { content.Properties[autoFillConfig.ExtensionFieldAlias].Value = string.Empty; } }
/// <summary> /// Populates the auto-fill properties of a content item, for a specified auto-fill configuration. /// </summary> /// <param name="content">The content item.</param> /// <param name="autoFillConfig">The auto-fill configuration.</param> /// <param name="filepath">The filesystem path to the uploaded file.</param> /// <remarks>The <paramref name="filepath"/> parameter is the path relative to the filesystem.</remarks> /// <param name="culture">Variation language.</param> /// <param name="segment">Variation segment.</param> public void Populate(IContentBase content, IImagingAutoFillUploadField autoFillConfig, string filepath, string culture, string segment) { if (content == null) { throw new ArgumentNullException(nameof(content)); } if (autoFillConfig == null) { throw new ArgumentNullException(nameof(autoFillConfig)); } // no file = reset, file = auto-fill if (filepath.IsNullOrWhiteSpace()) { ResetProperties(content, autoFillConfig, culture, segment); } else { // if anything goes wrong, just reset the properties try { using (var filestream = _mediaFileSystem.OpenFile(filepath)) { var extension = (Path.GetExtension(filepath) ?? "").TrimStart('.'); var size = _contentSection.IsImageFile(extension) ? (Size?)ImageHelper.GetDimensions(filestream) : null; SetProperties(content, autoFillConfig, size, filestream.Length, extension, culture, segment); } } catch (Exception ex) { _logger.Error(typeof(UploadAutoFillProperties), ex, "Could not populate upload auto-fill properties for file '{File}'.", filepath); ResetProperties(content, autoFillConfig, culture, segment); } } }
private static void SetProperties(IContentBase content, IImagingAutoFillUploadField autoFillConfig, Size?size, long length, string extension) { if (content == null) { throw new ArgumentNullException("content"); } if (autoFillConfig == null) { throw new ArgumentNullException("autoFillConfig"); } if (content.Properties.Contains(autoFillConfig.WidthFieldAlias)) { content.Properties[autoFillConfig.WidthFieldAlias].Value = size.HasValue ? size.Value.Width.ToInvariantString() : string.Empty; } if (content.Properties.Contains(autoFillConfig.HeightFieldAlias)) { content.Properties[autoFillConfig.HeightFieldAlias].Value = size.HasValue ? size.Value.Height.ToInvariantString() : string.Empty; } if (content.Properties.Contains(autoFillConfig.LengthFieldAlias)) { content.Properties[autoFillConfig.LengthFieldAlias].Value = length; } if (content.Properties.Contains(autoFillConfig.ExtensionFieldAlias)) { content.Properties[autoFillConfig.ExtensionFieldAlias].Value = extension; } }
private static void ResetProperties(IContentBase content, IImagingAutoFillUploadField autoFillConfig, string culture, string segment) { if (content == null) { throw new ArgumentNullException(nameof(content)); } if (autoFillConfig == null) { throw new ArgumentNullException(nameof(autoFillConfig)); } if (content.Properties.Contains(autoFillConfig.WidthFieldAlias)) { content.Properties[autoFillConfig.WidthFieldAlias].SetValue(string.Empty, culture, segment); } if (content.Properties.Contains(autoFillConfig.HeightFieldAlias)) { content.Properties[autoFillConfig.HeightFieldAlias].SetValue(string.Empty, culture, segment); } if (content.Properties.Contains(autoFillConfig.LengthFieldAlias)) { content.Properties[autoFillConfig.LengthFieldAlias].SetValue(string.Empty, culture, segment); } if (content.Properties.Contains(autoFillConfig.ExtensionFieldAlias)) { content.Properties[autoFillConfig.ExtensionFieldAlias].SetValue(string.Empty, culture, segment); } }
internal static void ResetFileMetaDataProperties(this IContentBase content, IImagingAutoFillUploadField uploadFieldConfigNode) { if (uploadFieldConfigNode == null) { throw new ArgumentNullException("uploadFieldConfigNode"); } ResetProperties(uploadFieldConfigNode, content); }
/// <summary> /// Resets the auto-fill properties of a content item, for a specified auto-fill configuration. /// </summary> /// <param name="content">The content item.</param> /// <param name="autoFillConfig">The auto-fill configuration.</param> public void Reset(IContentBase content, IImagingAutoFillUploadField autoFillConfig) { if (content == null) { throw new ArgumentNullException("content"); } if (autoFillConfig == null) { throw new ArgumentNullException("autoFillConfig"); } ResetProperties(content, autoFillConfig); }
/// <summary> /// Resets the auto-fill properties of a content item, for a specified auto-fill configuration. /// </summary> /// <param name="content">The content item.</param> /// <param name="autoFillConfig">The auto-fill configuration.</param> /// <param name="culture">Variation language.</param> /// <param name="segment">Variation segment.</param> public void Reset(IContentBase content, IImagingAutoFillUploadField autoFillConfig, string culture, string segment) { if (content == null) { throw new ArgumentNullException(nameof(content)); } if (autoFillConfig == null) { throw new ArgumentNullException(nameof(autoFillConfig)); } ResetProperties(content, autoFillConfig, culture, segment); }
private static void ResetProperties(IImagingAutoFillUploadField uploadFieldConfigNode, IContentBase content) { if (content.Properties.Contains(uploadFieldConfigNode.WidthFieldAlias)) { content.Properties[uploadFieldConfigNode.WidthFieldAlias].Value = string.Empty; } if (content.Properties.Contains(uploadFieldConfigNode.HeightFieldAlias)) { content.Properties[uploadFieldConfigNode.HeightFieldAlias].Value = string.Empty; } if (content.Properties.Contains(uploadFieldConfigNode.LengthFieldAlias)) { content.Properties[uploadFieldConfigNode.LengthFieldAlias].Value = string.Empty; } if (content.Properties.Contains(uploadFieldConfigNode.ExtensionFieldAlias)) { content.Properties[uploadFieldConfigNode.ExtensionFieldAlias].Value = string.Empty; } }
/// <summary> /// Populates the auto-fill properties of a content item. /// </summary> /// <param name="content">The content item.</param> /// <param name="autoFillConfig"></param> /// <param name="filepath">The filesystem-relative filepath, or null to clear properties.</param> /// <param name="filestream">The stream containing the file data.</param> public void Populate(IContentBase content, IImagingAutoFillUploadField autoFillConfig, string filepath, Stream filestream) { if (content == null) { throw new ArgumentNullException("content"); } if (autoFillConfig == null) { throw new ArgumentNullException("autoFillConfig"); } // no file = reset, file = auto-fill if (filepath.IsNullOrWhiteSpace() || filestream == null) { ResetProperties(content, autoFillConfig); } else { var extension = (Path.GetExtension(filepath) ?? "").TrimStart('.'); var size = _mediaFileSystem.IsImageFile(extension) ? (Size?)_mediaFileSystem.GetDimensions(filestream) : null; SetProperties(content, autoFillConfig, size, filestream.Length, extension); } }
/// <summary> /// Populates the auto-fill properties of a content item. /// </summary> /// <param name="content">The content item.</param> /// <param name="autoFillConfig"></param> /// <param name="filepath">The filesystem-relative filepath, or null to clear properties.</param> /// <param name="filestream">The stream containing the file data.</param> /// <param name="culture">Variation language.</param> /// <param name="segment">Variation segment.</param> public void Populate(IContentBase content, IImagingAutoFillUploadField autoFillConfig, string filepath, Stream filestream, string culture, string segment) { if (content == null) { throw new ArgumentNullException(nameof(content)); } if (autoFillConfig == null) { throw new ArgumentNullException(nameof(autoFillConfig)); } // no file = reset, file = auto-fill if (filepath.IsNullOrWhiteSpace() || filestream == null) { ResetProperties(content, autoFillConfig, culture, segment); } else { var extension = (Path.GetExtension(filepath) ?? "").TrimStart('.'); var size = _contentSection.IsImageFile(extension) ? (Size?)ImageHelper.GetDimensions(filestream) : null; SetProperties(content, autoFillConfig, size, filestream.Length, extension, culture, segment); } }
private static void FillProperties(IImagingAutoFillUploadField uploadFieldConfigNode, IContentBase content, UmbracoMediaFile um) { if (uploadFieldConfigNode == null) { throw new ArgumentNullException("uploadFieldConfigNode"); } if (content == null) { throw new ArgumentNullException("content"); } if (um == null) { throw new ArgumentNullException("um"); } var size = um.SupportsResizing ? (Size?)um.GetDimensions() : null; if (content.Properties.Contains(uploadFieldConfigNode.WidthFieldAlias)) { content.Properties[uploadFieldConfigNode.WidthFieldAlias].Value = size.HasValue ? size.Value.Width.ToInvariantString() : string.Empty; } if (content.Properties.Contains(uploadFieldConfigNode.HeightFieldAlias)) { content.Properties[uploadFieldConfigNode.HeightFieldAlias].Value = size.HasValue ? size.Value.Height.ToInvariantString() : string.Empty; } if (content.Properties.Contains(uploadFieldConfigNode.LengthFieldAlias)) { content.Properties[uploadFieldConfigNode.LengthFieldAlias].Value = um.Length; } if (content.Properties.Contains(uploadFieldConfigNode.ExtensionFieldAlias)) { content.Properties[uploadFieldConfigNode.ExtensionFieldAlias].Value = um.Extension; } }
private static void FillProperties(IImagingAutoFillUploadField uploadFieldConfigNode, IContentBase content, UmbracoMediaFile um) { var size = um.SupportsResizing ? (Size?)um.GetDimensions() : null; if (content.Properties.Contains(uploadFieldConfigNode.WidthFieldAlias)) content.Properties[uploadFieldConfigNode.WidthFieldAlias].Value = size.HasValue ? size.Value.Width.ToInvariantString() : string.Empty; if (content.Properties.Contains(uploadFieldConfigNode.HeightFieldAlias)) content.Properties[uploadFieldConfigNode.HeightFieldAlias].Value = size.HasValue ? size.Value.Height.ToInvariantString() : string.Empty; if (content.Properties.Contains(uploadFieldConfigNode.LengthFieldAlias)) content.Properties[uploadFieldConfigNode.LengthFieldAlias].Value = um.Length; if (content.Properties.Contains(uploadFieldConfigNode.ExtensionFieldAlias)) content.Properties[uploadFieldConfigNode.ExtensionFieldAlias].Value = um.Extension; }
internal static void PopulateFileMetaDataProperties(this IContentBase content, IImagingAutoFillUploadField uploadFieldConfigNode, string relativeFilePath) { if (uploadFieldConfigNode == null) { throw new ArgumentNullException("uploadFieldConfigNode"); } if (relativeFilePath.IsNullOrWhiteSpace() == false) { var mediaFileSystem = FileSystemProviderManager.Current.GetFileSystemProvider <MediaFileSystem>(); var fullPath = mediaFileSystem.GetFullPath(mediaFileSystem.GetRelativePath(relativeFilePath)); var umbracoFile = new UmbracoMediaFile(fullPath); FillProperties(uploadFieldConfigNode, content, umbracoFile); } else { //for now I'm just resetting this since we cant detect a file ResetProperties(uploadFieldConfigNode, content); } }
private static void ResetProperties(IImagingAutoFillUploadField uploadFieldConfigNode, IContentBase content) { if (content.Properties.Contains(uploadFieldConfigNode.WidthFieldAlias)) content.Properties[uploadFieldConfigNode.WidthFieldAlias].Value = string.Empty; if (content.Properties.Contains(uploadFieldConfigNode.HeightFieldAlias)) content.Properties[uploadFieldConfigNode.HeightFieldAlias].Value = string.Empty; if (content.Properties.Contains(uploadFieldConfigNode.LengthFieldAlias)) content.Properties[uploadFieldConfigNode.LengthFieldAlias].Value = string.Empty; if (content.Properties.Contains(uploadFieldConfigNode.ExtensionFieldAlias)) content.Properties[uploadFieldConfigNode.ExtensionFieldAlias].Value = string.Empty; }
private static void SetFileOnContent(IContentBase content, string propertyTypeAlias, string filename, Stream fileStream) { var property = content.Properties.FirstOrDefault(x => x.Alias == propertyTypeAlias); if (property == null) { return; } //TODO: ALl of this naming logic needs to be put into the ImageHelper and then we need to change FileUploadPropertyValueEditor to do the same! var numberedFolder = MediaSubfolderCounter.Current.Increment(); var fileName = UmbracoConfig.For.UmbracoSettings().Content.UploadAllowDirectories ? Path.Combine(numberedFolder.ToString(CultureInfo.InvariantCulture), filename) : numberedFolder + "-" + filename; var extension = Path.GetExtension(filename).Substring(1).ToLowerInvariant(); //the file size is the length of the stream in bytes var fileSize = fileStream.Length; var fs = FileSystemProviderManager.Current.GetFileSystemProvider <MediaFileSystem>(); fs.AddFile(fileName, fileStream); //Check if file supports resizing and create thumbnails var supportsResizing = UmbracoConfig.For.UmbracoSettings().Content.ImageFileTypes.InvariantContains(extension); //the config section used to auto-fill properties IImagingAutoFillUploadField uploadFieldConfigNode = null; //Check for auto fill of additional properties if (UmbracoConfig.For.UmbracoSettings().Content.ImageAutoFillProperties != null) { uploadFieldConfigNode = UmbracoConfig.For.UmbracoSettings().Content.ImageAutoFillProperties .FirstOrDefault(x => x.Alias == propertyTypeAlias); } if (supportsResizing) { //get the original image from the original stream if (fileStream.CanSeek) { fileStream.Seek(0, 0); } using (var originalImage = Image.FromStream(fileStream)) { var additionalSizes = new List <int>(); //Look up Prevalues for this upload datatype - if it is an upload datatype - get additional configured sizes if (property.PropertyType.PropertyEditorAlias == Constants.PropertyEditors.UploadFieldAlias) { //Get Prevalues by the DataType's Id: property.PropertyType.DataTypeId var values = ApplicationContext.Current.Services.DataTypeService.GetPreValuesByDataTypeId(property.PropertyType.DataTypeDefinitionId); var thumbnailSizes = values.FirstOrDefault(); //Additional thumbnails configured as prevalues on the DataType if (thumbnailSizes != null) { foreach (var thumb in thumbnailSizes.Split(new[] { ";", "," }, StringSplitOptions.RemoveEmptyEntries)) { int thumbSize; if (thumb != "" && int.TryParse(thumb, out thumbSize)) { additionalSizes.Add(thumbSize); } } } } ImageHelper.GenerateMediaThumbnails(fs, fileName, extension, originalImage, additionalSizes); //while the image is still open, we'll check if we need to auto-populate the image properties if (uploadFieldConfigNode != null) { content.SetValue(uploadFieldConfigNode.WidthFieldAlias, originalImage.Width.ToString(CultureInfo.InvariantCulture)); content.SetValue(uploadFieldConfigNode.HeightFieldAlias, originalImage.Height.ToString(CultureInfo.InvariantCulture)); } } } //if auto-fill is true, then fill the remaining, non-image properties if (uploadFieldConfigNode != null) { content.SetValue(uploadFieldConfigNode.LengthFieldAlias, fileSize.ToString(CultureInfo.InvariantCulture)); content.SetValue(uploadFieldConfigNode.ExtensionFieldAlias, extension); } //Set the value of the property to that of the uploaded file's url property.Value = fs.GetUrl(fileName); }
private void FillProperties(IImagingAutoFillUploadField uploadFieldConfigNode, Content content, UmbracoFile um) { var prop = content.getProperty(uploadFieldConfigNode.WidthFieldAlias); if (prop != null) prop.Value = um.SupportsResizing ? um.GetDimensions().Item1.ToString() : string.Empty; prop = content.getProperty(uploadFieldConfigNode.HeightFieldAlias); if (prop != null) prop.Value = um.SupportsResizing ? um.GetDimensions().Item2.ToString() : string.Empty; prop = content.getProperty(uploadFieldConfigNode.LengthFieldAlias); if (prop != null) prop.Value = um.Length; prop = content.getProperty(uploadFieldConfigNode.ExtensionFieldAlias); if (prop != null) prop.Value = um.Extension; }