Пример #1
0
        /// <summary>
        /// Creates an embedded shadow copy of a source image file.
        /// </summary>
        /// <param name="sourceFile"></param>
        /// <param name="fileService"></param>
        private void CreateShadowFile(ImageFileData sourceFile, ISupportingFileService fileService)
        {
            Size shadowSize = new Size(1280, 960);

            using (MemoryStream shadowStream = new MemoryStream())
            {
                ImageFormat format;
                string      fileExt;
                ImageHelper2.GetImageFormat(sourceFile.SupportingFile.FileName, out fileExt, out format);
                using (Bitmap sourceImage = new Bitmap(sourceFile.Uri.LocalPath))
                {
                    if (sourceImage.Width > shadowSize.Width || sourceImage.Height > shadowSize.Height)
                    {
                        shadowSize = ImageHelper2.SaveScaledThumbnailImage(Math.Min(shadowSize.Width, sourceImage.Width),
                                                                           Math.Min(shadowSize.Height, sourceImage.Height),
                                                                           sourceImage, format, shadowStream);
                    }
                    else
                    {
                        shadowSize = sourceImage.Size;
                        using (FileStream fs = File.OpenRead(sourceFile.Uri.LocalPath))
                        {
                            StreamHelper.Transfer(fs, shadowStream);
                        }
                    }
                }
                shadowStream.Seek(0, SeekOrigin.Begin);

                ISupportingFile supportingFile = fileService.CreateSupportingFile(sourceFile.SupportingFile.FileName, shadowStream);
                _imageSourceShadowFile = new ImageFileData(supportingFile, shadowSize.Width, shadowSize.Height, ImageFileRelationship.SourceShadow);
            }
        }
        internal BlogPostExtensionData(string id, BlogPostSettingsBag settings, ISupportingFileService fileService, Hashtable fileMappings)
        {
            _id          = id;
            _settings    = settings;
            _fileService = fileService;

            _fileIds         = fileMappings;
            _refreshCallBack = null;
            _objectContext   = null;
        }
 public BlogPostEditingContext(string destinationBlogId, BlogPost blogPost, PostEditorFile localFile, PostEditorFile autoSaveLocalFile, string serverSupportingFileDirectory, BlogPostSupportingFileStorage supportingFileStorage, BlogPostImageDataList imageDataList, BlogPostExtensionDataList extensionDataList, ISupportingFileService supportingFileService)
     : this(destinationBlogId, blogPost, localFile)
 {
     _serverSupportingFileDirectory = serverSupportingFileDirectory;
     _supportingFileStorage = supportingFileStorage;
     _imageDataList = imageDataList;
     _extensionDataList = extensionDataList;
     _fileService = supportingFileService;
     _autoSaveLocalFile = autoSaveLocalFile;
 }
 public BlogPostEditingContext(string destinationBlogId, BlogPost blogPost, PostEditorFile localFile, PostEditorFile autoSaveLocalFile, string serverSupportingFileDirectory, BlogPostSupportingFileStorage supportingFileStorage, BlogPostImageDataList imageDataList, BlogPostExtensionDataList extensionDataList, ISupportingFileService supportingFileService)
     : this(destinationBlogId, blogPost, localFile)
 {
     _serverSupportingFileDirectory = serverSupportingFileDirectory;
     _supportingFileStorage         = supportingFileStorage;
     _imageDataList     = imageDataList;
     _extensionDataList = extensionDataList;
     _fileService       = supportingFileService;
     _autoSaveLocalFile = autoSaveLocalFile;
 }
 internal void InitShadowFile(ISupportingFileService fileService)
 {
     if (_imageSourceShadowFile == null)
     {
         if (ImageSourceFile != null && File.Exists(ImageSourceFile.Uri.LocalPath))
         {
             CreateShadowFile(ImageSourceFile, fileService);
         }
         else if (LinkedImageFile != null && File.Exists(LinkedImageFile.Uri.LocalPath))
         {
             CreateShadowFile(LinkedImageFile, fileService);
         }
         else if (InlineImageFile != null && File.Exists(InlineImageFile.Uri.LocalPath))
         {
             CreateShadowFile(InlineImageFile, fileService);
         }
     }
 }
