Imported Upstream version 3.6.0

Former-commit-id: da6be194a6b1221998fc28233f2503bd61dd9d14
This commit is contained in:
Jo Shields
2014-08-13 10:39:27 +01:00
commit a575963da9
50588 changed files with 8155799 additions and 0 deletions

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,86 @@
// Copyright (c) Microsoft Corporation. All rights reserved. See License.txt in the project root for license information.
namespace System.Web.Helpers
{
public static class ChartTheme
{
// Review: Need better names.
public const string Blue =
@"<Chart BackColor=""#D3DFF0"" BackGradientStyle=""TopBottom"" BackSecondaryColor=""White"" BorderColor=""26, 59, 105"" BorderlineDashStyle=""Solid"" BorderWidth=""2"" Palette=""BrightPastel"">
<ChartAreas>
<ChartArea Name=""Default"" _Template_=""All"" BackColor=""64, 165, 191, 228"" BackGradientStyle=""TopBottom"" BackSecondaryColor=""White"" BorderColor=""64, 64, 64, 64"" BorderDashStyle=""Solid"" ShadowColor=""Transparent"" />
</ChartAreas>
<Legends>
<Legend _Template_=""All"" BackColor=""Transparent"" Font=""Trebuchet MS, 8.25pt, style=Bold"" IsTextAutoFit=""False"" />
</Legends>
<BorderSkin SkinStyle=""Emboss"" />
</Chart>";
public const string Green =
@"<Chart BackColor=""#C9DC87"" BackGradientStyle=""TopBottom"" BorderColor=""181, 64, 1"" BorderWidth=""2"" BorderlineDashStyle=""Solid"" Palette=""BrightPastel"">
<ChartAreas>
<ChartArea Name=""Default"" _Template_=""All"" BackColor=""Transparent"" BackSecondaryColor=""White"" BorderColor=""64, 64, 64, 64"" BorderDashStyle=""Solid"" ShadowColor=""Transparent"">
<AxisY LineColor=""64, 64, 64, 64"">
<MajorGrid Interval=""Auto"" LineColor=""64, 64, 64, 64"" />
<LabelStyle Font=""Trebuchet MS, 8.25pt, style=Bold"" />
</AxisY>
<AxisX LineColor=""64, 64, 64, 64"">
<MajorGrid LineColor=""64, 64, 64, 64"" />
<LabelStyle Font=""Trebuchet MS, 8.25pt, style=Bold"" />
</AxisX>
<Area3DStyle Inclination=""15"" IsClustered=""False"" IsRightAngleAxes=""False"" Perspective=""10"" Rotation=""10"" WallWidth=""0"" />
</ChartArea>
</ChartAreas>
<Legends>
<Legend _Template_=""All"" Alignment=""Center"" BackColor=""Transparent"" Docking=""Bottom"" Font=""Trebuchet MS, 8.25pt, style=Bold"" IsTextAutoFit =""False"" LegendStyle=""Row"">
</Legend>
</Legends>
<BorderSkin SkinStyle=""Emboss"" />
</Chart>";
public const string Vanilla =
@"<Chart Palette=""SemiTransparent"" BorderColor=""#000"" BorderWidth=""2"" BorderlineDashStyle=""Solid"">
<ChartAreas>
<ChartArea _Template_=""All"" Name=""Default"">
<AxisX>
<MinorGrid Enabled=""False"" />
<MajorGrid Enabled=""False"" />
</AxisX>
<AxisY>
<MajorGrid Enabled=""False"" />
<MinorGrid Enabled=""False"" />
</AxisY>
</ChartArea>
</ChartAreas>
</Chart>";
public const string Vanilla3D =
@"<Chart BackColor=""#555"" BackGradientStyle=""TopBottom"" BorderColor=""181, 64, 1"" BorderWidth=""2"" BorderlineDashStyle=""Solid"" Palette=""SemiTransparent"" AntiAliasing=""All"">
<ChartAreas>
<ChartArea Name=""Default"" _Template_=""All"" BackColor=""Transparent"" BackSecondaryColor=""White"" BorderColor=""64, 64, 64, 64"" BorderDashStyle=""Solid"" ShadowColor=""Transparent"">
<Area3DStyle LightStyle=""Simplistic"" Enable3D=""True"" Inclination=""30"" IsClustered=""False"" IsRightAngleAxes=""False"" Perspective=""10"" Rotation=""-30"" WallWidth=""0"" />
</ChartArea>
</ChartAreas>
</Chart>";
public const string Yellow =
@"<Chart BackColor=""#FADA5E"" BackGradientStyle=""TopBottom"" BorderColor=""#B8860B"" BorderWidth=""2"" BorderlineDashStyle=""Solid"" Palette=""EarthTones"">
<ChartAreas>
<ChartArea Name=""Default"" _Template_=""All"" BackColor=""Transparent"" BackSecondaryColor=""White"" BorderColor=""64, 64, 64, 64"" BorderDashStyle=""Solid"" ShadowColor=""Transparent"">
<AxisY>
<LabelStyle Font=""Trebuchet MS, 8.25pt, style=Bold"" />
</AxisY>
<AxisX LineColor=""64, 64, 64, 64"">
<LabelStyle Font=""Trebuchet MS, 8.25pt, style=Bold"" />
</AxisX>
</ChartArea>
</ChartAreas>
<Legends>
<Legend _Template_=""All"" BackColor=""Transparent"" Docking=""Bottom"" Font=""Trebuchet MS, 8.25pt, style=Bold"" LegendStyle=""Row"">
</Legend>
</Legends>
<BorderSkin SkinStyle=""Emboss"" />
</Chart>";
}
}

View File

@ -0,0 +1,80 @@
// Copyright (c) Microsoft Corporation. All rights reserved. See License.txt in the project root for license information.
using System.Diagnostics;
using System.Globalization;
using System.IO;
using System.Web.Helpers.Resources;
using System.Web.WebPages;
namespace System.Web.Helpers
{
internal static class VirtualPathUtil
{
/// <summary>
/// Resolves and maps a path (physical or virtual) to a physical path on the server.
/// </summary>
/// <param name="httpContext">The <see cref="HttpContextBase"/>.</param>
/// <param name="path">Either a physical rooted path or a virtual path to be mapped.
/// Physical paths are returned without modifications. Virtual paths are resolved relative to the current executing page.
/// </param>
/// <remarks>Result of this call should not be shown to the user (e.g. in an exception message) since
/// it could be security sensitive. But we need to pass this result to the file APIs like File.WriteAllBytes
/// which will show it if exceptions are raised from them. Unfortunately VirtualPathProvider doesn't have
/// APIs for writing so we can't use that.</remarks>
public static string MapPath(HttpContextBase httpContext, string path)
{
Debug.Assert(!String.IsNullOrEmpty(path));
if (Path.IsPathRooted(path))
{
return path;
}
// There is no TryMapPath API so we have to catch HttpException if we want to
// throw ArgumentException instead.
try
{
return httpContext.Request.MapPath(ResolvePath(TemplateStack.GetCurrentTemplate(httpContext), httpContext, path));
}
catch (HttpException)
{
throw new ArgumentException(
String.Format(CultureInfo.InvariantCulture, HelpersResources.PathUtils_IncorrectPath, path), "path");
}
}
/// <summary>
/// Resolves path relative to the current executing page
/// </summary>
public static string ResolvePath(string virtualPath)
{
if (String.IsNullOrEmpty(virtualPath))
{
return virtualPath;
}
if (HttpContext.Current == null)
{
return virtualPath;
}
var httpContext = new HttpContextWrapper(HttpContext.Current);
return ResolvePath(TemplateStack.GetCurrentTemplate(httpContext), httpContext, virtualPath);
}
internal static string ResolvePath(ITemplateFile templateFile, HttpContextBase httpContext, string virtualPath)
{
Debug.Assert(!String.IsNullOrEmpty(virtualPath));
string basePath;
if (templateFile != null)
{
// If a page is available resolve paths relative to it.
basePath = templateFile.TemplateInfo.VirtualPath;
}
else
{
basePath = httpContext.Request.AppRelativeCurrentExecutionFilePath;
}
return VirtualPathUtility.Combine(basePath, virtualPath);
}
}
}

View File

@ -0,0 +1,203 @@
// Copyright (c) Microsoft Corporation. All rights reserved. See License.txt in the project root for license information.
using System.ComponentModel;
using System.Diagnostics;
using System.Diagnostics.CodeAnalysis;
using System.Drawing;
using System.Drawing.Imaging;
using System.Reflection;
namespace System.Web.Helpers
{
internal static class ConversionUtil
{
private static MethodInfo _stringToEnumMethod;
internal static string ToString<T>(T obj)
{
Type type = typeof(T);
if (type.IsEnum)
{
return obj.ToString();
}
TypeConverter converter = TypeDescriptor.GetConverter(type);
if ((converter != null) && (converter.CanConvertTo(typeof(string))))
{
return converter.ConvertToInvariantString(obj);
}
return null;
}
[SuppressMessage("Microsoft.Design", "CA1031:DoNotCatchGeneralExceptionTypes",
Justification = "TypeConverter throws System.Exception instead of a more specific one.")]
internal static bool TryFromString(Type type, string value, out object result)
{
result = null;
if (type == typeof(string))
{
result = value;
return true;
}
if (type.IsEnum)
{
return TryFromStringToEnumHelper(type, value, out result);
}
if (type == typeof(Color))
{
Color color;
bool rval = TryFromStringToColor(value, out color);
result = color;
return rval;
}
// TypeConverter doesn't really have TryConvert APIs. We should avoid TypeConverter.IsValid
// which performs a duplicate conversion, and just handle the general exception ourselves.
TypeConverter converter = TypeDescriptor.GetConverter(type);
if ((converter != null) && converter.CanConvertFrom(typeof(string)))
{
try
{
result = converter.ConvertFromInvariantString(value);
return true;
}
catch
{
// Do nothing
}
}
return false;
}
internal static bool TryFromStringToEnum<T>(string value, out T result) where T : struct
{
return Enum.TryParse(value, ignoreCase: true, result: out result);
}
private static bool TryFromStringToEnumHelper(Type enumType, string value, out object result)
{
result = null;
if (_stringToEnumMethod == null)
{
_stringToEnumMethod = typeof(ConversionUtil).GetMethod("TryFromStringToEnum",
BindingFlags.Static | BindingFlags.NonPublic);
Debug.Assert(_stringToEnumMethod != null);
}
var args = new object[] { value, null };
var rval = (bool)_stringToEnumMethod.MakeGenericMethod(enumType).Invoke(null, args);
result = args[1];
return rval;
}
internal static bool TryFromStringToFontFamily(string fontFamily, out FontFamily result)
{
result = null;
bool converted = false;
foreach (FontFamily fontFamilyTemp in FontFamily.Families)
{
if (fontFamily.Equals(fontFamilyTemp.Name, StringComparison.OrdinalIgnoreCase))
{
result = fontFamilyTemp;
converted = true;
break;
}
}
return converted;
}
[SuppressMessage("Microsoft.Design", "CA1031:DoNotCatchGeneralExceptionTypes",
Justification = "TypeConverter throws System.Exception instad of a more specific one.")]
internal static bool TryFromStringToColor(string value, out Color result)
{
result = default(Color);
// Parse color specified as hex number
if (value.StartsWith("#", StringComparison.OrdinalIgnoreCase))
{
// Only allow colors in form of #RRGGBB or #RGB
if ((value.Length != 7) && (value.Length != 4))
{
return false;
}
// Expand short version
if (value.Length == 4)
{
char[] newValue = new char[7];
newValue[0] = '#';
newValue[1] = newValue[2] = value[1];
newValue[3] = newValue[4] = value[2];
newValue[5] = newValue[6] = value[3];
value = new string(newValue);
}
}
TypeConverter converter = TypeDescriptor.GetConverter(typeof(Color));
Debug.Assert((converter != null) && (converter.CanConvertFrom(typeof(string))));
// There are no TryConvert APIs on TypeConverter so we have to catch exception.
// In addition to that, invalid conversion just throws System.Exception with misleading message,
// instead of a more specific exception type.
try
{
result = (Color)converter.ConvertFromInvariantString(value);
}
catch (Exception)
{
return false;
}
return true;
}
[SuppressMessage("Microsoft.Globalization", "CA1308:NormalizeStringsToUppercase",
Justification = "Format names are used in Http headers and are usually specified in lower case")]
internal static string NormalizeImageFormat(string value)
{
value = value.ToLowerInvariant();
switch (value)
{
case "jpeg":
case "jpg":
case "pjpeg":
return "jpeg";
case "png":
case "x-png":
return "png";
case "icon":
case "ico":
return "icon";
}
return value;
}
internal static bool TryFromStringToImageFormat(string value, out ImageFormat result)
{
result = default(ImageFormat);
if (String.IsNullOrEmpty(value))
{
return false;
}
if (value.StartsWith("image/", StringComparison.OrdinalIgnoreCase))
{
value = value.Substring("image/".Length);
}
value = NormalizeImageFormat(value);
TypeConverter converter = TypeDescriptor.GetConverter(typeof(ImageFormat));
Debug.Assert((converter != null) && (converter.CanConvertFrom(typeof(string))));
try
{
result = (ImageFormat)converter.ConvertFromInvariantString(value);
}
catch (NotSupportedException)
{
return false;
}
return true;
}
}
}

