diff --git a/src/Microsoft.AspNet.Session/DistributedSession.cs b/src/Microsoft.AspNet.Session/DistributedSession.cs index b8cd99cfb3..dc78bb49a7 100644 --- a/src/Microsoft.AspNet.Session/DistributedSession.cs +++ b/src/Microsoft.AspNet.Session/DistributedSession.cs @@ -62,13 +62,13 @@ namespace Microsoft.AspNet.Session if (encodedKey.KeyBytes.Length > KeyLengthLimit) { throw new ArgumentOutOfRangeException(nameof(key), - string.Format("The key cannot be longer than '{0}' when encoded with UTF-8.", KeyLengthLimit)); + Resources.FormatException_KeyLengthIsExceeded(KeyLengthLimit)); } Load(); if (!_tryEstablishSession()) { - throw new InvalidOperationException("The session cannot be established after the response has started."); + throw new InvalidOperationException(Resources.Exception_InvalidSessionEstablishment); } _isModified = true; byte[] copy = new byte[value.Length]; @@ -187,7 +187,7 @@ namespace Microsoft.AspNet.Session { if (num < 0 || ushort.MaxValue < num) { - throw new ArgumentOutOfRangeException(nameof(num), "The value cannot be serialized in two bytes."); + throw new ArgumentOutOfRangeException(nameof(num), Resources.Exception_InvalidToSerializeIn2Bytes); } output.WriteByte((byte)(num >> 8)); output.WriteByte((byte)(0xFF & num)); @@ -202,7 +202,7 @@ namespace Microsoft.AspNet.Session { if (num < 0 || 0xFFFFFF < num) { - throw new ArgumentOutOfRangeException(nameof(num), "The value cannot be serialized in three bytes."); + throw new ArgumentOutOfRangeException(nameof(num), Resources.Exception_InvalidToSerializeIn3Bytes); } output.WriteByte((byte)(num >> 16)); output.WriteByte((byte)(0xFF & (num >> 8))); @@ -218,7 +218,7 @@ namespace Microsoft.AspNet.Session { if (num < 0) { - throw new ArgumentOutOfRangeException(nameof(num), "The value cannot be negative."); + throw new ArgumentOutOfRangeException(nameof(num), Resources.Exception_NumberShouldNotBeNegative); } output.WriteByte((byte)(num >> 24)); output.WriteByte((byte)(0xFF & (num >> 16))); diff --git a/src/Microsoft.AspNet.Session/Properties/Resources.Designer.cs b/src/Microsoft.AspNet.Session/Properties/Resources.Designer.cs new file mode 100644 index 0000000000..e92a12995b --- /dev/null +++ b/src/Microsoft.AspNet.Session/Properties/Resources.Designer.cs @@ -0,0 +1,110 @@ +// +namespace Microsoft.AspNet.Session +{ + using System.Globalization; + using System.Reflection; + using System.Resources; + + internal static class Resources + { + private static readonly ResourceManager _resourceManager + = new ResourceManager("Microsoft.AspNet.Session.Resources", typeof(Resources).GetTypeInfo().Assembly); + + /// + /// The key cannot be longer than '{0}' when encoded with UTF-8. + /// + internal static string Exception_KeyLengthIsExceeded + { + get { return GetString("Exception_KeyLengthIsExceeded"); } + } + + /// + /// The key cannot be longer than '{0}' when encoded with UTF-8. + /// + internal static string FormatException_KeyLengthIsExceeded(object p0) + { + return string.Format(CultureInfo.CurrentCulture, GetString("Exception_KeyLengthIsExceeded"), p0); + } + + /// + /// The session cannot be established after the response has started. + /// + internal static string Exception_InvalidSessionEstablishment + { + get { return GetString("Exception_InvalidSessionEstablishment"); } + } + + /// + /// The session cannot be established after the response has started. + /// + internal static string FormatException_InvalidSessionEstablishment() + { + return GetString("Exception_InvalidSessionEstablishment"); + } + + /// + /// The value cannot be serialized in two bytes. + /// + internal static string Exception_InvalidToSerializeIn2Bytes + { + get { return GetString("Exception_InvalidToSerializeIn2Bytes"); } + } + + /// + /// The value cannot be serialized in two bytes. + /// + internal static string FormatException_InvalidToSerializeIn2Bytes() + { + return GetString("Exception_InvalidToSerializeIn2Bytes"); + } + + /// + /// The value cannot be serialized in three bytes. + /// + internal static string Exception_InvalidToSerializeIn3Bytes + { + get { return GetString("Exception_InvalidToSerializeIn3Bytes"); } + } + + /// + /// The value cannot be serialized in three bytes. + /// + internal static string FormatException_InvalidToSerializeIn3Bytes() + { + return GetString("Exception_InvalidToSerializeIn3Bytes"); + } + + /// + /// The value cannot be negative. + /// + internal static string Exception_NumberShouldNotBeNegative + { + get { return GetString("Exception_NumberShouldNotBeNegative"); } + } + + /// + /// The value cannot be negative. + /// + internal static string FormatException_NumberShouldNotBeNegative() + { + return GetString("Exception_NumberShouldNotBeNegative"); + } + + private static string GetString(string name, params string[] formatterNames) + { + var value = _resourceManager.GetString(name); + + System.Diagnostics.Debug.Assert(value != null); + + if (formatterNames != null) + { + for (var i = 0; i < formatterNames.Length; i++) + { + value = value.Replace("{" + formatterNames[i] + "}", "{" + i + "}"); + } + } + + return value; + } + } +} \ No newline at end of file diff --git a/src/Microsoft.AspNet.Session/Resources.resx b/src/Microsoft.AspNet.Session/Resources.resx new file mode 100644 index 0000000000..8212053460 --- /dev/null +++ b/src/Microsoft.AspNet.Session/Resources.resx @@ -0,0 +1,135 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + The key cannot be longer than '{0}' when encoded with UTF-8. + + + The session cannot be established after the response has started. + + + The value cannot be serialized in two bytes. + + + The value cannot be serialized in three bytes. + + + The value cannot be negative. + + \ No newline at end of file