Пример #6
0
 internal void InitShadowFile(ISupportingFileService fileService)
 {
     if (_imageSourceShadowFile == null)
     {
         if (ImageSourceFile != null && File.Exists(ImageSourceFile.Uri.LocalPath))
         {
             CreateShadowFile(ImageSourceFile, fileService);
         }
         else if (LinkedImageFile != null && File.Exists(LinkedImageFile.Uri.LocalPath))
         {
             CreateShadowFile(LinkedImageFile, fileService);
         }
         else if (InlineImageFile != null && File.Exists(InlineImageFile.Uri.LocalPath))
         {
             CreateShadowFile(InlineImageFile, fileService);
         }
     }
 }
        /// <summary>
        /// Scans the DOM for images that have not yet been properly initialized by the editor.
        /// As part of the initialization, the default image settings and effects will be applied to the image.
        /// </summary>
        internal static void ScanAndInitializeNewImages(IBlogPostHtmlEditor currentEditor, ISupportingFileService fileService, IEditorAccount editorAccount, ContentEditor editor, Control owner, bool useDefaultTargetSettings, bool selectLastImage)
        {
            if (currentEditor is BlogPostHtmlEditorControl)
            {
                // Scanning the images and doing basic initialization is done on the UI thread.
                List<NewImageInfo> newImages = ScanImages(currentEditor, editorAccount, editor, useDefaultTargetSettings);

                if (newImages.Count > 0)
                {
                    // The time-consuming initialization is done in a background thread.
                    ImageInitializationAsyncOperation imageInitializer = new ImageInitializationAsyncOperation(newImages, fileService, owner);
                    imageInitializer.Completed += new EventHandler((sender, e) =>
                        ProcessInitializedImages(newImages, currentEditor, editor, owner, selectLastImage));

                    editor.DisposeOnEditorChange(imageInitializer);

                    imageInitializer.Start();
                }
            }
        }
Пример #8
0
        internal static string ReferenceFixer(BeginTag tag, string reference, ISupportingFileService _fileService, OpenLiveWriter.PostEditor.ContentEditor editor)
        {
            // If it isnt a file url, then it wont be an image from supporting files.
            if (!UrlHelper.IsFile(reference))
            {
                return(reference);
            }

            Uri uri = new Uri(reference);
            BlogPostImageData imageData = BlogPostImageDataList.LookupImageDataByInlineUri(editor.ImageList, uri);

            if (imageData == null)
            {
                if (BlogPostImageDataList.LookupImageDataByLinkedUri(editor.ImageList, uri) != null)
                {
                    return(null);
                }

                return(reference);
            }

            return(imageData.ImageSourceFile.Uri.AbsoluteUri);
        }
Пример #9
0
        /// <summary>
        /// Scans the DOM for images that have not yet been properly initialized by the editor.
        /// As part of the initialization, the default image settings and effects will be applied to the image.
        /// </summary>
        internal static void ScanAndInitializeNewImages(IBlogPostHtmlEditor currentEditor, ISupportingFileService fileService, IEditorAccount editorAccount, ContentEditor editor, Control owner, bool useDefaultTargetSettings, bool selectLastImage)
        {
            if (currentEditor is BlogPostHtmlEditorControl)
            {
                // Scanning the images and doing basic initialization is done on the UI thread.
                List <NewImageInfo> newImages = ScanImages(currentEditor, editorAccount, editor, useDefaultTargetSettings);

                if (newImages.Count > 0)
                {
                    // The time-consuming initialization is done in a background thread.
                    ImageInitializationAsyncOperation imageInitializer = new ImageInitializationAsyncOperation(newImages, fileService, owner);
                    imageInitializer.Completed += new EventHandler((sender, e) =>
                                                                   ProcessInitializedImages(newImages, currentEditor, editor, owner, selectLastImage));

                    editor.DisposeOnEditorChange(imageInitializer);

                    imageInitializer.Start();
                }
            }
        }
