public override FileServerResult StoreImage(System.Drawing.Image objImage, IFileQuery qryFileDestination, System.Drawing.Imaging.ImageFormat enuFormat = null) { if (CDNOnly) { var result = new FileServerResult(true); var blob = GetBlobForStorage(qryFileDestination); using (System.IO.MemoryStream stmImage = new System.IO.MemoryStream()) { if (enuFormat != null) { objImage.Save(stmImage, enuFormat); } else { objImage.Save(stmImage, objImage.RawFormat); } stmImage.Seek(0, SeekOrigin.Begin); blob.UploadFromStream(stmImage); } result.Uri = blob.Uri; return(result); } else { var result = base.WriteImageLocal(objImage, qryFileDestination, enuFormat); if (result.Success) { var blob = GetBlobForStorage(qryFileDestination); blob.UploadFromFile(GetLocalDiskPath(qryFileDestination)); result.Uri = blob.Uri; } return(result); } }
public override FileProperties GetFilePropertiesFromCDN(IFileQuery qryFile) { try { var objRef = S3TransferUtil.S3Client.GetObjectMetadata(GetCDNFolderPath(qryFile, true), GetFileName(qryFile)); FileProperties props = new FileProperties(); props.Source = objRef; props.Length = objRef.ContentLength; props.ETag = objRef.ETag; props.VersionNumber = objRef.VersionId; props.ContentMD5 = objRef.Headers.ContentMD5; props.ContentType = objRef.Headers.ContentType; props.LastModified = new DateTimeOffset(objRef.LastModified); props.Created = props.LastModified; props.URL = GetCDNURL(qryFile); if (objRef.Metadata != null) { props.MetaData = new Dictionary <string, string>(); foreach (var key in objRef.Metadata.Keys) { props.MetaData.Add(key, objRef.Metadata[key]); } } return(props); } catch (Amazon.S3.AmazonS3Exception ex) { if (ex.StatusCode == System.Net.HttpStatusCode.NotFound) { return(null); } throw; } }
protected CloudBlockBlob GetBlob(IFileQuery qryFile) { CloudBlobContainer objAzureContainer = AzureBlobClient.GetContainerReference(Settings.CDNStorageBucket); CloudBlockBlob blockBlob = objAzureContainer.GetBlockBlobReference(GetCDNPath(qryFile, false)); return(blockBlob); }
public virtual Task <FileServerResult> StoreImageAsync(Image objImage, IFileQuery qryFileDestination, System.Drawing.Imaging.ImageFormat enuFormat = null) { return(Task.Factory.StartNew(() => { return StoreImage(objImage, qryFileDestination, enuFormat); })); }
public virtual Task <FileServerResult> DeleteAsync(IFileQuery qryFile) { return(Task.Factory.StartNew(() => { return Delete(qryFile); })); }
public Task <FileServerResult> WriteImageLocalAsync(Image objImage, IFileQuery qryFile, System.Drawing.Imaging.ImageFormat enuFormat = null) { return(Task.Factory.StartNew(() => { return WriteImageLocal(objImage, qryFile, enuFormat); })); }
private CloudBlockBlob GetBlobForStorage(IFileQuery qryFileDestination) { var blockBlob = GetBlob(qryFileDestination); try { blockBlob.Properties.ContentType = Web.MimeTypeMap.GetMimeType(System.IO.Path.GetExtension(qryFileDestination.FileName)); } catch { } #region Meta Data blockBlob.Metadata.Add("FileName", qryFileDestination.FileName); if (!String.IsNullOrWhiteSpace(qryFileDestination.Folder)) { blockBlob.Metadata.Add("Folder", qryFileDestination.Folder); } if (!String.IsNullOrWhiteSpace(qryFileDestination.SubFolder)) { blockBlob.Metadata.Add("SubFolder", qryFileDestination.SubFolder); } foreach (var item in qryFileDestination.MetaData) { blockBlob.Metadata.Add(item); } #endregion return(blockBlob); }
public Task <FileServerResult> WriteFileLocalAsync(System.IO.Stream stmFile, IFileQuery qryFile) { return(Task.Factory.StartNew(() => { return WriteFileLocal(stmFile, qryFile); })); }
public Task <FileServerResult> WriteFileLocalAsync(string strSourceFilePath, IFileQuery qryFile) { return(Task.Factory.StartNew(() => { return WriteFileLocal(strSourceFilePath, qryFile); })); }
private TransferUtilityUploadRequest GetUploadRequest(IFileQuery qryFileDestination) { TransferUtilityUploadRequest fileTransferUtilityRequest = new TransferUtilityUploadRequest { BucketName = GetCDNFolderPath(qryFileDestination, true), StorageClass = StorageClass, Key = GetFileName(qryFileDestination), CannedACL = CurrentACL }; #region Meta Data fileTransferUtilityRequest.Metadata.Add("FileName", qryFileDestination.FileName); if (!String.IsNullOrWhiteSpace(qryFileDestination.Folder)) { fileTransferUtilityRequest.Metadata.Add("Folder", qryFileDestination.Folder); } if (!String.IsNullOrWhiteSpace(qryFileDestination.SubFolder)) { fileTransferUtilityRequest.Metadata.Add("SubFolder", qryFileDestination.SubFolder); } foreach (var item in qryFileDestination.MetaData) { fileTransferUtilityRequest.Metadata.Add(item.Key, item.Value); } #endregion return(fileTransferUtilityRequest); }
public string GetFolderPath(IFileQuery qryFile) { if (!String.IsNullOrWhiteSpace(qryFile.SubFolder)) { qryFile.SubFolder = CleanPathSegment(qryFile.SubFolder); if (!String.IsNullOrWhiteSpace(qryFile.SubFolder) && !qryFile.SubFolder.EndsWith("/")) { qryFile.SubFolder = qryFile.SubFolder + "/"; } } if (!String.IsNullOrWhiteSpace(qryFile.Folder) && !String.IsNullOrWhiteSpace(qryFile.SubFolder)) { return(qryFile.Folder + "/" + qryFile.SubFolder); } else if (!String.IsNullOrWhiteSpace(qryFile.Folder)) { return(qryFile.Folder); } else if (!String.IsNullOrWhiteSpace(qryFile.SubFolder)) { return(qryFile.SubFolder); } else { return(""); } }
public override FileProperties GetFilePropertiesFromCDN(IFileQuery qryFile) { var blob = GetBlob(qryFile); try { blob.FetchAttributes(); FileProperties props = new FileProperties(); props.MetaData = blob.Metadata; props.Source = blob.Properties; props.Length = blob.Properties.Length; props.ContentMD5 = blob.Properties.ContentMD5; props.ETag = blob.Properties.ETag; props.ContentType = blob.Properties.ContentType; props.LastModified = blob.Properties.LastModified; props.Created = props.LastModified; props.URL = blob.Uri.ToString(); return(props); } catch (Microsoft.Azure.Storage.StorageException ex) { if (ex.RequestInformation.HttpStatusCode == (int)System.Net.HttpStatusCode.NotFound) { return(null); } throw; } }
public Task <FileServerResult> DeleteFileLocalAsync(IFileQuery qryFile) { return(Task.Factory.StartNew(() => { return DeleteFileLocal(qryFile); })); }
public bool FileExistsLocal(IFileQuery qryFile) { if (Settings.DisableLocalStorage) { return(false); } return(System.IO.File.Exists(GetLocalDiskPath(qryFile))); }
public Image LoadImageLocal(IFileQuery qryFile) { if (!FileExistsLocal(qryFile)) { return(null); } return(new Bitmap(GetLocalDiskPath(qryFile))); }
public string LoadFileTextLocal(IFileQuery qryFile, System.Text.Encoding encoding) { if (!FileExistsLocal(qryFile)) { return(null); } return(System.IO.File.ReadAllText(GetLocalDiskPath(qryFile), encoding)); }
public byte[] LoadFileBytesLocal(IFileQuery qryFile) { if (!FileExistsLocal(qryFile)) { return(null); } return(System.IO.File.ReadAllBytes(GetLocalDiskPath(qryFile))); }
public System.IO.FileStream LoadFileStreamLocal(IFileQuery qryFile) { if (!FileExistsLocal(qryFile)) { return(null); } return(System.IO.File.OpenRead(GetLocalDiskPath(qryFile))); }
public FileServerResult DeleteFileLocal(IFileQuery qryFile) { if (FileExistsLocal(qryFile)) { System.IO.File.Delete(GetLocalDiskPath(qryFile)); } return(FileServerResult.Successful()); }
public string GetFileName(IFileQuery qryFile) { if (!String.IsNullOrWhiteSpace(Settings.GlobalFileNamePrepend)) { return(Settings.GlobalFileNamePrepend + qryFile.FileName); } return(qryFile.FileName); }
public FileService(IFileQuery fileQuery, IFileUpsertCommand fileCommand, IApplicationContext cntx) { this.fileQuery = fileQuery; this.fileCommand = fileCommand; this.cntx = cntx; }
public override System.IO.Stream LoadFileStream(IFileQuery qryFile) { if (FileExpiredLocal(qryFile)) { SaveFromCDN(qryFile); } return(base.LoadFileStream(qryFile)); }
public override byte[] LoadFileBytes(IFileQuery qryFile) { if (FileExpiredLocal(qryFile)) { SaveFromCDN(qryFile); } return(base.LoadFileBytes(qryFile)); }
public override System.Drawing.Image LoadImage(IFileQuery qryFile) { if (FileExpiredLocal(qryFile)) { SaveFromCDN(qryFile); } return(base.LoadImage(qryFile)); }
public override string LoadFileText(IFileQuery qryFile) { if (FileExpiredLocal(qryFile)) { SaveFromCDN(qryFile); } return(base.LoadFileText(qryFile)); }
public override string LoadFileText(IFileQuery qryFile, System.Text.Encoding encoding) { if (FileExpiredLocal(qryFile)) { SaveFromCDN(qryFile); } return(base.LoadFileText(qryFile, encoding)); }
public FileServerResult WriteImageLocal(string strSourceImagePath, IFileQuery qryFile) { if (Settings.LocalReadOnlyMode) { return(FileServerResult.Failure()); } System.IO.File.Copy(strSourceImagePath, GetAndCreateLocalDiskPath(qryFile), Settings.OverwriteExistingFiles); return(FileServerResult.Successful()); }
public override FileServerResult StoreImage(string strSourceImagePath, IFileQuery qryFileDestination) { var result = new FileServerResult(false); var blob = GetBlobForStorage(qryFileDestination); blob.UploadFromFile(strSourceImagePath); result = base.WriteImageLocal(strSourceImagePath, qryFileDestination); return(result); }
public bool ImportIfNeeded(IFileQuery qryFile) { if (FileExistsLocal(qryFile) && !FileExistsInCDN(qryFile)) { PushToCDN(qryFile); return(true); } return(false); }
private void SaveFromCDN(IFileQuery qryFile) { var blockBlobToDownload = GetBlob(qryFile); using (var fileStream = System.IO.File.OpenWrite(GetAndCreateLocalDiskPath(qryFile))) { blockBlobToDownload.DownloadToStream(fileStream); } }
public override bool FileExpiredLocal(IFileQuery qryFile) { var propsLocal = GetFilePropertiesLocal(qryFile); if (propsLocal == null) return true; var propsCDN = GetFilePropertiesFromCDN(qryFile); if (propsCDN == null) return false; return !propsLocal.IsCurrentVersionOf(propsCDN); }
public virtual Task<FileServerResult> StoreImageAsync(string strSourceImagePath, IFileQuery qryFileDestination) { return Task.Factory.StartNew(() => { return StoreImage(strSourceImagePath, qryFileDestination); }); }
public virtual FileServerResult Delete(IFileQuery qryFile) { return DeleteFileLocal(qryFile); }
public virtual Task<FileServerResult> StoreImageAsync(System.IO.Stream stmImage, IFileQuery qryFileDestination, System.Drawing.Imaging.ImageFormat enuFormat = null) { return Task.Factory.StartNew(() => { return StoreImage(stmImage, qryFileDestination, enuFormat); }); }
public virtual FileServerResult StoreImage(string strSourceImagePath, IFileQuery qryFileDestination) { return WriteImageLocal(strSourceImagePath, qryFileDestination); }
public virtual System.IO.Stream LoadFileStream(IFileQuery qryFile) { return LoadFileStreamLocal(qryFile); }
public virtual FileServerResult StoreImage(System.IO.Stream stmImage, IFileQuery qryFileDestination, System.Drawing.Imaging.ImageFormat enuFormat = null) { return WriteImageLocal(stmImage, qryFileDestination, enuFormat); }
public FileServerResult WriteImageLocal(System.IO.Stream stmImage, IFileQuery qryFile, System.Drawing.Imaging.ImageFormat enuFormat = null) { if (Settings.LocalReadOnlyMode) return FileServerResult.Failure; if (Settings.OverwriteExistingFiles) DeleteFileLocal(qryFile); using (Image img = System.Drawing.Image.FromStream(stmImage)) { if (enuFormat != null) img.Save(GetAndCreateLocalDiskPath(qryFile), enuFormat); else img.Save(GetAndCreateLocalDiskPath(qryFile)); } return FileServerResult.Successful; }
public Task<FileServerResult> WriteImageLocalAsync(Image objImage, IFileQuery qryFile, System.Drawing.Imaging.ImageFormat enuFormat = null) { return Task.Factory.StartNew(() => { return WriteImageLocal(objImage, qryFile, enuFormat); }); }
public FileServerResult WriteImageLocal(string strSourceImagePath, IFileQuery qryFile) { if (Settings.LocalReadOnlyMode) return FileServerResult.Failure; System.IO.File.Copy(strSourceImagePath, GetAndCreateLocalDiskPath(qryFile), Settings.OverwriteExistingFiles); return FileServerResult.Successful; }
public FileServerResult WriteFileLocal(System.IO.Stream stmFile, IFileQuery qryFile) { if (Settings.LocalReadOnlyMode) return FileServerResult.Failure; if (Settings.OverwriteExistingFiles) DeleteFileLocal(qryFile); using (var writer = new System.IO.StreamWriter(GetAndCreateLocalDiskPath(qryFile))) { stmFile.Seek(0, System.IO.SeekOrigin.Begin); stmFile.CopyTo(writer.BaseStream); writer.Close(); } return FileServerResult.Successful; }
public virtual string LoadFileText(IFileQuery qryFile, System.Text.Encoding encoding) { return LoadFileTextLocal(qryFile, encoding); }
public virtual string LoadFileText(IFileQuery qryFile) { return LoadFileTextLocal(qryFile); }
public virtual byte[] LoadFileBytes(IFileQuery qryFile) { return LoadFileBytesLocal(qryFile); }
public virtual Task<FileServerResult> DeleteAsync(IFileQuery qryFile) { return Task.Factory.StartNew(() => { return Delete(qryFile); }); }
public virtual string GetCDNURL(IFileQuery qryFile) { throw new NotImplementedException("No remote server has been specified for file retrieval"); }
public virtual bool FileExpiredLocal(IFileQuery qryFile) { throw new NotImplementedException("No remote server has been specified to check expiration"); }
public Task<FileServerResult> WriteFileFromStringLocalAsync(string strFileBody, IFileQuery qryFile) { return Task.Factory.StartNew(() => { return WriteFileFromStringLocal(strFileBody, qryFile); }); }
public FileServerResult WriteImageLocal(Image objImage, IFileQuery qryFile, System.Drawing.Imaging.ImageFormat enuFormat = null) { if (Settings.LocalReadOnlyMode) return FileServerResult.Failure; if (Settings.OverwriteExistingFiles) DeleteFileLocal(qryFile); if (enuFormat != null) objImage.Save(GetAndCreateLocalDiskPath(qryFile), enuFormat); else objImage.Save(GetAndCreateLocalDiskPath(qryFile)); return FileServerResult.Successful; }
public virtual FileProperties GetFilePropertiesFromCDN(IFileQuery qryFile) { throw new NotImplementedException("No remote server has been specified to check file dates"); }
public virtual Image LoadImage(IFileQuery qryFile) { return LoadImageLocal(qryFile); }
public Task<FileServerResult> WriteImageLocalAsync(string strSourceImagePath, IFileQuery qryFile) { return Task.Factory.StartNew(() => { return WriteImageLocal(strSourceImagePath, qryFile); }); }
public Task<FileServerResult> WriteFileLocalAsync(System.IO.Stream stmFile, IFileQuery qryFile) { return Task.Factory.StartNew(() => { return WriteFileLocal(stmFile, qryFile); }); }
public virtual FileServerResult StoreFile(System.IO.Stream stmFile, IFileQuery qryFileDestination) { return WriteFileLocal(stmFile, qryFileDestination); }
public Task<FileServerResult> DeleteFileLocalAsync(IFileQuery qryFile) { return Task.Factory.StartNew(() => { return DeleteFileLocal(qryFile); }); }
public virtual Task<FileServerResult> StoreFileAsync(System.IO.Stream stmFile, IFileQuery qryFileDestination) { return Task.Factory.StartNew(() => { return StoreFile(stmFile, qryFileDestination); }); }
public virtual FileServerResult StoreFileFromString(string strFileBody, IFileQuery qryFileDestination, System.Text.Encoding encoding = null) { return WriteFileFromStringLocal(strFileBody, qryFileDestination, encoding); }
public virtual Task<FileServerResult> StoreFileFromStringAsync(string strSourceFilePath, IFileQuery qryFileDestination, System.Text.Encoding encoding = null) { return Task.Factory.StartNew(() => { return StoreFileFromString(strSourceFilePath, qryFileDestination, encoding); }); }
public virtual bool FileExistsInCDN(IFileQuery qryFile) { throw new NotImplementedException("No remote server has been specified to check existance"); }
public FileServerResult WriteFileFromStringLocal(string strFileBody, IFileQuery qryFile, System.Text.Encoding encoding = null) { if (Settings.LocalReadOnlyMode) return FileServerResult.Failure; if (encoding != null) System.IO.File.WriteAllText(GetAndCreateLocalDiskPath(qryFile), strFileBody, encoding); else System.IO.File.WriteAllText(GetAndCreateLocalDiskPath(qryFile), strFileBody); return FileServerResult.Successful; }