View File

@ -0,0 +1,181 @@
// Copyright (c) Microsoft Corporation. All rights reserved. See License.txt in the project root for license information.
using System.Diagnostics.CodeAnalysis;
using System.Globalization;
using System.Runtime.CompilerServices;
using System.Security.Cryptography;
using System.Text;
using System.Web.Helpers.Resources;
namespace System.Web.Helpers
{
public static class Crypto
{
private const int PBKDF2IterCount = 1000; // default for Rfc2898DeriveBytes
private const int PBKDF2SubkeyLength = 256 / 8; // 256 bits
private const int SaltSize = 128 / 8; // 128 bits
[SuppressMessage("Microsoft.Naming", "CA1720:IdentifiersShouldNotContainTypeNames", MessageId = "byte", Justification = "It really is a byte length")]
internal static byte[] GenerateSaltInternal(int byteLength = SaltSize)
{
byte[] buf = new byte[byteLength];
using (var rng = new RNGCryptoServiceProvider())
{
rng.GetBytes(buf);
}
return buf;
}
[SuppressMessage("Microsoft.Naming", "CA1720:IdentifiersShouldNotContainTypeNames", MessageId = "byte", Justification = "It really is a byte length")]
public static string GenerateSalt(int byteLength = SaltSize)
{
return Convert.ToBase64String(GenerateSaltInternal(byteLength));
}
public static string Hash(string input, string algorithm = "sha256")
{
if (input == null)
{
throw new ArgumentNullException("input");
}
return Hash(Encoding.UTF8.GetBytes(input), algorithm);
}
public static string Hash(byte[] input, string algorithm = "sha256")
{
if (input == null)
{
throw new ArgumentNullException("input");
}
using (HashAlgorithm alg = HashAlgorithm.Create(algorithm))
{
if (alg != null)
{
byte[] hashData = alg.ComputeHash(input);
return BinaryToHex(hashData);
}
else
{
throw new InvalidOperationException(String.Format(CultureInfo.InvariantCulture, HelpersResources.Crypto_NotSupportedHashAlg, algorithm));
}
}
}
[SuppressMessage("Microsoft.Naming", "CA1709:IdentifiersShouldBeCasedCorrectly", MessageId = "SHA", Justification = "Consistent with the Framework, which uses SHA")]
public static string SHA1(string input)
{
return Hash(input, "sha1");
}
[SuppressMessage("Microsoft.Naming", "CA1709:IdentifiersShouldBeCasedCorrectly", MessageId = "SHA", Justification = "Consistent with the Framework, which uses SHA")]
public static string SHA256(string input)
{
return Hash(input, "sha256");
}
/* =======================
* HASHED PASSWORD FORMATS
* =======================
*
* Version 0:
* PBKDF2 with HMAC-SHA1, 128-bit salt, 256-bit subkey, 1000 iterations.
* (See also: SDL crypto guidelines v5.1, Part III)
* Format: { 0x00, salt, subkey }
*/
public static string HashPassword(string password)
{
if (password == null)
{
throw new ArgumentNullException("password");
}
// Produce a version 0 (see comment above) password hash.
byte[] salt;
byte[] subkey;
using (var deriveBytes = new Rfc2898DeriveBytes(password, SaltSize, PBKDF2IterCount))
{
salt = deriveBytes.Salt;
subkey = deriveBytes.GetBytes(PBKDF2SubkeyLength);
}
byte[] outputBytes = new byte[1 + SaltSize + PBKDF2SubkeyLength];
Buffer.BlockCopy(salt, 0, outputBytes, 1, SaltSize);
Buffer.BlockCopy(subkey, 0, outputBytes, 1 + SaltSize, PBKDF2SubkeyLength);
return Convert.ToBase64String(outputBytes);
}
// hashedPassword must be of the format of HashWithPassword (salt + Hash(salt+input)
public static bool VerifyHashedPassword(string hashedPassword, string password)
{
if (hashedPassword == null)
{
throw new ArgumentNullException("hashedPassword");
}
if (password == null)
{
throw new ArgumentNullException("password");
}
byte[] hashedPasswordBytes = Convert.FromBase64String(hashedPassword);
// Verify a version 0 (see comment above) password hash.
if (hashedPasswordBytes.Length != (1 + SaltSize + PBKDF2SubkeyLength) || hashedPasswordBytes[0] != 0x00)
{
// Wrong length or version header.
return false;
}
byte[] salt = new byte[SaltSize];
Buffer.BlockCopy(hashedPasswordBytes, 1, salt, 0, SaltSize);
byte[] storedSubkey = new byte[PBKDF2SubkeyLength];
Buffer.BlockCopy(hashedPasswordBytes, 1 + SaltSize, storedSubkey, 0, PBKDF2SubkeyLength);
byte[] generatedSubkey;
using (var deriveBytes = new Rfc2898DeriveBytes(password, salt, PBKDF2IterCount))
{
generatedSubkey = deriveBytes.GetBytes(PBKDF2SubkeyLength);
}
return ByteArraysEqual(storedSubkey, generatedSubkey);
}
internal static string BinaryToHex(byte[] data)
{
char[] hex = new char[data.Length * 2];
for (int iter = 0; iter < data.Length; iter++)
{
byte hexChar = ((byte)(data[iter] >> 4));
hex[iter * 2] = (char)(hexChar > 9 ? hexChar + 0x37 : hexChar + 0x30);
hexChar = ((byte)(data[iter] & 0xF));
hex[(iter * 2) + 1] = (char)(hexChar > 9 ? hexChar + 0x37 : hexChar + 0x30);
}
return new string(hex);
}
// Compares two byte arrays for equality. The method is specifically written so that the loop is not optimized.
[MethodImpl(MethodImplOptions.NoOptimization)]
private static bool ByteArraysEqual(byte[] a, byte[] b)
{
if (ReferenceEquals(a, b))
{
return true;
}
if (a == null || b == null || a.Length != b.Length)
{
return false;
}
bool areSame = true;
for (int i = 0; i < a.Length; i++)
{
areSame &= (a[i] == b[i]);
}
return areSame;
}
}
}

View File

@ -0,0 +1,48 @@
// Copyright (c) Microsoft Corporation. All rights reserved. See License.txt in the project root for license information.
using System.Collections.Generic;
using System.Diagnostics;
using System.Dynamic;
using System.Web.Script.Serialization;
using Microsoft.Internal.Web.Utils;
namespace System.Web.Helpers
{
/// <summary>
/// Converter that knows how to get the member values from a dynamic object.
/// </summary>
internal class DynamicJavaScriptConverter : JavaScriptConverter
{
public override IEnumerable<Type> SupportedTypes
{
get
{
// REVIEW: For some reason the converters don't pick up interfaces
yield return typeof(IDynamicMetaObjectProvider);
yield return typeof(DynamicObject);
}
}
public override object Deserialize(IDictionary<string, object> dictionary, Type type, JavaScriptSerializer serializer)
{
throw new NotSupportedException();
}
public override IDictionary<string, object> Serialize(object obj, JavaScriptSerializer serializer)
{
var values = new Dictionary<string, object>(StringComparer.OrdinalIgnoreCase);
var memberNames = DynamicHelper.GetMemberNames(obj);
// This should never happen
Debug.Assert(memberNames != null);
// Get the value for each member in the dynamic object
foreach (string memberName in memberNames)
{
values[memberName] = DynamicHelper.GetMemberValue(obj, memberName);
}
return values;
}
}
}

View File

@ -0,0 +1,80 @@
// Copyright (c) Microsoft Corporation. All rights reserved. See License.txt in the project root for license information.
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.Diagnostics.CodeAnalysis;
using System.Dynamic;
using System.Linq;
namespace System.Web.Helpers
{
[SuppressMessage("Microsoft.Naming", "CA1710:IdentifiersShouldHaveCorrectSuffix", Justification = "This class isn't meant to be used directly")]
public class DynamicJsonArray : DynamicObject, IEnumerable<object>
{
private readonly object[] _arrayValues;
public DynamicJsonArray(object[] arrayValues)
{
Debug.Assert(arrayValues != null);
_arrayValues = arrayValues.Select(Json.WrapObject).ToArray();
}
public int Length
{
get { return _arrayValues.Length; }
}
public dynamic this[int index]
{
get { return _arrayValues[index]; }
set { _arrayValues[index] = Json.WrapObject(value); }
}
public override bool TryConvert(ConvertBinder binder, out object result)
{
if (_arrayValues.GetType().IsAssignableFrom(binder.Type))
{
result = _arrayValues;
return true;
}
return base.TryConvert(binder, out result);
}
public override bool TryGetMember(GetMemberBinder binder, out object result)
{
// Testing for members should never throw. This is important when dealing with
// services that return different json results. Testing for a member shouldn't throw,
// it should just return null (or undefined)
result = null;
return true;
}
public IEnumerator GetEnumerator()
{
return _arrayValues.GetEnumerator();
}
private IEnumerable<object> GetEnumerable()
{
return _arrayValues.AsEnumerable();
}
IEnumerator<object> IEnumerable<object>.GetEnumerator()
{
return GetEnumerable().GetEnumerator();
}
[SuppressMessage("Microsoft.Usage", "CA2225:OperatorOverloadsHaveNamedAlternates", Justification = "This class isn't meant to be used directly")]
public static implicit operator object[](DynamicJsonArray obj)
{
return obj._arrayValues;
}
[SuppressMessage("Microsoft.Usage", "CA2225:OperatorOverloadsHaveNamedAlternates", Justification = "This class isn't meant to be used directly")]
public static implicit operator Array(DynamicJsonArray obj)
{
return obj._arrayValues;
}
}
}

View File

@ -0,0 +1,96 @@
// Copyright (c) Microsoft Corporation. All rights reserved. See License.txt in the project root for license information.
using System.Collections.Generic;
using System.Diagnostics;
using System.Dynamic;
using System.Globalization;
using System.Linq;
using System.Web.Helpers.Resources;
namespace System.Web.Helpers
{
// REVIEW: Consider implementing ICustomTypeDescriptor and IDictionary<string, object>
public class DynamicJsonObject : DynamicObject
{
private readonly IDictionary<string, object> _values;
public DynamicJsonObject(IDictionary<string, object> values)
{
Debug.Assert(values != null);
_values = values.ToDictionary(p => p.Key, p => Json.WrapObject(p.Value),
StringComparer.OrdinalIgnoreCase);
}
public override bool TryConvert(ConvertBinder binder, out object result)
{
result = null;
if (binder.Type.IsAssignableFrom(_values.GetType()))
{
result = _values;
}
else
{
throw new InvalidOperationException(String.Format(CultureInfo.CurrentCulture, HelpersResources.Json_UnableToConvertType, binder.Type));
}
return true;
}
public override bool TryGetMember(GetMemberBinder binder, out object result)
{
result = GetValue(binder.Name);
return true;
}
public override bool TrySetMember(SetMemberBinder binder, object value)
{
_values[binder.Name] = Json.WrapObject(value);
return true;
}
public override bool TrySetIndex(SetIndexBinder binder, object[] indexes, object value)
{
string key = GetKey(indexes);
if (!String.IsNullOrEmpty(key))
{
_values[key] = Json.WrapObject(value);
}
return true;
}
public override bool TryGetIndex(GetIndexBinder binder, object[] indexes, out object result)
{
string key = GetKey(indexes);
result = null;
if (!String.IsNullOrEmpty(key))
{
result = GetValue(key);
}
return true;
}
private static string GetKey(object[] indexes)
{
if (indexes.Length == 1)
{
return (string)indexes[0];
}
// REVIEW: Should this throw?
return null;
}
public override IEnumerable<string> GetDynamicMemberNames()
{
return _values.Keys;
}
private object GetValue(string name)
{
object result;
if (_values.TryGetValue(name, out result))
{
return result;
}
return null;
}
}
}

View File

