static void AutoFillProperties(IContentBase model)
        {
            var mediaFileSystem = FileSystemProviderManager.Current.GetFileSystemProvider<MediaFileSystem>();
            foreach (var p in model.Properties)
            {
                var uploadFieldConfigNode =
                    UmbracoConfig.For.UmbracoSettings().Content.ImageAutoFillProperties
                                        .FirstOrDefault(x => x.Alias == p.Alias);

                if (uploadFieldConfigNode != null)
                {
                    //now we need to check if there is a value
                    if (p.Value is string && ((string) p.Value).IsNullOrWhiteSpace() == false)
                    {
                        //there might be multiple, we can only process the first one!
                        var split = ((string) p.Value).Split(new[] {','}, StringSplitOptions.RemoveEmptyEntries);
                        if (split.Any())
                        {
                            var fullPath = mediaFileSystem.GetFullPath(mediaFileSystem.GetRelativePath(split[0]));
                            var umbracoFile = new UmbracoMediaFile(fullPath);
                            FillProperties(uploadFieldConfigNode, model, umbracoFile);
                        }
                    }
                    else
                    {
                        //there's no value so need to reset to zero
                        ResetProperties(uploadFieldConfigNode, model);
                    }
                }
            }            
        }
        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;
        }
Ejemplo n.º 3
0
 public UmbracoFile(string path)
 {
     _mediaFile = new UmbracoMediaFile(path);
 }
Ejemplo n.º 4
0
 internal UmbracoFile(UmbracoMediaFile mediaFile)
 {
     _mediaFile = mediaFile;
 }
Ejemplo n.º 5
0
 public UmbracoFile()
 {
     _mediaFile = new UmbracoMediaFile();
 }