コード例 #1
0
        /// <summary>
        /// Writes a set of images based on the settings specified in a ImagePropertiesInfo object.
        /// </summary>
        /// <param name="imageInfo">the image properties</param>
        /// <param name="allowEnlargement">if true, generated images will be scaled larger than the source image (if the imageInfo sizes are larger) </param>
        public void WriteImages(ImagePropertiesInfo imageInfo, bool allowEnlargement, ImageDecoratorInvocationSource invocationSource, CreateFileCallback inlineFileCreator, CreateFileCallback linkedFileCreator, IEditorOptions clientOptions)
        {
            string inlinePrefix = imageInfo.LinkTarget == LinkTargetType.IMAGE ? "_thumb" : "";

            ImageFilter inlineFilter = ImageFilterDecoratorAdapter.CreateImageDecoratorsFilter(imageInfo, ImageEmbedType.Embedded, invocationSource, clientOptions);
            ImageFilter targetFilter = ImageFilterDecoratorAdapter.CreateImageDecoratorsFilter(imageInfo, ImageEmbedType.Linked, invocationSource, clientOptions);

            using (Bitmap inlineBitmap = new Bitmap(imageInfo.ImageSourceUri.LocalPath))
            {
                string imgPath = writeImage(inlineBitmap, imageInfo.ImageSourceUri.LocalPath, inlinePrefix, inlineFilter, inlineFileCreator);
                string inlineImgPath = new Uri(UrlHelper.CreateUrlFromPath(imgPath)).ToString();
                imageInfo.InlineImageUrl = inlineImgPath;
            }

            //Generate the link image
            //Warning! this imageInfo.LinkTarget check must be done after the inline image because the resize
            //         decorator will set the default link target for the image the first time it
            //         is applied.
            //imageInfo.LinkTarget = origLinkTarget;
            if (imageInfo.LinkTarget == LinkTargetType.IMAGE && !ImageDecoratorDirective.ShouldSuppressLinked)
            {
                using (Bitmap targetBitmap = new Bitmap(imageInfo.ImageSourceUri.LocalPath))
                {
                    string anchorPath = writeImage(targetBitmap, imageInfo.ImageSourceUri.LocalPath, "", targetFilter, linkedFileCreator);
                    string targetUrl = new Uri(UrlHelper.CreateUrlFromPath(anchorPath)).ToString();
                    imageInfo.LinkTargetUrl = targetUrl;
                }
            }
        }
コード例 #2
0
 public static void Initialize(IHtmlEditorComponentContext editorContext, IBlogPostImageDataContext dataContext, CreateFileCallback callback)
 {
     // initialize one form per-thread
     if ( _imagePropertyForm == null )
     {
         _imagePropertyForm = new ImageEditingPropertyForm() ;
         _imagePropertyForm.Init(editorContext, dataContext, callback);
     }
 }
コード例 #3
0
 public ImagePropertiesSidebarHostControl(
     ISidebarContext sidebarContext,
     IHtmlEditorComponentContext editorContext,
     IBlogPostImageEditingContext imageEditingContext,
     CreateFileCallback createFileCallback)
 {
     // Instead of creating the image sidebar, we now create the manager for ribbon commands releated to image editing.
     _pictureEditingManager = new PictureEditingManager(editorContext, imageEditingContext, createFileCallback);
 }
コード例 #4
0
 public ImagePropertiesSidebar(
     IHtmlEditorComponentContext editorContext,
     IBlogPostImageEditingContext imageEditingContext,
     CreateFileCallback createFileCallback)
 {
     _editorContext = editorContext;
     _dataContext = imageEditingContext;
     _createFileCallback = createFileCallback;
 }
コード例 #5
0
 public ImagePropertiesSidebar(
     IHtmlEditorComponentContext editorContext,
     IBlogPostImageEditingContext imageEditingContext,
     CreateFileCallback createFileCallback)
 {
     _editorContext      = editorContext;
     _dataContext        = imageEditingContext;
     _createFileCallback = createFileCallback;
 }