Пример #10
0
 public CreateImageFileHandler(ISupportingFileService fileService, ISupportingFile supportingFile)
 {
     _fileService        = fileService;
     ImageSupportingFile = supportingFile;
 }
 public CreateImageFileHandler(ISupportingFileService fileService, ISupportingFile supportingFile)
 {
     _fileService = fileService;
     ImageSupportingFile = supportingFile;
 }
 internal BlogPostExtensionDataList(ISupportingFileService fileService)
 {
     _extensionData = new Hashtable();
     _fileService   = fileService;
 }
        internal static string ReferenceFixer(BeginTag tag, string reference, ISupportingFileService _fileService, OpenLiveWriter.PostEditor.ContentEditor editor)
        {
            // If it isnt a file url, then it wont be an image from supporting files.
            if (!UrlHelper.IsFile(reference))
                return reference;

            Uri uri = new Uri(reference);
            BlogPostImageData imageData = BlogPostImageDataList.LookupImageDataByInlineUri(editor.ImageList, uri);

            if (imageData == null)
            {
                if (BlogPostImageDataList.LookupImageDataByLinkedUri(editor.ImageList, uri) != null)
                    return null;

                return reference;
            }

            return imageData.ImageSourceFile.Uri.AbsoluteUri;
        }
 /// <summary>
 /// Initializes a new instance of the ImageInitializationAsyncOperation class.
 /// </summary>
 /// <param name="newImages">A list of images to initialize.</param>
 /// <param name="fileService">Allows us to register the images with the editor.</param>
 /// <param name="owner">All events raised from this object will be delivered via this target.</param>
 public ImageInitializationAsyncOperation(List<NewImageInfo> newImages, ISupportingFileService fileService, ISynchronizeInvoke owner)
     : base(owner)
 {
     this.newImages = newImages;
     this.fileService = fileService;
 }
        internal BlogPostExtensionData(string id, BlogPostSettingsBag settings, ISupportingFileService fileService, Hashtable fileMappings)
        {
            _id = id;
            _settings = settings;
            _fileService = fileService;

            _fileIds = fileMappings;
            _refreshCallBack = null;
            _objectContext = null;
        }
 public LocalFileTransformer(BlogPostReferenceFixer referenceFixer, BlogFileUploader uploader)
 {
     _referenceFixer = referenceFixer;
     _fileService    = _referenceFixer._uploadContext.EditingContext.SupportingFileService;
     _uploader       = uploader;
 }
