private BlogPostImageData(ImageFileData imageSource, ImageFileData imageShadowSource, ImageFileData inlineImageFile, ImageFileData linkedImageFile, BlogPostImageServiceUploadInfo uploadInfo, BlogPostSettingsBag decoratorSettings)
 {
     ImageSourceFile = imageSource;
     ImageSourceShadowFile = imageShadowSource;
     InlineImageFile = inlineImageFile;
     LinkedImageFile = linkedImageFile;
     UploadInfo = uploadInfo;
     ImageDecoratorSettings = decoratorSettings;
 }
Example #2
0
 private BlogPostImageData(ImageFileData imageSource, ImageFileData imageShadowSource, ImageFileData inlineImageFile, ImageFileData linkedImageFile, BlogPostImageServiceUploadInfo uploadInfo, BlogPostSettingsBag decoratorSettings)
 {
     ImageSourceFile        = imageSource;
     ImageSourceShadowFile  = imageShadowSource;
     InlineImageFile        = inlineImageFile;
     LinkedImageFile        = linkedImageFile;
     UploadInfo             = uploadInfo;
     ImageDecoratorSettings = decoratorSettings;
 }
        internal BlogPostExtensionData(string id, BlogPostSettingsBag settings, ISupportingFileService fileService, Hashtable fileMappings)
        {
            _id          = id;
            _settings    = settings;
            _fileService = fileService;

            _fileIds         = fileMappings;
            _refreshCallBack = null;
            _objectContext   = null;
        }
 public BlogPostSettingsBag CreateSubSettings(string key)
 {
     BlogPostSettingsBag val = GetSubSettings(key);
     if (val == null)
     {
         val = new BlogPostSettingsBag();
         subsettings[key] = val;
         subsettingsOrderedKeyList.Add(key);
     }
     return val;
 }
Example #5
0
        public BlogPostSettingsBag CreateSubSettings(string key)
        {
            BlogPostSettingsBag val = GetSubSettings(key);

            if (val == null)
            {
                val = new BlogPostSettingsBag();
                subsettings[key] = val;
                subsettingsOrderedKeyList.Add(key);
            }
            return(val);
        }
Example #6
0
        public object Clone()
        {
            BlogPostSettingsBag clone = new BlogPostSettingsBag();

            foreach (string key in Names)
            {
                string value = this[key];
                clone[key] = value;
            }

            foreach (string name in SubsettingNames)
            {
                BlogPostSettingsBag sub = GetSubSettings(name);
                clone.subsettings[name]         = (BlogPostSettingsBag)sub.Clone();
                clone.settingsOrderedKeyList    = (ArrayList)settingsOrderedKeyList.Clone();
                clone.subsettingsOrderedKeyList = (ArrayList)subsettingsOrderedKeyList.Clone();
            }
            return(clone);
        }
            public void ReferenceFixedCallback(string oldReference, string newReference)
            {
                ISupportingFile file = _editingContext.SupportingFileService.GetFileByUri(new Uri(newReference));

                if (file != null)
                {
                    foreach (BlogPostImageData imageData in _editingContext.ImageDataList)
                    {
                        // We can no longer trust the target settings for this file, so we must remove them
                        // this means the first time the object is clicked it will read the settings from the DOM
                        if (file.FileId == imageData.InlineImageFile.SupportingFile.FileId)
                        {
                            BlogPostSettingsBag settings =
                                imageData.ImageDecoratorSettings.GetSubSettings(HtmlImageTargetDecorator.Id);
                            foreach (string settingName in HtmlImageTargetDecoratorSettings.ImageReferenceFixedStaleProperties)
                            {
                                settings.Remove(settingName);
                            }
                        }
                    }
                }
            }