@ -0,0 +1,15 @@
// Copyright (c) Microsoft Corporation. All rights reserved. See License.txt in the project root for license information.
// This file is used by Code Analysis to maintain SuppressMessage
// attributes that are applied to this project.
// Project-level suppressions either have no target or are given
// a specific target and scoped to a namespace, type, member, etc.
//
// To add a suppression to this file, right-click the message in the
// Error List, point to "Suppress Message(s)", and click
// "In Project Suppression File".
// You do not need to add suppressions to this file manually.
using System.Diagnostics.CodeAnalysis;
[assembly: SuppressMessage("Microsoft.Naming", "CA1703:ResourceStringsShouldBeSpelledCorrectly", MessageId = "sha", Scope = "resource", Target = "System.Web.Helpers.Resources.HelpersResources.resources", Justification = "sha is the algorithm")]

View File

@ -0,0 +1,124 @@
// Copyright (c) Microsoft Corporation. All rights reserved. See License.txt in the project root for license information.
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Globalization;
using System.IO;
using System.Web.UI;
namespace System.Web.Helpers
{
internal class HtmlElement
{
public HtmlElement(string tagName)
{
TagName = tagName;
Attributes = new Dictionary<string, string>();
Children = new List<HtmlElement>();
}
internal string TagName { get; set; }
internal string InnerText { get; set; }
public IList<HtmlElement> Children { get; set; }
private IDictionary<string, string> Attributes { get; set; }
[SuppressMessage("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode", Justification = "It is there for completeness")]
public string this[string name]
{
get { return Attributes[name]; }
set { MergeAttribute(name, value); }
}
public HtmlElement SetInnerText(string innerText)
{
InnerText = innerText;
Children.Clear();
return this;
}
public HtmlElement AppendChild(HtmlElement e)
{
Children.Add(e);
return this;
}
public HtmlElement AppendChild(string innerText)
{
AppendChild(CreateSpan(innerText));
return this;
}
private void MergeAttribute(string name, string value)
{
Attributes[name] = value;
}
public HtmlElement AddCssClass(string className)
{
string currentValue;
if (!Attributes.TryGetValue("class", out currentValue))
{
Attributes["class"] = className;
}
else
{
Attributes["class"] = currentValue + " " + className;
}
return this;
}
public IHtmlString ToHtmlString()
{
using (StringWriter sw = new StringWriter(CultureInfo.InvariantCulture))
{
WriteTo(sw);
return new HtmlString(sw.ToString());
}
}
public void WriteTo(TextWriter writer)
{
WriteToInternal(new HtmlTextWriter(writer));
}
private void WriteToInternal(HtmlTextWriter writer)
{
foreach (var a in Attributes)
{
writer.AddAttribute(a.Key, a.Value, true);
}
writer.RenderBeginTag(TagName);
if (!String.IsNullOrEmpty(InnerText))
{
writer.WriteEncodedText(InnerText);
}
else
{
foreach (var e in Children)
{
e.WriteToInternal(writer);
}
}
writer.RenderEndTag();
}
public override string ToString()
{
return ToHtmlString().ToString();
}
internal static HtmlElement CreateSpan(string innerText, string cssClass = null)
{
var span = new HtmlElement("span");
span.SetInnerText(innerText);
if (!String.IsNullOrEmpty(cssClass))
{
span.AddCssClass(cssClass);
}
return span;
}
}
}

View File

