diff --git a/Localization.sln b/Localization.sln index cf7a3d9..841e5c4 100644 --- a/Localization.sln +++ b/Localization.sln @@ -22,6 +22,8 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution EndProject Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "CultureInfoGenerator", "src\CultureInfoGenerator\CultureInfoGenerator.xproj", "{BD22AE1C-6631-4DA6-874D-0DC0F803CEAB}" EndProject +Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "Microsoft.Framework.Globalization.CultureInfoCache", "src\Microsoft.Framework.Globalization.CultureInfoCache\Microsoft.Framework.Globalization.CultureInfoCache.xproj", "{F3988D3A-A4C8-4FD7-BAFE-13E0D0A1659A}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -48,6 +50,10 @@ Global {BD22AE1C-6631-4DA6-874D-0DC0F803CEAB}.Debug|Any CPU.Build.0 = Debug|Any CPU {BD22AE1C-6631-4DA6-874D-0DC0F803CEAB}.Release|Any CPU.ActiveCfg = Release|Any CPU {BD22AE1C-6631-4DA6-874D-0DC0F803CEAB}.Release|Any CPU.Build.0 = Release|Any CPU + {F3988D3A-A4C8-4FD7-BAFE-13E0D0A1659A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {F3988D3A-A4C8-4FD7-BAFE-13E0D0A1659A}.Debug|Any CPU.Build.0 = Debug|Any CPU + {F3988D3A-A4C8-4FD7-BAFE-13E0D0A1659A}.Release|Any CPU.ActiveCfg = Release|Any CPU + {F3988D3A-A4C8-4FD7-BAFE-13E0D0A1659A}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE @@ -58,5 +64,6 @@ Global {A1FCF259-70F6-4605-AA2D-E4B356BE771A} = {FB313677-BAB3-4E49-8CDB-4FA4A9564767} {55D9501F-15B9-4339-A0AB-6082850E5FCE} = {79878809-8D1C-4BD4-BA99-F1F13FF96FD8} {BD22AE1C-6631-4DA6-874D-0DC0F803CEAB} = {FB313677-BAB3-4E49-8CDB-4FA4A9564767} + {F3988D3A-A4C8-4FD7-BAFE-13E0D0A1659A} = {FB313677-BAB3-4E49-8CDB-4FA4A9564767} EndGlobalSection EndGlobal diff --git a/src/CultureInfoGenerator/Program.cs b/src/CultureInfoGenerator/Program.cs index 7843c92..f45c1c7 100644 --- a/src/CultureInfoGenerator/Program.cs +++ b/src/CultureInfoGenerator/Program.cs @@ -22,7 +22,7 @@ namespace CultureInfoGenerator public void Main(string[] args) { - var outputFilePath = args.Length > 0 ? args[0] : Path.Combine(_appPath, "../Microsoft.AspNet.Localization/Internal/CultureInfoList.cs"); + var outputFilePath = args.Length > 0 ? args[0] : Path.Combine(_appPath, "../Microsoft.Framework.Globalization.CultureCache/CultureInfoList.cs"); var netFxVersion = Get45or451FromRegistry(); var windowsVersion = Environment.OSVersion; @@ -31,16 +31,24 @@ namespace CultureInfoGenerator writer.WriteLine($@"// Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. +// *************************** THIS FILE IS GENERATED BY A TOOL *************************** +// To make changes to this file look at the CultureInfoGenerator project in this solution. + using System.Collections.Generic; -namespace Microsoft.AspNet.Localization.Internal +namespace Microsoft.Framework.Globalization {{ - public static class CultureInfoList + /// + /// Contains a list of known culture names that can be used to create a . + /// + public static partial class CultureInfoCache {{ - // This list of known cultures was generated by {_appName} using .NET Framework {netFxVersion} on - // {windowsVersion}. - // As new versions of .NET Framework and Windows are released, this list should be regenerated to ensure it - // contains the latest culture names. + /// + /// This list of known cultures was generated by {_appName} using .NET Framework {netFxVersion} on + /// {windowsVersion}. + /// As new versions of .NET Framework and Windows are released, this list should be regenerated to ensure it + /// contains the latest culture names. + /// public static readonly HashSet KnownCultureNames = new HashSet {{" ); diff --git a/src/Microsoft.AspNet.Localization/AcceptLanguageHeaderRequestCultureStrategy.cs b/src/Microsoft.AspNet.Localization/AcceptLanguageHeaderRequestCultureStrategy.cs index 45ac85e..eef5cf7 100644 --- a/src/Microsoft.AspNet.Localization/AcceptLanguageHeaderRequestCultureStrategy.cs +++ b/src/Microsoft.AspNet.Localization/AcceptLanguageHeaderRequestCultureStrategy.cs @@ -4,7 +4,7 @@ using System.Linq; using System.Threading.Tasks; using Microsoft.AspNet.Http; -using Microsoft.AspNet.Localization.Internal; +using Microsoft.Framework.Globalization; using Microsoft.Framework.Internal; using Microsoft.Net.Http.Headers; diff --git a/src/Microsoft.AspNet.Localization/CookieRequestCultureStrategy.cs b/src/Microsoft.AspNet.Localization/CookieRequestCultureStrategy.cs index 68e7c96..e142265 100644 --- a/src/Microsoft.AspNet.Localization/CookieRequestCultureStrategy.cs +++ b/src/Microsoft.AspNet.Localization/CookieRequestCultureStrategy.cs @@ -4,7 +4,7 @@ using System; using System.Threading.Tasks; using Microsoft.AspNet.Http; -using Microsoft.AspNet.Localization.Internal; +using Microsoft.Framework.Globalization; using Microsoft.Framework.Internal; namespace Microsoft.AspNet.Localization diff --git a/src/Microsoft.AspNet.Localization/QueryStringRequestCultureStrategy.cs b/src/Microsoft.AspNet.Localization/QueryStringRequestCultureStrategy.cs index 4a9a0b9..5c6ebab 100644 --- a/src/Microsoft.AspNet.Localization/QueryStringRequestCultureStrategy.cs +++ b/src/Microsoft.AspNet.Localization/QueryStringRequestCultureStrategy.cs @@ -3,7 +3,7 @@ using System.Threading.Tasks; using Microsoft.AspNet.Http; -using Microsoft.AspNet.Localization.Internal; +using Microsoft.Framework.Globalization; using Microsoft.Framework.Internal; namespace Microsoft.AspNet.Localization diff --git a/src/Microsoft.AspNet.Localization/project.json b/src/Microsoft.AspNet.Localization/project.json index 069295b..e127f98 100644 --- a/src/Microsoft.AspNet.Localization/project.json +++ b/src/Microsoft.AspNet.Localization/project.json @@ -3,9 +3,10 @@ "description": "Middleware for automatically applying culture information to HTTP requests.", "dependencies": { + "Microsoft.AspNet.Http.Extensions": "1.0.0-*", + "Microsoft.Framework.Globalization.CultureInfoCache": "1.0.0-*", "Microsoft.Framework.Localization.Abstractions": "1.0.0-*", - "Microsoft.Framework.NotNullAttribute.Internal": { "type": "build", "version": "1.0.0-*" }, - "Microsoft.AspNet.Http.Extensions": "1.0.0-*" + "Microsoft.Framework.NotNullAttribute.Internal": { "type": "build", "version": "1.0.0-*" } }, "frameworks": { @@ -13,7 +14,6 @@ "dnxcore50": { "dependencies": { "System.Collections": "4.0.10-*", - "System.Collections.Concurrent": "4.0.10-*", "System.Linq": "4.0.0-*", "System.Globalization": "4.0.10-*", "System.Threading": "4.0.10-*", diff --git a/src/Microsoft.AspNet.Localization/Internal/CultureInfoCache.cs b/src/Microsoft.Framework.Globalization.CultureInfoCache/CultureInfoCache.cs similarity index 70% rename from src/Microsoft.AspNet.Localization/Internal/CultureInfoCache.cs rename to src/Microsoft.Framework.Globalization.CultureInfoCache/CultureInfoCache.cs index 9e8ee0a..906fe77 100644 --- a/src/Microsoft.AspNet.Localization/Internal/CultureInfoCache.cs +++ b/src/Microsoft.Framework.Globalization.CultureInfoCache/CultureInfoCache.cs @@ -1,21 +1,32 @@ // Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. -using System; using System.Collections.Concurrent; using System.Globalization; -namespace Microsoft.AspNet.Localization.Internal +namespace Microsoft.Framework.Globalization { - public static class CultureInfoCache + /// + /// Provides read-only cached instances of . + /// + public static partial class CultureInfoCache { private static readonly ConcurrentDictionary _cache = new ConcurrentDictionary(); + /// + /// Gets a read-only cached for the specified name. Only names that exist in + /// will be used. + /// + /// The culture name. + /// + /// A read-only cached or null a match wasn't found in + /// . + /// public static CultureInfo GetCultureInfo(string name) { // Allow only known culture names as this API is called with input from users (HTTP requests) and // creating CultureInfo objects is expensive and we don't want it to throw either. - if (name == null || !CultureInfoList.KnownCultureNames.Contains(name)) + if (name == null || !KnownCultureNames.Contains(name)) { return null; } diff --git a/src/Microsoft.AspNet.Localization/Internal/CultureInfoList.cs b/src/Microsoft.Framework.Globalization.CultureInfoCache/CultureInfoList.cs similarity index 91% rename from src/Microsoft.AspNet.Localization/Internal/CultureInfoList.cs rename to src/Microsoft.Framework.Globalization.CultureInfoCache/CultureInfoList.cs index 1d17873..c29f8dc 100644 --- a/src/Microsoft.AspNet.Localization/Internal/CultureInfoList.cs +++ b/src/Microsoft.Framework.Globalization.CultureInfoCache/CultureInfoList.cs @@ -1,16 +1,24 @@ // Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. +// *************************** THIS FILE IS GENERATED BY A TOOL *************************** +// To make changes to this file look at the CultureInfoGenerator project in this solution. + using System.Collections.Generic; -namespace Microsoft.AspNet.Localization.Internal +namespace Microsoft.Framework.Globalization { - public static class CultureInfoList + /// + /// Contains a list of known culture names that can be used to create a . + /// + public static partial class CultureInfoCache { - // This list of known cultures was generated by CultureInfoGenerator using .NET Framework 4.6 RC or later on - // Microsoft Windows NT 6.2.9200.0. - // As new versions of .NET Framework and Windows are released, this list should be regenerated to ensure it - // contains the latest culture names. + /// + /// This list of known cultures was generated by CultureInfoGenerator using .NET Framework 4.6 RC or later on + /// Microsoft Windows NT 6.2.9200.0. + /// As new versions of .NET Framework and Windows are released, this list should be regenerated to ensure it + /// contains the latest culture names. + /// public static readonly HashSet KnownCultureNames = new HashSet { "", diff --git a/src/Microsoft.Framework.Globalization.CultureInfoCache/Microsoft.Framework.Globalization.CultureInfoCache.xproj b/src/Microsoft.Framework.Globalization.CultureInfoCache/Microsoft.Framework.Globalization.CultureInfoCache.xproj new file mode 100644 index 0000000..9b2995a --- /dev/null +++ b/src/Microsoft.Framework.Globalization.CultureInfoCache/Microsoft.Framework.Globalization.CultureInfoCache.xproj @@ -0,0 +1,20 @@ + + + + 14.0 + $(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion) + + + + + f3988d3a-a4c8-4fd7-bafe-13e0d0a1659a + Microsoft.Framework.Globalization.CultureInfoList + ..\..\artifacts\obj\$(MSBuildProjectName) + ..\..\artifacts\bin\$(MSBuildProjectName)\ + + + + 2.0 + + + diff --git a/src/Microsoft.Framework.Globalization.CultureInfoCache/project.json b/src/Microsoft.Framework.Globalization.CultureInfoCache/project.json new file mode 100644 index 0000000..25b5bca --- /dev/null +++ b/src/Microsoft.Framework.Globalization.CultureInfoCache/project.json @@ -0,0 +1,19 @@ +{ + "version": "1.0.0-*", + "description": "Provides cached instances of CultureInfo using a generated list of known culture names for use in scenarios where unbounded CultureInfo creation is undesirable.", + + "dependencies": { + }, + + "frameworks": { + "dnx451": { }, + "dnxcore50": { + "dependencies": { + "System.Collections": "4.0.10-*", + "System.Collections.Concurrent": "4.0.10-*", + "System.Globalization": "4.0.10-*", + "Microsoft.CSharp": "4.0.0-*" + } + } + } +}