public async ValueTask <IFileReference> SaveAsync(byte[] data, IPrivateFileReference file, string contentType, OverwritePolicy overwritePolicy = OverwritePolicy.Always, IDictionary <string, string> metadata = null) { using (var stream = new SyncMemoryStream(data, 0, data.Length)) { return(await this.SaveAsync(stream, file, contentType, overwritePolicy, metadata)); } }
public async ValueTask <IFileReference> SaveAsync(byte[] data, IPrivateFileReference file, string contentType, OverwritePolicy overwritePolicy = OverwritePolicy.Always) { using (var stream = new MemoryStream(data, 0, data.Length)) { return(await this.SaveAsync(stream, file, contentType, overwritePolicy)); } }
public Task SaveExtendedPropertiesAsync(string storeAbsolutePath, IPrivateFileReference file, FileExtendedProperties extendedProperties) { var extendedPropertiesPath = this.GetExtendedPropertiesPath(storeAbsolutePath, file); var toStore = JsonConvert.SerializeObject(extendedProperties); File.WriteAllText(extendedPropertiesPath, toStore); return(Task.FromResult(0)); }
public async Task<IFileReference> AddMetadataAsync(IPrivateFileReference file, IDictionary<string, string> metadata) { var fileReference = await InternalGetAsync(file, false); fileReference.AddMetadataAsync(metadata); return fileReference; }
public Task <IFileReference> SaveAsync(byte[] data, IPrivateFileReference file, string contentType) { var fileReference = InternalGetOrCreateAsync(file); EnsurePathExists(fileReference.FileSystemPath); File.WriteAllBytes(fileReference.FileSystemPath, data); return(Task.FromResult((IFileReference)fileReference)); }
public async Task<IFileReference> SaveAsync(Stream data, IPrivateFileReference file, string contentType) { var blockBlob = this.container.Value.GetBlockBlobReference(file.Path); await blockBlob.UploadFromStreamAsync(data); blockBlob.Properties.ContentType = contentType; blockBlob.Properties.CacheControl = "max-age=300, must-revalidate"; await blockBlob.SetPropertiesAsync(); return new Internal.AzureFileReference(blockBlob); }
private Internal.FileSystemFileReference InternalGetAsync(IPrivateFileReference file) { var reference = InternalGetOrCreateAsync(file); if (File.Exists(reference.FileSystemPath)) { return(reference); } return(null); }
private string GetExtendedPropertiesPath(string storeAbsolutePath, IPrivateFileReference file) { var fullPath = Path.GetFullPath(storeAbsolutePath).TrimEnd(Path.DirectorySeparatorChar); var rootPath = Path.GetDirectoryName(fullPath); var storeName = Path.GetFileName(fullPath); var extendedPropertiesPath = Path.Combine(rootPath, string.Format(this.options.FolderNameFormat, storeName), file.Path + ".json"); this.EnsurePathExists(extendedPropertiesPath); return(extendedPropertiesPath); }
public async Task <IFileReference> SaveAsync(Stream data, IPrivateFileReference file, string contentType) { var fileReference = InternalGetOrCreateAsync(file); EnsurePathExists(fileReference.FileSystemPath); using (var fileStream = File.Open(fileReference.FileSystemPath, FileMode.Create, FileAccess.Write)) { await data.CopyToAsync(fileStream); } return(fileReference); }
public async ValueTask <IFileReference> SaveAsync(Stream data, IPrivateFileReference file, string contentType, OverwritePolicy overwritePolicy = OverwritePolicy.Always, IDictionary <string, string> metadata = null) { var uploadBlob = true; var blockBlob = _container.Value.GetBlockBlobReference(file.Path); var blobExists = await blockBlob.ExistsAsync(); if (blobExists) { if (overwritePolicy == OverwritePolicy.Never) { throw new FileAlreadyExistsException(Name, file.Path); } await blockBlob.FetchAttributesAsync(); if (overwritePolicy == OverwritePolicy.IfContentModified) { using (var md5 = MD5.Create()) { data.Seek(0, SeekOrigin.Begin); var contentMd5 = Convert.ToBase64String(md5.ComputeHash(data)); data.Seek(0, SeekOrigin.Begin); uploadBlob = contentMd5 != blockBlob.Properties.ContentMD5; } } } if (metadata != null) { foreach (var kvp in metadata) { blockBlob.Metadata.Add(kvp.Key, kvp.Value); } } if (uploadBlob) { await blockBlob.UploadFromStreamAsync(data); } var reference = new AzureFileReference(blockBlob, true); if (reference.Properties.ContentType == contentType) { return(reference); } reference.Properties.ContentType = contentType; await reference.SavePropertiesAsync(); return(reference); }
public ValueTask <FileExtendedProperties> GetExtendedPropertiesAsync(string storeAbsolutePath, IPrivateFileReference file) { var extendedPropertiesPath = GetExtendedPropertiesPath(storeAbsolutePath, file); if (!File.Exists(extendedPropertiesPath)) { return(new ValueTask <FileExtendedProperties>(new FileExtendedProperties())); } var content = File.ReadAllText(extendedPropertiesPath); return(new ValueTask <FileExtendedProperties>( JsonConvert.DeserializeObject <FileExtendedProperties>(content))); }
public async ValueTask <IFileReference> SaveAsync(Stream data, IPrivateFileReference file, string contentType, OverwritePolicy overwritePolicy = OverwritePolicy.Always, IDictionary <string, string> metadata = null) { var fileReference = await InternalGetAsync(file, withMetadata : true, checkIfExists : false); var fileExists = File.Exists(fileReference.FileSystemPath); if (fileExists) { if (overwritePolicy == OverwritePolicy.Never) { throw new FileAlreadyExistsException(Name, file.Path); } } var properties = fileReference.Properties as FileSystemFileProperties; var(ETag, ContentMd5) = ComputeHashes(data); if (!fileExists || overwritePolicy == OverwritePolicy.Always || (overwritePolicy == OverwritePolicy.IfContentModified && properties.ContentMd5 != ContentMd5)) { EnsurePathExists(fileReference.FileSystemPath); using (var fileStream = File.Open(fileReference.FileSystemPath, FileMode.Create, FileAccess.Write)) { await data.CopyToAsync(fileStream); } } properties.ContentType = contentType; properties.ExtendedProperties.ETag = ETag; properties.ExtendedProperties.ContentMd5 = ContentMd5; if (metadata != null) { foreach (var kvp in metadata) { properties.Metadata.Add(kvp.Key, kvp.Value); } } await fileReference.SavePropertiesAsync(); return(fileReference); }
public async ValueTask <IFileReference> SaveAsync(Stream data, IPrivateFileReference file, string contentType, OverwritePolicy overwritePolicy = OverwritePolicy.Always) { var uploadBlob = true; var blockBlob = this.container.Value.GetBlockBlobReference(file.Path); var blobExists = await blockBlob.ExistsAsync(); if (blobExists) { if (overwritePolicy == OverwritePolicy.Never) { throw new Exceptions.FileAlreadyExistsException(this.Name, file.Path); } await blockBlob.FetchAttributesAsync(); if (overwritePolicy == OverwritePolicy.IfContentModified) { using (var md5 = MD5.Create()) { data.Seek(0, SeekOrigin.Begin); var contentMD5 = Convert.ToBase64String(md5.ComputeHash(data)); data.Seek(0, SeekOrigin.Begin); uploadBlob = (contentMD5 != blockBlob.Properties.ContentMD5); } } } if (uploadBlob) { await blockBlob.UploadFromStreamAsync(data); } var reference = new Internal.AzureFileReference(blockBlob, withMetadata: true); if (reference.Properties.ContentType != contentType) { reference.Properties.ContentType = contentType; await reference.SavePropertiesAsync(); } return(reference); }
private async Task<Internal.AzureFileReference> InternalGetAsync(IPrivateFileReference file, bool withMetadata) { var azureFile = file as Internal.AzureFileReference; if (azureFile != null) { return azureFile; } try { var blob = await this.container.Value.GetBlobReferenceFromServerAsync(file.Path); return new Internal.AzureFileReference(file.Path, blob); } catch (StorageException storageException) { if (storageException.RequestInformation.HttpStatusCode == 404) { return null; } throw; } }
public async ValueTask <IFileReference> SaveAsync(Stream data, IPrivateFileReference file, string contentType, OverwritePolicy overwritePolicy = OverwritePolicy.Always) { var fileReference = await this.InternalGetAsync(file, withMetadata : true, checkIfExists : false); var fileExists = File.Exists(fileReference.FileSystemPath); if (fileExists) { if (overwritePolicy == OverwritePolicy.Never) { throw new Exceptions.FileAlreadyExistsException(this.Name, file.Path); } } var properties = fileReference.Properties as Internal.FileSystemFileProperties; var hashes = ComputeHashes(data); if (!fileExists || overwritePolicy == OverwritePolicy.Always || (overwritePolicy == OverwritePolicy.IfContentModified && properties.ContentMD5 != hashes.ContentMD5)) { this.EnsurePathExists(fileReference.FileSystemPath); using (var fileStream = File.Open(fileReference.FileSystemPath, FileMode.Create, FileAccess.Write)) { await data.CopyToAsync(fileStream); } } properties.ContentType = contentType; properties.ExtendedProperties.ETag = hashes.ETag; properties.ExtendedProperties.ContentMD5 = hashes.ContentMD5; await fileReference.SavePropertiesAsync(); return(fileReference); }
public ValueTask <FileExtendedProperties> GetExtendedPropertiesAsync(string storeAbsolutePath, IPrivateFileReference file) { throw new InvalidOperationException("There is no FileSystem extended properties provider. Add "); }
public Task SaveExtendedPropertiesAsync(string storeAbsolutePath, IPrivateFileReference file, FileExtendedProperties extendedProperties) { throw new InvalidOperationException("There is no FileSystem extended properties provider."); }
public ValueTask <IFileReference> SaveAsync(byte[] data, IPrivateFileReference file, string contentType, OverwritePolicy overwritePolicy = OverwritePolicy.Always, IDictionary <string, string> metadata = null) => this.innerStore.SaveAsync(data, file, contentType, overwritePolicy);
public ValueTask <Stream> ReadAsync(IPrivateFileReference file) => this.innerStore.ReadAsync(file);
private ValueTask <FileSystemFileReference> InternalGetAsync(IPrivateFileReference file, bool withMetadata = false, bool checkIfExists = true) { return(InternalGetAsync(file.Path, withMetadata, checkIfExists)); }
public async ValueTask <byte[]> ReadAllBytesAsync(IPrivateFileReference file) { var fileReference = await this.InternalGetAsync(file); return(await fileReference.ReadAllBytesAsync()); }
public async Task DeleteAsync(IPrivateFileReference file) { var fileReference = await this.InternalGetAsync(file); await fileReference.DeleteAsync(); }
public async ValueTask <IFileReference> GetAsync(IPrivateFileReference file, bool withMetadata) { return(await this.InternalGetAsync(file, withMetadata)); }
public Task DeleteAsync(IPrivateFileReference file) => this.innerStore.DeleteAsync(file);
public async ValueTask <Stream> ReadAsync(IPrivateFileReference file) { var fileReference = await this.InternalGetAsync(file); return(await fileReference.ReadInMemoryAsync()); }
public ValueTask <IFileReference> GetAsync(IPrivateFileReference file, bool withMetadata) => this.innerStore.GetAsync(file, withMetadata);
public async ValueTask <string> ReadAllTextAsync(IPrivateFileReference file) { var fileReference = await this.InternalGetAsync(file); return(await fileReference.ReadAllTextAsync()); }
public ValueTask <byte[]> ReadAllBytesAsync(IPrivateFileReference file) => this.innerStore.ReadAllBytesAsync(file);
private ValueTask <Internal.AzureFileReference> InternalGetAsync(IPrivateFileReference file, bool withMetadata = false) { return(this.InternalGetAsync(new Uri(file.Path, UriKind.Relative), withMetadata)); }
public ValueTask <string> ReadAllTextAsync(IPrivateFileReference file) => this.innerStore.ReadAllTextAsync(file);