@ -0,0 +1,413 @@
// Copyright (c) Microsoft Corporation. All rights reserved. See License.txt in the project root for license information.
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.Diagnostics.CodeAnalysis;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Text;
using System.Web.Helpers.Resources;
namespace System.Web.Helpers
{
internal class HtmlObjectPrinter : ObjectVisitor
{
private const string Styles =
@"<style type=""text/css"">
.objectinfo { font-size: 13px; }
.objectinfo .type { color: #0000ff; }
.objectinfo .complexType { color: #2b91af; }
.objectinfo .name { color: Black; }
.objectinfo .value { color: Black; }
.objectinfo .quote { color: Brown; }
.objectinfo .null { color: Red; }
.objectinfo .exception { color:Red; }
.objectinfo .typeContainer { border-left: solid 2px #7C888A; padding-left: 3px; margin-left:3px; }
.objectinfo h3, h2 { margin:0; padding:0; }
.objectinfo ul { margin-top:0; margin-bottom:0; list-style-type:none; padding-left:10px; margin-left:10px; }
</style>
";
private static readonly HtmlElement _nullSpan = HtmlElement.CreateSpan("(null)", "null");
// List of chars to escape within strings
private static readonly Dictionary<char, string> _printableEscapeChars = new Dictionary<char, string>
{
{ '\0', "\\0" },
{ '\\', "\\\\" },
{ '\'', "'" },
{ '\"', "\\\"" },
{ '\a', "\\a" },
{ '\b', "\\b" },
{ '\f', "\\f" },
{ '\n', "\\n" },
{ '\r', "\\r" },
{ '\t', "\\t" },
{ '\v', "\\v" },
};
// We want to exclude the type name next to the value for members
private bool _excludeTypeName;
private Stack<HtmlElement> _elementStack = new Stack<HtmlElement>();
public HtmlObjectPrinter(int recursionLimit, int enumerationLimit)
: base(recursionLimit, enumerationLimit)
{
}
private HtmlElement Current
{
get
{
Debug.Assert(_elementStack.Count > 0);
return _elementStack.Peek();
}
}
public void WriteTo(object value, TextWriter writer)
{
HtmlElement rootElement = new HtmlElement("div");
rootElement.AddCssClass("objectinfo");
PushElement(rootElement);
Visit(value, 0);
PopElement();
Debug.Assert(_elementStack.Count == 0, "Stack should be empty");
// REVIEW: We should only do this once per page/request
writer.Write(Styles);
rootElement.WriteTo(writer);
}
public override void VisitKeyValues(object value, IEnumerable<object> keys, Func<object, object> valueSelector, int depth)
{
string id = GetObjectId(value);
HtmlElement ul = new HtmlElement("ul");
ul.AddCssClass("typeEnumeration");
ul["id"] = id;
PushElement(ul);
base.VisitKeyValues(value, keys, valueSelector, depth);
PopElement();
Current.AppendChild(ul);
}
public override void VisitKeyValue(object key, object value, int depth)
{
HtmlElement keyElement = new HtmlElement("span");
PushElement(keyElement);
Visit(key, depth);
PopElement();
HtmlElement valueElement = new HtmlElement("span");
PushElement(valueElement);
Visit(value, depth);
PopElement();
// Append the elements to the li
HtmlElement li = new HtmlElement("li");
li.AppendChild(keyElement);
li.AppendChild(" = ");
li.AppendChild(valueElement);
Current.AppendChild(li);
}
public override void VisitEnumerable(IEnumerable enumerable, int depth)
{
string id = GetObjectId(enumerable);
HtmlElement ul = new HtmlElement("ul");
ul.AddCssClass("typeEnumeration");
ul["id"] = id;
PushElement(ul);
base.VisitEnumerable(enumerable, depth);
PopElement();
Current.AppendChild(ul);
}
public override void VisitIndexedEnumeratedValue(int index, object item, int depth)
{
HtmlElement li = new HtmlElement("li");
li.AppendChild(String.Format(CultureInfo.InvariantCulture, "[{0}] = ", index));
PushElement(li);
base.VisitIndexedEnumeratedValue(index, item, depth);
PopElement();
Current.AppendChild(li);
}
public override void VisitEnumeratedValue(object item, int depth)
{
HtmlElement li = new HtmlElement("li");
PushElement(li);
base.VisitEnumeratedValue(item, depth);
PopElement();
Current.AppendChild(li);
}
public override void VisitEnumeratonLimitExceeded()
{
HtmlElement li = new HtmlElement("li");
li.AppendChild("...");
Current.AppendChild(li);
}
public override void VisitMembers(IEnumerable<string> names, Func<string, Type> typeSelector, Func<string, object> valueSelector, int depth)
{
HtmlElement ul = new HtmlElement("ul");
ul.AddCssClass("typeProperties");
PushElement(ul);
base.VisitMembers(names, typeSelector, valueSelector, depth);
PopElement();
Current.AppendChild(ul);
}
public override void VisitMember(string name, Type type, object value, int depth)
{
HtmlElement li = new HtmlElement("li");
if (type != null)
{
li.AppendChild(CreateTypeNameSpan(type));
li.AppendChild(" ");
}
li.AppendChild(CreateNameSpan(name));
li.AppendChild(" = ");
PushElement(li);
_excludeTypeName = true;
base.VisitMember(name, type, value, depth);
_excludeTypeName = false;
PopElement();
Current.AppendChild(li);
}
public override void VisitComplexObject(object value, int depth)
{
string id = GetObjectId(value);
HtmlElement objectElement = new HtmlElement("div");
objectElement.AddCssClass("typeContainer");
objectElement["id"] = id;
PushElement(objectElement);
base.VisitComplexObject(value, depth);
PopElement();
if (objectElement.Children.Any())
{
Current.AppendChild(objectElement);
}
}
public override void VisitNull()
{
Current.AppendChild(_nullSpan);
}
public override void VisitStringValue(string stringValue)
{
// Convert the string escape sequences
stringValue = "\"" + ConvertEscapseSequences(stringValue) + "\"";
Current.AppendChild(CreateQuotedSpan(stringValue));
}
public override void VisitVisitedObject(string id, object value)
{
Current.AppendChild(CreateVisitedLink(id));
}
public override void Visit(object value, int depth)
{
if (value != null)
{
if (!_excludeTypeName)
{
Current.AppendChild(CreateTypeNameSpan(value.GetType()));
Current.AppendChild(" ");
}
_excludeTypeName = false;
}
base.Visit(value, depth);
}
public override void VisitObjectVisitorException(ObjectVisitorException exception)
{
Current.AppendChild(CreateExceptionSpan(exception));
}
[SuppressMessage("Microsoft.Globalization", "CA1308:NormalizeStringsToUppercase", Justification = "Making the value lowercase has nothing to do with normalization. It's used to show true or false instead of the Title case version")]
public override void VisitConvertedValue(object value, string convertedValue)
{
Type type = value.GetType();
if (type.Equals(typeof(bool)))
{
// Convert True or False to lowercase
convertedValue = convertedValue.ToLowerInvariant();
Current.AppendChild(CreateTypeSpan(convertedValue));
return;
}
if (type.Equals(typeof(char)))
{
string charValue = GetCharValue((char)value);
Current.AppendChild(CreateQuotedSpan("'" + charValue + "'"));
return;
}
// See if the value is a Type itself
Type valueAsType = value as Type;
if (valueAsType != null)
{
// For types we're going to generate elements that print typeof(TypeName)
Current.AppendChild(CreateParentSpan(CreateTypeSpan("typeof"),
CreateOperatorSpan("("),
CreateTypeNameSpan(valueAsType),
CreateOperatorSpan(")")));
}
else
{
Current.AppendChild(CreateValueSpan(convertedValue));
}
}
private static HtmlElement CreateParentSpan(params HtmlElement[] elements)
{
HtmlElement span = new HtmlElement("span");
foreach (var e in elements)
{
span.AppendChild(e);
}
return span;
}
private static HtmlElement CreateNameSpan(string name)
{
return HtmlElement.CreateSpan(name, "name");
}
private static HtmlElement CreateOperatorSpan(string @operator)
{
return HtmlElement.CreateSpan(@operator, "operator");
}
private static HtmlElement CreateValueSpan(string value)
{
return HtmlElement.CreateSpan(value, "value");
}
private static HtmlElement CreateExceptionSpan(ObjectVisitorException exception)
{
HtmlElement span = new HtmlElement("span");
span.AppendChild(HelpersResources.ObjectInfo_PropertyThrewException);
span.AppendChild(HtmlElement.CreateSpan(exception.InnerException.Message, "exception"));
return span;
}
private static HtmlElement CreateQuotedSpan(string value)
{
return HtmlElement.CreateSpan(value, "quote");
}
private static HtmlElement CreateLink(string href, string linkText, string cssClass = null)
{
HtmlElement a = new HtmlElement("a");
a.SetInnerText(linkText);
a["href"] = href;
if (!String.IsNullOrEmpty(cssClass))
{
a.AddCssClass(cssClass);
}
return a;
}
private static HtmlElement CreateVisitedLink(string id)
{
string text = String.Format(CultureInfo.InvariantCulture, "[{0}]", HelpersResources.ObjectInfo_PreviousDisplayed);
return CreateLink("#" + id, text);
}
private static HtmlElement CreateTypeSpan(string value)
{
return HtmlElement.CreateSpan(value, "type");
}
private static HtmlElement CreateTypeNameSpan(Type type)
{
string typeName = GetTypeName(type);
HtmlElement span = new HtmlElement("span");
StringBuilder sb = new StringBuilder();
// Convert the type name into html elements with different css classes
foreach (var ch in typeName)
{
if (IsOperator(ch))
{
if (sb.Length > 0)
{
span.AppendChild(CreateTypeSpan(sb.ToString()));
sb.Clear();
}
span.AppendChild(CreateOperatorSpan(ch.ToString()));
}
else
{
sb.Append(ch);
}
}
if (sb.Length > 0)
{
span.AppendChild(CreateTypeSpan(sb.ToString()));
}
return span;
}
private static bool IsOperator(char ch)
{
// These are the operators we expect to see within type names
return ch == '[' || ch == ']' || ch == '<' || ch == '>' || ch == '&' || ch == '*';
}
internal void PushElement(HtmlElement element)
{
_elementStack.Push(element);
}
internal HtmlElement PopElement()
{
Debug.Assert(_elementStack.Count > 0);
return _elementStack.Pop();
}
internal static string ConvertEscapseSequences(string value)
{
StringBuilder sb = new StringBuilder();
foreach (var ch in value)
{
sb.Append(GetCharValue(ch));
}
return sb.ToString();
}
private static string GetCharValue(char ch)
{
string value;
if (_printableEscapeChars.TryGetValue(ch, out value))
{
return value;
}
// REVIEW: Perf?
return ch.ToString();
}
}
}

View File

@ -0,0 +1,72 @@
// Copyright (c) Microsoft Corporation. All rights reserved. See License.txt in the project root for license information.
using System.Collections.Generic;
using System.IO;
using System.Web.Script.Serialization;
namespace System.Web.Helpers
{
public static class Json
{
private static readonly JavaScriptSerializer _serializer = CreateSerializer();
public static string Encode(object value)
{
// Serialize our dynamic array type as an array
DynamicJsonArray jsonArray = value as DynamicJsonArray;
if (jsonArray != null)
{
return _serializer.Serialize((object[])jsonArray);
}
return _serializer.Serialize(value);
}
public static void Write(object value, TextWriter writer)
{
writer.Write(_serializer.Serialize(value));
}
public static dynamic Decode(string value)
{
return WrapObject(_serializer.DeserializeObject(value));
}
public static dynamic Decode(string value, Type targetType)
{
return WrapObject(_serializer.Deserialize(value, targetType));
}
public static T Decode<T>(string value)
{
return _serializer.Deserialize<T>(value);
}
private static JavaScriptSerializer CreateSerializer()
{
JavaScriptSerializer serializer = new JavaScriptSerializer();
serializer.RegisterConverters(new[] { new DynamicJavaScriptConverter() });
return serializer;
}
internal static dynamic WrapObject(object value)
{
// The JavaScriptSerializer returns IDictionary<string, object> for objects
// and object[] for arrays, so we wrap those in different dynamic objects
// so we can access the object graph using dynamic
var dictionaryValues = value as IDictionary<string, object>;
if (dictionaryValues != null)
{
return new DynamicJsonObject(dictionaryValues);
}
var arrayValues = value as object[];
if (arrayValues != null)
{
return new DynamicJsonArray(arrayValues);
}
return value;
}
}
}

View File

@ -0,0 +1,33 @@
// Copyright (c) Microsoft Corporation. All rights reserved. See License.txt in the project root for license information.
using System.Globalization;
using System.Web.WebPages;
using Microsoft.Internal.Web.Utils;
namespace System.Web.Helpers
{
public static class ObjectInfo
{
private const int DefaultRecursionLimit = 10;
private const int DefaultEnumerationLimit = 1000;
public static HelperResult Print(object value, int depth = DefaultRecursionLimit, int enumerationLength = DefaultEnumerationLimit)
{
if (depth < 0)
{
throw new ArgumentOutOfRangeException(
"depth",
String.Format(CultureInfo.InvariantCulture, CommonResources.Argument_Must_Be_GreaterThanOrEqualTo, 0));
}
if (enumerationLength <= 0)
{
throw new ArgumentOutOfRangeException(
"enumerationLength",
String.Format(CultureInfo.InvariantCulture, CommonResources.Argument_Must_Be_GreaterThan, 0));
}
HtmlObjectPrinter printer = new HtmlObjectPrinter(depth, enumerationLength);
return new HelperResult(writer => printer.WriteTo(value, writer));
}
}
}

View File

@ -0,0 +1,467 @@
// Copyright (c) Microsoft Corporation. All rights reserved. See License.txt in the project root for license information.
using System.Collections;
using System.Collections.Generic;
using System.Collections.Specialized;
using System.ComponentModel;
using System.Diagnostics;
using System.Diagnostics.CodeAnalysis;
using System.Dynamic;
using System.Globalization;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Serialization;
using Microsoft.Internal.Web.Utils;
namespace System.Web.Helpers
{
internal class ObjectVisitor
{
private static readonly Dictionary<Type, string> _typeNames = new Dictionary<Type, string>
{
{ typeof(string), "string" },
{ typeof(object), "object" },
{ typeof(int), "int" },
{ typeof(byte), "byte" },
{ typeof(short), "short" },
{ typeof(long), "long" },
{ typeof(decimal), "decimal" },
{ typeof(float), "float" },
{ typeof(double), "double" },
{ typeof(bool), "bool" },
{ typeof(char), "char" },
{ typeof(void), "void" }
};
private static readonly char[] _separators = { '&', '[', '*' };
private readonly int _recursionLimit;
private readonly int _enumerationLimit;
private Dictionary<object, string> _visited = new Dictionary<object, string>();
public ObjectVisitor(int recursionLimit, int enumerationLimit)
{
Debug.Assert(enumerationLimit > 0);
Debug.Assert(recursionLimit >= 0);
_enumerationLimit = enumerationLimit;
_recursionLimit = recursionLimit;
}
protected string GetObjectId(object value)
{
string id;
if (_visited.TryGetValue(value, out id))
{
return id;
}
return null;
}
public virtual void Visit(object value, int depth)
{
if (value == null || DBNull.Value.Equals(value))
{
VisitNull();
return;
}
// Check to see if the we've already visited this object
string id;
if (_visited.TryGetValue(value, out id))
{
VisitVisitedObject(id, value);
return;
}
string stringValue = value as string;
if (stringValue != null)
{
VisitStringValue(stringValue);
return;
}
if (TryConvertToString(value, out stringValue))
{
VisitConvertedValue(value, stringValue);
return;
}
// This exceptin occurs when we try to access the property and it fails
// for some reason. The actual exception is wrapped in the ObjectVisitorException
ObjectVisitorException exception = value as ObjectVisitorException;
if (exception != null)
{
VisitObjectVisitorException(exception);
return;
}
// Mark the object as visited
id = CreateObjectId(value);
_visited.Add(value, id);
NameValueCollection nameValueCollection = value as NameValueCollection;
if (nameValueCollection != null)
{
VisitNameValueCollection(nameValueCollection, depth);
return;
}
IDictionary dictionary = value as IDictionary;
if (dictionary != null)
{
VisitDictionary(dictionary, depth);
return;
}
IEnumerable enumerable = value as IEnumerable;
if (enumerable != null)
{
VisitEnumerable(enumerable, depth);
return;
}
VisitComplexObject(value, depth + 1);
}
public virtual void VisitObjectVisitorException(ObjectVisitorException exception)
{
}
public virtual void VisitConvertedValue(object value, string convertedValue)
{
VisitStringValue(convertedValue);
}
public virtual void VisitVisitedObject(string id, object value)
{
}
public virtual void VisitNull()
{
}
public virtual void VisitStringValue(string stringValue)
{
}
public virtual void VisitComplexObject(object value, int depth)
{
if (depth > _recursionLimit)
{
return;
}
Debug.Assert(value != null, "Value should not be null");
var dynamicObject = value as IDynamicMetaObjectProvider;
// Only look at dynamic objects that do not implement ICustomTypeDescriptor
if (dynamicObject != null && !(dynamicObject is ICustomTypeDescriptor))
{
var memberNames = DynamicHelper.GetMemberNames(dynamicObject);
if (memberNames != null)
{
// Always use the runtime type for dynamic objects since there is no metadata
VisitMembers(memberNames,
name => null,
name => DynamicHelper.GetMemberValue(dynamicObject, name),
depth);
}
}
else
{
// REVIEW: We should try to filter out properties of certain types
// Dump properties using type descriptor
var props = TypeDescriptor.GetProperties(value);
var propNames = from PropertyDescriptor p in props
select p.Name;
VisitMembers(propNames,
name => props.Find(name, ignoreCase: true).PropertyType,
name => GetPropertyDescriptorValue(value, name, props),
depth);
// Dump fields
var fields = value.GetType().GetFields(BindingFlags.Public | BindingFlags.Instance)
.ToDictionary(field => field.Name);
VisitMembers(fields.Keys,
name => fields[name].FieldType,
name => GetFieldValue(value, name, fields),
depth);
}
}
public virtual void VisitNameValueCollection(NameValueCollection collection, int depth)
{
VisitKeyValues(collection, collection.AllKeys.Cast<object>(), key => collection[(string)key], depth);
}
public virtual void VisitDictionary(IDictionary dictionary, int depth)
{
VisitKeyValues(dictionary, dictionary.Keys.Cast<object>(), key => dictionary[key], depth);
}
public virtual void VisitEnumerable(IEnumerable enumerable, int depth)
{
if (depth > _recursionLimit)
{
return;
}
Type enumerableType = enumerable.GetType();
bool isIndexedEnumeration = ImplementsInterface(enumerableType, typeof(IList<>))
|| ImplementsInterface(enumerableType, typeof(IList));
int index = 0;
foreach (var item in enumerable)
{
if (index >= _enumerationLimit)
{
VisitEnumeratonLimitExceeded();
break;
}
if (isIndexedEnumeration)
{
VisitIndexedEnumeratedValue(index, item, depth);
}
else
{
VisitEnumeratedValue(item, depth);
}
index++;
}
}
public virtual void VisitEnumeratedValue(object item, int depth)
{
Visit(item, depth);
}
public virtual void VisitIndexedEnumeratedValue(int index, object item, int depth)
{
Visit(item, depth);
}
public virtual void VisitEnumeratonLimitExceeded()
{
}
[SuppressMessage("Microsoft.Design", "CA1031:DoNotCatchGeneralExceptionTypes", Justification = "We don't want to fail surface any exceptions throw from getting property accessors")]
public virtual void VisitMembers(IEnumerable<string> names, Func<string, Type> typeSelector, Func<string, object> valueSelector, int depth)
{
foreach (string name in names)
{
Type type = null;
object value = null;
try
{
// Get the type and value
type = typeSelector(name);
value = valueSelector(name);
// If the type is null try using the runtime type
if (value != null && type == null)
{
type = value.GetType();
}
}
catch (Exception ex)
{
// Set the value as an exception we know about
value = new ObjectVisitorException(null, ex);
}
finally
{
VisitMember(name, type, value, depth);
}
}
}
public virtual void VisitMember(string name, Type type, object value, int depth)
{
Visit(value, depth);
}
public virtual void VisitKeyValues(object value, IEnumerable<object> keys, Func<object, object> valueSelector, int depth)
{
if (depth > _recursionLimit)
{
return;
}
foreach (var key in keys)
{
VisitKeyValue(key, valueSelector(key), depth);
}
}
public virtual void VisitKeyValue(object key, object value, int depth)
{
// Dump the key and value
Visit(key, depth);
Visit(value, depth);
}
protected virtual string CreateObjectId(object value)
{
// REVIEW: Maybe use a guid?
return value.GetHashCode().ToString(CultureInfo.InvariantCulture);
}
internal static string GetTypeName(Type type)
{
// See if we have the type name stored
string typeName;
if (_typeNames.TryGetValue(type, out typeName))
{
return typeName;
}
if (type.IsGenericType)
{
// Get the generic type name without arguments
string genericTypeName = GetGenericTypeName(type);
// Create a user friendly type name
var arguments = from argType in type.GetGenericArguments()
select GetTypeName(argType);
return String.Format(CultureInfo.InvariantCulture, "{0}<{1}>", genericTypeName, String.Join(", ", arguments));
}
if (type.IsByRef || type.IsArray || type.IsPointer)
{
// Get the element type name
string elementTypeName = GetTypeName(type.GetElementType());
// Append the separator
int sepIndex = type.Name.IndexOfAny(_separators);
return elementTypeName + type.Name.Substring(sepIndex);
}
// Fallback to using the type name as is
return type.Name;
}
private static string GetGenericTypeName(Type type)
{
Debug.Assert(type.IsGenericType, "Type is not a generic type");
// Check for anonymous types
if (IsAnonymousType(type))
{
return "AnonymousType";
}
string genericTypeDefinitionName = type.GetGenericTypeDefinition().Name;
int index = genericTypeDefinitionName.IndexOf('`');
Debug.Assert(index >= 0);
// Get the generic type name without the `
return genericTypeDefinitionName.Substring(0, index);
}
// Copied from System.Web.WebPages/Util/TypeHelpers.cs
private static bool IsAnonymousType(Type type)
{
Debug.Assert(type != null, "Type should not be null");
// TODO: The only way to detect anonymous types right now.
return Attribute.IsDefined(type, typeof(CompilerGeneratedAttribute), false)
&& type.IsGenericType && type.Name.Contains("AnonymousType")
&& (type.Name.StartsWith("<>", StringComparison.OrdinalIgnoreCase) || type.Name.StartsWith("VB$", StringComparison.OrdinalIgnoreCase))
&& (type.Attributes & TypeAttributes.NotPublic) == TypeAttributes.NotPublic;
}
private static bool ImplementsInterface(Type type, Type targetInterfaceType)
{
Func<Type, bool> implementsInterface = t => targetInterfaceType.IsAssignableFrom(t);
if (targetInterfaceType.IsGenericType)
{
implementsInterface = t => t.IsGenericType && targetInterfaceType.IsAssignableFrom(t.GetGenericTypeDefinition());
}
return implementsInterface(type) || type.GetInterfaces().Any(implementsInterface);
}
private static object GetFieldValue(object value, string name, IDictionary<string, FieldInfo> fields)
{
FieldInfo fieldInfo;
// Get the value from the dictionary
bool result = fields.TryGetValue(name, out fieldInfo);
Debug.Assert(result, "Entry should exist");
return fieldInfo.GetValue(value);
}
private static object GetPropertyDescriptorValue(object value, string name, PropertyDescriptorCollection props)
{
PropertyDescriptor propertyDescriptor = props.Find(name, ignoreCase: true);
Debug.Assert(propertyDescriptor != null, "Property descriptor shouldn't be null");
return propertyDescriptor.GetValue(value);
}
[SuppressMessage("Microsoft.Design", "CA1031:DoNotCatchGeneralExceptionTypes", Justification = "We don't want to surface any exceptions while trying to convert from string")]
private static bool TryConvertToString(object value, out string stringValue)
{
stringValue = null;
try
{
IConvertible convertibe = value as IConvertible;
if (convertibe != null)
{
stringValue = convertibe.ToString(CultureInfo.CurrentCulture);
return true;
}
TypeConverter converter = TypeDescriptor.GetConverter(value);
if (converter.CanConvertFrom(typeof(string)))
{
stringValue = converter.ConvertToString(value);
return true;
}
Type type = value.GetType();
if (type == typeof(object))
{
stringValue = value.ToString();
return true;
}
Type valueAsType = value as Type;
if (valueAsType != null)
{
stringValue = "typeof(" + GetTypeName(valueAsType) + ")";
return true;
}
}
catch (Exception)
{
// If we failed to convert the type for any reason return false
}
return false;
}
[Serializable]
public class ObjectVisitorException : Exception
{
public ObjectVisitorException()
{
}
public ObjectVisitorException(string message)
: base(message)
{
}
public ObjectVisitorException(string message, Exception inner)
: base(message, inner)
{
}
protected ObjectVisitorException(
SerializationInfo info,
StreamingContext context)
: base(info, context)
{
}
}
}
}

View File

@ -0,0 +1,12 @@
// Copyright (c) Microsoft Corporation. All rights reserved. See License.txt in the project root for license information.
using System.Reflection;
using System.Runtime.CompilerServices;
// General Information about an assembly is controlled through the following
// set of attributes. Change these attribute values to modify the information
// associated with an assembly.
[assembly: AssemblyTitle("System.Web.Helpers")]
[assembly: AssemblyDescription("")]
[assembly: InternalsVisibleTo("System.Web.Helpers.Test, PublicKey=0024000004800000940000000602000000240000525341310004000001000100b5fc90e7027f67871e773a8fde8938c81dd402ba65b9201d60593e96c492651e889cc13f1415ebb53fac1131ae0bd333c5ee6021672d9718ea31a8aebd0da0072f25d87dba6fc90ffd598ed4da35e44c398c454307e8e33b8426143daec9f596836f97c8f74750e5975c64e2189f45def46b2a2b1247adc3652bf5c308055da9")]

View File

@ -0,0 +1,141 @@
//------------------------------------------------------------------------------
// <auto-generated>
// This code was generated by a tool.
// Runtime Version:4.0.30319.1
//
// Changes to this file may cause incorrect behavior and will be lost if
// the code is regenerated.
// </auto-generated>
//------------------------------------------------------------------------------
namespace Microsoft.WebPages.Helpers.Resources {
using System;
/// <summary>
/// A strongly-typed resource class, for looking up localized strings, etc.
/// </summary>
// This class was auto-generated by the StronglyTypedResourceBuilder
// class via a tool like ResGen or Visual Studio.
// To add or remove a member, edit your .ResX file then rerun ResGen
// with the /str option, or rebuild your VS project.
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "4.0.0.0")]
[global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
[global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
internal class ChartTemplates {
private static global::System.Resources.ResourceManager resourceMan;
private static global::System.Globalization.CultureInfo resourceCulture;
[global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")]
internal ChartTemplates() {
}
/// <summary>
/// Returns the cached ResourceManager instance used by this class.
/// </summary>
[global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
internal static global::System.Resources.ResourceManager ResourceManager {
get {
if (object.ReferenceEquals(resourceMan, null)) {
global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("Microsoft.WebPages.Helpers.Resources.ChartTemplates", typeof(ChartTemplates).Assembly);
resourceMan = temp;
}
return resourceMan;
}
}
/// <summary>
/// Overrides the current thread's CurrentUICulture property for all
/// resource lookups using this strongly typed resource class.
/// </summary>
[global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
internal static global::System.Globalization.CultureInfo Culture {
get {
return resourceCulture;
}
set {
resourceCulture = value;
}
}
/// <summary>
/// Looks up a localized string similar to - &lt;Chart BackColor=&quot;#D3DFF0&quot; BackGradientStyle=&quot;TopBottom&quot; BackSecondaryColor=&quot;White&quot; BorderColor=&quot;26, 59, 105&quot; BorderlineDashStyle=&quot;Solid&quot; BorderWidth=&quot;2&quot; Palette=&quot;BrightPastel&quot;&gt;
///- &lt;ChartAreas&gt;
/// &lt;ChartArea Name=&quot;Default&quot; _Template_=&quot;All&quot; BackColor=&quot;64, 165, 191, 228&quot; BackGradientStyle=&quot;TopBottom&quot; BackSecondaryColor=&quot;White&quot; BorderColor=&quot;64, 64, 64, 64&quot; BorderDashStyle=&quot;Solid&quot; ShadowColor=&quot;Transparent&quot; /&gt;
/// &lt;/ChartAreas&gt;
/// &lt;Legends&gt;
/// &lt;Legend _Template_=&quot;All&quot; BackColor=&quot;Transparent&quot; Font=&quot;Trebuchet MS, [rest of string was truncated]&quot;;.
/// </summary>
internal static string Blue {
get {
return ResourceManager.GetString("Blue", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to &lt;Chart BackColor=&quot;#C9DC87&quot; BackGradientStyle=&quot;TopBottom&quot; BorderColor=&quot;181, 64, 1&quot; BorderWidth=&quot;2&quot; BorderlineDashStyle=&quot;Solid&quot; Palette=&quot;BrightPastel&quot;&gt;
/// &lt;ChartAreas&gt;
/// &lt;ChartArea Name=&quot;Default&quot; _Template_=&quot;All&quot; BackColor=&quot;Transparent&quot; BackSecondaryColor=&quot;White&quot; BorderColor=&quot;64, 64, 64, 64&quot; BorderDashStyle=&quot;Solid&quot; ShadowColor=&quot;Transparent&quot;&gt;
/// &lt;AxisY LineColor=&quot;64, 64, 64, 64&quot;&gt;
/// &lt;MajorGrid Interval=&quot;Auto&quot; LineColor=&quot;64, 64, 64, 64&quot; /&gt;
/// &lt;LabelStyle Font=&quot;Trebuchet MS, 8.25pt, style=Bold [rest of string was truncated]&quot;;.
/// </summary>
internal static string Green {
get {
return ResourceManager.GetString("Green", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to &lt;Chart Palette=&quot;SemiTransparent&quot; BorderColor=&quot;#000&quot; BorderWidth=&quot;2&quot; BorderlineDashStyle=&quot;Solid&quot;&gt;
///&lt;ChartAreas&gt;
/// &lt;ChartArea _Template_=&quot;All&quot; Name=&quot;Default&quot;&gt;
/// &lt;AxisX&gt;
/// &lt;MinorGrid Enabled=&quot;False&quot; /&gt;
/// &lt;MajorGrid Enabled=&quot;False&quot; /&gt;
/// &lt;/AxisX&gt;
/// &lt;AxisY&gt;
/// &lt;MajorGrid Enabled=&quot;False&quot; /&gt;
/// &lt;MinorGrid Enabled=&quot;False&quot; /&gt;
/// &lt;/AxisY&gt;
/// &lt;/ChartArea&gt;
///&lt;/ChartAreas&gt;
///&lt;/Chart&gt;.
/// </summary>
internal static string Vanilla {
get {
return ResourceManager.GetString("Vanilla", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to &lt;Chart BackColor=&quot;#555&quot; BackGradientStyle=&quot;TopBottom&quot; BorderColor=&quot;181, 64, 1&quot; BorderWidth=&quot;2&quot; BorderlineDashStyle=&quot;Solid&quot; Palette=&quot;Excel&quot; AntiAliasing=&quot;All&quot;&gt;
/// &lt;ChartAreas&gt;
/// &lt;ChartArea Name=&quot;Default&quot; _Template_=&quot;All&quot; BackColor=&quot;Transparent&quot; BackSecondaryColor=&quot;White&quot; BorderColor=&quot;64, 64, 64, 64&quot; BorderDashStyle=&quot;Solid&quot; ShadowColor=&quot;Transparent&quot;&gt;
/// &lt;Area3DStyle LightStyle=&quot;Simplistic&quot; Enable3D=&quot;True&quot; Inclination=&quot;5&quot; IsClustered=&quot;False&quot; IsRightAngleAxes=&quot;False&quot; Perspective=&quot;10&quot; Rotation [rest of string was truncated]&quot;;.
/// </summary>
internal static string Vanilla3D {
get {
return ResourceManager.GetString("Vanilla3D", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to &lt;Chart BackColor=&quot;#FADA5E&quot; BackGradientStyle=&quot;TopBottom&quot; BorderColor=&quot;#B8860B&quot; BorderWidth=&quot;2&quot; BorderlineDashStyle=&quot;Solid&quot; Palette=&quot;EarthTones&quot;&gt;
/// &lt;ChartAreas&gt;
/// &lt;ChartArea Name=&quot;Default&quot; _Template_=&quot;All&quot; BackColor=&quot;Transparent&quot; BackSecondaryColor=&quot;White&quot; BorderColor=&quot;64, 64, 64, 64&quot; BorderDashStyle=&quot;Solid&quot; ShadowColor=&quot;Transparent&quot;&gt;
/// &lt;AxisY&gt;
/// &lt;LabelStyle Font=&quot;Trebuchet MS, 8.25pt, style=Bold&quot; /&gt;
/// &lt;/AxisY&gt;
/// &lt;AxisX LineColor=&quot;64, 64, 64, 64&quot;&gt;
/// &lt;LabelStyle Font=&quot;Trebuch [rest of string was truncated]&quot;;.
/// </summary>
internal static string Yellow {
get {
return ResourceManager.GetString("Yellow", resourceCulture);
}
}
}
}

View File

@ -0,0 +1,197 @@
<?xml version="1.0" encoding="utf-8"?>
<root>
<!--
Microsoft ResX Schema
Version 2.0
The primary goals of this format is to allow a simple XML format
that is mostly human readable. The generation and parsing of the
various data types are done through the TypeConverter classes
associated with the data types.
Example:
... ado.net/XML headers & schema ...
<resheader name="resmimetype">text/microsoft-resx</resheader>
<resheader name="version">2.0</resheader>
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
<value>[base64 mime encoded serialized .NET Framework object]</value>
</data>
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
<comment>This is a comment</comment>
</data>
There are any number of "resheader" rows that contain simple
name/value pairs.
Each data row contains a name, and value. The row also contains a
type or mimetype. Type corresponds to a .NET class that support
text/value conversion through the TypeConverter architecture.
Classes that don't support this are serialized and stored with the
mimetype set.
The mimetype is used for serialized objects, and tells the
ResXResourceReader how to depersist the object. This is currently not
extensible. For a given mimetype the value must be set accordingly:
Note - application/x-microsoft.net.object.binary.base64 is the format
that the ResXResourceWriter will generate, however the reader can
read any of the formats listed below.
mimetype: application/x-microsoft.net.object.binary.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.soap.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.bytearray.base64
value : The object must be serialized into a byte array
: using a System.ComponentModel.TypeConverter
: and then encoded with base64 encoding.
-->
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
<xsd:element name="root" msdata:IsDataSet="true">
<xsd:complexType>
<xsd:choice maxOccurs="unbounded">
<xsd:element name="metadata">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" />
</xsd:sequence>
<xsd:attribute name="name" use="required" type="xsd:string" />
<xsd:attribute name="type" type="xsd:string" />
<xsd:attribute name="mimetype" type="xsd:string" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="assembly">
<xsd:complexType>
<xsd:attribute name="alias" type="xsd:string" />
<xsd:attribute name="name" type="xsd:string" />
</xsd:complexType>
</xsd:element>
<xsd:element name="data">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="resheader">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" />
</xsd:complexType>
</xsd:element>
</xsd:choice>
</xsd:complexType>
</xsd:element>
</xsd:schema>
<resheader name="resmimetype">
<value>text/microsoft-resx</value>
</resheader>
<resheader name="version">
<value>2.0</value>
</resheader>
<resheader name="reader">
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<data name="Blue" xml:space="preserve">
<value>&lt;Chart BackColor="#D3DFF0" BackGradientStyle="TopBottom" BackSecondaryColor="White" BorderColor="26, 59, 105" BorderlineDashStyle="Solid" BorderWidth="2" Palette="BrightPastel"&gt;
&lt;ChartAreas&gt;
&lt;ChartArea Name="Default" _Template_="All" BackColor="64, 165, 191, 228" BackGradientStyle="TopBottom" BackSecondaryColor="White" BorderColor="64, 64, 64, 64" BorderDashStyle="Solid" ShadowColor="Transparent" /&gt;
&lt;/ChartAreas&gt;
&lt;Legends&gt;
&lt;Legend _Template_="All" BackColor="Transparent" Font="Trebuchet MS, 8.25pt, style=Bold" IsTextAutoFit="False" /&gt;
&lt;/Legends&gt;
&lt;BorderSkin SkinStyle="Emboss" /&gt;
&lt;/Chart&gt;</value>
</data>
<data name="Green" xml:space="preserve">
<value>&lt;Chart BackColor="#C9DC87" BackGradientStyle="TopBottom" BorderColor="181, 64, 1" BorderWidth="2" BorderlineDashStyle="Solid" Palette="BrightPastel"&gt;
&lt;ChartAreas&gt;
&lt;ChartArea Name="Default" _Template_="All" BackColor="Transparent" BackSecondaryColor="White" BorderColor="64, 64, 64, 64" BorderDashStyle="Solid" ShadowColor="Transparent"&gt;
&lt;AxisY LineColor="64, 64, 64, 64"&gt;
&lt;MajorGrid Interval="Auto" LineColor="64, 64, 64, 64" /&gt;
&lt;LabelStyle Font="Trebuchet MS, 8.25pt, style=Bold" /&gt;
&lt;/AxisY&gt;
&lt;AxisX LineColor="64, 64, 64, 64"&gt;
&lt;MajorGrid LineColor="64, 64, 64, 64" /&gt;
&lt;LabelStyle Font="Trebuchet MS, 8.25pt, style=Bold" /&gt;
&lt;/AxisX&gt;
&lt;Area3DStyle Inclination="15" IsClustered="False" IsRightAngleAxes="False" Perspective="10" Rotation="10" WallWidth="0" /&gt;
&lt;/ChartArea&gt;
&lt;/ChartAreas&gt;
&lt;Legends&gt;
&lt;Legend _Template_="All" Alignment="Center" BackColor="Transparent" Docking="Bottom" Font="Trebuchet MS, 8.25pt, style=Bold" IsTextAutoFit ="False" LegendStyle="Row"&gt;
&lt;/Legend&gt;
&lt;/Legends&gt;
&lt;BorderSkin SkinStyle="Emboss" /&gt;
&lt;/Chart&gt;</value>
</data>
<data name="Vanilla" xml:space="preserve">
<value>&lt;Chart Palette="SemiTransparent" BorderColor="#000" BorderWidth="2" BorderlineDashStyle="Solid"&gt;
&lt;ChartAreas&gt;
&lt;ChartArea _Template_="All" Name="Default"&gt;
&lt;AxisX&gt;
&lt;MinorGrid Enabled="False" /&gt;
&lt;MajorGrid Enabled="False" /&gt;
&lt;/AxisX&gt;
&lt;AxisY&gt;
&lt;MajorGrid Enabled="False" /&gt;
&lt;MinorGrid Enabled="False" /&gt;
&lt;/AxisY&gt;
&lt;/ChartArea&gt;
&lt;/ChartAreas&gt;
&lt;/Chart&gt;</value>
</data>
<data name="Vanilla3D" xml:space="preserve">
<value>&lt;Chart BackColor="#555" BackGradientStyle="TopBottom" BorderColor="181, 64, 1" BorderWidth="2" BorderlineDashStyle="Solid" Palette="SemiTransparent" AntiAliasing="All"&gt;
&lt;ChartAreas&gt;
&lt;ChartArea Name="Default" _Template_="All" BackColor="Transparent" BackSecondaryColor="White" BorderColor="64, 64, 64, 64" BorderDashStyle="Solid" ShadowColor="Transparent"&gt;
&lt;Area3DStyle LightStyle="Simplistic" Enable3D="True" Inclination="30" IsClustered="False" IsRightAngleAxes="False" Perspective="10" Rotation="-30" WallWidth="0" /&gt;
&lt;/ChartArea&gt;
&lt;/ChartAreas&gt;
&lt;/Chart&gt;</value>
</data>
<data name="Yellow" xml:space="preserve">
<value>&lt;Chart BackColor="#FADA5E" BackGradientStyle="TopBottom" BorderColor="#B8860B" BorderWidth="2" BorderlineDashStyle="Solid" Palette="EarthTones"&gt;
&lt;ChartAreas&gt;
&lt;ChartArea Name="Default" _Template_="All" BackColor="Transparent" BackSecondaryColor="White" BorderColor="64, 64, 64, 64" BorderDashStyle="Solid" ShadowColor="Transparent"&gt;
&lt;AxisY&gt;
&lt;LabelStyle Font="Trebuchet MS, 8.25pt, style=Bold" /&gt;
&lt;/AxisY&gt;
&lt;AxisX LineColor="64, 64, 64, 64"&gt;
&lt;LabelStyle Font="Trebuchet MS, 8.25pt, style=Bold" /&gt;
&lt;/AxisX&gt;
&lt;/ChartArea&gt;
&lt;/ChartAreas&gt;
&lt;Legends&gt;
&lt;Legend _Template_="All" Alignment="Left" BackColor="Transparent" Docking="Bottom" Font="Trebuchet MS, 8.25pt, style=Bold" LegendStyle="Row"&gt;
&lt;/Legend&gt;
&lt;/Legends&gt;
&lt;BorderSkin SkinStyle="Emboss" /&gt;
&lt;/Chart&gt;</value>
</data>
</root>

View File

@ -0,0 +1,414 @@
//------------------------------------------------------------------------------
// <auto-generated>
// This code was generated by a tool.
// Runtime Version:4.0.30319.225
//
// Changes to this file may cause incorrect behavior and will be lost if
// the code is regenerated.
// </auto-generated>
//------------------------------------------------------------------------------
namespace System.Web.Helpers.Resources {
using System;
/// <summary>
/// A strongly-typed resource class, for looking up localized strings, etc.
/// </summary>
// This class was auto-generated by the StronglyTypedResourceBuilder
// class via a tool like ResGen or Visual Studio.
// To add or remove a member, edit your .ResX file then rerun ResGen
// with the /str option, or rebuild your VS project.
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "4.0.0.0")]
[global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
[global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
internal class HelpersResources {
private static global::System.Resources.ResourceManager resourceMan;
private static global::System.Globalization.CultureInfo resourceCulture;
[global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")]
internal HelpersResources() {
}
/// <summary>
/// Returns the cached ResourceManager instance used by this class.
/// </summary>
[global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
internal static global::System.Resources.ResourceManager ResourceManager {
get {
if (object.ReferenceEquals(resourceMan, null)) {
global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("System.Web.Helpers.Resources.HelpersResources", typeof(HelpersResources).Assembly);
resourceMan = temp;
}
return resourceMan;
}
}
/// <summary>
/// Overrides the current thread's CurrentUICulture property for all
/// resource lookups using this strongly typed resource class.
/// </summary>
[global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
internal static global::System.Globalization.CultureInfo Culture {
get {
return resourceCulture;
}
set {
resourceCulture = value;
}
}
/// <summary>
/// Looks up a localized string similar to Argument conversion to type &quot;{0}&quot; failed..
/// </summary>
internal static string Chart_ArgumentConversionFailed {
get {
return ResourceManager.GetString("Chart_ArgumentConversionFailed", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to A series cannot be data-bound to a string object..
/// </summary>
internal static string Chart_ExceptionDataBindSeriesToString {
get {
return ResourceManager.GetString("Chart_ExceptionDataBindSeriesToString", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to The theme file &quot;{0}&quot; could not be found..
/// </summary>
internal static string Chart_ThemeFileNotFound {
get {
return ResourceManager.GetString("Chart_ThemeFileNotFound", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to The hash algorithm &apos;{0}&apos; is not supported, valid values are: sha256, sha1, md5.
/// </summary>
internal static string Crypto_NotSupportedHashAlg {
get {
return ResourceManager.GetString("Crypto_NotSupportedHashAlg", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to &quot;{0}&quot; is invalid image format. Valid values are image format names like: &quot;JPEG&quot;, &quot;BMP&quot;, &quot;GIF&quot;, &quot;PNG&quot;, etc..
/// </summary>
internal static string Image_IncorrectImageFormat {
get {
return ResourceManager.GetString("Image_IncorrectImageFormat", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to Unable to convert to &quot;{0}&quot;. Use Json.Decode&lt;T&gt; instead..
/// </summary>
internal static string Json_UnableToConvertType {
get {
return ResourceManager.GetString("Json_UnableToConvertType", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to Previously Displayed.
/// </summary>
internal static string ObjectInfo_PreviousDisplayed {
get {
return ResourceManager.GetString("ObjectInfo_PreviousDisplayed", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to Accessing a property threw an exception: .
/// </summary>
internal static string ObjectInfo_PropertyThrewException {
get {
return ResourceManager.GetString("ObjectInfo_PropertyThrewException", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to File path &quot;{0}&quot; is invalid..
/// </summary>
internal static string PathUtils_IncorrectPath {
get {
return ResourceManager.GetString("PathUtils_IncorrectPath", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to Additional server information is available when the page is running with high trust..
/// </summary>
internal static string ServerInfo_AdditionalInfo {
get {
return ResourceManager.GetString("ServerInfo_AdditionalInfo", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to Environment Variables.
/// </summary>
internal static string ServerInfo_EnvVars {
get {
return ResourceManager.GetString("ServerInfo_EnvVars", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to ASP.NET Server Information.
/// </summary>
internal static string ServerInfo_Header {
get {
return ResourceManager.GetString("ServerInfo_Header", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to HTTP Runtime Information.
/// </summary>
internal static string ServerInfo_HttpRuntime {
get {
return ResourceManager.GetString("ServerInfo_HttpRuntime", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to Legacy Code Access Security.
/// </summary>
internal static string ServerInfo_LegacyCAS {
get {
return ResourceManager.GetString("ServerInfo_LegacyCAS", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to Legacy Code Access Security has been detected on your system. Microsoft WebPage features require the ASP.NET 4 Code Access Security model. For information about how to resolve this, contact your server administrator..
/// </summary>
internal static string ServerInfo_LegacyCasHelpInfo {
get {
return ResourceManager.GetString("ServerInfo_LegacyCasHelpInfo", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to no value.
/// </summary>
internal static string ServerInfo_NoValue {
get {
return ResourceManager.GetString("ServerInfo_NoValue", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to Server Configuration.
/// </summary>
internal static string ServerInfo_ServerConfigTable {
get {
return ResourceManager.GetString("ServerInfo_ServerConfigTable", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to ASP.NET Server Variables.
/// </summary>
internal static string ServerInfo_ServerVars {
get {
return ResourceManager.GetString("ServerInfo_ServerVars", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to The column name cannot be null or an empty string unless a custom format is specified..
/// </summary>
internal static string WebGrid_ColumnNameOrFormatRequired {
get {
return ResourceManager.GetString("WebGrid_ColumnNameOrFormatRequired", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to Column &quot;{0}&quot; does not exist..
/// </summary>
internal static string WebGrid_ColumnNotFound {
get {
return ResourceManager.GetString("WebGrid_ColumnNotFound", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to The WebGrid instance is already bound to a data source..
/// </summary>
internal static string WebGrid_DataSourceBound {
get {
return ResourceManager.GetString("WebGrid_DataSourceBound", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to A data source must be bound before this operation can be performed..
/// </summary>
internal static string WebGrid_NoDataSourceBound {
get {
return ResourceManager.GetString("WebGrid_NoDataSourceBound", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to This operation is not supported when paging is disabled for the &quot;WebGrid&quot; object..
/// </summary>
internal static string WebGrid_NotSupportedIfPagingIsDisabled {
get {
return ResourceManager.GetString("WebGrid_NotSupportedIfPagingIsDisabled", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to This operation is not supported when sorting is disabled for the &quot;WebGrid&quot; object..
/// </summary>
internal static string WebGrid_NotSupportedIfSortingIsDisabled {
get {
return ResourceManager.GetString("WebGrid_NotSupportedIfSortingIsDisabled", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to To use this argument, pager mode &quot;{0}&quot; must be enabled..
/// </summary>
internal static string WebGrid_PagerModeMustBeEnabled {
get {
return ResourceManager.GetString("WebGrid_PagerModeMustBeEnabled", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to This property cannot be set after the &quot;WebGrid&quot; object has been sorted or paged. Make sure that this property is set prior to invoking the &quot;Rows&quot; property directly or indirectly through other methods such as &quot;GetHtml&quot;, &quot;Pager&quot;, &quot;Table&quot;, etc..
/// </summary>
internal static string WebGrid_PropertySetterNotSupportedAfterDataBound {
get {
return ResourceManager.GetString("WebGrid_PropertySetterNotSupportedAfterDataBound", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to A value for &quot;rowCount&quot; must be specified when &quot;autoSortAndPage&quot; is set to true and paging is enabled..
/// </summary>
internal static string WebGrid_RowCountNotSpecified {
get {
return ResourceManager.GetString("WebGrid_RowCountNotSpecified", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to Select.
/// </summary>
internal static string WebGrid_SelectLinkText {
get {
return ResourceManager.GetString("WebGrid_SelectLinkText", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to The &quot;fontColor&quot; value is invalid. Valid values are names like &quot;White&quot;, &quot;Black&quot;, or &quot;DarkBlue&quot;, or hexadecimal values in the form &quot;#RRGGBB&quot; or &quot;#RGB&quot;..
/// </summary>
internal static string WebImage_IncorrectColorName {
get {
return ResourceManager.GetString("WebImage_IncorrectColorName", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to The &quot;fontFamily&quot; value is invalid. Valid values are font family names like: &quot;Arial&quot;, &quot;Times New Roman&quot;, etc. Make sure that the font family you are trying to use is installed on the server..
/// </summary>
internal static string WebImage_IncorrectFontFamily {
get {
return ResourceManager.GetString("WebImage_IncorrectFontFamily", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to The &quot;fontStyle&quot; value is invalid. Valid values are: &quot;Regular&quot;, &quot;Bold&quot;, &quot;Italic&quot;, &quot;Underline&quot;, and &quot;Strikeout&quot;..
/// </summary>
internal static string WebImage_IncorrectFontStyle {
get {
return ResourceManager.GetString("WebImage_IncorrectFontStyle", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to The &quot;horizontalAlign&quot; value is invalid. Valid values are: &quot;Right&quot;, &quot;Left&quot;, and &quot;Center&quot;..
/// </summary>
internal static string WebImage_IncorrectHorizontalAlignment {
get {
return ResourceManager.GetString("WebImage_IncorrectHorizontalAlignment", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to The &quot;verticalAlign&quot; value is invalid. Valid values are: &quot;Top&quot;, &quot;Bottom&quot;, and &quot;Middle&quot;..
/// </summary>
internal static string WebImage_IncorrectVerticalAlignment {
get {
return ResourceManager.GetString("WebImage_IncorrectVerticalAlignment", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to Watermark width and height must both be positive or both be zero..
/// </summary>
internal static string WebImage_IncorrectWidthAndHeight {
get {
return ResourceManager.GetString("WebImage_IncorrectWidthAndHeight", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to An image could not be constructed from the content provided..
/// </summary>
internal static string WebImage_InvalidImageContents {
get {
return ResourceManager.GetString("WebImage_InvalidImageContents", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to The &quot;priority&quot; value is invalid. Valid values are &quot;Low&quot;, &quot;Normal&quot; and &quot;High&quot;..
/// </summary>
internal static string WebMail_InvalidPriority {
get {
return ResourceManager.GetString("WebMail_InvalidPriority", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to A string in the collection is null or empty..
/// </summary>
internal static string WebMail_ItemInCollectionIsNull {
get {
return ResourceManager.GetString("WebMail_ItemInCollectionIsNull", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to &quot;SmtpServer&quot; was not specified..
/// </summary>
internal static string WebMail_SmtpServerNotSpecified {
get {
return ResourceManager.GetString("WebMail_SmtpServerNotSpecified", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to No &quot;From&quot; email address was specified and a default value could not be assigned..
/// </summary>
internal static string WebMail_UnableToDetermineFrom {
get {
return ResourceManager.GetString("WebMail_UnableToDetermineFrom", resourceCulture);
}
}
}
}

View File

@ -0,0 +1,237 @@
<?xml version="1.0" encoding="utf-8"?>
<root>
<!--
Microsoft ResX Schema
Version 2.0
The primary goals of this format is to allow a simple XML format
that is mostly human readable. The generation and parsing of the
various data types are done through the TypeConverter classes
associated with the data types.
Example:
... ado.net/XML headers & schema ...
<resheader name="resmimetype">text/microsoft-resx</resheader>
<resheader name="version">2.0</resheader>
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
<value>[base64 mime encoded serialized .NET Framework object]</value>
</data>
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
<comment>This is a comment</comment>
</data>
There are any number of "resheader" rows that contain simple
name/value pairs.
Each data row contains a name, and value. The row also contains a
type or mimetype. Type corresponds to a .NET class that support
text/value conversion through the TypeConverter architecture.
Classes that don't support this are serialized and stored with the
mimetype set.
The mimetype is used for serialized objects, and tells the
ResXResourceReader how to depersist the object. This is currently not
extensible. For a given mimetype the value must be set accordingly:
Note - application/x-microsoft.net.object.binary.base64 is the format
that the ResXResourceWriter will generate, however the reader can
read any of the formats listed below.
mimetype: application/x-microsoft.net.object.binary.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.soap.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.bytearray.base64
value : The object must be serialized into a byte array
: using a System.ComponentModel.TypeConverter
: and then encoded with base64 encoding.
-->
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
<xsd:element name="root" msdata:IsDataSet="true">
<xsd:complexType>
<xsd:choice maxOccurs="unbounded">
<xsd:element name="metadata">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" />
</xsd:sequence>
<xsd:attribute name="name" use="required" type="xsd:string" />
<xsd:attribute name="type" type="xsd:string" />
<xsd:attribute name="mimetype" type="xsd:string" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="assembly">
<xsd:complexType>
<xsd:attribute name="alias" type="xsd:string" />
<xsd:attribute name="name" type="xsd:string" />
</xsd:complexType>
</xsd:element>
<xsd:element name="data">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="resheader">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" />
</xsd:complexType>
</xsd:element>
</xsd:choice>
</xsd:complexType>
</xsd:element>
</xsd:schema>
<resheader name="resmimetype">
<value>text/microsoft-resx</value>
</resheader>
<resheader name="version">
<value>2.0</value>
</resheader>
<resheader name="reader">
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<data name="Chart_ArgumentConversionFailed" xml:space="preserve">
<value>Argument conversion to type "{0}" failed.</value>
</data>
<data name="Chart_ExceptionDataBindSeriesToString" xml:space="preserve">
<value>A series cannot be data-bound to a string object.</value>
</data>
<data name="Chart_ThemeFileNotFound" xml:space="preserve">
<value>The theme file "{0}" could not be found.</value>
</data>
<data name="Crypto_NotSupportedHashAlg" xml:space="preserve">
<value>The hash algorithm '{0}' is not supported, valid values are: sha256, sha1, md5</value>
</data>
<data name="Image_IncorrectImageFormat" xml:space="preserve">
<value>"{0}" is invalid image format. Valid values are image format names like: "JPEG", "BMP", "GIF", "PNG", etc.</value>
</data>
<data name="Json_UnableToConvertType" xml:space="preserve">
<value>Unable to convert to "{0}". Use Json.Decode&lt;T&gt; instead.</value>
</data>
<data name="ObjectInfo_PreviousDisplayed" xml:space="preserve">
<value>Previously Displayed</value>
</data>
<data name="ObjectInfo_PropertyThrewException" xml:space="preserve">
<value>Accessing a property threw an exception: </value>
</data>
<data name="PathUtils_IncorrectPath" xml:space="preserve">
<value>File path "{0}" is invalid.</value>
</data>
<data name="ServerInfo_AdditionalInfo" xml:space="preserve">
<value>Additional server information is available when the page is running with high trust.</value>
</data>
<data name="ServerInfo_EnvVars" xml:space="preserve">
<value>Environment Variables</value>
</data>
<data name="ServerInfo_Header" xml:space="preserve">
<value>ASP.NET Server Information</value>
</data>
<data name="ServerInfo_HttpRuntime" xml:space="preserve">
<value>HTTP Runtime Information</value>
</data>
<data name="ServerInfo_LegacyCAS" xml:space="preserve">
<value>Legacy Code Access Security</value>
</data>
<data name="ServerInfo_LegacyCasHelpInfo" xml:space="preserve">
<value>Legacy Code Access Security has been detected on your system. Microsoft WebPage features require the ASP.NET 4 Code Access Security model. For information about how to resolve this, contact your server administrator.</value>
</data>
<data name="ServerInfo_NoValue" xml:space="preserve">
<value>no value</value>
</data>
<data name="ServerInfo_ServerConfigTable" xml:space="preserve">
<value>Server Configuration</value>
</data>
<data name="ServerInfo_ServerVars" xml:space="preserve">
<value>ASP.NET Server Variables</value>
</data>
<data name="WebGrid_ColumnNameOrFormatRequired" xml:space="preserve">
<value>The column name cannot be null or an empty string unless a custom format is specified.</value>
</data>
<data name="WebGrid_ColumnNotFound" xml:space="preserve">
<value>Column "{0}" does not exist.</value>
</data>
<data name="WebGrid_DataSourceBound" xml:space="preserve">
<value>The WebGrid instance is already bound to a data source.</value>
</data>
<data name="WebGrid_NoDataSourceBound" xml:space="preserve">
<value>A data source must be bound before this operation can be performed.</value>
</data>
<data name="WebGrid_NotSupportedIfPagingIsDisabled" xml:space="preserve">
<value>This operation is not supported when paging is disabled for the "WebGrid" object.</value>
</data>
<data name="WebGrid_NotSupportedIfSortingIsDisabled" xml:space="preserve">
<value>This operation is not supported when sorting is disabled for the "WebGrid" object.</value>
</data>
<data name="WebGrid_PagerModeMustBeEnabled" xml:space="preserve">
<value>To use this argument, pager mode "{0}" must be enabled.</value>
</data>
<data name="WebGrid_PropertySetterNotSupportedAfterDataBound" xml:space="preserve">
<value>This property cannot be set after the "WebGrid" object has been sorted or paged. Make sure that this property is set prior to invoking the "Rows" property directly or indirectly through other methods such as "GetHtml", "Pager", "Table", etc.</value>
</data>
<data name="WebGrid_RowCountNotSpecified" xml:space="preserve">
<value>A value for "rowCount" must be specified when "autoSortAndPage" is set to true and paging is enabled.</value>
</data>
<data name="WebGrid_SelectLinkText" xml:space="preserve">
<value>Select</value>
</data>
<data name="WebImage_IncorrectColorName" xml:space="preserve">
<value>The "fontColor" value is invalid. Valid values are names like "White", "Black", or "DarkBlue", or hexadecimal values in the form "#RRGGBB" or "#RGB".</value>
</data>
<data name="WebImage_IncorrectFontFamily" xml:space="preserve">
<value>The "fontFamily" value is invalid. Valid values are font family names like: "Arial", "Times New Roman", etc. Make sure that the font family you are trying to use is installed on the server.</value>
</data>
<data name="WebImage_IncorrectFontStyle" xml:space="preserve">
<value>The "fontStyle" value is invalid. Valid values are: "Regular", "Bold", "Italic", "Underline", and "Strikeout".</value>
</data>
<data name="WebImage_IncorrectHorizontalAlignment" xml:space="preserve">
<value>The "horizontalAlign" value is invalid. Valid values are: "Right", "Left", and "Center".</value>
</data>
<data name="WebImage_IncorrectVerticalAlignment" xml:space="preserve">
<value>The "verticalAlign" value is invalid. Valid values are: "Top", "Bottom", and "Middle".</value>
</data>
<data name="WebImage_IncorrectWidthAndHeight" xml:space="preserve">
<value>Watermark width and height must both be positive or both be zero.</value>
</data>
<data name="WebImage_InvalidImageContents" xml:space="preserve">
<value>An image could not be constructed from the content provided.</value>
</data>
<data name="WebMail_InvalidPriority" xml:space="preserve">
<value>The "priority" value is invalid. Valid values are "Low", "Normal" and "High".</value>
</data>
<data name="WebMail_ItemInCollectionIsNull" xml:space="preserve">
<value>A string in the collection is null or empty.</value>
</data>
<data name="WebMail_SmtpServerNotSpecified" xml:space="preserve">
<value>"SmtpServer" was not specified.</value>
</data>
<data name="WebMail_UnableToDetermineFrom" xml:space="preserve">
<value>No "From" email address was specified and a default value could not be assigned.</value>
</data>
</root>

View File

@ -0,0 +1,329 @@
// Copyright (c) Microsoft Corporation. All rights reserved. See License.txt in the project root for license information.
using System.Collections;
using System.Collections.Generic;
using System.Collections.Specialized;
using System.Diagnostics;
using System.Diagnostics.CodeAnalysis;
using System.Globalization;
using System.Linq;
using System.Reflection;
using System.Security;
using System.Text;
using System.Web.Helpers.Resources;
using System.Web.WebPages;
namespace System.Web.Helpers
{
/// <summary>
/// Provides various info about ASP.NET server.
/// </summary>
public static class ServerInfo
{
/// <remarks>
/// todo: figure out right place for this
/// </remarks>
private const string Style =
"<style type=\"text/css\">" +
" div.server-info { text-align: center; }" +
" table.server-info { border-collapse:collapse; text-align:center; margin: auto; width:600px; direction: ltr; }" +
" table.server-info tbody tr:nth-child(even){ background-color: #EEE; }" +
" table.server-info, table.server-info th, table.server-info td { border:1px solid black; }" +
" table.server-info th, table.server-info td " +
" { text-align:left; padding:2px; font-family:Tahoma, Arial, sans-serif; font-size:0.75em; }" +
" h1.server-info { font-family:Tahoma, Arial, sans-serif; font-size:150%; text-align:center; }" +
" table.server-info h2 { font-family:Tahoma, Arial, sans-serif; font-size:125%; text-align:center; }" +
" p.server-info { text-align:center; font-family:Tahoma, Arial, sans-serif; font-size:0.75em; }" +
" .ital { font-style: italic; } " +
" .warn { color: #F00; } " +
"</style>";
internal static IDictionary<string, string> EnvironmentVariables()
{
// todo: extract well defined subset for special use?
// use a case-insensitive dictionary since environment variables are case-insensitive.
IDictionary<string, string> environmentVariablesResult = new SortedDictionary<string, string>(StringComparer.OrdinalIgnoreCase);
IDictionary environmentVariables;
// todo: better way to deal with security; query config for trust level?
try
{
environmentVariables = Environment.GetEnvironmentVariables();
}
catch (SecurityException)
{
return environmentVariablesResult;
}
foreach (DictionaryEntry entry in environmentVariables)
{
environmentVariablesResult.Add(entry.Key.ToString(), InsertWhiteSpace(entry.Value.ToString()));
}
return environmentVariablesResult;
}
internal static IDictionary<string, string> ServerVariables()
{
var httpContext = HttpContext.Current;
return ServerVariables(httpContext != null ? new HttpContextWrapper(httpContext) : null);
}
internal static IDictionary<string, string> ServerVariables(HttpContextBase context)
{
// todo: extract well defined subset for special use?
IDictionary<string, string> serverVariablesResult = new SortedDictionary<string, string>();
NameValueCollection serverVariables;
// todo: better way to deal with security; query config for trust level?
try
{
if ((context != null) && (context.Request != null))
{
serverVariables = context.Request.ServerVariables;
}
else
{
// Just return empty collection when there is no context available.
return serverVariablesResult;
}
}
catch (SecurityException)
{
return serverVariablesResult;
}
foreach (string key in serverVariables.AllKeys)
{
// todo: these values contains very long strings with no spaces that distorts table layout - figure out how to deal with it
if (key.Equals("ALL_HTTP", StringComparison.OrdinalIgnoreCase) ||
key.Equals("ALL_RAW", StringComparison.OrdinalIgnoreCase) ||
key.Equals("HTTP_AUTHORIZATION", StringComparison.OrdinalIgnoreCase) ||
key.Equals("HTTP_COOKIE", StringComparison.OrdinalIgnoreCase))
{
continue;
}
serverVariablesResult.Add(key, InsertWhiteSpace(serverVariables[key]));
}
return serverVariablesResult;
}
internal static IDictionary<string, string> Configuration()
{
IDictionary<string, string> info = new Dictionary<string, string>();
// todo: do we need to localize these strings or would that be confusing
// (Since we just display API names that are all in English)
info.Add("Current Local Time", DateTime.Now.ToString(CultureInfo.CurrentCulture));
info.Add("Current UTC Time", DateTime.UtcNow.ToString(CultureInfo.CurrentCulture));
info.Add("Current Culture", CultureInfo.CurrentCulture.DisplayName);
info.Add("Machine Name", Environment.MachineName);
info.Add("OS Version", Environment.OSVersion.ToString());
info.Add("ASP.NET Version", Environment.Version.ToString());
info.Add("ASP.NET Web Pages Version", new AssemblyName(typeof(WebPage).Assembly.FullName).Version.ToString());
info.Add("User Name", Environment.UserName);
info.Add("User Interactive", Environment.UserInteractive.ToString());
info.Add("Processor Count", Environment.ProcessorCount.ToString(CultureInfo.InvariantCulture));
info.Add("Tick Count", Environment.TickCount.ToString(CultureInfo.InvariantCulture));
// Calls bellow require full trust.
try
{
info.Add("Current Directory", Environment.CurrentDirectory);
}
catch (SecurityException)
{
return info;
}
info.Add("System Directory", Environment.SystemDirectory);
info.Add("User Domain Name", Environment.UserDomainName);
info.Add("Working Set", Environment.WorkingSet.ToString(CultureInfo.InvariantCulture) + " bytes");
return info;
}
internal static IDictionary<string, string> HttpRuntimeInfo()
{
IDictionary<string, string> info = new Dictionary<string, string>();
// todo: better way to deal with security; query config for trust level?
try
{
info.Add("CLR Install Directory", HttpRuntime.ClrInstallDirectory);
}
catch (SecurityException)
{
return info;
}
try
{
info.Add("Codegen Directory", HttpRuntime.CodegenDir);
info.Add("Bin Directory", HttpRuntime.BinDirectory);
info.Add("AppDomain Application Path", HttpRuntime.AppDomainAppPath);
}
catch (ArgumentException)
{
// do nothing
// These APIs don't check if path is set before setting security demands, which causes exception.
// So far this happens only when running from unit tests.
}
info.Add("Asp Install Directory", HttpRuntime.AspInstallDirectory);
info.Add("Machine Configuration Directory", HttpRuntime.MachineConfigurationDirectory);
info.Add("AppDomain Id", HttpRuntime.AppDomainId);
info.Add("AppDomain Application Id", HttpRuntime.AppDomainAppId);
info.Add("AppDomain Application Virtual Path", HttpRuntime.AppDomainAppVirtualPath);
info.Add("Asp Client Script Physical Path", HttpRuntime.AspClientScriptPhysicalPath);
info.Add("Asp Client Script Virtual Path", HttpRuntime.AspClientScriptVirtualPath);
info.Add("Cache Size", HttpRuntime.Cache.Count.ToString(CultureInfo.InvariantCulture));
info.Add("Cache Effective Percentage Physical Memory Limit", HttpRuntime.Cache.EffectivePercentagePhysicalMemoryLimit.ToString(CultureInfo.InvariantCulture));
info.Add("Cache Effective Private Bytes Limit", HttpRuntime.Cache.EffectivePrivateBytesLimit.ToString(CultureInfo.InvariantCulture));
info.Add("On UNC Share", HttpRuntime.IsOnUNCShare.ToString());
return info;
}
internal static IDictionary<string, string> LegacyCAS()
{
return LegacyCAS(AppDomain.CurrentDomain);
}
internal static IDictionary<string, string> LegacyCAS(AppDomain appDomain)
{
IDictionary<string, string> info = new Dictionary<string, string>();
try
{
bool legacyCasModeEnabled = !appDomain.IsHomogenous;
if (legacyCasModeEnabled)
{
info[HelpersResources.ServerInfo_LegacyCAS] = HelpersResources.ServerInfo_LegacyCasHelpInfo;
}
}
catch (SecurityException)
{
return info;
}
return info;
}
/// <summary>
/// Generates HTML required to display server information.
/// </summary>
/// <remarks>
/// HTML generated is XHTML 1.0 compliant but not XHTML 1.1 or HTML5 compliant. The reason is that we
/// generate &lt;style&gt; tag inside &lt;body&gt; tag, which is not allowed. This is by design for now since ServerInfo
/// is debugging aid and should not be used as a permanent part of any web page.
/// </remarks>
[SuppressMessage("Microsoft.Design", "CA1024:UsePropertiesWhereAppropriate",
Justification = "This could be time consuming operation that does not just retrieve a field.")]
public static HtmlString GetHtml()
{
StringBuilder sb = new StringBuilder(Style);
sb.AppendLine(String.Format(CultureInfo.InvariantCulture, "<h1 class=\"server-info\">{0}</h1>",
HttpUtility.HtmlEncode(HelpersResources.ServerInfo_Header)));
var configuration = Configuration();
Debug.Assert((configuration != null) && (configuration.Count > 0));
PrintInfoSection(sb, HttpUtility.HtmlEncode(HelpersResources.ServerInfo_ServerConfigTable), configuration);
var serverVariables = ServerVariables();
Debug.Assert((serverVariables != null));
PrintInfoSection(sb, HelpersResources.ServerInfo_ServerVars, serverVariables);
var legacyCAS = LegacyCAS();
if (legacyCAS.Any())
{
PrintInfoSection(sb, HelpersResources.ServerInfo_LegacyCAS, legacyCAS);
}
// Info below is not available in medium trust.
var httpRuntimeInfo = HttpRuntimeInfo();
Debug.Assert(httpRuntimeInfo != null);
if (!httpRuntimeInfo.Any())
{
sb.AppendLine(String.Format(CultureInfo.InvariantCulture, "<p class=\"server-info\">{0}</p>",
HttpUtility.HtmlEncode(HelpersResources.ServerInfo_AdditionalInfo)));
return new HtmlString(sb.ToString());
}
else
{
PrintInfoSection(sb, HelpersResources.ServerInfo_HttpRuntime, httpRuntimeInfo);
var envVariables = EnvironmentVariables();
Debug.Assert(envVariables != null);
PrintInfoSection(sb, HelpersResources.ServerInfo_EnvVars, envVariables);
}
return new HtmlString(sb.ToString());
}
/// <summary>
/// Renders a table section printing out rows and columns.
/// </summary>
private static void PrintInfoSection(StringBuilder builder, string sectionTitle, IDictionary<string, string> entries)
{
builder.AppendLine("<div class=\"server-info\">");
builder.AppendLine("<table class=\"server-info\" dir=\"ltr\">");
if (!String.IsNullOrEmpty(sectionTitle))
{
builder.AppendLine("<caption>");
builder.AppendFormat(CultureInfo.InvariantCulture, "<h2>{0}</h2>", HttpUtility.HtmlEncode(sectionTitle)).AppendLine();
builder.AppendLine("</caption>");
}
builder.AppendLine("<colgroup><col style=\"width:30%;\" /> <col style=\"width:70%;\" /></colgroup>");
builder.AppendLine("<tbody>");
foreach (var entry in entries)
{
var css = String.Empty;
string value = entry.Value;
if (entry.Key == HelpersResources.ServerInfo_LegacyCAS)
{
// TODO: suboptimal solution, but its easier to do this than come up with something that works better
css = "warn";
}
else if (String.IsNullOrEmpty(entry.Value))
{
css = "ital";
value = HelpersResources.ServerInfo_NoValue;
}
if (css.Any())
{
css = " class=\"" + css + "\"";
}
builder.Append("<tr>");
builder.AppendFormat(CultureInfo.InvariantCulture, "<th scope=\"row\">{0}</th>", HttpUtility.HtmlEncode(entry.Key));
builder.AppendFormat(CultureInfo.InvariantCulture, "<td{0}>{1}</td>", css, HttpUtility.HtmlEncode(value));
builder.AppendLine("</tr>");
}
builder.AppendLine("</tbody>");
builder.AppendLine("</table>");
builder.AppendLine("</div>");
}
/// <summary>
/// Inserts spaces after ',' and ';' so table can be rendered properly.
/// </summary>
private static string InsertWhiteSpace(string s)
{
return s.Replace(",", ", ").Replace(";", "; ");
}
}
}

Some files were not shown because too many files have changed in this diff Show More