コード例 #1
0
 public FileUploadContext(BlogFileUploader fileUploader, string postId, ISupportingFile supportingFile, ISupportingFileUploadInfo uploadInfo, bool forceDirectImageLink)
 {
     _fileUploader         = fileUploader;
     _blogId               = fileUploader.BlogId;
     _postId               = postId;
     _supportingFile       = supportingFile;
     _uploadInfo           = uploadInfo;
     _forceDirectImageLink = forceDirectImageLink;
 }
コード例 #2
0
            public void UploadFilesAfterPublish(string postId)
            {
                // create a file uploader
                using (BlogFileUploader fileUploader = BlogFileUploader.CreateFileUploader(_blog, _publishingContext.EditingContext.ServerSupportingFileDirectory))
                {
                    // connect to the file uploader
                    fileUploader.Connect();

                    _referenceFixer.UploadFilesAfterPublish(postId, fileUploader);
                }
            }
コード例 #3
0
 public void DoAfterPostUploadWork(BlogFileUploader fileUploader, string postId)
 {
     foreach (ISupportingFile file in _fileList)
     {
         string uploadContext = fileUploader.DestinationContext;
         if (_uploadedFiles.ContainsKey(file.FileId))
         {
             ISupportingFileUploadInfo uploadInfo        = file.GetUploadInfo(uploadContext);
             FileUploadContext         fileUploadContext = new FileUploadContext(fileUploader, postId, file, uploadInfo, false);
             fileUploader.DoUploadWorkAfterPublish(fileUploadContext);
         }
     }
 }
コード例 #4
0
            public void DoUploadWork(string fileReference, BlogFileUploader fileUploader, bool isLightboxCloneEnabled)
            {
                // Get both strings into the same state which is unescaped
                string          unescapedFileReference = new Uri(fileReference).ToString();
                ISupportingFile file = null;

                foreach (ISupportingFile supportingFile in _fileList)
                {
                    if (supportingFile.FileUri.ToString() == unescapedFileReference)
                    {
                        file = supportingFile;
                        break;
                    }
                }

                if (file == null)
                {
                    string listString = "";
                    foreach (ISupportingFile supportingFile in _fileList)
                    {
                        listString += supportingFile.FileUri + "\r\n";
                    }
                    Trace.Fail(String.Format(CultureInfo.InvariantCulture, "Reference found to file that does not exist in SupportingFileService \r\nfileReference: {0}\r\n_fileList:\r\n{1}", fileReference, listString));
                    return;
                }


                string uploadContext = fileUploader.DestinationContext;

                ISupportingFileUploadInfo uploadInfo        = file.GetUploadInfo(uploadContext);
                FileUploadContext         fileUploadContext = new FileUploadContext(fileUploader, _postId, file, uploadInfo, isLightboxCloneEnabled);

                if (fileUploader.DoesFileNeedUpload(file, fileUploadContext))
                {
                    if (!_uploadedFiles.ContainsKey(file.FileId))
                    {
                        _uploadedFiles[file.FileId] = file;
                        Uri uploadUri = fileUploader.DoUploadWorkBeforePublish(fileUploadContext);
                        if (uploadUri != null)
                        {
                            file.MarkUploaded(uploadContext, uploadUri);
                            Debug.WriteLine(String.Format(CultureInfo.InvariantCulture, "File Uploaded: {0}", file.FileName));
                        }
                    }
                    else
                    {
                        Trace.Fail("This file has already been uploaded during this publish operation: " + file.FileName);
                    }
                }
            }
コード例 #5
0
            internal ImageReferenceFixer(BlogPostImageDataList list, string blogId)
            {
                string uploadDestinationContext = BlogFileUploader.GetFileUploadDestinationContext(blogId);

                foreach (BlogPostImageData imageData in list)
                {
                    if (imageData.InlineImageFile != null && imageData.InlineImageFile.GetPublishedUri(uploadDestinationContext) != null)
                    {
                        urlFixupTable[imageData.InlineImageFile.GetPublishedUri(uploadDestinationContext)] = imageData.InlineImageFile.Uri;
                        if (imageData.LinkedImageFile != null)
                        {
                            urlFixupTable[imageData.LinkedImageFile.GetPublishedUri(uploadDestinationContext)] = imageData.LinkedImageFile.Uri;
                        }
                    }
                }
            }
コード例 #6
0
            public void UploadFilesBeforePublish()
            {
                // create a file uploader
                using (BlogFileUploader fileUploader = BlogFileUploader.CreateFileUploader(_blog, _publishingContext.EditingContext.ServerSupportingFileDirectory))
                {
                    // connect to the file uploader
                    fileUploader.Connect();

                    // upload the files and fixup references within the contents of the blog post
                    string htmlContents = _publishingContext.EditingContext.BlogPost.Contents;

                    _referenceFixer = new BlogPostReferenceFixer(htmlContents, _publishingContext);
                    _referenceFixer.Parse();

                    string fixedHtml = HtmlReferenceFixer.FixLocalFileReferences(htmlContents, _referenceFixer.GetFileUploadReferenceFixer(fileUploader));
                    _publishingContext.EditingContext.BlogPost.Contents = fixedHtml;
                }
            }
コード例 #7
0
 public LocalFileTransformer(BlogPostReferenceFixer referenceFixer, BlogFileUploader uploader)
 {
     _referenceFixer = referenceFixer;
     _fileService    = _referenceFixer._uploadContext.EditingContext.SupportingFileService;
     _uploader       = uploader;
 }
コード例 #8
0
 public ReferenceFixer GetFileUploadReferenceFixer(BlogFileUploader uploader)
 {
     return(new ReferenceFixer(new LocalFileTransformer(this, uploader).Transform));
 }
コード例 #9
0
 public void UploadFilesAfterPublish(string postId, BlogFileUploader fileUploader)
 {
     _fileUploadWorker.DoAfterPostUploadWork(fileUploader, postId);
 }
コード例 #10
0
 public FileUploadContext(BlogFileUploader fileUploader, string postId, ISupportingFile supportingFile, ISupportingFileUploadInfo uploadInfo, bool forceDirectImageLink)
 {
     _fileUploader = fileUploader;
     _blogId = fileUploader.BlogId;
     _postId = postId;
     _supportingFile = supportingFile;
     _uploadInfo = uploadInfo;
     _forceDirectImageLink = forceDirectImageLink;
 }
コード例 #11
0
 public void DoAfterPostUploadWork(BlogFileUploader fileUploader, string postId)
 {
     foreach (ISupportingFile file in _fileList)
     {
         string uploadContext = fileUploader.DestinationContext;
         if (_uploadedFiles.ContainsKey(file.FileId))
         {
             ISupportingFileUploadInfo uploadInfo = file.GetUploadInfo(uploadContext);
             FileUploadContext fileUploadContext = new FileUploadContext(fileUploader, postId, file, uploadInfo, false);
             fileUploader.DoUploadWorkAfterPublish(fileUploadContext);
         }
     }
 }
コード例 #12
0
            public void DoUploadWork(string fileReference, BlogFileUploader fileUploader, bool isLightboxCloneEnabled)
            {
                // Get both strings into the same state which is unescaped
                string unescapedFileReference = new Uri(fileReference).ToString();
                ISupportingFile file = null;
                foreach (ISupportingFile supportingFile in _fileList)
                {
                    if (supportingFile.FileUri.ToString() == unescapedFileReference)
                    {
                        file = supportingFile;
                        break;
                    }
                }

                if (file == null)
                {
                    string listString = "";
                    foreach (ISupportingFile supportingFile in _fileList)
                    {
                        listString += supportingFile.FileUri + "\r\n";
                    }
                    Trace.Fail(String.Format(CultureInfo.InvariantCulture, "Reference found to file that does not exist in SupportingFileService \r\nfileReference: {0}\r\n_fileList:\r\n{1}", fileReference, listString));
                    return;
                }

                string uploadContext = fileUploader.DestinationContext;

                ISupportingFileUploadInfo uploadInfo = file.GetUploadInfo(uploadContext);
                FileUploadContext fileUploadContext = new FileUploadContext(fileUploader, _postId, file, uploadInfo, isLightboxCloneEnabled);

                if (fileUploader.DoesFileNeedUpload(file, fileUploadContext))
                {
                    if (!_uploadedFiles.ContainsKey(file.FileId))
                    {
                        _uploadedFiles[file.FileId] = file;
                        Uri uploadUri = fileUploader.DoUploadWorkBeforePublish(fileUploadContext);
                        if (uploadUri != null)
                        {
                            file.MarkUploaded(uploadContext, uploadUri);
                            Debug.WriteLine(String.Format(CultureInfo.InvariantCulture, "File Uploaded: {0}", file.FileName));
                        }
                    }
                    else
                    {
                        Trace.Fail("This file has already been uploaded during this publish operation: " + file.FileName);
                    }
                }

            }
コード例 #13
0
 public LocalFileTransformer(BlogPostReferenceFixer referenceFixer, BlogFileUploader uploader)
 {
     _referenceFixer = referenceFixer;
     _fileService = _referenceFixer._uploadContext.EditingContext.SupportingFileService;
     _uploader = uploader;
 }
コード例 #14
0
 public ReferenceFixer GetFileUploadReferenceFixer(BlogFileUploader uploader)
 {
     return new ReferenceFixer(new LocalFileTransformer(this, uploader).Transform);
 }
コード例 #15
0
 public void UploadFilesAfterPublish(string postId, BlogFileUploader fileUploader)
 {
     _fileUploadWorker.DoAfterPostUploadWork(fileUploader, postId);
 }