Skip to content
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

Fix inconsistent number style + replaced clientCulture with currentCulture (code *was* inconsistent) #2716

Closed
wants to merge 12 commits into from
Closed

Fix inconsistent number style + replaced clientCulture with currentCulture (code *was* inconsistent) #2716

wants to merge 12 commits into from

Conversation

304NotModified
Copy link
Contributor

fixes #2710

Created C# extensions for:

  • DetermineClientLocale => HttpRequestExtensions
  • Formatting number with client culture: NumberExtensions.ToNuGetNumberString

TODO:

@dnfclas
Copy link

dnfclas commented Oct 2, 2015

Hi @304NotModified, I'm your friendly neighborhood .NET Foundation Pull Request Bot (You can call me DNFBOT). Thanks for your contribution!

In order for us to evaluate and accept your PR, we ask that you sign a contribution license agreement. It's all electronic and will take just minutes. I promise there's no faxing. https://cla2.dotnetfoundation.org.

TTYL, DNFBOT;

@dnfclas
Copy link

dnfclas commented Oct 3, 2015

@304NotModified, Thanks for signing the contribution license agreement so quickly! Actual humans will now validate the agreement and then evaluate the PR.

Thanks, DNFBOT;

@304NotModified
Copy link
Contributor Author

Todo

  • alignment of downloads at package versions (should by right)

@304NotModified
Copy link
Contributor Author

I was thinking about this. I think the current solution isn't optimal. I should be:

request language => thread culture (UI + normal?) => toString methods with currentCulture.

This is more a .Net approach, and also, it fixes the tostrings of datetime etc. This also solves the unit test issue because we can set the current thread culture easily in an unit test.

It's a more refactor step than this one. So I fix it now, or in a later PR. What do you think?

@304NotModified
Copy link
Contributor Author

Except the unit test, this is done.

@304NotModified
Copy link
Contributor Author

Todo:

  • search : package list/search is missing number style

image

@304NotModified
Copy link
Contributor Author

Please give me feedback :)

besides unit test (where I need feedback for), everything is fixed.

@304NotModified
Copy link
Contributor Author

Note: I have created & tested #2716 (comment) in a separate branch. (not in this PR, yet?)
This will fix the unit test and also I have successfully removed clientCulture everywhere - which is an improvement IMO. Let me know if I should merge it into this PR.

Downloads = stats.Downloads.ToString("n0", clientCulture),
UniquePackages = stats.UniquePackages.ToString("n0", clientCulture),
TotalPackages = stats.TotalPackages.ToString("n0", clientCulture),
Downloads = stats.Downloads.ToNuGetNumberString(),
Copy link
Contributor

Choose a reason for hiding this comment

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

"ToLocalizedNumberString()" sounds more clear

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I also don't like the name ToNuGetNumberString. But it's consistent with DateTimeExtensions, like ToNuGetShortDateTimeString, ToNuGetShortDateString and ToNuGetLongDateString.

This is also mentioned in NumberExtensions:
image

@maartenba
Copy link
Contributor

Added a minor comment to code (rename method so it's more clear what it does).

Regarding the unit test you can:

@304NotModified
Copy link
Contributor Author

Thanks for the feedback and review.

I'd maybe pass the context into the extension methods at https://github.com/304NotModified/NuGetGallery/blob/304NotModified-2710-fix-inconsistent-number-style/src/NuGetGallery/Extensions/NumberExtensions.cs - it feels less clean when using the method but does make it perfectly clear that the context is needed. In fact I think passing in the Request object is enough - does not need the entire context

Passing the Request wasn't always possible. I could write some more overloads, but everything was getting ugly.

I only clean way was to implement my proposal of #2716 (comment)

Before executing an action (see AppController.OnActionExecuting), the CurrentCulture will be set by checking the Request.

I fully removed clientCulture. This is good because:

  • DateTimeExtensions was using CurrentCulture already.
  • The "official" way of .Net is using the CurrentCulture.
  • Passing the ClientCulture was not nice.
  • This makes it unit testable. The unit test didn't even had to change :)
  • Parsing the Userlanguage is now done once per request.

Status: all done

@304NotModified 304NotModified changed the title Fix inconsistent number style Fix inconsistent number style + removed clientCulture Oct 5, 2015
@304NotModified 304NotModified changed the title Fix inconsistent number style + removed clientCulture Fix inconsistent number style + replaced clientCulture with currentCulture (code *was* inconsistent) Oct 5, 2015
@maartenba
Copy link
Contributor

Thanks @304NotModified - will give this a thorough look tomorrow but looks sweet so far :)

@maartenba maartenba self-assigned this Oct 5, 2015
@304NotModified
Copy link
Contributor Author

OK, I see the unit test still fails at appveyor, but works locally. Have to check that first. I will let you know when it's fixed.

  • fix unit test

edit: in an unit test "OnActionExecuting" was never called.

@304NotModified
Copy link
Contributor Author

the unit test has been fixed. See build status / succeeding unit tests: https://ci.appveyor.com/project/304NotModified/nugetgallery/build/1.0.20

I needed a trick to execute the "OnActionExecuting" before calling the "action". This is (proper) implemented in the unit test class.

maartenba pushed a commit that referenced this pull request Oct 6, 2015
@maartenba
Copy link
Contributor

Merged into dev instead - 440d22c

Thanks @304NotModified for your contribution!

@maartenba maartenba closed this Oct 6, 2015
@maartenba maartenba mentioned this pull request Oct 6, 2015
7 tasks
@304NotModified
Copy link
Contributor Author

No problem. But I preferred that I had created a new PR to "dev", because now the PR looks un-merged :(

@maartenba
Copy link
Contributor

Ah no worries, that's GitHub I'm afraid.

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.

Inconsistent number style (group or thousand separators)
3 participants