Example #8
0
            public object ReadImageFiles(XmlTextReader reader)
            {
                BlogPostImageDataList imageFiles = new BlogPostImageDataList();
                BlogPostImageData blogPostImageData = null;
                while (reader.Read())
                {
                    if (reader.NodeType == XmlNodeType.Element)
                    {
                        if (reader.LocalName == IMAGE_FILE_ELEMENT)
                        {
                            blogPostImageData = new BlogPostImageData();
                        }
                        else if (reader.LocalName == IMAGE_FILE_LINK_ELEMENT || reader.LocalName == SUPPORTING_FILE_LINK_ELEMENT)
                        {
                            if (blogPostImageData == null)
                                throw PostEditorStorageException.Create(new StorageInvalidFormatException());

                            ImageFileData imageFileData;
                            if (reader.LocalName == IMAGE_FILE_LINK_ELEMENT) //BACKWARDS_COMPATABILITY: used for backward compatibility with pre-Beta2 Writer files
                            {
                                ISupportingFile supportingFile;
                                string storagePath = reader.GetAttribute(IMAGE_FILE_LINK_PATH_ATTRIBUTE);

                                //the old image data saves a "corrupted" lowercase version of the embedded URL,
                                //so we need to take that into account and fix it
                                bool embeddedFile =
                                    storagePath.StartsWith(SupportingFilePersister.SUPPORTING_FILE_PREFIX.ToLower(CultureInfo.InvariantCulture));
                                if (embeddedFile)
                                {
                                    //fix up the corrupted storage path URL so that the reference fixer can resolve it.
                                    storagePath = storagePath.Replace(SupportingFilePersister.SUPPORTING_FILE_PREFIX.ToLower(CultureInfo.InvariantCulture),
                                        SupportingFilePersister.SUPPORTING_FILE_PREFIX).TrimEnd('/');

                                    //convert the internal storage path to the local temp path
                                    storagePath = _supportingFilePersister.LoadFilesAndFixupReferences(new string[] { storagePath })[0];

                                    //register the supporting file
                                    supportingFile = _fileService.CreateSupportingFileFromStoragePath(Path.GetFileName(storagePath), storagePath);
                                }
                                else
                                {
                                    //register the linked supporting file
                                    supportingFile = _fileService.AddLinkedSupportingFileReference(new Uri(storagePath));
                                }

                                imageFileData = new ImageFileData(supportingFile);
                                for (int i = 0; i < reader.AttributeCount; i++)
                                {
                                    reader.MoveToAttribute(i);
                                    switch (reader.LocalName)
                                    {
                                        case IMAGE_FILE_LINK_WIDTH_ATTRIBUTE:
                                            imageFileData.Width = Int32.Parse(reader.Value, CultureInfo.InvariantCulture);
                                            break;
                                        case IMAGE_FILE_LINK_HEIGHT_ATTRIBUTE:
                                            imageFileData.Height = Int32.Parse(reader.Value, CultureInfo.InvariantCulture);
                                            break;
                                        case IMAGE_FILE_LINK_RELATIONSHIP_ATTRIBUTE:
                                            imageFileData.Relationship = (ImageFileRelationship)ImageFileRelationship.Parse(typeof(ImageFileRelationship), reader.Value);
                                            break;
                                        case IMAGE_FILE_LINK_PUBLISH_URL_ATTRIBUTE: //BACKWARDS_COMPATABILITY: not compatible with Beta2
                                            //imageFileData.PublishedUri = new Uri(reader.Value);
                                            break;
                                    }
                                }
                            }
                            else
                            {
                                string fileId = reader.GetAttribute(SUPPORTING_FILE_LINK_FILE_ID_ATTRIBUTE);
                                ISupportingFile supportingFile = _fileService.GetFileById(fileId);
                                if (supportingFile != null)
                                {
                                    imageFileData = new ImageFileData(supportingFile);
                                }
                                else
                                {
                                    Debug.Fail("Invalid post file state detected: image is referencing a file that is not attached");
                                    imageFileData = null;
                                }
                            }
                            if (imageFileData != null)
                            {
                                if (imageFileData.Relationship == ImageFileRelationship.Inline)
                                    blogPostImageData.InlineImageFile = imageFileData;
                                else if (imageFileData.Relationship == ImageFileRelationship.Linked)
                                    blogPostImageData.LinkedImageFile = imageFileData;
                                else if (imageFileData.Relationship == ImageFileRelationship.Source)
                                    blogPostImageData.ImageSourceFile = imageFileData;
                                else if (imageFileData.Relationship == ImageFileRelationship.SourceShadow)
                                    blogPostImageData.ImageSourceShadowFile = imageFileData;
                                else
                                    Debug.Fail("Unknown image file relationship detected: " + imageFileData.Relationship.ToString());
                            }
                        }
                        else if (reader.LocalName == IMAGE_UPLOAD_ELEMENT)
                        {
                            for (int i = 0; i < reader.AttributeCount; i++)
                            {
                                reader.MoveToAttribute(i);
                                switch (reader.LocalName)
                                {
                                    case IMAGE_UPLOAD_SERVICE_ID_ATTRIBUTE:
                                        blogPostImageData.UploadInfo.ImageServiceId = reader.Value;
                                        break;
                                }
                            }
                        }
                        else if (reader.LocalName == SETTINGS_BAG_ELEMENT)
                        {
                            BlogPostSettingsBag settings = new BlogPostSettingsBag();
                            string settingsBagName = ReadBlogPostSettingsBag(reader, settings);
                            if (settingsBagName == IMAGE_DECORATORS_SETTINGSBAG_NAME)
                            {
                                blogPostImageData.ImageDecoratorSettings = settings;
                            }
                            else if (settingsBagName == IMAGE_UPLOAD_SETTINGSBAG_NAME)
                            {
                                blogPostImageData.UploadInfo.Settings = settings;
                            }
                            else
                                Debug.Fail("Unknown settings bag encountered: " + settingsBagName);
                        }
                    }
                    else if (reader.NodeType == XmlNodeType.EndElement && reader.LocalName == IMAGE_FILE_ELEMENT)
                    {
                        //initialize the shadow file if one doesn't already exist. (necessary for pre-beta2 post files)
                        blogPostImageData.InitShadowFile(_fileService);

                        imageFiles.AddImage(blogPostImageData);
                        blogPostImageData = null;
                    }
                }
                return imageFiles;
            }