Пример #17
0
        /// <summary>
        /// Inserts a set of images into the current editor, optionally assigning each image an id.
        /// </summary>
        /// <param name="imagePaths">paths of the images to insert</param>
        internal static void InsertImagesCore(IBlogPostHtmlEditor currentEditor, ISupportingFileService fileService, IEditorAccount editorAccount, OpenLiveWriter.PostEditor.ContentEditor editor, string[] imagePaths)
        {
            using (OpenLiveWriter.PostEditor.ContentEditor.EditorUndoUnit undo = new OpenLiveWriter.PostEditor.ContentEditor.EditorUndoUnit(currentEditor))
            {
                StringBuilder htmlBuilder = new StringBuilder();

                //calculate the size for inserted images (based on the user's saved default for this blog)
                DefaultImageSettings defaultImageSettings = new DefaultImageSettings(editorAccount.Id, editor.DecoratorsManager);
                Size defaultImageSize = defaultImageSettings.GetDefaultInlineImageSize();

                //Generate the default img HTML for the image paths.  Initially, the images are linked to the source image
                //path so that the DOM version of the HTML can be loaded.  Once the images are loaded into the DOM, we can apply
                //the image decorators to generate scaled images, borders, etc.
                ImagePropertiesInfo[] imageInfos = new ImagePropertiesInfo[imagePaths.Length];

                // don't insert into the title
                currentEditor.FocusBody();

                for (int i = 0; i < imageInfos.Length; i++)
                {
                    string imagePath = imagePaths[i];

                    Uri imgUri;
                    if (UrlHelper.IsUrl(imagePath))
                    {
                        imgUri = new Uri(imagePath);
                    }
                    else
                    {
                        imgUri = new Uri(UrlHelper.CreateUrlFromPath(imagePath));
                    }

                    Size imageSize = new Size(1, 1);
                    if (imgUri.IsFile && File.Exists(imagePath))
                    {
                        if (!File.Exists(imgUri.LocalPath))
                        {
                            Trace.Fail("Error inserting image - the image URL was corrupted: " + imagePath);
                        }
                        else
                        {
                            try
                            {
                                //check the validity of the image file
                                imageSize = ImageUtils.GetImageSize(imagePath);
                            }
                            catch (Exception)
                            {
                                Trace.WriteLine("There is a problem with the image file: " + imagePath);

                                // Insert anyway, MSHTML will show a red X in place of the image.
                                htmlBuilder.AppendFormat(CultureInfo.InvariantCulture, "<img src=\"{0}\" />", HtmlUtils.EscapeEntities(UrlHelper.SafeToAbsoluteUri(imgUri)));

                                continue;
                            }
                        }
                    }

                    // If the image has an embedded thumbnail, we'll use it as a place holder for the <img src="...">
                    // until we generate an inline image and apply decorators.
                    Stream embeddedThumbnailStream = ImageHelper2.GetEmbeddedThumbnailStream(imagePath);

                    if (embeddedThumbnailStream != null)
                    {
                        // Save thumbnail to disk.
                        ISupportingFile imageFileEmbeddedThumbnail = fileService.CreateSupportingFile(Path.GetFileName(imagePath), Guid.NewGuid().ToString(), embeddedThumbnailStream);

                        imageSize = ImageUtils.GetScaledImageSize(defaultImageSize.Width, defaultImageSize.Height, imageSize);
                        //insert the default image html
                        String imageElementAttrs = String.Format(CultureInfo.InvariantCulture, " width=\"{0}\" height=\"{1}\"", imageSize.Width, imageSize.Height);

                        htmlBuilder.AppendFormat(CultureInfo.InvariantCulture, "<img src=\"{0}\" srcDelay=\"{1}\" {2} />", HtmlUtils.EscapeEntities(UrlHelper.SafeToAbsoluteUri(imageFileEmbeddedThumbnail.FileUri)), HtmlUtils.EscapeEntities(imgUri.ToString()), imageElementAttrs);
                    }
                    else if (currentEditor is BlogPostHtmlEditorControl && (imagePaths.Length > DELAYED_IMAGE_THRESHOLD || imageSize.Width * imageSize.Height > 16777216 /*4096 X 4096*/))
                    {
                        // If we are using a delayed loading tactic then we insert using the srcdelay
                        htmlBuilder.Append(MakeHtmlForImageSourceDelay(imgUri.ToString()));
                    }
                    else
                    {
                        imageSize = ImageUtils.GetScaledImageSize(defaultImageSize.Width, defaultImageSize.Height, imageSize);
                        //insert the default image html
                        String imageElementAttrs = imgUri.IsFile ? String.Format(CultureInfo.InvariantCulture, " width=\"{0}\" height=\"{1}\"", imageSize.Width, imageSize.Height) : String.Empty;

                        htmlBuilder.AppendFormat(CultureInfo.InvariantCulture, "<img src=\"{0}\" {1} />", HtmlUtils.EscapeEntities(UrlHelper.SafeToAbsoluteUri(imgUri)), imageElementAttrs);
                    }
                }

                //insert the HTML into the editor
                currentEditor.InsertHtml(htmlBuilder.ToString(), false);

                selectionChanged = false;
                BlogPostHtmlEditorControl blogPostEditor = currentEditor as BlogPostHtmlEditorControl;
                if (blogPostEditor != null)
                {
                    blogPostEditor.SelectionChanged += blogPostEditor_SelectionChanged;
                }

                //now that the image HTML is inserted into the editor, apply the default settings to the new images.
                undo.Commit();
            }
        }
        /// <summary>
        /// Inserts a set of images into the current editor, optionally assigning each image an id.
        /// </summary>
        /// <param name="imagePaths">paths of the images to insert</param>
        internal static void InsertImagesCore(IBlogPostHtmlEditor currentEditor, ISupportingFileService fileService, IEditorAccount editorAccount, OpenLiveWriter.PostEditor.ContentEditor editor, string[] imagePaths)
        {
            using (OpenLiveWriter.PostEditor.ContentEditor.EditorUndoUnit undo = new OpenLiveWriter.PostEditor.ContentEditor.EditorUndoUnit(currentEditor))
            {
                StringBuilder htmlBuilder = new StringBuilder();

                //calculate the size for inserted images (based on the user's saved default for this blog)
                DefaultImageSettings defaultImageSettings = new DefaultImageSettings(editorAccount.Id, editor.DecoratorsManager);
                Size defaultImageSize = defaultImageSettings.GetDefaultInlineImageSize();

                //Generate the default img HTML for the image paths.  Initially, the images are linked to the source image
                //path so that the DOM version of the HTML can be loaded.  Once the images are loaded into the DOM, we can apply
                //the image decorators to generate scaled images, borders, etc.
                ImagePropertiesInfo[] imageInfos = new ImagePropertiesInfo[imagePaths.Length];

                // don't insert into the title
                currentEditor.FocusBody();

                for (int i = 0; i < imageInfos.Length; i++)
                {
                    string imagePath = imagePaths[i];

                    Uri imgUri;
                    if (UrlHelper.IsUrl(imagePath))
                        imgUri = new Uri(imagePath);
                    else
                        imgUri = new Uri(UrlHelper.CreateUrlFromPath(imagePath));

                    Size imageSize = new Size(1, 1);
                    if (imgUri.IsFile && File.Exists(imagePath))
                    {
                        if (!File.Exists(imgUri.LocalPath))
                            Trace.Fail("Error inserting image - the image URL was corrupted: " + imagePath);
                        else
                        {
                            try
                            {
                                //check the validity of the image file
                                imageSize = ImageUtils.GetImageSize(imagePath);
                            }
                            catch (Exception)
                            {
                                Trace.WriteLine("There is a problem with the image file: " + imagePath);

                                // Insert anyway, MSHTML will show a red X in place of the image.
                                htmlBuilder.AppendFormat(CultureInfo.InvariantCulture, "<img src=\"{0}\" />", HtmlUtils.EscapeEntities(UrlHelper.SafeToAbsoluteUri(imgUri)));

                                continue;
                            }
                        }
                    }

                    // If the image has an embedded thumbnail, we'll use it as a place holder for the <img src="...">
                    // until we generate an inline image and apply decorators.
                    Stream embeddedThumbnailStream = ImageHelper2.GetEmbeddedThumbnailStream(imagePath);

                    if (embeddedThumbnailStream != null)
                    {
                        // Save thumbnail to disk.
                        ISupportingFile imageFileEmbeddedThumbnail = fileService.CreateSupportingFile(Path.GetFileName(imagePath), Guid.NewGuid().ToString(), embeddedThumbnailStream);

                        imageSize = ImageUtils.GetScaledImageSize(defaultImageSize.Width, defaultImageSize.Height, imageSize);
                        //insert the default image html
                        String imageElementAttrs = String.Format(CultureInfo.InvariantCulture, " width=\"{0}\" height=\"{1}\"", imageSize.Width, imageSize.Height);

                        htmlBuilder.AppendFormat(CultureInfo.InvariantCulture, "<img src=\"{0}\" srcDelay=\"{1}\" {2} />", HtmlUtils.EscapeEntities(UrlHelper.SafeToAbsoluteUri(imageFileEmbeddedThumbnail.FileUri)), HtmlUtils.EscapeEntities(imgUri.ToString()), imageElementAttrs);
                    }
                    else if (currentEditor is BlogPostHtmlEditorControl && (imagePaths.Length > DELAYED_IMAGE_THRESHOLD || imageSize.Width * imageSize.Height > 16777216/*4096 X 4096*/))
                    {
                        // If we are using a delayed loading tactic then we insert using the srcdelay
                        htmlBuilder.Append(MakeHtmlForImageSourceDelay(imgUri.ToString()));
                    }
                    else
                    {
                        imageSize = ImageUtils.GetScaledImageSize(defaultImageSize.Width, defaultImageSize.Height, imageSize);
                        //insert the default image html
                        String imageElementAttrs = imgUri.IsFile ? String.Format(CultureInfo.InvariantCulture, " width=\"{0}\" height=\"{1}\"", imageSize.Width, imageSize.Height) : String.Empty;

                        htmlBuilder.AppendFormat(CultureInfo.InvariantCulture, "<img src=\"{0}\" {1} />", HtmlUtils.EscapeEntities(UrlHelper.SafeToAbsoluteUri(imgUri)), imageElementAttrs);
                    }
                }

                //insert the HTML into the editor
                currentEditor.InsertHtml(htmlBuilder.ToString(), false);

                selectionChanged = false;
                BlogPostHtmlEditorControl blogPostEditor = currentEditor as BlogPostHtmlEditorControl;
                if (blogPostEditor != null)
                    blogPostEditor.SelectionChanged += blogPostEditor_SelectionChanged;

                //now that the image HTML is inserted into the editor, apply the default settings to the new images.
                undo.Commit();
            }
        }
