Skip to content

Conversation

ghost
Copy link

@ghost ghost commented Oct 16, 2016

See #470.

Would be nice if someone could check the comments, as there might be minor language issues.

TODO:

  • Documentation
  • Unit tests

@dnfclas
Copy link

dnfclas commented Oct 16, 2016

Hi @jlnostr, I'm your friendly neighborhood .NET Foundation Pull Request Bot (You can call me DNFBOT). Thanks for your contribution!
You've already signed the contribution license agreement. Thanks!

The agreement was validated by .NET Foundation and real humans are currently evaluating your PR.

TTYL, DNFBOT;

@ghost ghost changed the title Add StorageFile extensions [WIP] Add StorageFile extensions Oct 16, 2016
@ghost
Copy link
Author

ghost commented Oct 16, 2016

I'm thinking about only making the FileExistsAsync task with the ìsRecursive option available to the user, the other ones should be internal. This would result in just one extension instead of three. What do you think about this change?

internal static async Task<bool> FileExistsInSubtreeAsync(StorageFolder rootFolder, string fileName)
{
if (fileName.IndexOf('"') >= 0)
{
Copy link
Contributor

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>
Copy link
Contributor

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">
Copy link
Contributor

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>
Copy link
Contributor

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.

@ghost
Copy link
Author

ghost commented Oct 16, 2016

Applied the requested changes, thanks for the review @ScottIsAFool.

@deltakosh
Copy link
Contributor

for the sake of coherence, I'm wondering if we should provide shortcut methods like:

  • FileExistsInLocalFolderAsync
  • FileExistsInLocalCacheAsync
  • FileExistsInKnownFolderAsync

@ghost
Copy link
Author

ghost commented Oct 18, 2016

Sounds like a good idea to me 👍

@ScottIsAFool
Copy link
Contributor

@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.

@andrewleader
Copy link
Contributor

andrewleader commented Oct 18, 2016

Agreed with Scott, I'm not seeing a clear benefit.

ApplicationData.Current.LocalFolder.FileExistsAsync("tacos.txt")

and

StorageFileHelpers.FileExistsInLocalFolderAsync("tacos.txt")

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)

@deltakosh
Copy link
Contributor

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.
perhaps it is my "I need a 100% completion" problem :)

loadedText = await StorageFileHelper.ReadTextFromLocalFileAsync("appFilename.txt");

// Check if a file exists in a specific folder
bool exists = await StorageFileHelper.FileExistsAsync(localFolder, "appFilename.txt");
Copy link
Contributor

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)

Copy link
Author

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 :)

@ScottIsAFool
Copy link
Contributor

@deltakosh I'm not sure you're going to convince me of this :)

@deltakosh
Copy link
Contributor

I'm not trying to hard to be honest. I'm fine with just the extension!

@deltakosh
Copy link
Contributor

I only have one comment in the code and then I'm fine to merge

@ghost
Copy link
Author

ghost commented Oct 18, 2016

and then I'm fine to merge

So, no unit tests then?

@deltakosh
Copy link
Contributor

I'm fine to merge (but only when unit tests and doc will be provided)
:D

@ghost
Copy link
Author

ghost commented Oct 18, 2016

While writing the unit tests I realized that there's a IsFileExistsAsync extension in StreamHelpers.cs already (see here). What to do with it? Keeping it as a duplicate doesn't make sense to me. Honestly, I don't even understand what it has to do in StreamHelpers.

@deltakosh
Copy link
Contributor

OMG, I completely forgot about this.
We have two options now: Keep them here but it does not make a lot of sense but it saves the back compat OR deprecate them and point them to the StorageFileHelper version (my favorite)

@ghost
Copy link
Author

ghost commented Oct 18, 2016

Because of compatibility, making the old helpers obsolete is the better solution IMO.

@ghost
Copy link
Author

ghost commented Oct 18, 2016

Should I delete the related unit tests as well?

@deltakosh
Copy link
Contributor

Done deal(and you can then remove them from the unit tests, mark them as deprecate and just use the StorageFileHelper internally

@ghost
Copy link
Author

ghost commented Oct 18, 2016

Will do!

@ghost ghost changed the title [WIP] Add StorageFile extensions Add StorageFile extensions Oct 18, 2016
{
Assert.IsTrue(await StreamHelper.IsPackagedFileExistsAsync(PackagedFilePath));
var packageFolder = Package.Current.InstalledLocation;
Assert.IsTrue(await StorageFileHelper.FileExistsAsync(packageFolder, PackagedFilePath));
Copy link
Contributor

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

Copy link
Author

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.

Copy link
Contributor

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)
Copy link
Contributor

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?

Copy link
Author

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.

Copy link
Contributor

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

Copy link
Author

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?

Copy link
Contributor

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

Copy link
Contributor

@hermitdave hermitdave left a 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))
Copy link
Contributor

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 ?

Copy link
Contributor

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))
Copy link
Contributor

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?

@deltakosh
Copy link
Contributor

agree with Scott

@hermitdave
Copy link
Contributor

@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 ?

@deltakosh
Copy link
Contributor

Ping? I guess we are almost done to merge this one

FolderDepth = FolderDepth.Deep,
UserSearchFilter = $"filename:=\"{fileName}\"" // “:=” is the exact-match operator
};

Copy link
Contributor

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)
{
Copy link
Contributor

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

@deltakosh
Copy link
Contributor

Up? I would like to merge this one for 1.2

@ScottIsAFool ScottIsAFool merged commit ebef9a1 into CommunityToolkit:dev Nov 3, 2016
@ScottIsAFool
Copy link
Contributor

@jlnostr I have made the requested changes and merged your PR in.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants