internal ImageDecoratorsList(ImageDecoratorsManager decoratorsManager, BlogPostSettingsBag settingsBag, bool addDefaultBorderDecorator)
        {
            _decoratorsManager     = decoratorsManager;
            _decoratorsSettingsBag = settingsBag;
            List <ImageDecorator> decorators = new List <ImageDecorator>();

            string appliedDecorators = settingsBag.GetString(APPLIED_DECORATORS, "");

            //Add all of the defined decorators from the settings bag to the decoratorslist.
            //Bug fix note: collect decorators into an arraylist to avoid enumeration modified exception
            //from _decoratorsSettingsBag.SubsettingNames when calling AddDecorator(decorator);
            foreach (string decoratorId in appliedDecorators.Split(','))
            {
                ImageDecorator decorator = decoratorsManager.GetImageDecorator(decoratorId);
                if (decorator != null)
                {
                    decorators.Add(decorator);
                }
            }

            AddDecorator(decorators.ToArray());

            if (addDefaultBorderDecorator && (BorderImageDecorator == null))
            {
                AddDecorator(HtmlBorderDecorator.Id);
            }
        }
Exemple #2
0
 internal VersionedSupportingFile(SupportingFileFactory fileFactory, int version, Uri fileUri, string fileName, string fileNameUniqueToken, bool embedded, BlogPostSettingsBag fileProperties)
 {
     _fileFactory         = fileFactory;
     _fileVersion         = version;
     _fileUri             = fileUri;
     _fileName            = fileName;
     _embedded            = embedded;
     _properties          = fileProperties;
     _fileNameUniqueToken = fileNameUniqueToken;
 }
        private void AddSettings(string prefix, BlogPostSettingsBag settings)
        {
            foreach (string name in settings.Names)
            {
                AddData(prefix + name, settings[name]);
            }

            foreach (string subsettingsName in settings.SubsettingNames)
            {
                AddSettings(prefix + subsettingsName + "/", settings.GetSubSettings(subsettingsName));
            }
        }
 internal void MarkUploaded(string uploadContextId, int fileVersion, Uri uploadUri, BlogPostSettingsBag uploadSettings)
 {
     SupportingFileUploadInfo uploadInfo = (SupportingFileUploadInfo)_uploadInfos[uploadContextId];
     if (uploadInfo != null)
     {
         //update the existing info
         uploadInfo.UploadedFileVersion = fileVersion;
         uploadInfo.UploadUri = uploadUri;
         uploadInfo.UploadSettings = uploadSettings;
     }
     else
     {
         _uploadInfos[uploadContextId] = new SupportingFileUploadInfo(fileVersion, uploadUri, uploadSettings);
     }
 }
        internal ImageDecoratorsList(ImageDecoratorsManager decoratorsManager, BlogPostSettingsBag settingsBag, bool addDefaultBorderDecorator)
        {
            _decoratorsManager = decoratorsManager;
            _decoratorsSettingsBag = settingsBag;
            List<ImageDecorator> decorators = new List<ImageDecorator>();

            string appliedDecorators = settingsBag.GetString(APPLIED_DECORATORS, "");
            //Add all of the defined decorators from the settings bag to the decoratorslist.
            //Bug fix note: collect decorators into an arraylist to avoid enumeration modified exception
            //from _decoratorsSettingsBag.SubsettingNames when calling AddDecorator(decorator);
            foreach (string decoratorId in appliedDecorators.Split(','))
            {
                ImageDecorator decorator = decoratorsManager.GetImageDecorator(decoratorId);
                if (decorator != null)
                {
                    decorators.Add(decorator);
                }
            }

            AddDecorator(decorators.ToArray());

            if (addDefaultBorderDecorator && (BorderImageDecorator == null))
                AddDecorator(HtmlBorderDecorator.Id);
        }
