Skip to content

Commit 73f5faa

Browse files
committed
LocalFile fixes
1 parent 5096272 commit 73f5faa

File tree

8 files changed

+54
-19
lines changed

8 files changed

+54
-19
lines changed

Directory.Build.props

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@
1414
<PackageLicenseExpression>MIT</PackageLicenseExpression>
1515
<PackageReadmeFile>README.md</PackageReadmeFile>
1616
<Product>Managed Code - Storage</Product>
17-
<Version>2.1.6</Version>
18-
<PackageVersion>2.1.6</PackageVersion>
17+
<Version>2.1.7</Version>
18+
<PackageVersion>2.1.7</PackageVersion>
1919
</PropertyGroup>
2020
<PropertyGroup Condition="'$(GITHUB_ACTIONS)' == 'true'">
2121
<ContinuousIntegrationBuild>true</ContinuousIntegrationBuild>

ManagedCode.Storage.AspNetExtensions/StorageExtensions.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ public static async Task<Result<FileResult>> DownloadAsFileResult(this IStorage
2121

2222
var fileStream = new FileStreamResult(result.Value!.FileStream, MimeHelper.GetMimeType(result.Value.FileInfo.Extension))
2323
{
24-
FileDownloadName = result.Value.FileName
24+
FileDownloadName = result.Value.Name
2525
};
2626

2727
return Result<FileResult>.Succeed(fileStream);
@@ -40,7 +40,7 @@ public static async Task<Result<FileResult>> DownloadAsFileResult(this IStorage
4040

4141
var fileStream = new FileStreamResult(result.Value!.FileStream, MimeHelper.GetMimeType(result.Value.FileInfo.Extension))
4242
{
43-
FileDownloadName = result.Value.FileName
43+
FileDownloadName = result.Value.Name
4444
};
4545

4646
return Result<FileResult>.Succeed(fileStream);

ManagedCode.Storage.Core/BaseStorage.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
using System.Diagnostics.Contracts;
44
using System.IO;
55
using System.Text.Json;
6-
using System.Text.Json.Serialization;
76
using System.Threading;
87
using System.Threading.Tasks;
98
using ManagedCode.Communication;

ManagedCode.Storage.Core/Models/LocalFile.cs

Lines changed: 38 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,12 +43,12 @@ public LocalFile(string? path = null, bool keepAlive = false)
4343
fs.Close();
4444
}
4545

46-
FileName = FileInfo.Name;
46+
Name = FileInfo.Name;
4747
}
4848

4949
public string FilePath { get; }
5050

51-
public string FileName { get; }
51+
public string Name { get; }
5252

5353
public bool KeepAlive { get; set; }
5454

@@ -115,6 +115,42 @@ public void Dispose()
115115
}
116116
}
117117

118+
public string ReadAllText()
119+
{
120+
lock (_lockObject)
121+
{
122+
CloseFileStream();
123+
return File.ReadAllText(FilePath);
124+
}
125+
}
126+
127+
public Task<string> ReadAllTextAsync()
128+
{
129+
lock (_lockObject)
130+
{
131+
CloseFileStream();
132+
return File.ReadAllTextAsync(FilePath);
133+
}
134+
}
135+
136+
public string[] ReadAllLines()
137+
{
138+
lock (_lockObject)
139+
{
140+
CloseFileStream();
141+
return File.ReadAllLines(FilePath);
142+
}
143+
}
144+
145+
public Task<string[]> ReadAllLinesAsync()
146+
{
147+
lock (_lockObject)
148+
{
149+
CloseFileStream();
150+
return File.ReadAllLinesAsync(FilePath);
151+
}
152+
}
153+
118154
~LocalFile()
119155
{
120156
Dispose();

ManagedCode.Storage.FileSystem/FileSystemStorage.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -114,9 +114,9 @@ private string GetPathFromOptions(BaseOptions options)
114114
{
115115
filePath = Path.Combine(StorageClient, options.FileName);
116116
}
117-
117+
118118
EnsureDirectoryExist(Path.GetDirectoryName(filePath));
119-
119+
120120
return filePath;
121121
}
122122

ManagedCode.Storage.Tests/AspNetExtensions/FormFileExtensionsTests.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ public async Task ToLocalFileAsync_SmallFile()
2323

