|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
namespace MvcCallInterceptors.Interceptors
{
public class InterceptorExecutionContext
{
IEnumerable<ActionInterceptor> _interceptors;
IList<ActionInterceptor> _readOnlyinterceptors;
IList<InterceptorExecutionStatus> _interceptorsExecutionStatus;
IDictionary<string, object> _interceptorsParameters;
InterceptorParasDictionary<string, object> _actionParameters;
ControllerContext context;
ActionInterceptor _currentActionInterceptor;
string _chainofExecutionTerminationMessage;
internal InterceptorExecutionContext(ControllerContext context, IEnumerable<ActionInterceptor> interceptors, IDictionary<string, object> parameters)
{
if (interceptors == null)
{
throw new ArgumentNullException("interceptors");
}
_interceptorsParameters = new Dictionary<string, object>();
_interceptors = interceptors;
_readOnlyinterceptors = interceptors.ToList().AsReadOnly();
_interceptorsExecutionStatus = new List<InterceptorExecutionStatus>(_readOnlyinterceptors.Count);
Exceptions = new List<Exception>();
for (int i = 0; i < _readOnlyinterceptors.Count; i++)
_interceptorsExecutionStatus.Add(InterceptorExecutionStatus.Pending);
_actionParameters = new InterceptorParasDictionary<string, object>(parameters);
}
internal void SetInterceptorStatus(InterceptorExecutionStatus interceptorExecutionStatus)
{
_interceptorsExecutionStatus[ActionInterceptors.IndexOf(CurrentInterceptor)] = interceptorExecutionStatus;
}
internal InterceptorExecutionStatus GetInterceptorStatus()
{
return _interceptorsExecutionStatus[ActionInterceptors.IndexOf(CurrentInterceptor)];
}
public InterceptorParasDictionary<string, object> ActionParameters
{
get { return _actionParameters; }
}
internal string ChainofExecutionTerminationMessage
{
get { return _chainofExecutionTerminationMessage; }
}
public List<Exception> Exceptions { get; set; }
public object InterceptorResult { get; set; }
/// <summary>
/// This would terminate whole execution chain but send result to the client up till evaluated by previous methods
/// </summary>
public bool CancelAllExecutions { get; set; }
public void CancelAllExecutionsWithTerminationMessage(string terminationMessage)
{
CancelAllExecutions = true;
_chainofExecutionTerminationMessage = terminationMessage;
}
public IList<ActionInterceptor> ActionInterceptors
{
get { return _readOnlyinterceptors; }
}
public ControllerContext ControllerContext
{
get { return context; }
}
public ActionInterceptor CurrentInterceptor
{
get
{
if (_currentActionInterceptor == null)
{
throw new Exception("No interceptor in execution state.");
}
return _currentActionInterceptor;
}
internal set
{
_currentActionInterceptor = value;
}
}
public ActionInterceptor ActionInterceptor
{
get
{
throw new System.NotImplementedException();
}
set
{
}
}
}
}
|
By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.
If a file you wish to view isn't highlighted, and is a text file (not binary), please
let us know and we'll add colourisation support for it.