Example #1
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 #2
0
 private bool IsReferencedImage(BlogPostImageData imageInfo)
 {
     ImageFileData[] imageFileArray = new ImageFileData[] { imageInfo.InlineImageFile, imageInfo.LinkedImageFile };
     foreach (ImageFileData imageFile in imageFileArray)
     {
         if (imageFile != null && _referenceList.IsReferenced(imageFile.SupportingFile))
         {
             return true;
         }
     }
     return false;
 }
Example #3
0
 public void RemoveImage(BlogPostImageData imageData)
 {
     _list.Add(imageData);
 }
Example #4
0
 public void AddImage(BlogPostImageData imageData)
 {
     _list.Add(imageData);
 }
 public void RemoveImage(BlogPostImageData imageData)
 {
     _list.Add(imageData);
 }
 public void AddImage(BlogPostImageData imageData)
 {
     _list.Add(imageData);
 }
 public BlogPostImageDataList(BlogPostImageData[] images)
 {
     _list.AddRange(images);
 }