Пример #19
0
 /// <summary>
 /// Initializes a new instance of the ImageInitializationAsyncOperation class.
 /// </summary>
 /// <param name="newImages">A list of images to initialize.</param>
 /// <param name="fileService">Allows us to register the images with the editor.</param>
 /// <param name="owner">All events raised from this object will be delivered via this target.</param>
 public ImageInitializationAsyncOperation(List <NewImageInfo> newImages, ISupportingFileService fileService, ISynchronizeInvoke owner)
     : base(owner)
 {
     this.newImages   = newImages;
     this.fileService = fileService;
 }
        /// <summary>
        /// Creates an embedded shadow copy of a source image file.
        /// </summary>
        /// <param name="sourceFile"></param>
        /// <param name="fileService"></param>
        private void CreateShadowFile(ImageFileData sourceFile, ISupportingFileService fileService)
        {
            Size shadowSize = new Size(1280, 960);
            using (MemoryStream shadowStream = new MemoryStream())
            {
                ImageFormat format;
                string fileExt;
                ImageHelper2.GetImageFormat(sourceFile.SupportingFile.FileName, out fileExt, out format);
                using (Bitmap sourceImage = new Bitmap(sourceFile.Uri.LocalPath))
                {
                    if (sourceImage.Width > shadowSize.Width || sourceImage.Height > shadowSize.Height)
                    {
                        shadowSize = ImageHelper2.SaveScaledThumbnailImage(Math.Min(shadowSize.Width, sourceImage.Width),
                                                                           Math.Min(shadowSize.Height, sourceImage.Height),
                                                                           sourceImage, format, shadowStream);
                    }
                    else
                    {
                        shadowSize = sourceImage.Size;
                        using (FileStream fs = File.OpenRead(sourceFile.Uri.LocalPath))
                        {
                            StreamHelper.Transfer(fs, shadowStream);
                        }
                    }
                }
                shadowStream.Seek(0, SeekOrigin.Begin);

                ISupportingFile supportingFile = fileService.CreateSupportingFile(sourceFile.SupportingFile.FileName, shadowStream);
                _imageSourceShadowFile = new ImageFileData(supportingFile, shadowSize.Width, shadowSize.Height, ImageFileRelationship.SourceShadow);
            }
        }
 internal BlogPostExtensionDataList(ISupportingFileService fileService)
 {
     _extensionData = new Hashtable();
     _fileService = fileService;
 }
 public LocalFileTransformer(BlogPostReferenceFixer referenceFixer, BlogFileUploader uploader)
 {
     _referenceFixer = referenceFixer;
     _fileService = _referenceFixer._uploadContext.EditingContext.SupportingFileService;
     _uploader = uploader;
 }