当前位置: 首页>>代码示例>>C#>>正文


C# Storage.OpenStorage方法代码示例

本文整理汇总了C#中Storage.OpenStorage方法的典型用法代码示例。如果您正苦于以下问题:C# Storage.OpenStorage方法的具体用法?C# Storage.OpenStorage怎么用?C# Storage.OpenStorage使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Storage的用法示例。


在下文中一共展示了Storage.OpenStorage方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: SaveCore

        private void SaveCore(IBlogPostEditingContext editingContext, PostEditorFile autoSaveSourceFile, string filePath)
        {
            // did this file exist prior to the attempt to save (if no, we need to delete
            // it if an exceptoin occurs -- otherwise we leave a "zombie" post file with
            // no available streams
            bool isPreviouslyUnsaved = !IsSaved;

            try
            {
                try
                {
                    // alias blog-post
                    BlogPost blogPost = editingContext.BlogPost;
                    Debug.Assert(!blogPost.IsTemporary, "Saving temporary style detection post!?");

                    // write out all of the fields
                    using (Storage postStorage = new Storage(filePath, StorageMode.OpenOrCreate, true))
                    {
                        // file-format clsid
                        postStorage.Clsid = Version2FormatCLSID;

                        // meta-data
                        WriteString(postStorage, DESTINATION_BLOG_ID, editingContext.BlogId);
                        WriteString(postStorage, SERVER_SUPPORTING_FILE_DIR, editingContext.ServerSupportingFileDirectory);

                        // blog post
                        WriteString(postStorage, POST_ID, blogPost.Id);
                        WriteBoolean(postStorage, POST_ISPAGE, blogPost.IsPage);
                        WriteString(postStorage, POST_TITLE, blogPost.Title);
                        WriteXml(postStorage, POST_CATEGORIES, blogPost.Categories, new XmlWriteHandler(WriteCategories));
                        WriteXml(postStorage, POST_NEW_CATEGORIES, blogPost.NewCategories, new XmlWriteHandler(WriteCategories));
                        WriteDateTime(postStorage, POST_DATEPUBLISHED, blogPost.DatePublished);
                        WriteDateTime(postStorage, POST_DATEPUBLISHED_OVERRIDE, blogPost.DatePublishedOverride);
                        WriteCommentPolicy(postStorage, blogPost.CommentPolicy);
                        WriteTrackbackPolicy(postStorage, blogPost.TrackbackPolicy);
                        WriteString(postStorage, POST_KEYWORDS, blogPost.Keywords);
                        WriteString(postStorage, POST_EXCERPT, blogPost.Excerpt);
                        WriteString(postStorage, POST_PERMALINK, blogPost.Permalink);
                        WriteString(postStorage, POST_LINK, blogPost.Permalink); // write for legacy compatability with beta 1
                        WriteXml(postStorage, POST_PINGURLS_PENDING, blogPost.PingUrlsPending, new XmlWriteHandler(WritePingUrls));
                        WriteXml(postStorage, POST_PINGURLS_SENT, blogPost.PingUrlsSent, new XmlWriteHandler(WritePingUrls));
                        WriteString(postStorage, POST_SLUG, blogPost.Slug);
                        WriteString(postStorage, POST_PASSWORD, blogPost.Password);
                        WriteString(postStorage, POST_AUTHOR_ID, blogPost.Author.Id);
                        WriteString(postStorage, POST_AUTHOR_NAME, blogPost.Author.Name);
                        WriteString(postStorage, POST_PAGE_PARENT_ID, blogPost.PageParent.Id);
                        WriteString(postStorage, POST_PAGE_PARENT_NAME, blogPost.PageParent.Name);
                        WriteString(postStorage, POST_PAGE_ORDER, blogPost.PageOrder);
                        WriteString(postStorage, POST_ETAG, blogPost.ETag);
                        WriteXml(postStorage, POST_ATOM_REMOTE_POST, blogPost.AtomRemotePost, new XmlWriteHandler(XmlDocWriteHandler));

                        //save the post info hash
                        WriteString(postStorage, POST_CONTENTS_VERSION_SIGNATURE, blogPost.ContentsVersionSignature);

                        // contents (with fixups for local files)
                        SupportingFilePersister supportingFilePersister = new SupportingFilePersister(postStorage.OpenStorage(POST_SUPPORTING_FILES, StorageMode.Create, true));
                        //BlogPostReferenceFixedHandler fixedReferenceHandler = new BlogPostReferenceFixedHandler(editingContext.ImageDataList);
                        //string fixedUpPostContents = supportingFilePersister.SaveFilesAndFixupReferences(blogPost.Contents, new ReferenceFixedCallback(fixedReferenceHandler.HandleReferenceFixed)) ;

                        //write the attached file data
                        //supportingFilePersister.
                        SupportingFileReferenceList referenceList = SupportingFileReferenceList.CalculateReferencesForSave(editingContext);
                        WriteXml(postStorage, POST_ATTACHED_FILES, null, new XmlWriteHandler(new AttachedFileListWriter(supportingFilePersister, editingContext, referenceList).WriteAttachedFileList));

                        WriteXml(postStorage, POST_IMAGE_FILES, editingContext.ImageDataList, new XmlWriteHandler(new AttachedImageListWriter(referenceList).WriteImageFiles));

                        //write the extension data
                        WriteXml(postStorage, POST_EXTENSION_DATA_LIST, editingContext.ExtensionDataList, new XmlWriteHandler(new ExtensionDataListWriter(supportingFilePersister, blogPost.Contents).WriteExtensionDataList));

                        //Convert file references in the HTML contents to the new storage path
                        string fixedUpPostContents = supportingFilePersister.FixupHtmlReferences(blogPost.Contents);
                        WriteStringUtf8(postStorage, POST_CONTENTS, fixedUpPostContents);

                        string originalSourcePath = autoSaveSourceFile == null ? ""
                            : autoSaveSourceFile.IsSaved ? autoSaveSourceFile.TargetFile.FullName
                            : autoSaveSourceFile.TargetDirectory.FullName;
                        WriteStringUtf8(postStorage, ORIGINAL_SOURCE_PATH, originalSourcePath);

                        // save to storage
                        postStorage.Commit();

                        // mark file as saved
                        TargetFile = new FileInfo(filePath);
                    }
                }
                catch (Exception ex)
                {
                    Trace.Fail("Unexpected exception type in PostEditorFile.Save. 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);
                }
            }
            catch
            {
                // if we had no file previously and an exception occurs then
                // we need to delete the file
                if (isPreviouslyUnsaved && File.Exists(filePath))
                    try { File.Delete(filePath); }
                    catch { }

//.........这里部分代码省略.........
开发者ID:igoravl,项目名称:OpenLiveWriter,代码行数:101,代码来源:PostEditorFile.cs

示例2: Load

        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);
            }
        }
开发者ID:igoravl,项目名称:OpenLiveWriter,代码行数:95,代码来源:PostEditorFile.cs


注:本文中的Storage.OpenStorage方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。