コード例 #6
0
 public ImagePropertiesSidebarHostControl(
     ISidebarContext sidebarContext,
     IHtmlEditorComponentContext editorContext,
     IBlogPostImageEditingContext imageEditingContext,
     CreateFileCallback createFileCallback)
 {
     // Instead of creating the image sidebar, we now create the manager for ribbon commands releated to image editing.
     _pictureEditingManager = new PictureEditingManager(editorContext, imageEditingContext, createFileCallback);
 }
コード例 #7
0
        private void Init(IHtmlEditorComponentContext editorContext, IBlogPostImageDataContext dataContext, CreateFileCallback callback)
        {
            _editorContext = editorContext;
            _editorContext.SelectionChanged += new EventHandler(_editorContext_SelectionChanged);
            _imageDataContext = dataContext;

            _createFileCallback = callback;

            this.imagePropertyEditorControl.Init(dataContext);
        }
コード例 #8
0
        public PictureEditingManager(
            IHtmlEditorComponentContext editorContext,
            IBlogPostImageEditingContext imageEditingContext,
            CreateFileCallback createFileCallback)
        {
            _editorContext       = editorContext;
            _imageEditingContext = imageEditingContext;
            _createFileCallback  = createFileCallback;

            InitializeCommands();
        }
コード例 #9
0
        public PictureEditingManager(
            IHtmlEditorComponentContext editorContext,
            IBlogPostImageEditingContext imageEditingContext,
            CreateFileCallback createFileCallback)
        {
            _editorContext = editorContext;
            _imageEditingContext = imageEditingContext;
            _createFileCallback = createFileCallback;

            InitializeCommands();
        }
コード例 #10
0
        private void Init(IHtmlEditorComponentContext editorContext, IBlogPostImageDataContext dataContext, CreateFileCallback callback)
        {
            _editorContext = editorContext ;
            _editorContext.SelectionChanged +=new EventHandler(_editorContext_SelectionChanged);
            _imageDataContext = dataContext;

            _createFileCallback = callback ;

            this.imagePropertyEditorControl1.Init(dataContext);

            base.Init(editorContext.MainFrameWindow, typeof(CommandViewImageProperties)) ;
        }
コード例 #11
0
        private void Init(IHtmlEditorComponentContext editorContext, IBlogPostImageDataContext dataContext, CreateFileCallback callback)
        {
            _editorContext = editorContext;
            _editorContext.SelectionChanged += new EventHandler(_editorContext_SelectionChanged);
            _imageDataContext = dataContext;

            _createFileCallback = callback;

            this.imagePropertyEditorControl1.Init(dataContext);

            base.Init(editorContext.MainFrameWindow, typeof(CommandViewImageProperties));
        }
コード例 #12
0
        private string writeImage(Bitmap image, string srcFileName, string suffix, ImageFilter filter, CreateFileCallback createFileCallback)
        {
            string extension = Path.GetExtension(srcFileName).ToLower(CultureInfo.InvariantCulture);
            srcFileName = Path.GetFileNameWithoutExtension(srcFileName) + suffix + extension;
            try
            {
                //save the thumbnail to disk
                ImageFormat imageFormat;
                ImageHelper2.GetImageFormat(srcFileName, out extension, out imageFormat);
                string filename = createFileCallback(Path.GetFileNameWithoutExtension(srcFileName) + extension);
                try
                {
                    if (filter != null)
                        image = filter(image);

                    using (FileStream fs = new FileStream(filename, FileMode.Create))
                    {
                        ImageHelper2.SaveImage(image, imageFormat, fs);
                    }
                    return filename;
                }
                catch (Exception e)
                {
                    Trace.Fail("Failed to save image as format " + imageFormat.Guid + ": " + e.ToString());

                    //try to fall back to generating a PNG version of the image
                    imageFormat = ImageFormat.Png;
                    extension = ".png";
                    filename = createFileCallback(Path.GetFileNameWithoutExtension(srcFileName) + extension);

                    using (FileStream fs = new FileStream(filename, FileMode.Create))
                    {
                        ImageHelper2.SaveImage(image, ImageFormat.Png, fs);
                    }
                    return filename;
                }
            }
            catch (Exception e)
            {
                Trace.Fail("Error while trying to create thumbnail: " + e.Message, e.StackTrace);
                throw;
            }
        }
