// Copyright (c) Microsoft Open Technologies, Inc. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using Microsoft.Framework.Logging;
namespace Microsoft.AspNet.Mvc.Logging
{
///
/// Logging representation of the state of an or
/// . Logged during action discovery.
///
public class ActionDescriptorValues : LoggerStructureBase
{
public ActionDescriptorValues([NotNull] ActionDescriptor inner)
{
Name = inner.Name;
DisplayName = inner.DisplayName;
Parameters = inner.Parameters.Select(p => new ParameterDescriptorValues(p)).ToList();
FilterDescriptors = inner.FilterDescriptors.Select(f => new FilterDescriptorValues(f)).ToList();
RouteConstraints = inner.RouteConstraints.Select(r => new RouteDataActionConstraintValues(r)).ToList();
AttributeRouteInfo = new AttributeRouteInfoValues(inner.AttributeRouteInfo);
RouteValueDefaults = inner.RouteValueDefaults.ToDictionary(i => i.Key, i => i.Value.ToString());
ActionConstraints = inner.ActionConstraints?.Select(a => new ActionConstraintValues(a))?.ToList();
HttpMethods =
inner.ActionConstraints?.OfType().SelectMany(c => c.HttpMethods).ToList();
Properties = inner.Properties.ToDictionary(i => i.Key.ToString(), i => i.Value.GetType());
var controllerActionDescriptor = inner as ControllerActionDescriptor;
if (controllerActionDescriptor != null)
{
MethodInfo = controllerActionDescriptor.MethodInfo;
ControllerName = controllerActionDescriptor.ControllerName;
ControllerTypeInfo = controllerActionDescriptor.ControllerTypeInfo;
}
}
///
/// The name of the action. See .
///
public string Name { get; }
///
/// A friendly name for the action. See .
///
public string DisplayName { get; }
///
/// The parameters of the action as .
/// See .
///
public List Parameters { get; }
///
/// The filters of the action as .
/// See .
///
public List FilterDescriptors { get; }
///
/// The route constraints of the action as .
/// See
///
public List RouteConstraints { get; }
///
/// The attribute route info of the action as .
/// See .
///
public AttributeRouteInfoValues AttributeRouteInfo { get; }
///
/// See .
///
public Dictionary RouteValueDefaults { get; }
///
/// The action constraints of the action as .
/// See .
///
public List ActionConstraints { get; }
///
/// The http methods this action supports.
///
public List HttpMethods { get; }
///
/// See .
///
public Dictionary Properties { get; }
///
/// The method info of the action if this is a .
/// See .
///
public MethodInfo MethodInfo { get; }
///
/// The name of the action's controller if this is a .
/// See .
///
public string ControllerName { get; }
///
/// The type info of the action's controller if this is a .
/// See .
///
public TypeInfo ControllerTypeInfo { get; }
public override string Format()
{
return LogFormatter.FormatStructure(this);
}
}
}