Example #9
0
        public BlogPostSettingsBag GetSubSettings(string key)
        {
            BlogPostSettingsBag val = (BlogPostSettingsBag)subsettings[key];

            return(val);
        }
Example #10
0
        private static void WriteBlogPostSettingsBag(XmlTextWriter writer, BlogPostSettingsBag settings, string name)
        {
            writer.WriteStartElement(SETTINGS_BAG_ELEMENT);
            WriteNonNullAttribute(writer, SETTINGS_BAG_NAME_ATTRIBUTE, name);
            foreach (string key in settings.Names)
            {
                writer.WriteStartElement(SETTINGS_BAG_SETTING_ELEMENT);
                writer.WriteAttributeString(SETTINGS_BAG_NAME_ATTRIBUTE, key);
                WriteNonNullAttribute(writer, SETTINGS_BAG_VALUE_ATTRIBUTE, settings[key]);
                writer.WriteEndElement(); //end SETTINGS_BAG_SETTING_ELEMENT
            }

            //save out the subsettings
            foreach (string subSettingName in settings.SubsettingNames)
            {
                WriteBlogPostSettingsBag(writer, settings.GetSubSettings(subSettingName), subSettingName);
            }

            writer.WriteEndElement();	//end SETTINGS_BAG_ELEMENT
        }
Example #11
0
 internal BlogPostImageServiceUploadInfo()
 {
     Settings = new BlogPostSettingsBag();
 }
        public object Clone()
        {
            BlogPostSettingsBag clone = new BlogPostSettingsBag();
            foreach (string key in Names)
            {
                string value = this[key];
                clone[key] = value;
            }

            foreach (string name in SubsettingNames)
            {
                BlogPostSettingsBag sub = GetSubSettings(name);
                clone.subsettings[name] = (BlogPostSettingsBag)sub.Clone();
                clone.settingsOrderedKeyList = (ArrayList)settingsOrderedKeyList.Clone();
                clone.subsettingsOrderedKeyList = (ArrayList)subsettingsOrderedKeyList.Clone();
            }
            return clone;
        }
 internal BlogPostImageServiceUploadInfo(string imageServiceId, BlogPostSettingsBag settings)
 {
     ImageServiceId = imageServiceId;
     Settings = settings;
 }
 internal BlogPostImageServiceUploadInfo()
 {
     Settings = new BlogPostSettingsBag();
 }
