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;
 }
        public IBlogPostEditingContext Load(bool addToRecentDocs)
        {
            try
            {
                if (!IsSaved)
                    throw new InvalidOperationException("Attempted to load a PostEditorFile that has never been saved!");

                // add to shell recent documents
                if (addToRecentDocs)
                    Shell32.SHAddToRecentDocs(SHARD.PATHW, TargetFile.FullName);

                using (Storage postStorage = new Storage(TargetFile.FullName, StorageMode.Open, false))
                {
                    // meta-data
                    string destinationBlogId = ReadString(postStorage, DESTINATION_BLOG_ID);
                    string serverSupportingFileDirectory = ReadString(postStorage, SERVER_SUPPORTING_FILE_DIR);

                    // blog post
                    BlogPost blogPost = new BlogPost();
                    blogPost.Id = ReadString(postStorage, POST_ID);
                    blogPost.IsPage = SafeReadBoolean(postStorage, POST_ISPAGE, false);
                    blogPost.Title = ReadString(postStorage, POST_TITLE);
                    blogPost.Categories = (BlogPostCategory[])ReadXml(postStorage, POST_CATEGORIES, new XmlReadHandler(ReadCategories));
                    blogPost.NewCategories = (BlogPostCategory[])SafeReadXml(postStorage, POST_NEW_CATEGORIES, new XmlReadHandler(ReadCategories), new BlogPostCategory[] { });
                    blogPost.DatePublished = ReadDateTime(postStorage, POST_DATEPUBLISHED);
                    blogPost.DatePublishedOverride = ReadDateTime(postStorage, POST_DATEPUBLISHED_OVERRIDE);
                    blogPost.CommentPolicy = ReadCommentPolicy(postStorage);
                    blogPost.TrackbackPolicy = ReadTrackbackPolicy(postStorage);
                    blogPost.Keywords = ReadString(postStorage, POST_KEYWORDS);
                    blogPost.Excerpt = ReadString(postStorage, POST_EXCERPT);
                    blogPost.Permalink = SafeReadString(postStorage, POST_PERMALINK, String.Empty);
                    blogPost.PingUrlsPending = (string[])ReadXml(postStorage, POST_PINGURLS_PENDING, new XmlReadHandler(ReadPingUrls));
                    blogPost.PingUrlsSent = (string[])SafeReadXml(postStorage, POST_PINGURLS_SENT, new XmlReadHandler(ReadPingUrls), new string[0]);
                    blogPost.Slug = SafeReadString(postStorage, POST_SLUG, String.Empty);
                    blogPost.Password = SafeReadString(postStorage, POST_PASSWORD, String.Empty);
                    string authorId = SafeReadString(postStorage, POST_AUTHOR_ID, String.Empty);
                    string authorName = SafeReadString(postStorage, POST_AUTHOR_NAME, String.Empty);
                    blogPost.Author = new PostIdAndNameField(authorId, authorName);
                    string pageParentId = SafeReadString(postStorage, POST_PAGE_PARENT_ID, String.Empty);
                    string pageParentName = SafeReadString(postStorage, POST_PAGE_PARENT_NAME, String.Empty);
                    blogPost.PageParent = new PostIdAndNameField(pageParentId, pageParentName);
                    blogPost.PageOrder = SafeReadString(postStorage, POST_PAGE_ORDER, String.Empty);
                    blogPost.ETag = SafeReadString(postStorage, POST_ETAG, String.Empty);
                    blogPost.AtomRemotePost = (XmlDocument)SafeReadXml(postStorage, POST_ATOM_REMOTE_POST, new XmlReadHandler(XmlDocReadHandler), null);

                    try
                    {
                        blogPost.ContentsVersionSignature = ReadString(postStorage, POST_CONTENTS_VERSION_SIGNATURE);
                    }
                    catch (StorageFileNotFoundException) { } //BACKWARDS_COMPATABILITY: occurs if this file was created before the introduction of content signatures (pre-Beta2)

                    // post contents (must extract supporting files -- protect against leakage with try/catch
                    BlogPostSupportingFileStorage supportingFileStorage = new BlogPostSupportingFileStorage();
                    using (Storage postSupportStorage = postStorage.OpenStorage(POST_SUPPORTING_FILES, StorageMode.Open, false))
                    {
                        SupportingFilePersister supportingFilePersister = new SupportingFilePersister(postSupportStorage, supportingFileStorage);

                        //read the attached files
                        SupportingFileService supportingFileService = new SupportingFileService(supportingFileStorage);
                        try
                        {
                            ReadXml(postStorage, POST_ATTACHED_FILES, new XmlReadHandler(new AttachedFileListReader(supportingFileService, supportingFilePersister).ReadAttachedFileList));
                        }
                        catch (StorageFileNotFoundException) { } //occurs if this file was created before the introduction of extension data

                        //read in the image data (note: this must happen before fixing the file references)
                        BlogPostImageDataList imageDataList = (BlogPostImageDataList)ReadXml(postStorage, POST_IMAGE_FILES, new XmlReadHandler(new ImageListReader(supportingFilePersister, supportingFileService).ReadImageFiles));

                        //read the extension data settings
                        BlogPostExtensionDataList extensionDataList = new BlogPostExtensionDataList(supportingFileService);
                        try
                        {
                            ReadXml(postStorage, POST_EXTENSION_DATA_LIST, new XmlReadHandler(new ExtensionDataListReader(extensionDataList, supportingFilePersister, supportingFileService).ReadExtensionDataList));
                        }
                        catch (StorageFileNotFoundException) { } //occurs if this file was created before the introduction of extension data

                        //fix up the HTML content to reference the extracted files
                        blogPost.Contents = supportingFilePersister.FixupHtmlReferences(ReadStringUtf8(postStorage, POST_CONTENTS));

                        string originalSourcePath = SafeReadString(postStorage, ORIGINAL_SOURCE_PATH, null);
                        PostEditorFile autoSaveFile;
                        PostEditorFile file = GetFileFromSourcePath(originalSourcePath, out autoSaveFile);

                        // return init params
                        return new BlogPostEditingContext(destinationBlogId, blogPost, file, autoSaveFile, serverSupportingFileDirectory, supportingFileStorage, imageDataList, extensionDataList, supportingFileService);
                    }
                }
            }
            catch (Exception ex)
            {
                Trace.Fail("Unexpected exception type in PostEditorFile.Load. It is critical that only IO exceptions occur at this level of the system so please check the code which threw the exeption and see if there is a way to behave more robustly!\r\n"
                    + ex.ToString());
                throw PostEditorStorageException.Create(ex);
            }
        }
 public SupportingFilePersister(Storage fileSubStorage, BlogPostSupportingFileStorage supportingFileStorage)
     : this(fileSubStorage)
 {
     _supportingFileStorage = supportingFileStorage;
 }
 private void WriteSpellingContextDictionary(Storage postStorage, BlogPostSupportingFileStorage supportingFileStorage)
 {
     Stream spellingStream = supportingFileStorage.ReadSpellingContextDictionary();
     if (spellingStream != null)
     {
         using (spellingStream)
         {
             using (Stream stream = postStorage.OpenStream(SPELLING_CONTEXT_DICTIONARY, StorageMode.Create))
                 StreamHelper.Transfer(spellingStream, stream);
         }
     }
 }
        private void ReadSpellingContextDictionary(Storage postStorage, BlogPostSupportingFileStorage supportingFileStorage)
        {
            // try to get the dictionary stream
            Stream dictionaryStream;
            try { dictionaryStream = postStorage.OpenStream(SPELLING_CONTEXT_DICTIONARY, StorageMode.Open); }
            catch (StorageException) { return; }

            // write it to supporting file storage
            using (dictionaryStream)
                supportingFileStorage.WriteSpellingContextDictionary(dictionaryStream);
        }