本文整理汇总了C#中IMethodInvocation.CreateExceptionMethodReturn方法的典型用法代码示例。如果您正苦于以下问题:C# IMethodInvocation.CreateExceptionMethodReturn方法的具体用法?C# IMethodInvocation.CreateExceptionMethodReturn怎么用?C# IMethodInvocation.CreateExceptionMethodReturn使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IMethodInvocation
的用法示例。
在下文中一共展示了IMethodInvocation.CreateExceptionMethodReturn方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Invoke
public IMethodReturn Invoke(IMethodInvocation input, GetNextHandlerDelegate getNext)
{
Dictionary<Type, Validator> validators = new Dictionary<Type, Validator>();
Int32 i = 0;
ValidationResults results = new ValidationResults();
IMethodReturn result = null;
foreach (Type type in input.MethodBase.GetParameters().Select(p => p.ParameterType))
{
if (validators.ContainsKey(type) == false)
{
validators[type] = ValidationFactory.CreateValidator(type, this.Ruleset);
}
Validator validator = validators[type];
validator.Validate(input.Arguments[i], results);
++i;
}
if (results.IsValid == false)
{
result = input.CreateExceptionMethodReturn(new Exception(String.Join(Environment.NewLine, results.Select(r => r.Message).ToArray())));
}
else
{
result = getNext()(input, getNext);
}
return (result);
}
示例2: Invoke
public IMethodReturn Invoke(IMethodInvocation input, GetNextHandlerDelegate getNext)
{
var results = input.Arguments.Cast<object>().SelectMany(entity => validator.Validate(entity));
return !results.Any()
? getNext()(input, getNext) //no errors
: input.CreateExceptionMethodReturn(new ValidationFailedException(results));
}
示例3: InvokeINotifyPropertyChangedMethod
private IMethodReturn InvokeINotifyPropertyChangedMethod(IMethodInvocation input)
{
if (input.MethodBase.DeclaringType == typeof(INotifyPropertyChanged))
{
switch (input.MethodBase.Name)
{
case "add_PropertyChanged":
lock (handlerLock)
{
handler = (PropertyChangedEventHandler)Delegate.Combine(handler, (Delegate)input.Arguments[0]);
}
break;
case "remove_PropertyChanged":
lock (handlerLock)
{
handler = (PropertyChangedEventHandler)Delegate.Remove(handler, (Delegate)input.Arguments[0]);
}
break;
default:
return input.CreateExceptionMethodReturn(new InvalidOperationException());
}
return input.CreateMethodReturn(null);
}
return null;
}
示例4: Invoke
/// <summary>
/// Invokes the specified input.
/// </summary>
/// <param name="input">The input.</param>
/// <param name="getNext">The get next.</param>
/// <returns>The method return result.</returns>
public IMethodReturn Invoke(IMethodInvocation input, GetNextHandlerDelegate getNext)
{
foreach (var argument in input.Arguments)
{
string target = argument as string;
if (string.IsNullOrEmpty(target))
{
continue;
}
if (Regex.Match(target, @"[a-z0-9!#$%&'*+/=?^_`{|}~-]+(?:\.[a-z0-9!#$%&'*+/=?^_`{|}~-]+)*@(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?").Success)
{
continue;
}
ArgumentException argumentException = new ArgumentException("Invalid e-mail format", input.MethodBase.Name);
Log.Error("Argument exception", argumentException, this);
return input.CreateExceptionMethodReturn(argumentException);
}
return getNext()(input, getNext);
}
示例5: Invoke
public IMethodReturn Invoke(IMethodInvocation input, GetNextInterceptionBehaviorDelegate getNext)
{
var methodReturn = InvokeINotifyPropertyChangedMethod(input);
if (methodReturn != null)
{
return methodReturn;
}
methodReturn = getNext()(input, getNext);
if (methodReturn.Exception == null && input.MethodBase.IsSpecialName)
{
var property = GetPropertyInfoForSetMethod(input);
if (property != null)
{
var currentHandler = this.handler;
if (currentHandler != null)
{
try
{
currentHandler(input.Target, new PropertyChangedEventArgs(property.Name));
}
catch (Exception e)
{
return input.CreateExceptionMethodReturn(e);
}
}
}
}
return methodReturn;
}
示例6: Invoke
public IMethodReturn Invoke(
IMethodInvocation input,
GetNextHandlerDelegate getNext)
{
if (this.allowedRoles.Length > 0)
{
IPrincipal currentPrincipal = Thread.CurrentPrincipal;
if (currentPrincipal != null)
{
bool allowed = false;
foreach (string role in this.allowedRoles)
{
if (allowed = currentPrincipal.IsInRole(role))
{
break;
}
}
if (!allowed)
{
// short circuit the call
return input.CreateExceptionMethodReturn(
new UnauthorizedAccessException(
"User not allowed to invoke the method"));
}
}
}
return getNext()(input, getNext);
}
示例7: Invoke
public IMethodReturn Invoke(IMethodInvocation input, GetNextInterceptionBehaviorDelegate getNext)
{
if (!this.IsValidUser())
{
return input.CreateExceptionMethodReturn(new UnauthorizedAccessException("..."));
}
return getNext()(input, getNext);
}
示例8: Invoke
public IMethodReturn Invoke(IMethodInvocation input, GetNextHandlerDelegate getNext)
{
User user = input.Inputs[0] as User;
if (user.PassWord.Length < 0) {
return input.CreateExceptionMethodReturn(new Exception("密码长度不能小于10位"));
}
Console.WriteLine("参数检测无误");
return getNext()(input, getNext);
}
示例9: Invoke
/// <summary>
/// Handler de invocação do método com atributo
/// </summary>
/// <param name="input">Informações da chamada</param>
/// <param name="getNext">Próximo handler de execução do método</param>
/// <returns>Caso estejamos fora dum UoW, retorna exception, caso contrário segue a execução</returns>
public IMethodReturn Invoke(IMethodInvocation input, GetNextHandlerDelegate getNext)
{
if (UnitOfWork.Current == null)
{
return input.CreateExceptionMethodReturn(new Exception("Método " + input.MethodBase.Name + " chamado fora de UnitOfWork."));
}
// Retornamos normalmente
return getNext()(input, getNext);
}
示例10: Invoke
public IMethodReturn Invoke(IMethodInvocation input, GetNextHandlerDelegate getNext)
{
for (int i = 0; i < input.Inputs.Count; i++) {
object target = input.Inputs[i];
if (target == null) {
ParameterInfo parameterInfo = input.Inputs.GetParameterInfo(i);
ArgumentNullException ex = new ArgumentNullException(parameterInfo.Name);
return input.CreateExceptionMethodReturn(ex);
}
}
return getNext()(input, getNext);
}
示例11: Invoke
public IMethodReturn Invoke(IMethodInvocation input, GetNextHandlerDelegate getNext)
{
if (input.Inputs.Count == 0) { return getNext()(input, getNext); }
Order order = input.Inputs[0] as Order;
if (order == null) { return getNext()(input, getNext); }
if (order.OrderDate > DateTime.Today)
{
return input.CreateExceptionMethodReturn(new OrderValidationException("The order date is later than the current date!"));
}
if (order.Items.Count == 0)
{
return input.CreateExceptionMethodReturn(new OrderValidationException("There are not any items for the order!"));
}
if (this.ValidateSupplier)
{
if (!LegalSuppliers.Contains<string>(order.Supplier))
{
return input.CreateExceptionMethodReturn(new OrderValidationException("The supplier is inllegal!"));
}
}
if (this.ValidateTotalPrice)
{
double totalPrice = 0;
foreach (OrderItem item in order.Items)
{
totalPrice += item.Quantity * item.UnitPrice;
}
if (totalPrice != order.TotalPrice)
{
return input.CreateExceptionMethodReturn(new OrderValidationException("The sum of the order item is not equal to the order total price!"));
}
}
return getNext()(input, getNext);
}
示例12: Invoke
public IMethodReturn Invoke(IMethodInvocation input, GetNextHandlerDelegate getNext)
{
IMethodReturn result = null;
if (Transaction.Current == null)
{
result = input.CreateExceptionMethodReturn(new Exception("Ambient transaction required"));
}
else
{
result = getNext()(input, getNext);
}
return (result);
}
示例13: Invoke
/// <summary>
/// Performs the operation of the handler.
/// </summary>
/// <param name="input">Input to the method call.</param>
/// <param name="getNext">Delegate used to get the next delegate in the call handler pipeline.</param>
/// <returns>Returns value from the target method, or an <see cref="UnauthorizedAccessException"/>
/// if the call fails the authorization check.</returns>
public IMethodReturn Invoke(IMethodInvocation input, GetNextHandlerDelegate getNext)
{
if (input == null) throw new ArgumentNullException("input");
if (getNext == null) throw new ArgumentNullException("getNext");
ReplacementFormatter formatter = new MethodInvocationFormatter(input);
if (!this.AuthorizationProvider.Authorize(Thread.CurrentPrincipal, formatter.Format(OperationName)))
{
UnauthorizedAccessException unauthorizedExeption =
new UnauthorizedAccessException(Resources.AuthorizationFailed);
return input.CreateExceptionMethodReturn(unauthorizedExeption);
}
return getNext().Invoke(input, getNext);
}
示例14: Invoke
public IMethodReturn Invoke(IMethodInvocation input, GetNextHandlerDelegate getNext)
{
try
{
using (TransactionScope transactionScope = new TransactionScope())
{
IMethodReturn methodReturn = getNext()(input, getNext);
transactionScope.Complete();
return methodReturn;
}
}
catch (Exception ex)
{
return input.CreateExceptionMethodReturn(ex);
}
}
示例15: Invoke
public IMethodReturn Invoke(IMethodInvocation input, GetNextHandlerDelegate getNext)
{
bool autenticado = true;
autenticado = ControladorDeSessao.EstaAutenticado();
if (autenticado)
{
IMethodReturn result = getNext()(input, getNext);
return result;
}
else
{
// TODO: criar tratamento de erro para autenticacao
return input.CreateExceptionMethodReturn(new ApplicationValidationErrorsException("Usuário não autenticado."));
}
}