Example #15
0
            public void ReadUploadInfoData(XmlTextReader reader, SupportingFileFactory fileFactory)
            {
                Debug.Assert(reader.LocalName == ATTACHED_FILE_UPLOAD_ELEMENT, "Xml reader is improperly positioned");
                int depth = 0;

                string contextId = reader.GetAttribute(ATTACHED_FILE_UPLOAD_CONTEXT_ATTRIBUTE);
                string uploadUri = reader.GetAttribute(ATTACHED_FILE_UPLOAD_URI_ATTRIBUTE);
                string uploadVersionString = reader.GetAttribute(ATTACHED_FILE_UPLOAD_VERSION_ATTRIBUTE);
                int uploadVersion = -1;
                if (uploadVersionString != null)
                    uploadVersion = Int32.Parse(uploadVersionString, CultureInfo.InvariantCulture);

                //fixup the reference path
                BlogPostSettingsBag settings = new BlogPostSettingsBag();
                if (!reader.IsEmptyElement)
                {
                    depth = 1;
                    while (reader.Read())
                    {
                        if (reader.NodeType == XmlNodeType.Element)
                        {
                            bool isEmptyElement = reader.IsEmptyElement;
                            depth++;
                            if (reader.LocalName == SETTINGS_BAG_ELEMENT)
                            {
                                ReadBlogPostSettingsBag(reader, settings);

                                //this element was completely handled, and the stack was reset to its end element,
                                //so unset the depth and re-start the loop
                                depth--;
                                continue;
                            }
                            if (isEmptyElement)
                                depth--;
                        }
                        else if (reader.NodeType == XmlNodeType.EndElement)
                        {
                            depth--;
                        }

                        if (depth == 0)
                            break;
                    }
                }

                Trace.Assert(uploadUri != null, "Informational: UploadUri is null");

                fileFactory.AddUploadInfo(contextId, uploadVersion, uploadUri == null ? null : new Uri(uploadUri), settings);
                Debug.Assert(depth == 0 && reader.LocalName == ATTACHED_FILE_UPLOAD_ELEMENT, "Xmlreader is unexpectedly positioned (probably read to far!)");
            }
Example #16
0
            public void ReadFileVersionData(XmlTextReader reader, SupportingFileFactory fileFactory)
            {
                Debug.Assert(reader.LocalName == ATTACHED_FILE_VERSION_ELEMENT, "Xml reader is improperly positioned");
                int depth = 0;

                string fileName = reader.GetAttribute(ATTACHED_FILE_NAME);

                string fileNameUniqueToken = reader.GetAttribute(ATTACHED_FILE_NAME_UNIQUETOKEN);
                if (fileNameUniqueToken == null) //necessary for interim Wave2 M1 builds
                    fileNameUniqueToken = _fileService.CreateUniqueFileNameToken(fileName);

                string fileVersionString = reader.GetAttribute(ATTACHED_FILE_VERSION_ATTRIBUTE);
                int fileVersion = -1;
                if (fileVersionString != null)
                    fileVersion = Int32.Parse(fileVersionString, CultureInfo.InvariantCulture);

                bool embedded = bool.Parse(reader.GetAttribute(ATTACHED_FILE_EMBEDDED_ATTRIBUTE));
                string fileUriString = reader.GetAttribute(ATTACHED_FILE_URI_ATTRIBUTE);

                //fixup the reference path
                if (embedded)
                    fileUriString = _supportingFilePersister.LoadFilesAndFixupReferences(new string[] { fileUriString })[0];

                BlogPostSettingsBag settings = new BlogPostSettingsBag();
                if (!reader.IsEmptyElement)
                {
                    depth = 1;
                    while (reader.Read())
                    {
                        if (reader.NodeType == XmlNodeType.Element)
                        {
                            bool isEmptyElement = reader.IsEmptyElement;
                            depth++;
                            if (reader.LocalName == SETTINGS_BAG_ELEMENT)
                            {
                                ReadBlogPostSettingsBag(reader, settings);

                                //this element was completely handled, and the stack was reset to its end element,
                                //so unset the depth and re-start the loop
                                depth--;
                                continue;
                            }
                            if (isEmptyElement)
                                depth--;
                        }
                        else if (reader.NodeType == XmlNodeType.EndElement)
                        {
                            depth--;
                        }

                        if (depth == 0)
                            break;
                    }
                }

                fileFactory.CreateSupportingFile(new Uri(UrlHelper.CreateUrlFromPath(fileUriString)), fileVersion, fileName, fileNameUniqueToken, embedded, settings);

                Debug.Assert(depth == 0 && reader.LocalName == ATTACHED_FILE_VERSION_ELEMENT, "Xmlreader is unexpectedly positioned (probably read to far!)");
            }
