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;
 }
            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);
                }
            }
 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);
         }
     }
 }
Exemplo n.º 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);
                    }
                }
            }
            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;
                        }
                    }
                }
            }
            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;
                }
            }
 public LocalFileTransformer(BlogPostReferenceFixer referenceFixer, BlogFileUploader uploader)
 {
     _referenceFixer = referenceFixer;
     _fileService    = _referenceFixer._uploadContext.EditingContext.SupportingFileService;
     _uploader       = uploader;
 }
 public ReferenceFixer GetFileUploadReferenceFixer(BlogFileUploader uploader)
 {
     return(new ReferenceFixer(new LocalFileTransformer(this, uploader).Transform));
 }
 public void UploadFilesAfterPublish(string postId, BlogFileUploader fileUploader)
 {
     _fileUploadWorker.DoAfterPostUploadWork(fileUploader, postId);
 }
 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;
 }
 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);
         }
     }
 }
            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);
                    }
                }

            }
 public LocalFileTransformer(BlogPostReferenceFixer referenceFixer, BlogFileUploader uploader)
 {
     _referenceFixer = referenceFixer;
     _fileService = _referenceFixer._uploadContext.EditingContext.SupportingFileService;
     _uploader = uploader;
 }
 public ReferenceFixer GetFileUploadReferenceFixer(BlogFileUploader uploader)
 {
     return new ReferenceFixer(new LocalFileTransformer(this, uploader).Transform);
 }
 public void UploadFilesAfterPublish(string postId, BlogFileUploader fileUploader)
 {
     _fileUploadWorker.DoAfterPostUploadWork(fileUploader, postId);
 }