Exemple #6
0
        internal void MarkUploaded(string uploadContextId, int fileVersion, Uri uploadUri, BlogPostSettingsBag uploadSettings)
        {
            SupportingFileUploadInfo uploadInfo = (SupportingFileUploadInfo)_uploadInfos[uploadContextId];

            if (uploadInfo != null)
            {
                //update the existing info
                uploadInfo.UploadedFileVersion = fileVersion;
                uploadInfo.UploadUri           = uploadUri;
                uploadInfo.UploadSettings      = uploadSettings;
            }
            else
            {
                _uploadInfos[uploadContextId] = new SupportingFileUploadInfo(fileVersion, uploadUri, uploadSettings);
            }
        }
Exemple #7
0
        internal void AddUploadInfo(string uploadContext, int uploadedFileVersion, Uri uploadUri, BlogPostSettingsBag settings)
        {
            SupportingFileUploadInfo uploadInfo = new SupportingFileUploadInfo(uploadedFileVersion, uploadUri, settings);

            _uploadInfos[uploadContext] = uploadInfo;
        }
Exemple #8
0
 public SupportingFileUploadInfo(int uploadedFileVersion, Uri uploadUri, BlogPostSettingsBag settings)
 {
     _uploadUri           = uploadUri;
     _uploadSettings      = settings;
     _uploadedFileVersion = uploadedFileVersion;
 }
        internal ISupportingFile CreateSupportingFile(Uri uri, int version, string fileName, string fileNameUniqueToken, bool embedded, BlogPostSettingsBag settings)
        {
            Debug.Assert(fileNameUniqueToken != null); //bulletproofing for old post files

            return RegisterSupportingFile(new VersionedSupportingFile(this, version, uri, fileName, fileNameUniqueToken, embedded, settings));
        }
Exemple #10
0
        internal ISupportingFile CreateSupportingFile(Uri uri, int version, string fileName, string fileNameUniqueToken, bool embedded, BlogPostSettingsBag settings)
        {
            Debug.Assert(fileNameUniqueToken != null);             //bulletproofing for old post files

            return(RegisterSupportingFile(new VersionedSupportingFile(this, version, uri, fileName, fileNameUniqueToken, embedded, settings)));
        }
Exemple #11
0
 public ImageDecoratorSettingsBagAdapter(BlogPostSettingsBag settingsBag)
 {
     _settingsBag = settingsBag;
 }
        private void AddSettings(string prefix, BlogPostSettingsBag settings)
        {
            foreach (string name in settings.Names)
            {
                AddData(prefix + name, settings[name]);
            }

            foreach (string subsettingsName in settings.SubsettingNames)
            {
                AddSettings(prefix + subsettingsName + "/", settings.GetSubSettings(subsettingsName));
            }
        }
 internal ImageDecoratorsList(ImageDecoratorsManager decoratorsManager, BlogPostSettingsBag settingsBag)
     : this(decoratorsManager, settingsBag, true)
 {
 }