コード例 #13
0
        /// <summary>
        /// Writes a set of images based on the settings specified in a ImagePropertiesInfo object.
        /// </summary>
        /// <param name="imageInfo">the image properties</param>
        /// <param name="allowEnlargement">if true, generated images will be scaled larger than the source image (if the imageInfo sizes are larger) </param>
        public void WriteImages(ImagePropertiesInfo imageInfo, bool allowEnlargement, ImageDecoratorInvocationSource invocationSource, CreateFileCallback inlineFileCreator, CreateFileCallback linkedFileCreator, IEditorOptions clientOptions)
        {
            string inlinePrefix = imageInfo.LinkTarget == LinkTargetType.IMAGE ? "_thumb" : "";

            ImageFilter inlineFilter = ImageFilterDecoratorAdapter.CreateImageDecoratorsFilter(imageInfo, ImageEmbedType.Embedded, invocationSource, clientOptions);
            ImageFilter targetFilter = ImageFilterDecoratorAdapter.CreateImageDecoratorsFilter(imageInfo, ImageEmbedType.Linked, invocationSource, clientOptions);

            using (Bitmap inlineBitmap = new Bitmap(imageInfo.ImageSourceUri.LocalPath))
            {
                string imgPath       = writeImage(inlineBitmap, imageInfo.ImageSourceUri.LocalPath, inlinePrefix, inlineFilter, inlineFileCreator);
                string inlineImgPath = new Uri(UrlHelper.CreateUrlFromPath(imgPath)).ToString();
                imageInfo.InlineImageUrl = inlineImgPath;
            }

            //Generate the link image
            //Warning! this imageInfo.LinkTarget check must be done after the inline image because the resize
            //         decorator will set the default link target for the image the first time it
            //         is applied.
            //imageInfo.LinkTarget = origLinkTarget;
            if (imageInfo.LinkTarget == LinkTargetType.IMAGE && !ImageDecoratorDirective.ShouldSuppressLinked)
            {
                using (Bitmap targetBitmap = new Bitmap(imageInfo.ImageSourceUri.LocalPath))
                {
                    string anchorPath = writeImage(targetBitmap, imageInfo.ImageSourceUri.LocalPath, "", targetFilter, linkedFileCreator);
                    string targetUrl  = new Uri(UrlHelper.CreateUrlFromPath(anchorPath)).ToString();
                    imageInfo.LinkTargetUrl = targetUrl;
                }
            }
        }
コード例 #14
0
 public static void Initialize(IHtmlEditorComponentContext editorContext, IBlogPostImageDataContext dataContext, CreateFileCallback callback)
 {
     // initialize one form per-thread
     if (_imagePropertySidebar == null)
     {
         _imagePropertySidebar = new ImageEditingPropertySidebar();
         _imagePropertySidebar.Init(editorContext, dataContext, callback);
     }
 }
