Skip to content

feat(storage): Added Overload for ReadPackageFileAsync - #2734

Open
DevTKSS wants to merge 11 commits into
unoplatform:mainfrom
DevTKSS:feat(storage)-Add-Read-Package-file-overload
Open

DevTKSS wants to merge 11 commits into
unoplatform:mainfrom
DevTKSS:feat(storage)-Add-Read-Package-file-overload

Conversation

@DevTKSS

@DevTKSS DevTKSS commented Apr 20, 2025 •

Copy link
Copy Markdown
Contributor

GitHub Issue (If applicable): closes #2710 #2630 #unoplatform/uno#19088

PR Type

What kind of change does this PR introduce?

  • Feature
  • Documentation content changes

What is the current behavior?

only Json or Xml formats are having existing ISerializers, so when it comes to native file formats like txt or similar, the string from the existing function has get looped or a stream return would have to get considered.
Stream would then mean to pay attention to closing this stream again afterwards.

Storage Documentation almoast completly missing

What is the new behavior?

  • Overload allowes providing specific lines for the return, not only all or nothing.
  • not requiring Stream usage
  • Added reference and Samples in their topics

PR Checklist

Please check if your PR fulfills the following requirements:

  • Tested code with current supported SDKs
    not able to run tests because of runtimetests.csproj having 255.255.255.255 value and only uno.ui tests are documented. the linked readme file above does not even contain the header "supported" maybe to be fixed?
    image
    image
  • Unit Tests and/or UI Tests for the changes have been added (for bug fixes / features) (if applicable) => not possible because of above problem
  • Wasm UI Tests are not showing unexpected any differences. Validate PR Screenshots Compare Test Run results. => not possible because of above problem
  • Docs have been added/updated which fit documentation template. (for bug fixes / features)
    Feature Template is not applyable, since its no control feature, but yes, I added Usage Samples for all IStorage Functions available
  • Contains NO breaking changes
  • Updated the Release Notes
  • Associated with an issue (GitHub or internal)

Other information

please tell how to edit ReleaseNotes suitable, did not found a guide in the docs to this

Internal Issue (If applicable):

@unodevops

Copy link
Copy Markdown
Contributor

⚠️⚠️ The build 164203 has failed on uno.extensions.

@unodevops

Copy link
Copy Markdown
Contributor

⚠️⚠️ The build 165171 has failed on uno.extensions.

@DevTKSS

DevTKSS commented May 11, 2025

Copy link
Copy Markdown
Contributor Author

Hm will add a parameter into the constructor to enable nullbased(default) and 1-based enumerations from list or similar to be used. So StorageExtension would then tell it 1-based enumeration because if we have lines numbered in vs editor they are starting by 1 and so the user would provide its values 1 based.
Updated this already locally on my own extensions. Will have a look if I find time to push and copy the adjustments tomorrow.

Overloads allows providing specific lines for the return. Useful in cases its for example txt file, which has no ISerializer like for Json or xaml format.
@DevTKSS
DevTKSS force-pushed the feat(storage)-Add-Read-Package-file-overload branch from 072e76f to 779a278 Compare June 28, 2025 20:30
@DevTKSS

DevTKSS commented Jul 1, 2025

Copy link
Copy Markdown
Contributor Author

@jeromelaban could someone take a look and tell if there is anything left to do?

Comment thread .editorconfig Resolved
Comment thread doc/toc.yml Resolved
/// An enumerable collection of strings, where each string represents the items within a specified range.
/// If a range is invalid (e.g. start is greater than the last one), an empty string is returned for that range.
/// </returns>
public static IEnumerable<string> SelectItemsByRanges(this IEnumerable<string> source, IEnumerable<(int Start, int End)> ranges, bool isNullBased = true)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@kazoo maybe you would see a more serialization friendly way than IEnumerable<(int,int)> here? In my Gallery App, I defined a "Lines" type with this propertys like this:

public record Lines
{
    public int Start { get; init; }
    public int End { get; init; }
}

But maybe you would know a better way or setup to get the same result?
I would see a usecase for non serialization friendly files to be better handle able using the IStorage Extensions.

DevTKSS added 4 commits July 8, 2025 22:01
… to extension based


