本文整理汇总了C#中System.Web.Mvc.ControllerDescriptor类的典型用法代码示例。如果您正苦于以下问题:C# ControllerDescriptor类的具体用法?C# ControllerDescriptor怎么用?C# ControllerDescriptor使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
ControllerDescriptor类属于System.Web.Mvc命名空间,在下文中一共展示了ControllerDescriptor类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GetInferredAction
protected virtual InferredAction GetInferredAction(ControllerDescriptor controllerDescriptor, string actionName) {
return InferredActions.Current
.Where(inferred => inferred.Controller == controllerDescriptor.ControllerType)
.Where( inferred =>
string.Equals(inferred.ActionName, actionName, StringComparison.CurrentCultureIgnoreCase))
.FirstOrDefault();
}
示例2: TaskAsyncActionDescriptor
/// <summary>
/// Конструктор, сохраняет нужные данные
/// </summary>
/// <param name="methodInfo">данные о вызываемом action'е</param>
/// <param name="actionName">имя action'а</param>
/// <param name="controllerDescriptor">дескриптор контроллера</param>
public TaskAsyncActionDescriptor(
MethodInfo methodInfo, string actionName, ControllerDescriptor controllerDescriptor)
{
_methodInfo = methodInfo;
_actionName = actionName;
_controllerDescriptor = controllerDescriptor;
}
示例3: FindAction
public virtual ActionDescriptor FindAction(ControllerContext controllerContext,
ControllerDescriptor controllerDescriptor, string actionName)
{
// Todo we may want convention here.
//if (controllerContext.HttpContext.Request.HttpMethod != Verbs.Post)
//{
// return null;
//}
var controllerName = controllerContext.RouteData.Values["controller"].ToString().ToLowerInvariant();
var service = _Registry.GetService(controllerName);
if (service == null)
{
return null;
}
var commandAction = service.FindAction(actionName);
if (commandAction == null || !commandAction.IsCommand())
{
return null;
}
var commandDescriptor = _Locator.GetInstance<ReflectedCommand>();
commandDescriptor.SetActionName(actionName);
commandDescriptor.SetControllerDescriptor(controllerDescriptor);
commandDescriptor.SetAction(commandAction);
return commandDescriptor;
}
示例4: FindAction
protected override ActionDescriptor FindAction(
ControllerContext controllerContext,
ControllerDescriptor controllerDescriptor,
string actionName)
{
var action = base.FindAction(controllerContext, controllerDescriptor, actionName);
if (action != null)
{
return action;
}
if (typeof(CqrsController).IsAssignableFrom(controllerDescriptor.ControllerType))
{
//TODO: cache command types?
var messagesAssembly = Assembly.Load(new AssemblyName("ECom.Messages"));
var commandTypes = messagesAssembly.GetTypes()
.Where(t => typeof(ICommand).IsAssignableFrom(t))
.Select(t => new { Name = t.Name, Type = t });
var command = commandTypes.FirstOrDefault(c => c.Name.Equals(actionName, StringComparison.InvariantCultureIgnoreCase));
if (command != null)//we have a command action but the action itself is not declared
{
//fallback to cqrs controller generic command action
var actionInfo = controllerDescriptor.ControllerType.GetMethod("SubmitCommand").MakeGenericMethod(command.Type);
if (actionInfo != null)
{
return new ReflectedActionDescriptor(actionInfo, actionName, controllerDescriptor);
}
}
}
return null;
}
示例5: ReflectedActionDescriptor
internal ReflectedActionDescriptor(MethodInfo methodInfo, string actionName, ControllerDescriptor controllerDescriptor, bool validateMethod)
{
if (methodInfo == null)
{
throw new ArgumentNullException("methodInfo");
}
if (String.IsNullOrEmpty(actionName))
{
throw new ArgumentException(MvcResources.Common_NullOrEmpty, "actionName");
}
if (controllerDescriptor == null)
{
throw new ArgumentNullException("controllerDescriptor");
}
if (validateMethod)
{
string failedMessage = VerifyActionMethodIsCallable(methodInfo);
if (failedMessage != null)
{
throw new ArgumentException(failedMessage, "methodInfo");
}
}
MethodInfo = methodInfo;
_actionName = actionName;
_controllerDescriptor = controllerDescriptor;
}
示例6: FindAction
protected override ActionDescriptor FindAction(ControllerContext controllerContext, ControllerDescriptor controllerDescriptor, string actionName)
{
var method = controllerContext.HttpContext.Request.HttpMethod;
var actionDescriptor = controllerDescriptor.FindAction(controllerContext, method);
return actionDescriptor;
}
示例7: GetActionDescriptor
/// <summary>
/// Gets the action descriptor and caches it
/// </summary>
/// <param name="controllerContext"></param>
/// <param name="controllerDescriptor"></param>
/// <param name="actionName"></param>
/// <returns></returns>
protected ReflectedActionDescriptor GetActionDescriptor(ControllerContext controllerContext, ControllerDescriptor controllerDescriptor, string actionName)
{
var found = _descriptorCache.GetOrAdd(
controllerDescriptor.UniqueId,
s => new ReflectedActionDescriptor(
controllerContext.Controller.GetType().GetMethods()
.First(x => x.Name == actionName &&
x.GetCustomAttributes(typeof(NonActionAttribute), false).Any() == false),
actionName,
controllerDescriptor));
//check if the action name matches, it won't if the user has changed the action name in umbraco, if this occurs we need to refresh the cache
if (!found.ActionName.InvariantEquals(actionName))
{
var newDescriptor = new ReflectedActionDescriptor(
controllerContext.Controller.GetType().GetMethods()
.First(x => x.Name == actionName &&
x.GetCustomAttributes(typeof (NonActionAttribute), false).Any() == false),
actionName,
controllerDescriptor);
_descriptorCache.TryUpdate(controllerDescriptor.UniqueId, newDescriptor, found);
found = newDescriptor;
}
return found;
}
示例8: FindAction
protected override ActionDescriptor FindAction(ControllerContext controllerContext, ControllerDescriptor controllerDescriptor, string actionName)
{
var ad = base.FindAction(controllerContext, controllerDescriptor, actionName);
//now we need to check if it exists, if not we need to return the Index by default
if (ad == null)
{
if (controllerContext.RouteData.DataTokens.ContainsKey("__virtualnodefinder__"))
{
var virtualNode = controllerContext.RouteData.DataTokens["__virtualnodefinder__"] as IPublishedContent;
if (virtualNode != null)
{
var action = controllerContext.RouteData.GetRequiredString("action");
var categoryUrl = virtualNode.GetPropertyValue<string>("categoriesUrlName");
if (action.InvariantEquals(categoryUrl))
{
return GetActionDescriptor(controllerContext, controllerDescriptor, "Categories");
}
var tagsUrl = virtualNode.GetPropertyValue<string>("tagsUrlName");
if (action.InvariantEquals(tagsUrl))
{
return GetActionDescriptor(controllerContext, controllerDescriptor, "Tags");
}
}
}
}
return ad;
}
示例9: GetControllerDetails
public string GetControllerDetails(ControllerDescriptor controllerDescriptor, RequestContext requestContext)
{
var template = new ControllerDetails
{
Model = GetControllerModel(controllerDescriptor, requestContext)
};
return template.TransformText();
}
示例10: RegistrySelector
protected RegistrySelector(ActionDescriptor actionDescriptor, ControllerDescriptor controllerDescriptor, ControllerContext controllerContext)
{
ActionDescriptor = actionDescriptor;
ControllerDescriptor = controllerDescriptor;
ControllerContext = controllerContext;
if (ControllerContextIsValid()) RegisterControllerRequestData(ControllerContext.HttpContext.Request);
if (ControllerRouteDataIsValid()) RegisterControllerRouteData(ControllerContext.RouteData);
}
示例11: GetActionMapping
public virtual ILookup<string, ApiActionDescriptor> GetActionMapping(ControllerDescriptor controllerDescriptor)
{
if (controllerDescriptor == null)
{
throw Error.ArgumentNull("controllerDescriptor");
}
//return this.GetInternalSelector(controllerDescriptor).GetActionMapping();
throw new NotImplementedException();
}
示例12: FindAction
protected override ActionDescriptor FindAction(ControllerContext controllerContext, ControllerDescriptor controllerDescriptor, string actionName) {
if (actionName == restActionToken) {
// cleanup the restActionToken we set earlier
controllerContext.RequestContext.RouteData.Values["action"] = null;
List<ActionDescriptor> matches = new List<ActionDescriptor>();
foreach (ActionDescriptor ad in controllerDescriptor.GetCanonicalActions()) {
object[] acceptVerbs = ad.GetCustomAttributes(typeof(AcceptVerbsAttribute), false);
if (acceptVerbs.Length > 0) {
foreach (object o in acceptVerbs) {
AcceptVerbsAttribute ava = o as AcceptVerbsAttribute;
if (ava != null) {
if (ava.Verbs.Contains(controllerContext.HttpContext.Request.GetHttpMethodOverride().ToUpperInvariant())) {
matches.Add(ad);
}
}
}
}
}
switch (matches.Count) {
case 0:
break;
case 1:
ActionDescriptor ad = matches[0];
actionName = ad.ActionName;
controllerContext.RequestContext.RouteData.Values["action"] = actionName;
return ad;
default:
StringBuilder matchesString = new StringBuilder(matches[0].ActionName);
for (int index = 1; index < matches.Count; index++) {
matchesString.Append(", ");
matchesString.Append(matches[index].ActionName);
}
return new ResourceErrorActionDescriptor(
controllerDescriptor,
HttpStatusCode.Conflict,
String.Format(
CultureInfo.CurrentCulture,
MvcResources.ResourceControllerFactory_ConflictingActions,
controllerDescriptor.ControllerName,
matchesString.ToString()
)
);
}
}
return base.FindAction(controllerContext, controllerDescriptor, actionName) ??
new ResourceErrorActionDescriptor(
controllerDescriptor,
HttpStatusCode.NotFound,
String.Format(
CultureInfo.CurrentCulture,
MvcResources.ResourceControllerFactory_NoActions,
controllerDescriptor.ControllerName
)
);
}
示例13: FindAction
protected override ActionDescriptor FindAction(ControllerContext controllerContext, ControllerDescriptor controllerDescriptor, string actionName)
{
var result = base.FindAction(controllerContext, controllerDescriptor, actionName);
if (result == null)
{
return new NotFoundActionDescriptor();
}
return result;
}
示例14: FixtureSetUp
public void FixtureSetUp()
{
_baseControllerContext = new ControllerContext {Controller = new TestController()};
_baseMethodInfo = TestController.GetAction1MethodInfo<TestController>();
_actionName = _baseMethodInfo.Name;
_controllerDescriptor = new Mock<ControllerDescriptor>().Object;
_reflectedActionDescriptor = new ReflectedActionDescriptor(_baseMethodInfo, _actionName, _controllerDescriptor);
}
示例15: FindAction
/// <summary>
/// Finds the action for the controller, if not it is inferred.
/// </summary>
/// <param name="controllerContext"></param>
/// <param name="controllerDescriptor"></param>
/// <param name="actionName"></param>
/// <returns></returns>
protected override ActionDescriptor FindAction(ControllerContext controllerContext,
ControllerDescriptor controllerDescriptor, string actionName)
{
var foundAction = base.FindAction(controllerContext, controllerDescriptor, actionName);
if (foundAction == null) {
InferredAction inferredAction = GetInferredAction(controllerDescriptor, actionName);
foundAction = new InferredActionDescriptor(actionName, controllerDescriptor, inferredAction);
}
return foundAction;
}