コード例 #15
0
        private string writeImage(Bitmap image, string srcFileName, string suffix, ImageFilter filter, CreateFileCallback createFileCallback)
        {
            string extension = Path.GetExtension(srcFileName).ToLower(CultureInfo.InvariantCulture);

            srcFileName = Path.GetFileNameWithoutExtension(srcFileName) + suffix + extension;
            try
            {
                //save the thumbnail to disk
                ImageFormat imageFormat;
                ImageHelper2.GetImageFormat(srcFileName, out extension, out imageFormat);
                string filename = createFileCallback(Path.GetFileNameWithoutExtension(srcFileName) + extension);
                try
                {
                    if (filter != null)
                    {
                        image = filter(image);
                    }

                    using (FileStream fs = new FileStream(filename, FileMode.Create))
                    {
                        ImageHelper2.SaveImage(image, imageFormat, fs);
                    }
                    return(filename);
                }
                catch (Exception e)
                {
                    Trace.Fail("Failed to save image as format " + imageFormat.Guid + ": " + e.ToString());

                    //try to fall back to generating a PNG version of the image
                    imageFormat = ImageFormat.Png;
                    extension   = ".png";
                    filename    = createFileCallback(Path.GetFileNameWithoutExtension(srcFileName) + extension);

                    using (FileStream fs = new FileStream(filename, FileMode.Create))
                    {
                        ImageHelper2.SaveImage(image, ImageFormat.Png, fs);
                    }
                    return(filename);
                }
            }
            catch (Exception e)
            {
                Trace.Fail("Error while trying to create thumbnail: " + e.Message, e.StackTrace);
                throw;
            }
        }
コード例 #16
0
        private void Init(IHtmlEditorComponentContext editorContext, IBlogPostImageDataContext dataContext, CreateFileCallback callback)
        {
            _editorContext = editorContext ;
            _editorContext.SelectionChanged +=new EventHandler(_editorContext_SelectionChanged);
            _imageDataContext = dataContext;

            _createFileCallback = callback ;

            this.imagePropertyEditorControl.Init(dataContext);
        }
コード例 #17
0
    protected async Task <FileObject> AddFileAsync(FileParameters option, CreateFileCallback createFileCallback, CancellationToken cancel = default, bool noOpen = false)
    {
        using (VfsPathParserContext ctx = await ParsePathInternalAsync(option.Path, cancel))
        {
            if (ctx.Exception == null)
            {
                if (ctx.LastEntity is VfsFile file)
                {
                    // Already exists
                    if (option.Mode == FileMode.CreateNew)
                    {
                        throw new VfsException(option.Path, $"The file already exists.");
                    }

                    if (noOpen == false)
                    {
                        return(await file.OpenAsync(option, ctx.NormalizedPath, cancel));
                    }
                    else
                    {
                        return(null !);
                    }
                }
                else
                {
                    // There is existing another type object
                    throw new VfsException(option.Path, $"There are existing object at the speficied path.");
                }
            }

            if (ctx.Exception is VfsNotFoundException && ctx.RemainingPathElements.Count == 1 && ctx.LastEntity is VfsDirectory && option.Mode != FileMode.Open)
            {
                // Create new RAM file
                VfsDirectory lastDir = (VfsDirectory)ctx.LastEntity;

                string fileName = ctx.RemainingPathElements.Peek();

                var newFile = await createFileCallback(fileName, option, cancel);

                string fullPath = PathParser.Combine(ctx.NormalizedPath, fileName);

                try
                {
                    await lastDir.AddFileAsync(newFile);
                }
                catch
                {
                    await newFile.ReleaseLinkAsync(true);

                    throw;
                }

                if (noOpen == false)
                {
                    return(await newFile.OpenAsync(option, fullPath, cancel));
                }
                else
                {
                    return(null !);
                }
            }
            else
            {
                throw ctx.Exception;
            }
        }
    }
コード例 #18
0
 internal ImageEditingPropertyHandler(IImagePropertyEditingContext propertyEditingContext, CreateFileCallback createFileCallback, IBlogPostImageEditingContext imageEditingContext)
 {
     _propertyEditingContext = propertyEditingContext;
     _imageInsertHandler = new ImageInsertHandler();
     _editorContext = imageEditingContext;
 }
コード例 #19
0
 internal ImageEditingPropertyHandler(IImagePropertyEditingContext propertyEditingContext, CreateFileCallback createFileCallback, IBlogPostImageEditingContext imageEditingContext)
 {
     _propertyEditingContext = propertyEditingContext;
     _imageInsertHandler     = new ImageInsertHandler();
     _editorContext          = imageEditingContext;
 }