-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Add StorageFile extensions #481
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Hi @jlnostr, I'm your friendly neighborhood .NET Foundation Pull Request Bot (You can call me DNFBOT). Thanks for your contribution! The agreement was validated by .NET Foundation and real humans are currently evaluating your PR. TTYL, DNFBOT; |
I'm thinking about only making the |
internal static async Task<bool> FileExistsInSubtreeAsync(StorageFolder rootFolder, string fileName) | ||
{ | ||
if (fileName.IndexOf('"') >= 0) | ||
{ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use nameof()
/// </param> | ||
/// <returns> | ||
/// Returns true, if the file exists. | ||
/// </returns> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not the exception that is being thrown
/// <returns> | ||
/// Returns true, if the file exists. | ||
/// </returns> | ||
/// <exception cref="ArgumentNullException"> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nor the reason
/// </param> | ||
/// <returns> | ||
/// Returns true, if the file exists. | ||
/// </returns> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remove the async keyword here, then remove the awaits below it.
Applied the requested changes, thanks for the review @ScottIsAFool. |
for the sake of coherence, I'm wondering if we should provide shortcut methods like:
|
Sounds like a good idea to me 👍 |
@deltakosh those wouldn't be extension methods though, right? Or would they be extension methods of ApplicationData? If so, I'm not sure I see the benefit. |
Agreed with Scott, I'm not seeing a clear benefit.
and
are quite equivalent when it comes to the developer API level. I don't see any clear benefit of the second option, especially when it means we have to implement 5 different methods (Local, LocalCache, Roaming, Temp, Known) |
I see a benefit because you have everything under the same helper. It is just nice to have as it does not require advance coding. |
docs/helpers/StorageFiles.md
Outdated
loadedText = await StorageFileHelper.ReadTextFromLocalFileAsync("appFilename.txt"); | ||
|
||
// Check if a file exists in a specific folder | ||
bool exists = await StorageFileHelper.FileExistsAsync(localFolder, "appFilename.txt"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we demonstrate this version or the extension? (I'm more for the extension)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, might be the better solution. Will modify it :)
@deltakosh I'm not sure you're going to convince me of this :) |
I'm not trying to hard to be honest. I'm fine with just the extension! |
I only have one comment in the code and then I'm fine to merge |
So, no unit tests then? |
I'm fine to merge (but only when unit tests and doc will be provided) |
While writing the unit tests I realized that there's a |
OMG, I completely forgot about this. |
Because of compatibility, making the old helpers obsolete is the better solution IMO. |
Should I delete the related unit tests as well? |
Done deal(and you can then remove them from the unit tests, mark them as deprecate and just use the StorageFileHelper internally |
Will do! |
{ | ||
Assert.IsTrue(await StreamHelper.IsPackagedFileExistsAsync(PackagedFilePath)); | ||
var packageFolder = Package.Current.InstalledLocation; | ||
Assert.IsTrue(await StorageFileHelper.FileExistsAsync(packageFolder, PackagedFilePath)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do you mind using extensions instead? The unit tests are also used to demonstrate the feature
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, no problem. But every other test is it using the above way and I want to keep a bit of consistency.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually I mentioned this for all tests:)
[Obsolete("Use StorageFileHelper.FileExistsAsync instead.")] | ||
public static async Task<bool> IsFileExistsAsync( | ||
this StorageFolder workingFolder, | ||
string fileName) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should rely on the StorageFileHelper instead of duplicating the code?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's very confusing due to the similar names. I marked it as Obsolete
so devs have time to adapt the changes. With the 1.3 release we could probably remove the IsFileExistsAsync
method from the StreamHelper
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure to understand why it is confusing. We will for sure remove it in next version
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A developer might ask: Should I use IsFileExistsAsync
or FileExistsAsync
? What's the difference? Why is the syntax different? Is one better than another?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As IsFileExistsAsync is marked obsolete I think this is already a good reason no to use it
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good otherwise...
Assert.IsTrue(await StreamHelper.IsKnownFolderFileExistsAsync(folder, Filename)); | ||
Assert.IsTrue(await knownFolder.FileExistsAsync(Filename)); | ||
|
||
using (var stream = await StreamHelper.GetKnowFoldersFileStreamAsync(folder, Filename)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If StreamHelper methods are now obsolete, should we move the tests elsewhere ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If the methods are obsolete, shouldn't we delete the tests?
Assert.IsTrue(await StreamHelper.IsKnownFolderFileExistsAsync(folder, Filename)); | ||
Assert.IsTrue(await knownFolder.FileExistsAsync(Filename)); | ||
|
||
using (var stream = await StreamHelper.GetKnowFoldersFileStreamAsync(folder, Filename)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If the methods are obsolete, shouldn't we delete the tests?
agree with Scott |
@jlnostr can we delete the old tests for methods marked obsolete. Please add a few that directly use the new methods and name those accordingly ? |
Ping? I guess we are almost done to merge this one |
FolderDepth = FolderDepth.Deep, | ||
UserSearchFilter = $"filename:=\"{fileName}\"" // “:=” is the exact-match operator | ||
}; | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No reason for thread switching. Should have .ConfigureAwait(false)
at the end.
/// Returns true, if the file exists. | ||
/// </returns> | ||
internal static async Task<bool> FileExistsInFolderAsync(StorageFolder folder, string fileName) | ||
{ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No reason for thread switching. Should have .ConfigureAwait(false) at the end
Up? I would like to merge this one for 1.2 |
@jlnostr I have made the requested changes and merged your PR in. |
See #470.
Would be nice if someone could check the comments, as there might be minor language issues.
TODO: