public override string DoBeforePublishUploadWork(IFileUploadContext uploadContext) { string albumName = ApplicationEnvironment.ProductName; string path = uploadContext.GetContentsLocalFilePath(); if (Options.FileUploadNameFormat != null && Options.FileUploadNameFormat.Length > 0) { string formattedFileName = uploadContext.FormatFileName(uploadContext.PreferredFileName); string[] chunks = StringHelper.Reverse(formattedFileName).Split(new char[] { '/' }, 2); if (chunks.Length == 2) albumName = StringHelper.Reverse(chunks[1]); } string EDIT_MEDIA_LINK = "EditMediaLink"; string srcUrl; string editUri = uploadContext.Settings.GetString(EDIT_MEDIA_LINK, null); if (editUri == null || editUri.Length == 0) { PostNewImage(albumName, path, out srcUrl, out editUri); } else { try { UpdateImage(editUri, path, out srcUrl, out editUri); } catch (Exception e) { Trace.Fail(e.ToString()); if (e is WebException) HttpRequestHelper.LogException((WebException)e); bool success = false; srcUrl = null; // compiler complains without this line try { // couldn't update existing image? try posting a new one PostNewImage(albumName, path, out srcUrl, out editUri); success = true; } catch { } if (!success) throw; // rethrow the exception from the update, not the post } } uploadContext.Settings.SetString(EDIT_MEDIA_LINK, editUri); PicasaRefererBlockingWorkaround(uploadContext.BlogId, uploadContext.Role, ref srcUrl); return srcUrl; }
public virtual bool DoesFileNeedUpload(ISupportingFile file, IFileUploadContext uploadContext) { // Check to see if we have already uploaded this file. if (!file.IsUploaded(DestinationContext)) { return(true); } else { Debug.WriteLine(String.Format(CultureInfo.InvariantCulture, "File is up-to-date: {0}", file.FileName)); return(false); } }
public override bool DoesFileNeedUpload(ISupportingFile file, IFileUploadContext uploadContext) { // Let the blog client decide if it wants to upload this file or not bool?shouldUpload = _blogClient.DoesFileNeedUpload(uploadContext); // Check to see if the blog client made a decision, if so, then use it if (shouldUpload != null) { return(shouldUpload.Value); } // Check to see if it was already uploaded and saved in the content for this post return(base.DoesFileNeedUpload(file, uploadContext)); }
public string DoBeforePublishUploadWork(IFileUploadContext uploadContext) { string path = uploadContext.GetContentsLocalFilePath(); string srcUrl; string editUri = uploadContext.Settings.GetString(EDIT_MEDIA_LINK, null); string editEntryUri = uploadContext.Settings.GetString(EDIT_MEDIA_ENTRY_LINK, null); string etag = uploadContext.Settings.GetString(MEDIA_ETAG, null); if (string.IsNullOrEmpty(editUri)) { PostNewImage(path, false, out srcUrl, out editUri, out editEntryUri); } else { try { UpdateImage(ref editUri, path, editEntryUri, etag, true, out srcUrl); } catch (Exception e) { Trace.Fail(e.ToString()); bool success = false; srcUrl = null; // compiler complains without this line try { // couldn't update existing image? try posting a new one PostNewImage(path, false, out srcUrl, out editUri, out editEntryUri); success = true; if (e is WebException) { Trace.WriteLine("Image PUT failed, but POST succeeded. PUT exception follows."); HttpRequestHelper.LogException((WebException)e); } } catch { } if (!success) throw; // rethrow the exception from the update, not the post } } uploadContext.Settings.SetString(EDIT_MEDIA_LINK, editUri); uploadContext.Settings.SetString(EDIT_MEDIA_ENTRY_LINK, editEntryUri); uploadContext.Settings.SetString(MEDIA_ETAG, null); UpdateETag(uploadContext, editUri); return srcUrl; }
public string DoBeforePublishUploadWork(IFileUploadContext uploadContext) { string albumName = ApplicationEnvironment.ProductName; string path = uploadContext.GetContentsLocalFilePath(); if (Options.FileUploadNameFormat != null && Options.FileUploadNameFormat.Length > 0) { string formattedFileName = uploadContext.FormatFileName(uploadContext.PreferredFileName); string[] chunks = StringHelper.Reverse(formattedFileName).Split(new char[] { '/' }, 2); if (chunks.Length == 2) { albumName = StringHelper.Reverse(chunks[1]); } } return(PostNewImage(albumName, path)); }
public static IBlobImport Create(IFileUploadContext fileUploadContext, FileUploadType fileType, string storageAccountConnection) { var employerBlobStorage = new EmployerBlobStorage(storageAccountConnection); switch (fileType) { case FileUploadType.Employer: return(new EmployerBlobImport(new EmployerDataLoader(employerBlobStorage), new EmployerDataValidator())); case FileUploadType.Contact: return(new ContactBlobImport(new ContactDataLoader(employerBlobStorage), new ContactDataValidator())); case FileUploadType.Query: return(new QueryBlobImport(new QueryDataLoader(employerBlobStorage), new QueryDataValidator())); } throw new InvalidOperationException(); }
public override bool? DoesFileNeedUpload(IFileUploadContext uploadContext) { // This is a new post, we want to upload it if (String.IsNullOrEmpty(uploadContext.PostId)) { return true; } // Check to see if we have uploaded this file to this blog with this post id string value = uploadContext.Settings.GetString(uploadContext.PostId, String.Empty); // We have uploaded this file to this blog with this post id so we should not upload it if (value == FILE_ALREADY_UPLOADED) { return null; } return true; }
public override bool?DoesFileNeedUpload(IFileUploadContext uploadContext) { // This is a new post, we want to upload it if (String.IsNullOrEmpty(uploadContext.PostId)) { return(true); } // Check to see if we have uploaded this file to this blog with this post id string value = uploadContext.Settings.GetString(uploadContext.PostId, String.Empty); // We have uploaded this file to this blog with this post id so we should not upload it if (value == FILE_ALREADY_UPLOADED) { return(null); } return(true); }
public FileUploadInfo GetUploadFileInfosWhenSaveFile(IFileUploadContext context) { var result = new FileUploadInfo() { UploadFileFolder = Path.Combine(context.GetForguncyUploadFilesFolderLocalPath(), "CarouselCellType", "Images") }; if (ImageInfos != null) { foreach (var imageInfo in ImageInfos) { if (string.IsNullOrEmpty(imageInfo.ImagePath)) { continue; } result.AllUsedUploadFilePaths.Add(imageInfo.ImagePath); } } return(result); }
public override void DoUploadWorkAfterPublish(IFileUploadContext uploadContext) { try { _blogClient.DoAfterPublishUploadWork(uploadContext); } catch (IOException ex) { Trace.Fail(ex.ToString()); throw new BlogClientIOException(new FileInfo(uploadContext.GetContentsLocalFilePath()), ex); } catch (BlogClientException ex) { Trace.Fail(ex.ToString()); throw; } catch (Exception ex) { Trace.Fail(ex.ToString()); throw new BlogClientException(Res.Get(StringId.FileUploadFailedException), ex.Message); } return; }
public override void DoAfterPublishUploadWork(IFileUploadContext uploadContext) { FileAttachSettings attachSettings = new FileAttachSettings(uploadContext.Settings); if (attachSettings.AttachmentFileName == null) { CalculateUploadVariables(uploadContext.FormatFileName(uploadContext.PreferredFileName), attachSettings); } string listGuid = SharepointBlogIdToListGuid(uploadContext.BlogId); if (listGuid != null) { SharePointListsService listsServicesharePointLists = new SharePointListsService(attachSettings.UploadServiceUrl); listsServicesharePointLists.Credentials = GetHttpCredentials(); //The AddAttachment() call will throw an error if the attachment already exists, so we need to delete //the attachment first (if it exists). To delete the attachment, we must construct the attachment URL //that is typically generated internally by the server. //Sample URL: http://sharepoint/sites/writer/b2/blog/Lists/Posts/Attachments/13/Sunset_thumb1.jpg string attachDeleteUrl = String.Format(CultureInfo.InvariantCulture, "{0}{1}/Lists/Posts/Attachments/{2}/{3}", attachSettings.BaseUrl, attachSettings.BlogUrlPart, uploadContext.PostId, attachSettings.AttachmentFileName); try { listsServicesharePointLists.DeleteAttachment(listGuid, uploadContext.PostId, attachDeleteUrl); } catch (Exception) {} //Add the attachment using (Stream fileContents = uploadContext.GetContents()) listsServicesharePointLists.AddAttachment(listGuid, uploadContext.PostId, attachSettings.AttachmentFileName, Convert.ToBase64String(StreamHelper.AsBytes(fileContents))); uploadContext.Settings.SetString(uploadContext.PostId, FILE_ALREADY_UPLOADED); return; } throw new BlogClientFileUploadNotSupportedException(); }
public virtual bool DoesFileNeedUpload(ISupportingFile file, IFileUploadContext uploadContext) { // Check to see if we have already uploaded this file. if (!file.IsUploaded(DestinationContext)) { return true; } else { Debug.WriteLine(String.Format(CultureInfo.InvariantCulture, "File is up-to-date: {0}", file.FileName)); return false; } }
public override Uri DoUploadWorkBeforePublish(IFileUploadContext uploadContext) { try { string uploadUrl = _blogClient.DoBeforePublishUploadWork(uploadContext); if (!UrlHelper.IsUrl(uploadUrl)) { string baseURL; if (uploadUrl.StartsWith("/")) baseURL = UrlHelper.GetBaseUrl(_blogHomepageUrl); else baseURL = UrlHelper.GetBasePathUrl(_blogHomepageUrl); uploadUrl = UrlHelper.UrlCombineIfRelative(baseURL, uploadUrl); } return new Uri(uploadUrl); } catch (BlogClientOperationCancelledException) { throw; // No need to assert when an operation is cancelled } catch (IOException ex) { Trace.Fail(ex.ToString()); throw new BlogClientIOException(new FileInfo(uploadContext.GetContentsLocalFilePath()), ex); } catch (BlogClientAuthenticationException ex) { Trace.Fail(ex.ToString()); throw; } catch (BlogClientProviderException ex) { Trace.Fail(ex.ToString()); // provider exceptions that are not authentication exceptions are presumed // to be lack of support for newMediaObject we may want to filter this down // further -- not sure how to do this other than by trial and error with the // various services. throw new BlogClientFileUploadNotSupportedException(ex.ErrorCode, ex.ErrorString); } catch (BlogClientException ex) { Trace.Fail(ex.ToString()); throw; } catch (Exception ex) { Trace.Fail(ex.ToString()); if (ex is WebException) { HttpRequestHelper.LogException((WebException)ex); } throw new BlogClientException(Res.Get(StringId.FileUploadFailedException), ex.Message); } }
public override void DoAfterPublishUploadWork(IFileUploadContext uploadContext) { }
public UpdateContactCommand(IFileUploadContext fileUploadContext) { _fileUploadContext = fileUploadContext; }
public string DoBeforePublishUploadWork(IFileUploadContext uploadContext) { string path = uploadContext.GetContentsLocalFilePath(); return(DoPostImage(path)); }
public abstract Uri DoUploadWorkBeforePublish(IFileUploadContext uploadContext);
public GetContactQuery(IFileUploadContext fileUploadContext) { _fileUploadContext = fileUploadContext; }
public abstract string DoBeforePublishUploadWork(IFileUploadContext uploadContext);
public override string DoBeforePublishUploadWork(IFileUploadContext uploadContext) { AtomMediaUploader uploader = new AtomMediaUploader(_nsMgr, RequestFilter, Options.ImagePostingUrl, Options); return uploader.DoBeforePublishUploadWork(uploadContext); }
public GetIndustryPlacementQuery(IFileUploadContext fileUploadContext) { _fileUploadContext = fileUploadContext; }
public override string DoBeforePublishUploadWork(IFileUploadContext uploadContext) { const int REQUEST_COUNT = 2; // get as many challenge tokens as we'll need (one for each authenticated request) FotobilderRequestManager frm = new FotobilderRequestManager(Username, Password); XmlDocument doc = frm.PerformGet("GetChallenges", null, "GetChallenges.Qty", REQUEST_COUNT.ToString(CultureInfo.InvariantCulture)); XmlNodeList challengeNodes = doc.SelectNodes(@"/FBResponse/GetChallengesResponse/Challenge"); Trace.Assert(challengeNodes.Count == REQUEST_COUNT); Stack challenges = new Stack(challengeNodes.Count); foreach (XmlNode node in challengeNodes) challenges.Push(node.InnerText); // login long bytesAvailable = long.MaxValue; doc = frm.PerformGet("Login", (string)challenges.Pop(), "Login.ClientVersion", ApplicationEnvironment.UserAgent); XmlNode remainingQuotaNode = doc.SelectSingleNode("/FBResponse/LoginResponse/Quota/Remaining"); if (remainingQuotaNode != null) bytesAvailable = long.Parse(remainingQuotaNode.InnerText, CultureInfo.InvariantCulture); // upload picture using (Stream fileContents = uploadContext.GetContents()) { doc = frm.PerformPut("UploadPic", (string)challenges.Pop(), fileContents, "UploadPic.PicSec", "255", "UploadPic.Meta.Filename", uploadContext.FormatFileName(uploadContext.PreferredFileName), "UploadPic.Gallery._size", "1", "UploadPic.Gallery.0.GalName", ApplicationEnvironment.ProductName, "UploadPic.Gallery.0.GalSec", "255"); } XmlNode picUrlNode = doc.SelectSingleNode("/FBResponse/UploadPicResponse/URL"); if (picUrlNode != null) { return picUrlNode.InnerText; } else { throw new BlogClientInvalidServerResponseException("LiveJournal.UploadPic", "No URL returned from server", doc.OuterXml); } }
public GetFileUploadQuery(IFileUploadContext fileUploadContext) { _fileUploadContext = fileUploadContext; }
public override bool DoesFileNeedUpload(ISupportingFile file, IFileUploadContext uploadContext) { // Let the blog client decide if it wants to upload this file or not bool? shouldUpload = _blogClient.DoesFileNeedUpload(uploadContext); // Check to see if the blog client made a decision, if so, then use it if (shouldUpload != null) { return shouldUpload.Value; } // Check to see if it was already uploaded and saved in the content for this post return base.DoesFileNeedUpload(file, uploadContext); }
public virtual string DoBeforePublishUploadWork(IFileUploadContext uploadContext) { throw new BlogClientMethodUnsupportedException("UploadFileBeforePublish"); }
public virtual void DoAfterPublishUploadWork(IFileUploadContext uploadContext) { throw new BlogClientMethodUnsupportedException("UploadFileAfterPublish"); }
public virtual bool? DoesFileNeedUpload(IFileUploadContext uploadContext) { return null; }
public override void DoAfterPublishUploadWork(IFileUploadContext uploadContext) { FileAttachSettings attachSettings = new FileAttachSettings(uploadContext.Settings); if (attachSettings.AttachmentFileName == null) { CalculateUploadVariables(uploadContext.FormatFileName(uploadContext.PreferredFileName), attachSettings); } string listGuid = SharepointBlogIdToListGuid(uploadContext.BlogId); if (listGuid != null) { SharePointListsService listsServicesharePointLists = new SharePointListsService(attachSettings.UploadServiceUrl); listsServicesharePointLists.Credentials = GetHttpCredentials(); //The AddAttachment() call will throw an error if the attachment already exists, so we need to delete //the attachment first (if it exists). To delete the attachment, we must construct the attachment URL //that is typically generated internally by the server. //Sample URL: http://sharepoint/sites/writer/b2/blog/Lists/Posts/Attachments/13/Sunset_thumb1.jpg string attachDeleteUrl = String.Format(CultureInfo.InvariantCulture, "{0}{1}/Lists/Posts/Attachments/{2}/{3}", attachSettings.BaseUrl, attachSettings.BlogUrlPart, uploadContext.PostId, attachSettings.AttachmentFileName); try { listsServicesharePointLists.DeleteAttachment(listGuid, uploadContext.PostId, attachDeleteUrl); } catch (Exception) { } //Add the attachment using (Stream fileContents = uploadContext.GetContents()) listsServicesharePointLists.AddAttachment(listGuid, uploadContext.PostId, attachSettings.AttachmentFileName, Convert.ToBase64String(StreamHelper.AsBytes(fileContents))); uploadContext.Settings.SetString(uploadContext.PostId, FILE_ALREADY_UPLOADED); return; } throw new BlogClientFileUploadNotSupportedException(); }
public override Uri DoUploadWorkBeforePublish(IFileUploadContext uploadContext) { try { ConnectForUpload(); string uploadPath = uploadContext.Settings.GetString(UPLOAD_PATH, null); bool overwrite = uploadPath != null; if (uploadPath == null) { string uploadFolder = null; string fileName = uploadContext.PreferredFileName; string filePath = uploadContext.FormatFileName(fileName); string[] pathParts = filePath.Split('/'); if (pathParts.Length > 1) { uploadFolder = FileHelper.GetValidAnsiFileName(pathParts[0]); for (int i = 1; i < pathParts.Length - 1; i++) { uploadFolder = uploadFolder + "/" + FileHelper.GetValidAnsiFileName(pathParts[i]); } } fileName = FileHelper.GetValidAnsiFileName(pathParts[pathParts.Length - 1]); uploadPath = _fileDestination.CombinePath(uploadFolder, fileName); if (_fileDestination.FileExists(uploadPath)) { string fileBaseName = Path.GetFileNameWithoutExtension(fileName); string fileExtension = Path.GetExtension(fileName); try { Hashtable existingFiles = new Hashtable(); foreach (string name in _fileDestination.ListFiles(uploadFolder)) { existingFiles[name] = name; } for (int i = 3; i < Int32.MaxValue && existingFiles.ContainsKey(fileName); i++) { fileName = FileHelper.GetValidAnsiFileName(fileBaseName + "_" + i + fileExtension); } } catch (Exception e) { Debug.Fail("Error while calculating unique filename", e.ToString()); } uploadPath = _fileDestination.CombinePath(uploadFolder, fileName); if (_fileDestination.FileExists(uploadPath)) { Debug.Fail("Failed to calculate unique filename"); fileName = FileHelper.GetValidAnsiFileName(fileBaseName + Guid.NewGuid().ToString() + fileExtension); uploadPath = _fileDestination.CombinePath(uploadFolder, fileName); } } } // transfer the file _fileDestination.DoTransfer( uploadContext.GetContentsLocalFilePath(), uploadPath, overwrite); uploadContext.Settings.SetString(UPLOAD_PATH, uploadPath); // return the url to the transferred file string baseUrl = UrlHelper.InsureTrailingSlash(_settings.UrlMapping); string relativeUrl = uploadPath; return(new Uri(UrlHelper.UrlCombine(baseUrl, relativeUrl))); } catch (Exception ex) { WebPublishMessage message = WebPublishUtils.ExceptionToErrorMessage(ex); throw new BlogClientFileTransferException(new FileInfo(uploadContext.GetContentsLocalFilePath()), message.Title, message.Text); } }
protected virtual void UpdateETag(IFileUploadContext uploadContext, string editUri) { try { string newEtag = AtomClient.GetEtag(editUri, _requestFilter); uploadContext.Settings.SetString(MEDIA_ETAG, newEtag); } catch (Exception) { } }
public virtual void DoUploadWorkAfterPublish(IFileUploadContext uploadContext) { }
public override string DoBeforePublishUploadWork(IFileUploadContext uploadContext) { FileAttachSettings attachSettings = new FileAttachSettings(uploadContext.Settings); if (attachSettings.AttachmentFileName == null) { string fileName = uploadContext.FormatFileName(CleanUploadFilename(uploadContext.PreferredFileName)); CalculateUploadVariables(fileName, attachSettings); } return attachSettings.AttachmentUrl; }
public CreateFileUploadCommand(IFileUploadContext fileUploadContext) { _fileUploadContext = fileUploadContext; }
public async Task <string> DoBeforePublishUploadWork(IFileUploadContext uploadContext) { string albumName = ApplicationEnvironment.ProductName; string fileName = uploadContext.PreferredFileName; var fileStream = uploadContext.GetContents(); if (Options.FileUploadNameFormat != null && Options.FileUploadNameFormat.Length > 0) { string formattedFileName = uploadContext.FormatFileName(uploadContext.PreferredFileName); string[] chunks = StringHelper.Reverse(formattedFileName).Split(new char[] { '/' }, 2); if (chunks.Length == 2) { albumName = StringHelper.Reverse(chunks[1]); } } string EDIT_MEDIA_LINK = "EditMediaLink"; var postImage = new PicasaPostImage(); //postImage.editUri = uploadContext.Settings.GetString(EDIT_MEDIA_LINK, null); if (postImage.editUri == null || postImage.editUri.Length == 0) { await PostNewImage(albumName, fileStream, fileName, postImage); } else { try { await UpdateImage(postImage.editUri, fileStream, fileName, postImage); } catch (Exception e) { Debug.Fail(e.ToString()); if (e is WebException) { HttpRequestHelper.LogException((WebException)e); } bool success = false; postImage.srcUrl = null; // compiler complains without this line try { // couldn't update existing image? try posting a new one await PostNewImage(albumName, fileStream, fileName, postImage); success = true; } catch { } if (!success) { throw; // rethrow the exception from the update, not the post } } } //uploadContext.Settings.SetString(EDIT_MEDIA_LINK, postImage.editUri); postImage.srcUrl = await PicasaRefererBlockingWorkaround(uploadContext.BlogId, uploadContext.Role, postImage.srcUrl); return(postImage.srcUrl); }
public void DoAfterPublishUploadWork(IFileUploadContext uploadContext) { // Nothing to do. }
public Task DoAfterPublishUploadWork(IFileUploadContext uploadContext) { // Nothing to do. return(Task.FromResult(true)); }
public override Uri DoUploadWorkBeforePublish(IFileUploadContext uploadContext) { throw new BlogClientFileUploadNotSupportedException(); }
public string DoBeforePublishUploadWork(IFileUploadContext uploadContext) { string albumName = ApplicationEnvironment.ProductName; string path = uploadContext.GetContentsLocalFilePath(); if (Options.FileUploadNameFormat != null && Options.FileUploadNameFormat.Length > 0) { string formattedFileName = uploadContext.FormatFileName(uploadContext.PreferredFileName); string[] chunks = StringHelper.Reverse(formattedFileName).Split(new char[] { '/' }, 2); if (chunks.Length == 2) { albumName = StringHelper.Reverse(chunks[1]); } } string EDIT_MEDIA_LINK = "EditMediaLink"; string srcUrl; string editUri = uploadContext.Settings.GetString(EDIT_MEDIA_LINK, null); if (editUri == null || editUri.Length == 0) { PostNewImage(albumName, path, out srcUrl, out editUri); } else { try { UpdateImage(editUri, path, out srcUrl, out editUri); } catch (Exception e) { Trace.Fail(e.ToString()); if (e is WebException) { HttpRequestHelper.LogException((WebException)e); } bool success = false; srcUrl = null; // compiler complains without this line try { // couldn't update existing image? try posting a new one PostNewImage(albumName, path, out srcUrl, out editUri); success = true; } catch { } if (!success) { throw; // rethrow the exception from the update, not the post } } } uploadContext.Settings.SetString(EDIT_MEDIA_LINK, editUri); PicasaRefererBlockingWorkaround(uploadContext.BlogId, uploadContext.Role, ref srcUrl); return(srcUrl); }
public override Uri DoUploadWorkBeforePublish(IFileUploadContext uploadContext) { try { ConnectForUpload(); string uploadPath = uploadContext.Settings.GetString(UPLOAD_PATH, null); bool overwrite = uploadPath != null; if (uploadPath == null) { string uploadFolder = null; string fileName = uploadContext.PreferredFileName; string filePath = uploadContext.FormatFileName(fileName); string[] pathParts = filePath.Split('/'); if (pathParts.Length > 1) { uploadFolder = FileHelper.GetValidAnsiFileName(pathParts[0]); for (int i = 1; i < pathParts.Length - 1; i++) uploadFolder = uploadFolder + "/" + FileHelper.GetValidAnsiFileName(pathParts[i]); } fileName = FileHelper.GetValidAnsiFileName(pathParts[pathParts.Length - 1]); uploadPath = _fileDestination.CombinePath(uploadFolder, fileName); if (_fileDestination.FileExists(uploadPath)) { string fileBaseName = Path.GetFileNameWithoutExtension(fileName); string fileExtension = Path.GetExtension(fileName); try { Hashtable existingFiles = new Hashtable(); foreach (string name in _fileDestination.ListFiles(uploadFolder)) existingFiles[name] = name; for (int i = 3; i < Int32.MaxValue && existingFiles.ContainsKey(fileName); i++) { fileName = FileHelper.GetValidAnsiFileName(fileBaseName + "_" + i + fileExtension); } } catch (Exception e) { Debug.Fail("Error while calculating unique filename", e.ToString()); } uploadPath = _fileDestination.CombinePath(uploadFolder, fileName); if (_fileDestination.FileExists(uploadPath)) { Debug.Fail("Failed to calculate unique filename"); fileName = FileHelper.GetValidAnsiFileName(fileBaseName + Guid.NewGuid().ToString() + fileExtension); uploadPath = _fileDestination.CombinePath(uploadFolder, fileName); } } } // transfer the file _fileDestination.DoTransfer( uploadContext.GetContentsLocalFilePath(), uploadPath, overwrite); uploadContext.Settings.SetString(UPLOAD_PATH, uploadPath); // return the url to the transferred file string baseUrl = UrlHelper.InsureTrailingSlash(_settings.UrlMapping); string relativeUrl = uploadPath; return new Uri(UrlHelper.UrlCombine(baseUrl, relativeUrl)); } catch (Exception ex) { WebPublishMessage message = WebPublishUtils.ExceptionToErrorMessage(ex); throw new BlogClientFileTransferException(new FileInfo(uploadContext.GetContentsLocalFilePath()), message.Title, message.Text); } }
public override Uri DoUploadWorkBeforePublish(IFileUploadContext uploadContext) { try { string uploadUrl = _blogClient.DoBeforePublishUploadWork(uploadContext); if (!UrlHelper.IsUrl(uploadUrl)) { string baseURL; if (uploadUrl.StartsWith("/")) { baseURL = UrlHelper.GetBaseUrl(_blogHomepageUrl); } else { baseURL = UrlHelper.GetBasePathUrl(_blogHomepageUrl); } uploadUrl = UrlHelper.UrlCombineIfRelative(baseURL, uploadUrl); } return(new Uri(uploadUrl)); } catch (BlogClientOperationCancelledException) { throw; // No need to assert when an operation is cancelled } catch (IOException ex) { Trace.Fail(ex.ToString()); throw new BlogClientIOException(new FileInfo(uploadContext.GetContentsLocalFilePath()), ex); } catch (BlogClientAuthenticationException ex) { Trace.Fail(ex.ToString()); throw; } catch (BlogClientProviderException ex) { Trace.Fail(ex.ToString()); // provider exceptions that are not authentication exceptions are presumed // to be lack of support for newMediaObject we may want to filter this down // further -- not sure how to do this other than by trial and error with the // various services. throw new BlogClientFileUploadNotSupportedException(ex.ErrorCode, ex.ErrorString); } catch (BlogClientException ex) { Trace.Fail(ex.ToString()); throw; } catch (Exception ex) { Trace.Fail(ex.ToString()); if (ex is WebException) { HttpRequestHelper.LogException((WebException)ex); } throw new BlogClientException(Res.Get(StringId.FileUploadFailedException), ex.Message); } }
public override string DoBeforePublishUploadWork(IFileUploadContext uploadContext) { string uploadFileName = uploadContext.FormatFileName(CleanUploadFilename(uploadContext.PreferredFileName)); // call the method XmlNode result; using (Stream fileContents = uploadContext.GetContents()) { result = CallMethod("metaWeblog.newMediaObject", new XmlRpcString(uploadContext.BlogId), new XmlRpcString(Username), new XmlRpcString(Password, true), new XmlRpcStruct(new XmlRpcMember[] { new XmlRpcMember( "name", uploadFileName ), new XmlRpcMember( "type", MimeHelper.GetContentType(Path.GetExtension(uploadContext.PreferredFileName),MimeHelper.APP_OCTET_STREAM )), new XmlRpcMember( "bits", new XmlRpcBase64( StreamHelper.AsBytes(fileContents) ) ), } )); } // return the url to the file on the server XmlNode urlNode = result.SelectSingleNode("struct/member[name='url']/value"); if (urlNode != null) { return urlNode.InnerText; } else { throw new BlogClientInvalidServerResponseException("metaWeblog.newMediaObject", "No URL returned from server", result.OuterXml); } }
public virtual void DoAfterPublishUploadWork(IFileUploadContext uploadContext) { }
public UpdateEmployerCommand(IFileUploadContext fileUploadContext) { _fileUploadContext = fileUploadContext; }
public FileUploadInputModelBinder(IGetRootPathToSaveUploadedFilesToHelper getRootPathToSaveUploadedFilesToHelper, IFileUploadContext fileUploadContext) { this.fileUploadContext = fileUploadContext; this.getRootPathToSaveUploadedFilesToHelper = getRootPathToSaveUploadedFilesToHelper; }
public bool?DoesFileNeedUpload(IFileUploadContext uploadContext) => null;
public bool?DoesFileNeedUpload(IFileUploadContext uploadContext) { return(null); }