Permalink
Browse files

MVC3 integrated, with some changes to make it compile on Mono and wit…

…h Razor2
  • Loading branch information...
1 parent a3bd80f commit 3f4e22a0ce7206b9321991123893a63b2dd398d4 @grendello grendello committed Mar 29, 2012
Showing 347 changed files with 24,592 additions and 1 deletion.
View
@@ -189,7 +189,8 @@ net_4_0_dirs := \
System.Web.Razor \
System.Web.WebPages.Deployment \
System.Web.WebPages \
- System.Web.WebPages.Razor
+ System.Web.WebPages.Razor \
+ System.Web.Mvc3
net_4_0_only_dirs := \
System.ComponentModel.Composition
@@ -0,0 +1,18 @@
+// 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.Design", "CA2210:AssembliesShouldHaveValidStrongNames", Justification = "Assembly is delay-signed.")]
+[assembly: SuppressMessage("Microsoft.Design", "CA1020:AvoidNamespacesWithFewTypes", Scope = "namespace", Target = "System.Web.Mvc.Ajax", Justification = "Helpers reside within a separate namespace to support alternate helper classes.")]
+[assembly: SuppressMessage("Microsoft.Design", "CA1033:InterfaceMethodsShouldBeCallableByChildTypes", Scope = "member", Target = "System.Web.Mvc.TempDataDictionary.#System.Collections.Generic.ICollection`1<System.Collections.Generic.KeyValuePair`2<System.String,System.Object>>.Contains(System.Collections.Generic.KeyValuePair`2<System.String,System.Object>)", Justification = "There are no defined scenarios for wanting to derive from this class, but we don't want to prevent it either.")]
+[assembly: SuppressMessage("Microsoft.Design", "CA1033:InterfaceMethodsShouldBeCallableByChildTypes", Scope = "member", Target = "System.Web.Mvc.TempDataDictionary.#System.Collections.Generic.ICollection`1<System.Collections.Generic.KeyValuePair`2<System.String,System.Object>>.CopyTo(System.Collections.Generic.KeyValuePair`2<System.String,System.Object>[],System.Int32)", Justification = "There are no defined scenarios for wanting to derive from this class, but we don't want to prevent it either.")]
+[assembly: SuppressMessage("Microsoft.Design", "CA1033:InterfaceMethodsShouldBeCallableByChildTypes", Scope = "member", Target = "System.Web.Mvc.TempDataDictionary.#System.Collections.Generic.ICollection`1<System.Collections.Generic.KeyValuePair`2<System.String,System.Object>>.IsReadOnly", Justification = "There are no defined scenarios for wanting to derive from this class, but we don't want to prevent it either.")]
+[assembly: SuppressMessage("Microsoft.Naming", "CA1703:ResourceStringsShouldBeSpelledCorrectly", MessageId = "Param", Scope = "resource", Target = "System.Web.Mvc.Resources.MvcResources.resources", Justification = "This is the name that matches ASP.NET")]
@@ -0,0 +1,42 @@
+thisdir = class/System.Web.Mvc3
+SUBDIRS =
+include ../../build/rules.make
+
+LIBRARY = System.Web.Mvc3.dll
+LIBRARY_NAME = System.Web.Mvc.dll
+LIBRARY_USE_INTERMEDIATE_FILE = yes
+
+RESX_DIST = Mvc/Resources/MvcResources.resx
+
+LIB_MCS_FLAGS = \
+ /warn:1 \
+ /noconfig \
+ /keyfile:../winfx.pub \
+ /d:MONO \
+ /delaysign \
+ /r:Microsoft.Web.Infrastructure.dll \
+ /r:System.dll \
+ /r:System.Core.dll \
+ /r:System.Configuration.dll \
+ /r:System.Data.dll \
+ /r:System.Xml.dll \
+ /r:System.Web.dll \
+ /r:System.Web.Abstractions.dll \
+ /r:System.Web.Routing.dll \
+ /r:System.Web.Extensions.dll \
+ /r:System.ComponentModel.DataAnnotations.dll \
+ /r:System.Data.Linq.dll \
+ /r:System.Runtime.Caching.dll \
+ /r:System.Web.Razor.dll \
+ /r:System.Web.WebPages.Razor.dll \
+ /r:System.Web.WebPages.dll \
+ $(foreach r, $(RESOURCES), /resource:$(r),System.Web.Mvc.Resources.$(notdir $(r)))
+
+EXTRA_DISTFILES = $(RESX_DIST)
+RESOURCES = $(RESX_DIST:.resx=.resources)
+include ../../build/library.make
+
+$(build_lib): $(RESOURCES)
+
+$(RESOURCES): %.resources: %.resx
+ $(RESGEN) `echo $< | $(PLATFORM_CHANGE_SEPARATOR_CMD)`
@@ -0,0 +1,58 @@
+namespace System.Web.Mvc {
+ using System;
+ using System.Collections.Generic;
+ using System.Collections.ObjectModel;
+ using System.Diagnostics.CodeAnalysis;
+ using System.Linq;
+ using System.Reflection;
+ using System.Web.Mvc.Resources;
+
+ [SuppressMessage("Microsoft.Design", "CA1019:DefineAccessorsForAttributeArguments", Justification = "The accessor is exposed as an ICollection<string>.")]
+ [AttributeUsage(AttributeTargets.Method, AllowMultiple = false, Inherited = true)]
+ public sealed class AcceptVerbsAttribute : ActionMethodSelectorAttribute {
+ public AcceptVerbsAttribute(HttpVerbs verbs)
+ : this(EnumToArray(verbs)) {
+ }
+
+ public AcceptVerbsAttribute(params string[] verbs) {
+ if (verbs == null || verbs.Length == 0) {
+ throw new ArgumentException(MvcResources.Common_NullOrEmpty, "verbs");
+ }
+
+ Verbs = new ReadOnlyCollection<string>(verbs);
+ }
+
+ public ICollection<string> Verbs {
+ get;
+ private set;
+ }
+
+ private static void AddEntryToList(HttpVerbs verbs, HttpVerbs match, List<string> verbList, string entryText) {
+ if ((verbs & match) != 0) {
+ verbList.Add(entryText);
+ }
+ }
+
+ internal static string[] EnumToArray(HttpVerbs verbs) {
+ List<string> verbList = new List<string>();
+
+ AddEntryToList(verbs, HttpVerbs.Get, verbList, "GET");
+ AddEntryToList(verbs, HttpVerbs.Post, verbList, "POST");
+ AddEntryToList(verbs, HttpVerbs.Put, verbList, "PUT");
+ AddEntryToList(verbs, HttpVerbs.Delete, verbList, "DELETE");
+ AddEntryToList(verbs, HttpVerbs.Head, verbList, "HEAD");
+
+ return verbList.ToArray();
+ }
+
+ public override bool IsValidForRequest(ControllerContext controllerContext, MethodInfo methodInfo) {
+ if (controllerContext == null) {
+ throw new ArgumentNullException("controllerContext");
+ }
+
+ string incomingVerb = controllerContext.HttpContext.Request.GetHttpMethodOverride();
+
+ return Verbs.Contains(incomingVerb, StringComparer.OrdinalIgnoreCase);
+ }
+ }
+}
@@ -0,0 +1,175 @@
+namespace System.Web.Mvc {
+ using System;
+ using System.Collections.Generic;
+ using System.ComponentModel;
+ using System.Diagnostics.CodeAnalysis;
+ using System.Globalization;
+ using System.Linq;
+ using System.Reflection;
+ using System.Web.Mvc.Resources;
+
+ public abstract class ActionDescriptor : ICustomAttributeProvider, IUniquelyIdentifiable {
+
+ private readonly static ActionMethodDispatcherCache _staticDispatcherCache = new ActionMethodDispatcherCache();
+ private ActionMethodDispatcherCache _instanceDispatcherCache;
+ private readonly Lazy<string> _uniqueId;
+
+ private static readonly ActionSelector[] _emptySelectors = new ActionSelector[0];
+
+ protected ActionDescriptor() {
+ _uniqueId = new Lazy<string>(CreateUniqueId);
+ }
+
+ public abstract string ActionName {
+ get;
+ }
+
+ public abstract ControllerDescriptor ControllerDescriptor {
+ get;
+ }
+
+ internal ActionMethodDispatcherCache DispatcherCache {
+ get {
+ if (_instanceDispatcherCache == null) {
+ _instanceDispatcherCache = _staticDispatcherCache;
+ }
+ return _instanceDispatcherCache;
+ }
+ set {
+ _instanceDispatcherCache = value;
+ }
+ }
+
+ [SuppressMessage("Microsoft.Security", "CA2119:SealMethodsThatSatisfyPrivateInterfaces", Justification = "This is overridden elsewhere in System.Web.Mvc")]
+ public virtual string UniqueId {
+ get {
+ return _uniqueId.Value;
+ }
+ }
+
+ private string CreateUniqueId() {
+ return DescriptorUtil.CreateUniqueId(GetType(), ControllerDescriptor, ActionName);
+ }
+
+ public abstract object Execute(ControllerContext controllerContext, IDictionary<string, object> parameters);
+
+ internal static object ExtractParameterFromDictionary(ParameterInfo parameterInfo, IDictionary<string, object> parameters, MethodInfo methodInfo) {
+ object value;
+
+ if (!parameters.TryGetValue(parameterInfo.Name, out value)) {
+ // the key should always be present, even if the parameter value is null
+ string message = String.Format(CultureInfo.CurrentCulture, MvcResources.ReflectedActionDescriptor_ParameterNotInDictionary,
+ parameterInfo.Name, parameterInfo.ParameterType, methodInfo, methodInfo.DeclaringType);
+ throw new ArgumentException(message, "parameters");
+ }
+
+ if (value == null && !TypeHelpers.TypeAllowsNullValue(parameterInfo.ParameterType)) {
+ // tried to pass a null value for a non-nullable parameter type
+ string message = String.Format(CultureInfo.CurrentCulture, MvcResources.ReflectedActionDescriptor_ParameterCannotBeNull,
+ parameterInfo.Name, parameterInfo.ParameterType, methodInfo, methodInfo.DeclaringType);
+ throw new ArgumentException(message, "parameters");
+ }
+
+ if (value != null && !parameterInfo.ParameterType.IsInstanceOfType(value)) {
+ // value was supplied but is not of the proper type
+ string message = String.Format(CultureInfo.CurrentCulture, MvcResources.ReflectedActionDescriptor_ParameterValueHasWrongType,
+ parameterInfo.Name, methodInfo, methodInfo.DeclaringType, value.GetType(), parameterInfo.ParameterType);
+ throw new ArgumentException(message, "parameters");
+ }
+
+ return value;
+ }
+
+ internal static object ExtractParameterOrDefaultFromDictionary(ParameterInfo parameterInfo, IDictionary<string, object> parameters) {
+ Type parameterType = parameterInfo.ParameterType;
+
+ object value;
+ parameters.TryGetValue(parameterInfo.Name, out value);
+
+ // if wrong type, replace with default instance
+ if (parameterType.IsInstanceOfType(value)) {
+ return value;
+ }
+ else {
+ object defaultValue;
+ if (ParameterInfoUtil.TryGetDefaultValue(parameterInfo, out defaultValue)) {
+ return defaultValue;
+ }
+ else {
+ return TypeHelpers.GetDefaultValue(parameterType);
+ }
+ }
+ }
+
+ public virtual object[] GetCustomAttributes(bool inherit) {
+ return GetCustomAttributes(typeof(object), inherit);
+ }
+
+ public virtual object[] GetCustomAttributes(Type attributeType, bool inherit) {
+ if (attributeType == null) {
+ throw new ArgumentNullException("attributeType");
+ }
+
+ return (object[])Array.CreateInstance(attributeType, 0);
+ }
+
+ internal virtual IEnumerable<FilterAttribute> GetFilterAttributes(bool useCache) {
+ return GetCustomAttributes(typeof(FilterAttribute), inherit: true).Cast<FilterAttribute>();
+ }
+
+ [EditorBrowsable(EditorBrowsableState.Never)]
+ [Obsolete("Please call System.Web.Mvc.FilterProviders.Providers.GetFilters() now.", true)]
+ public virtual FilterInfo GetFilters() {
+ return new FilterInfo();
+ }
+
+ public abstract ParameterDescriptor[] GetParameters();
+
+ [SuppressMessage("Microsoft.Design", "CA1024:UsePropertiesWhereAppropriate", Justification = "This method may perform non-trivial work.")]
+ public virtual ICollection<ActionSelector> GetSelectors() {
+ return _emptySelectors;
+ }
+
+ public virtual bool IsDefined(Type attributeType, bool inherit) {
+ if (attributeType == null) {
+ throw new ArgumentNullException("attributeType");
+ }
+
+ return false;
+ }
+
+ internal static string VerifyActionMethodIsCallable(MethodInfo methodInfo) {
+ // we can't call static methods
+ if (methodInfo.IsStatic) {
+ return String.Format(CultureInfo.CurrentCulture,
+ MvcResources.ReflectedActionDescriptor_CannotCallStaticMethod,
+ methodInfo,
+ methodInfo.ReflectedType.FullName);
+ }
+
+ // we can't call instance methods where the 'this' parameter is a type other than ControllerBase
+ if (!typeof(ControllerBase).IsAssignableFrom(methodInfo.ReflectedType)) {
+ return String.Format(CultureInfo.CurrentCulture, MvcResources.ReflectedActionDescriptor_CannotCallInstanceMethodOnNonControllerType,
+ methodInfo, methodInfo.ReflectedType.FullName);
+ }
+
+ // we can't call methods with open generic type parameters
+ if (methodInfo.ContainsGenericParameters) {
+ return String.Format(CultureInfo.CurrentCulture, MvcResources.ReflectedActionDescriptor_CannotCallOpenGenericMethods,
+ methodInfo, methodInfo.ReflectedType.FullName);
+ }
+
+ // we can't call methods with ref/out parameters
+ ParameterInfo[] parameterInfos = methodInfo.GetParameters();
+ foreach (ParameterInfo parameterInfo in parameterInfos) {
+ if (parameterInfo.IsOut || parameterInfo.ParameterType.IsByRef) {
+ return String.Format(CultureInfo.CurrentCulture, MvcResources.ReflectedActionDescriptor_CannotCallMethodsWithOutOrRefParameters,
+ methodInfo, methodInfo.ReflectedType.FullName, parameterInfo);
+ }
+ }
+
+ // we can call this method
+ return null;
+ }
+ }
+}
@@ -0,0 +1,55 @@
+namespace System.Web.Mvc {
+ using System;
+ using System.Diagnostics.CodeAnalysis;
+
+ public class ActionExecutedContext : ControllerContext {
+
+ private ActionResult _result;
+
+ // parameterless constructor used for mocking
+ public ActionExecutedContext() {
+ }
+
+ [SuppressMessage("Microsoft.Usage", "CA2214:DoNotCallOverridableMethodsInConstructors", Justification = "The virtual property setters are only to support mocking frameworks, in which case this constructor shouldn't be called anyway.")]
+ public ActionExecutedContext(ControllerContext controllerContext, ActionDescriptor actionDescriptor, bool canceled, Exception exception)
+ : base(controllerContext) {
+ if (actionDescriptor == null) {
+ throw new ArgumentNullException("actionDescriptor");
+ }
+
+ ActionDescriptor = actionDescriptor;
+ Canceled = canceled;
+ Exception = exception;
+ }
+
+ public virtual ActionDescriptor ActionDescriptor {
+ get;
+ set;
+ }
+
+ public virtual bool Canceled {
+ get;
+ set;
+ }
+
+ public virtual Exception Exception {
+ get;
+ set;
+ }
+
+ public bool ExceptionHandled {
+ get;
+ set;
+ }
+
+ public ActionResult Result {
+ get {
+ return _result ?? EmptyResult.Instance;
+ }
+ set {
+ _result = value;
+ }
+ }
+
+ }
+}
Oops, something went wrong.

0 comments on commit 3f4e22a

Please sign in to comment.