Example #17
0
 internal BlogPostImageServiceUploadInfo(string imageServiceId, BlogPostSettingsBag settings)
 {
     ImageServiceId = imageServiceId;
     Settings       = settings;
 }
Example #18
0
        private static string ReadBlogPostSettingsBag(XmlTextReader reader, BlogPostSettingsBag settings)
        {
            Debug.Assert(reader.LocalName == SETTINGS_BAG_ELEMENT, "Xml reader is improperly positioned");
            int depth = 0;
            string settingsBagName = reader.GetAttribute(SETTINGS_BAG_NAME_ATTRIBUTE);
            if (!reader.IsEmptyElement)
            {
                depth = 1;
                while (reader.Read())
                {
                    if (reader.NodeType == XmlNodeType.Element)
                    {
                        bool isEmptyElement = reader.IsEmptyElement;
                        depth++;
                        if (reader.LocalName == SETTINGS_BAG_ELEMENT)
                        {
                            string subsettingsName = reader.GetAttribute(SETTINGS_BAG_NAME_ATTRIBUTE);
                            BlogPostSettingsBag subsettings = settings.CreateSubSettings(subsettingsName);
                            ReadBlogPostSettingsBag(reader, subsettings);

                            //this element was completely handled, and the stack was reset to its end element,
                            //so unset the depth and re-start the loop
                            depth--;
                            continue;
                        }
                        else if (reader.LocalName == SETTINGS_BAG_SETTING_ELEMENT)
                        {
                            string settingName = null;
                            string settingValue = null;

                            for (int i = 0; i < reader.AttributeCount; i++)
                            {
                                reader.MoveToAttribute(i);
                                switch (reader.LocalName)
                                {
                                    case SETTINGS_BAG_NAME_ATTRIBUTE:
                                        settingName = reader.Value;
                                        break;
                                    case SETTINGS_BAG_VALUE_ATTRIBUTE:
                                        settingValue = reader.Value;
                                        break;
                                }
                            }
                            settings[settingName] = settingValue;
                        }
                        if (isEmptyElement)
                            depth--;
                    }
                    else if (reader.NodeType == XmlNodeType.EndElement)
                    {
                        depth--;
                    }

                    if (depth == 0)
                        break;
                }
            }
            Debug.Assert(depth == 0 && reader.LocalName == SETTINGS_BAG_ELEMENT, "Xmlreader is unexpectedly positioned (probably read to far!)");
            return settingsBagName;
        }
        internal BlogPostExtensionData(string id, BlogPostSettingsBag settings, ISupportingFileService fileService, Hashtable fileMappings)
        {
            _id = id;
            _settings = settings;
            _fileService = fileService;

            _fileIds = fileMappings;
            _refreshCallBack = null;
            _objectContext = null;
        }