Exemple #14
0
        private static List <NewImageInfo> ScanImages(IBlogPostHtmlEditor currentEditor, IEditorAccount editorAccount, ContentEditor editor, bool useDefaultTargetSettings)
        {
            List <NewImageInfo> newImages = new List <NewImageInfo>();

            ApplicationPerformance.ClearEvent("InsertImage");
            ApplicationPerformance.StartEvent("InsertImage");

            using (new WaitCursor())
            {
                IHTMLElement2 postBodyElement = (IHTMLElement2)((BlogPostHtmlEditorControl)currentEditor).PostBodyElement;
                if (postBodyElement != null)
                {
                    foreach (IHTMLElement imgElement in postBodyElement.getElementsByTagName("img"))
                    {
                        string imageSrc = imgElement.getAttribute("srcDelay", 2) as string;

                        if (string.IsNullOrEmpty(imageSrc))
                        {
                            imageSrc = imgElement.getAttribute("src", 2) as string;
                        }

                        // WinLive 96840 - Copying and pasting images within shared canvas should persist source
                        // decorator settings. "wlCopySrcUrl" is inserted while copy/pasting within canvas.
                        bool   copyDecoratorSettings = false;
                        string attributeCopySrcUrl   = imgElement.getAttribute("wlCopySrcUrl", 2) as string;
                        if (!string.IsNullOrEmpty(attributeCopySrcUrl))
                        {
                            copyDecoratorSettings = true;
                            imgElement.removeAttribute("wlCopySrcUrl", 0);
                        }

                        // Check if we need to apply default values for image decorators
                        bool   applyDefaultDecorator       = true;
                        string attributeNoDefaultDecorator = imgElement.getAttribute("wlNoDefaultDecorator", 2) as string;
                        if (!string.IsNullOrEmpty(attributeNoDefaultDecorator) && string.Compare(attributeNoDefaultDecorator, "TRUE", StringComparison.OrdinalIgnoreCase) == 0)
                        {
                            applyDefaultDecorator = false;
                            imgElement.removeAttribute("wlNoDefaultDecorator", 0);
                        }

                        string applyDefaultMargins = imgElement.getAttribute("wlApplyDefaultMargins", 2) as string;
                        if (!String.IsNullOrEmpty(applyDefaultMargins))
                        {
                            DefaultImageSettings defaultImageSettings = new DefaultImageSettings(editorAccount.Id, editor.DecoratorsManager);
                            MarginStyle          defaultMargin        = defaultImageSettings.GetDefaultImageMargin();
                            // Now apply it to the image
                            imgElement.style.marginTop    = String.Format(CultureInfo.InvariantCulture, "{0} px", defaultMargin.Top);
                            imgElement.style.marginLeft   = String.Format(CultureInfo.InvariantCulture, "{0} px", defaultMargin.Left);
                            imgElement.style.marginBottom = String.Format(CultureInfo.InvariantCulture, "{0} px", defaultMargin.Bottom);
                            imgElement.style.marginRight  = String.Format(CultureInfo.InvariantCulture, "{0} px", defaultMargin.Right);
                            imgElement.removeAttribute("wlApplyDefaultMargins", 0);
                        }

                        if ((UrlHelper.IsFileUrl(imageSrc) || IsFullPath(imageSrc)) && !ContentSourceManager.IsSmartContent(imgElement))
                        {
                            Uri imageSrcUri = new Uri(imageSrc);
                            try
                            {
                                BlogPostImageData imageData = BlogPostImageDataList.LookupImageDataByInlineUri(editor.ImageList, imageSrcUri);
                                Emoticon          emoticon  = EmoticonsManager.GetEmoticon(imgElement);
                                if (imageData == null && emoticon != null)
                                {
                                    // This is usually an emoticon copy/paste and needs to be cleaned up.
                                    Uri inlineImageUri = editor.EmoticonsManager.GetInlineImageUri(emoticon);
                                    imgElement.setAttribute("src", UrlHelper.SafeToAbsoluteUri(inlineImageUri), 0);
                                }
                                else if (imageData == null)
                                {
                                    if (!File.Exists(imageSrcUri.LocalPath))
                                    {
                                        throw new FileNotFoundException(imageSrcUri.LocalPath);
                                    }

                                    // WinLive 188841: Manually attach the behavior so that the image cannot be selected or resized while its loading.
                                    DisabledImageElementBehavior disabledImageBehavior = new DisabledImageElementBehavior(editor.IHtmlEditorComponentContext);
                                    disabledImageBehavior.AttachToElement(imgElement);

                                    Size sourceImageSize                      = ImageUtils.GetImageSize(imageSrcUri.LocalPath);
                                    ImagePropertiesInfo  imageInfo            = new ImagePropertiesInfo(imageSrcUri, sourceImageSize, new ImageDecoratorsList(editor.DecoratorsManager, new BlogPostSettingsBag()));
                                    DefaultImageSettings defaultImageSettings = new DefaultImageSettings(editorAccount.Id, editor.DecoratorsManager);

                                    // Make sure this is set because some imageInfo properties depend on it.
                                    imageInfo.ImgElement = imgElement;

                                    bool isMetafile = ImageHelper2.IsMetafile(imageSrcUri.LocalPath);
                                    ImageClassification imgClass = ImageHelper2.Classify(imageSrcUri.LocalPath);
                                    if (!isMetafile && ((imgClass & ImageClassification.AnimatedGif) != ImageClassification.AnimatedGif))
                                    {
                                        // WinLive 96840 - Copying and pasting images within shared canvas should persist source
                                        // decorator settings.
                                        if (copyDecoratorSettings)
                                        {
                                            // Try to look up the original copied source image.
                                            BlogPostImageData imageDataOriginal = BlogPostImageDataList.LookupImageDataByInlineUri(editor.ImageList, new Uri(attributeCopySrcUrl));
                                            if (imageDataOriginal != null && imageDataOriginal.GetImageSourceFile() != null)
                                            {
                                                // We have the original image reference, so lets make a clone of it.
                                                BlogPostSettingsBag originalBag            = (BlogPostSettingsBag)imageDataOriginal.ImageDecoratorSettings.Clone();
                                                ImageDecoratorsList originalDecoratorsList = new ImageDecoratorsList(editor.DecoratorsManager, originalBag);

                                                ImageFileData originalImageFileData = imageDataOriginal.GetImageSourceFile();
                                                Size          originalImageSize     = new Size(originalImageFileData.Width, originalImageFileData.Height);
                                                imageInfo = new ImagePropertiesInfo(originalImageFileData.Uri, originalImageSize, originalDecoratorsList);
                                            }
                                            else
                                            {
                                                // There are probably decorators applied to the image, but in a different editor so we can't access them.
                                                // We probably don't want to apply any decorators to this image, so apply blank decorators and load the
                                                // image as full size so it looks like it did before.
                                                imageInfo.ImageDecorators     = defaultImageSettings.LoadBlankLocalImageDecoratorsList();
                                                imageInfo.InlineImageSizeName = ImageSizeName.Full;
                                            }
                                        }
                                        else if (applyDefaultDecorator)
                                        {
                                            imageInfo.ImageDecorators = defaultImageSettings.LoadDefaultImageDecoratorsList();

                                            if ((imgClass & ImageClassification.TransparentGif) == ImageClassification.TransparentGif)
                                            {
                                                imageInfo.ImageDecorators.AddDecorator(NoBorderDecorator.Id);
                                            }
                                        }
                                        else
                                        {
                                            // Don't use default values for decorators
                                            imageInfo.ImageDecorators     = defaultImageSettings.LoadBlankLocalImageDecoratorsList();
                                            imageInfo.InlineImageSizeName = ImageSizeName.Full;
                                        }
                                    }
                                    else
                                    {
                                        ImageDecoratorsList decorators = new ImageDecoratorsList(editor.DecoratorsManager, new BlogPostSettingsBag());
                                        decorators.AddDecorator(editor.DecoratorsManager.GetDefaultRemoteImageDecorators());
                                        imageInfo.ImageDecorators = decorators;
                                    }

                                    imageInfo.ImgElement       = imgElement;
                                    imageInfo.DhtmlImageViewer = editorAccount.EditorOptions.DhtmlImageViewer;

                                    //discover the "natural" target settings from the DOM
                                    string linkTargetUrl = imageInfo.LinkTargetUrl;
                                    if (linkTargetUrl == imageSrc)
                                    {
                                        imageInfo.LinkTarget = LinkTargetType.IMAGE;
                                    }
                                    else if (!String.IsNullOrEmpty(linkTargetUrl) && !UrlHelper.IsFileUrl(linkTargetUrl))
                                    {
                                        imageInfo.LinkTarget = LinkTargetType.URL;
                                    }
                                    else
                                    {
                                        imageInfo.LinkTarget = LinkTargetType.NONE;
                                    }

                                    if (useDefaultTargetSettings)
                                    {
                                        if (!GlobalEditorOptions.SupportsFeature(ContentEditorFeature.SupportsImageClickThroughs) && imageInfo.DefaultLinkTarget == LinkTargetType.IMAGE)
                                        {
                                            imageInfo.DefaultLinkTarget = LinkTargetType.NONE;
                                        }

                                        if (imageInfo.LinkTarget == LinkTargetType.NONE)
                                        {
                                            imageInfo.LinkTarget = imageInfo.DefaultLinkTarget;
                                        }
                                        if (imageInfo.DefaultLinkOptions.ShowInNewWindow)
                                        {
                                            imageInfo.LinkOptions.ShowInNewWindow = true;
                                        }
                                        imageInfo.LinkOptions.UseImageViewer       = imageInfo.DefaultLinkOptions.UseImageViewer;
                                        imageInfo.LinkOptions.ImageViewerGroupName = imageInfo.DefaultLinkOptions.ImageViewerGroupName;
                                    }

                                    Size defaultImageSize = defaultImageSettings.GetDefaultInlineImageSize();
                                    Size initialSize      = ImageUtils.GetScaledImageSize(defaultImageSize.Width, defaultImageSize.Height, sourceImageSize);

                                    // add to list of new images
                                    newImages.Add(new NewImageInfo(imageInfo, imgElement, initialSize, disabledImageBehavior));
                                }
                                else
                                {
                                    // When switching blogs, try to adapt image viewer settings according to the blog settings.

                                    ImagePropertiesInfo imageInfo = new ImagePropertiesInfo(imageSrcUri, ImageUtils.GetImageSize(imageSrcUri.LocalPath), new ImageDecoratorsList(editor.DecoratorsManager, imageData.ImageDecoratorSettings));
                                    imageInfo.ImgElement = imgElement;
                                    // Make sure the new crop and tilt decorators get loaded
                                    imageInfo.ImageDecorators.MergeDecorators(DefaultImageSettings.GetImplicitLocalImageDecorators());
                                    string viewer = imageInfo.DhtmlImageViewer;
                                    if (viewer != editorAccount.EditorOptions.DhtmlImageViewer)
                                    {
                                        imageInfo.DhtmlImageViewer = editorAccount.EditorOptions.DhtmlImageViewer;
                                        imageInfo.LinkOptions      = imageInfo.DefaultLinkOptions;
                                    }

                                    // If the image is an emoticon, update the EmoticonsManager with the image's uri so that duplicate emoticons can point to the same file.
                                    if (emoticon != null)
                                    {
                                        editor.EmoticonsManager.SetInlineImageUri(emoticon, imageData.InlineImageFile.Uri);
                                    }
                                }
                            }
                            catch (ArgumentException e)
                            {
                                Trace.WriteLine("Could not initialize image: " + imageSrc);
                                Trace.WriteLine(e.ToString());
                            }
                            catch (DirectoryNotFoundException)
                            {
                                Debug.WriteLine("Image file does not exist: " + imageSrc);
                            }
                            catch (FileNotFoundException)
                            {
                                Debug.WriteLine("Image file does not exist: " + imageSrc);
                            }
                            catch (IOException e)
                            {
                                Debug.WriteLine("Image file cannot be read: " + imageSrc + " " + e);
                                DisplayMessage.Show(MessageId.FileInUse, imageSrc);
                            }
                        }
                    }
                }
            }

            return(newImages);
        }
 internal void AddUploadInfo(string uploadContext, int uploadedFileVersion, Uri uploadUri, BlogPostSettingsBag settings)
 {
     SupportingFileUploadInfo uploadInfo = new SupportingFileUploadInfo(uploadedFileVersion, uploadUri, settings);
     _uploadInfos[uploadContext] = uploadInfo;
 }
 public SupportingFileUploadInfo(int uploadedFileVersion, Uri uploadUri, BlogPostSettingsBag settings)
 {
     _uploadUri = uploadUri;
     _uploadSettings = settings;
     _uploadedFileVersion = uploadedFileVersion;
 }
 internal VersionedSupportingFile(SupportingFileFactory fileFactory, int version, Uri fileUri, string fileName, string fileNameUniqueToken, bool embedded, BlogPostSettingsBag fileProperties)
 {
     _fileFactory = fileFactory;
     _fileVersion = version;
     _fileUri = fileUri;
     _fileName = fileName;
     _embedded = embedded;
     _properties = fileProperties;
     _fileNameUniqueToken = fileNameUniqueToken;
 }
        internal ImageDecoratorsList(ImageDecoratorsManager decoratorsManager, BlogPostSettingsBag settingsBag)
            : this(decoratorsManager, settingsBag, true)
        {

        }
 public ImageDecoratorSettingsBagAdapter(BlogPostSettingsBag settingsBag)
 {
     _settingsBag = settingsBag;
 }