2424
// Assert
2525
localFile.FileStream.Length.Should().Be(formFile.Length);
26-
localFile.FileName.Should().Be(formFile.FileName);
26+
localFile.Name.Should().Be(formFile.FileName);
2727
}
2828

2929
[Fact]
@@ -39,7 +39,7 @@ public async Task ToLocalFileAsync_LargeFile()
3939

4040
// Assert
4141
localFile.FileStream.Length.Should().Be(formFile.Length);
42-
localFile.FileName.Should().Be(formFile.FileName);
42+
localFile.Name.Should().Be(formFile.FileName);
4343
}
4444

4545
[Fact]
@@ -66,7 +66,7 @@ public async Task ToLocalFilesAsync_SmallFiles()
6666
for (var i = 0; i < filesCount; i++)
6767
{
6868
localFiles[i].FileStream.Length.Should().Be(collection[i].Length);
69-
localFiles[i].FileName.Should().Be(collection[i].FileName);
69+
localFiles[i].Name.Should().Be(collection[i].FileName);
7070
}
7171
}
7272
}

ManagedCode.Storage.Tests/AspNetExtensions/StorageExtensionsTests.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ public async Task UploadToStorageAsync_SmallFile()
4646

4747
// Assert
4848
localFile!.Value.FileInfo.Length.Should().Be(formFile.Length);
49-
localFile.Value.FileName.Should().Be(formFile.FileName);
49+
localFile.Value.Name.Should().Be(formFile.FileName);
5050

5151
await Storage.DeleteAsync(fileName);
5252
}
@@ -64,7 +64,7 @@ public async Task UploadToStorageAsync_LargeFile()
6464
var result = await Storage.DownloadAsync(fileName);
6565

6666
// Assert
67-
result.Value.FileName.Should().Be(formFile.FileName);
67+
result.Value.Name.Should().Be(formFile.FileName);
6868

6969
await Storage.DeleteAsync(fileName);
7070
}
@@ -84,7 +84,7 @@ public async Task UploadToStorageAsync_WithRandomName()
8484
// Assert
8585
result.IsSuccess.Should().BeTrue();
8686
localFile.Value.FileInfo.Length.Should().Be(formFile.Length);
87-
localFile.Value.FileName.Should().Be(fileName);
87+
localFile.Value.Name.Should().Be(fileName);
8888

8989
await Storage.DeleteAsync(fileName);
9090
}
@@ -104,7 +104,7 @@ public async Task DownloadAsFileResult_WithFileName()
104104
// Assert
105105
result.IsSuccess.Should().BeTrue();
106106
result.Value!.ContentType.Should().Be(MimeHelper.GetMimeType(localFile.FileInfo.Extension));
107-
result.Value.FileDownloadName.Should().Be(localFile.FileName);
107+
result.Value.FileDownloadName.Should().Be(localFile.Name);
108108

109109
await Storage.DeleteAsync(fileName);
110110
}
@@ -126,7 +126,7 @@ public async Task DownloadAsFileResult_WithBlobMetadata()
126126
// Assert
127127
result.IsSuccess.Should().Be(true);
128128
result.Value!.ContentType.Should().Be(MimeHelper.GetMimeType(localFile.FileInfo.Extension));
129-
result.Value.FileDownloadName.Should().Be(localFile.FileName);
129+
result.Value.FileDownloadName.Should().Be(localFile.Name);
130130

131131
await Storage.DeleteAsync(fileName);
132132
}

ManagedCode.Storage.Tests/StorageBaseTests.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,7 @@ protected async Task<FileInfo> GetTestFileAsync()
198198
//
199199
// foreach (var localFile in bigFiles)
200200
// {
201-
// await Storage.UploadStreamAsync(localFile.FileName, localFile.FileStream);
201+
// await Storage.UploadStreamAsync(localFile.Name, localFile.FileStream);
202202
// await localFile.DisposeAsync();
203203
// }
204204
//
@@ -209,7 +209,7 @@ protected async Task<FileInfo> GetTestFileAsync()
209209
//
210210
// foreach (var localFile in bigFiles)
211211
// {
212-
// await Storage.DeleteAsync(localFile.FileName);
212+
// await Storage.DeleteAsync(localFile.Name);
213213
// }
214214
// }
215215

0 commit comments

Comments
 (0)