using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using MvcCallInterceptors.Controllers;
namespace MvcCallInterceptors.Interceptors
{
public class ActionInterceptorAttribute : Attribute
{
InterceptionOrder _interceptionOrder;
Type _interceptionForViewControllerType;
string _viewName;
string _actionName;
bool _breakExecutionOnException;
public ActionInterceptorAttribute(InterceptionOrder interceptionOrder, Type interceptionForViewControllerType, string actionName, bool breakExecutionOnException = true) :
this(interceptionOrder, interceptionForViewControllerType, string.Empty, actionName, breakExecutionOnException)
{
}
public ActionInterceptorAttribute(InterceptionOrder interceptionOrder, string viewName, string actionName, bool breakExecutionOnException = true) :
this(interceptionOrder, null, viewName, actionName, breakExecutionOnException)
{
}
public ActionInterceptorAttribute(string viewName, string actionName, bool breakExecutionOnException = true) :
this(InterceptionOrder.After, null, viewName, actionName, breakExecutionOnException)
{
}
public ActionInterceptorAttribute(Type interceptionForView, string actionName, bool breakExecutionOnException = true) :
this(InterceptionOrder.After, interceptionForView, string.Empty, actionName, breakExecutionOnException)
{
}
private ActionInterceptorAttribute(InterceptionOrder interceptionOrder, Type interceptionForViewControllerType, string viewName, string actionName, bool breakExecutionOnException)
{
if (string.IsNullOrWhiteSpace(actionName))
{
throw new ArgumentNullException("actionName");
}
if (interceptionForViewControllerType == null && string.IsNullOrWhiteSpace(viewName))
{
throw new Exception("Failed to initialize required parameters in ActionInterceptor decorator.");
}
if (interceptionForViewControllerType!=null && !interceptionForViewControllerType.IsSubclassOf(typeof(BaseMvcController)))
{
throw new Exception(string.Format("{0} is not valid for action interception.", interceptionForViewControllerType));
}
_interceptionOrder = interceptionOrder;
_interceptionForViewControllerType = interceptionForViewControllerType;
_viewName = viewName;
_actionName = actionName;
_breakExecutionOnException = breakExecutionOnException;
}
public InterceptionOrder InterceptionOrder
{
get { return _interceptionOrder; }
}
public Type InterceptionForViewControllerType
{
get { return _interceptionForViewControllerType; }
}
public string ViewName
{
get { return _viewName; }
}
public string ActionName
{
get { return _actionName; }
}
public bool BreakExecutionOnException
{
get { return _breakExecutionOnException; }
}
}
}