The functionallity should extend the capabilities of IStorage, not introduce a change requirement for Implementing Classes of course
Copilot AI review requested due to automatic review settings July 27, 2025 14:10

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR adds a new overload method for reading package files with line range specification, allowing developers to extract specific lines from text files without needing to handle streams directly. The changes provide more granular control over file reading operations while improving documentation.

  • Added ReadLinesFromPackageFile extension method with line range selection capability
  • Introduced enumerable extension utilities for range-based item selection
  • Enhanced documentation with missing XML comments and return type descriptions

Reviewed Changes

Copilot reviewed 7 out of 7 changed files in this pull request and generated 4 comments.

Show a summary per file
File Description
src/Uno.Extensions.Storage/Uno.Extensions.Storage.csproj Added Uno.Core package dependencies for enumerable extensions
src/Uno.Extensions.Storage/StorageExtensions.cs Added new overload method for reading specific lines from package files
src/Uno.Extensions.Storage/GlobalUsings.cs Added global using for new enumerable extensions namespace
src/Uno.Extensions.Storage/EnumerableExtensions.string.cs New utility class providing range-based selection methods for string collections
src/Uno.Extensions.Storage.UI/HostBuilderExtensions.cs Fixed missing XML documentation return tag
src/Uno.Extensions.Storage.UI/GlobalUsings.cs Added global using for enumerable extensions namespace
src/Uno.Extensions.Storage.UI/FileStorage.cs Added missing inheritdoc comments for interface implementations

{
string fileContent = await storage.ReadPackageFileAsync(filePath) ?? string.Empty;

if (!(lineRanges.Any()))

Copilot AI Jul 27, 2025

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[nitpick] The negation operator should be applied directly to the method call for better readability. Use !lineRanges.Any() instead of !(lineRanges.Any()).

Suggested change
if (!(lineRanges.Any()))
if (!lineRanges.Any())

Copilot uses AI. Check for mistakes.
max: list.Count); // Ensure 'End' does not exceed available lines

return list.Skip(startIndex)
.Take(endIndex - startIndex)

Copilot AI Jul 27, 2025

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The Take operation should use (endIndex - startIndex + 1) to include the end index line, since the documentation states ranges are inclusive on both ends.

Suggested change
.Take(endIndex - startIndex)
.Take(endIndex - startIndex + 1)

Copilot uses AI. Check for mistakes.
Comment on lines +59 to +60
public static string GetItemsWithinRange(this IEnumerable<string> source, (int Start, int End) range, bool isNullBased = true) // TODO: Consider to limit int to min 0 value instead of implicit allowing negative.
{

Copilot AI Jul 27, 2025

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove the TODO comment from production code. Either implement the validation for negative values or create a proper issue to track this enhancement.

Suggested change
public static string GetItemsWithinRange(this IEnumerable<string> source, (int Start, int End) range, bool isNullBased = true) // TODO: Consider to limit int to min 0 value instead of implicit allowing negative.
{
public static string GetItemsWithinRange(this IEnumerable<string> source, (int Start, int End) range, bool isNullBased = true)
{
if (range.Start < 0 || range.End < 0)
{
return string.Empty;
}

Copilot uses AI. Check for mistakes.
@DevTKSS

DevTKSS commented Sep 25, 2025

Copy link
Copy Markdown
Contributor Author

@kazo0 could you please check which of the copilot change requests are valid? I had it suggesting false logic also while writing and it was constantly changing its advise, so it would be great to have some non-AI check this before just accepting those...

@DevTKSS

DevTKSS commented Dec 15, 2025

Copy link
Copy Markdown
Contributor Author

@kazo0 small update for this PR here:

I reworked and fully xUnit test covered my Extension on my SampleApps Repo branch here:

But I am not finding the right way/place to add this to a Uno Test Project and assuming you wouldn't want to add another Test Project for this?

Could you maybe introduce me to the place you want this to be added? Or let me know, if Uno don't want to add non-Secret-Vault Extensions to be added to their Storage Extensions, then I would at some point in the future simply add this package under my own name to nuget, so you dont have more Work with this 🤷

But infinity-duration pending PR would be nothing I would want and could think of, you neither 👍

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.

4 participants