Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 2 additions & 7 deletions src/GeekLearning.Storage.Azure/AzureStore.cs
Original file line number Diff line number Diff line change
Expand Up @@ -231,14 +231,9 @@ internal static SharedAccessBlobPermissions FromGenericToAzure(SharedAccessPermi
return result;
}

private async ValueTask<Internal.AzureFileReference> InternalGetAsync(IPrivateFileReference file, bool withMetadata = false)
private ValueTask<Internal.AzureFileReference> InternalGetAsync(IPrivateFileReference file, bool withMetadata = false)
{
if (file is Internal.AzureFileReference azureFile)
{
return azureFile;
}

return await this.InternalGetAsync(new Uri(file.Path, UriKind.Relative), withMetadata);
return this.InternalGetAsync(new Uri(file.Path, UriKind.Relative), withMetadata);
}

private async ValueTask<Internal.AzureFileReference> InternalGetAsync(Uri uri, bool withMetadata)
Expand Down
15 changes: 15 additions & 0 deletions src/GeekLearning.Storage.Azure/Internal/AzureFileReference.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,13 @@
public class AzureFileReference : IFileReference
{
private Lazy<AzureFileProperties> propertiesLazy;
private bool withMetadata;

public AzureFileReference(string path, ICloudBlob cloudBlob, bool withMetadata)
{
this.Path = path;
this.CloudBlob = cloudBlob;
this.withMetadata = withMetadata;
this.propertiesLazy = new Lazy<AzureFileProperties>(() =>
{
if (withMetadata && cloudBlob.Metadata != null && cloudBlob.Properties != null)
Expand Down Expand Up @@ -95,5 +97,18 @@ public ValueTask<string> GetSharedAccessSignature(ISharedAccessPolicy policy)

return new ValueTask<string>(this.CloudBlob.GetSharedAccessSignature(adHocPolicy));
}

public async Task FetchProperties()
{
if (this.withMetadata)
{
return;
}

await this.CloudBlob.FetchAttributesAsync();

this.propertiesLazy = new Lazy<AzureFileProperties>(() => new AzureFileProperties(this.CloudBlob));
this.withMetadata = true;
}
}
}
9 changes: 2 additions & 7 deletions src/GeekLearning.Storage.FileSystem/FileSystemStore.cs
Original file line number Diff line number Diff line change
Expand Up @@ -153,14 +153,9 @@ public ValueTask<string> GetSharedAccessSignatureAsync(ISharedAccessPolicy polic
throw new NotSupportedException();
}

private async ValueTask<Internal.FileSystemFileReference> InternalGetAsync(IPrivateFileReference file, bool withMetadata = false, bool checkIfExists = true)
private ValueTask<Internal.FileSystemFileReference> InternalGetAsync(IPrivateFileReference file, bool withMetadata = false, bool checkIfExists = true)
{
if (file is Internal.FileSystemFileReference fileSystemFile)
{
return fileSystemFile;
}

return await this.InternalGetAsync(file.Path, withMetadata, checkIfExists);
return this.InternalGetAsync(file.Path, withMetadata, checkIfExists);
}

private async ValueTask<Internal.FileSystemFileReference> InternalGetAsync(string path, bool withMetadata, bool checkIfExists = true)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,10 @@
public class FileSystemFileReference : IFileReference
{
private readonly FileSystemStore store;
private readonly Lazy<IFileProperties> propertiesLazy;
private readonly Lazy<string> publicUrlLazy;
private readonly IExtendedPropertiesProvider extendedPropertiesProvider;
private bool withMetadata;
private Lazy<IFileProperties> propertiesLazy;

public FileSystemFileReference(
string filePath,
Expand All @@ -24,6 +25,7 @@ public FileSystemFileReference(
this.Path = path.Replace('\\', '/');
this.store = store;
this.extendedPropertiesProvider = extendedPropertiesProvider;
this.withMetadata = withMetadata;

this.propertiesLazy = new Lazy<IFileProperties>(() =>
{
Expand Down Expand Up @@ -108,5 +110,25 @@ public ValueTask<string> GetSharedAccessSignature(ISharedAccessPolicy policy)
{
throw new NotSupportedException();
}

public async Task FetchProperties()
{
if (this.withMetadata)
{
return;
}

if (this.extendedPropertiesProvider == null)
{
throw new InvalidOperationException("There is no FileSystem extended properties provider.");
}

var extendedProperties = await this.extendedPropertiesProvider.GetExtendedPropertiesAsync(
this.store.AbsolutePath,
this);

this.propertiesLazy = new Lazy<IFileProperties>(() => new FileSystemFileProperties(this.FileSystemPath, extendedProperties));
this.withMetadata = true;
}
}
}
2 changes: 2 additions & 0 deletions src/GeekLearning.Storage/IFileReference.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,5 +24,7 @@ public interface IFileReference : IPrivateFileReference
Task SavePropertiesAsync();

ValueTask<string> GetSharedAccessSignature(ISharedAccessPolicy policy);

Task FetchProperties();
}
}