本文整理汇总了C#中GetNextHandlerDelegate类的典型用法代码示例。如果您正苦于以下问题:C# GetNextHandlerDelegate类的具体用法?C# GetNextHandlerDelegate怎么用?C# GetNextHandlerDelegate使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
GetNextHandlerDelegate类属于命名空间,在下文中一共展示了GetNextHandlerDelegate类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Invoke
public IMethodReturn Invoke(IMethodInvocation input, GetNextHandlerDelegate getNext)
{
var methodName = input.MethodBase.Name;
var target = input.Target;
return getNext()(input, getNext);
}
示例2: 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);
}
示例3: Invoke
public IMethodReturn Invoke(IMethodInvocation input, GetNextHandlerDelegate getNext)
{
// Before invoking the method on the original target.
this.logger.Log(
"{0}: Invoking method {1}",
DateTime.Now.ToLongTimeString(),
input.MethodBase.Name);
// Invoke the next behavior in the chain.
var result = getNext()(input, getNext);
// After invoking the method on the original target.
if (result.Exception != null)
{
this.logger.Log(
"{0}: Method {1} threw exception {2}",
DateTime.Now.ToLongTimeString(),
input.MethodBase.Name,
result.Exception.Message);
}
else
{
this.logger.Log(
"{0}: Method {1} returned {2}",
DateTime.Now.ToLongTimeString(),
input.MethodBase.Name,
result.ReturnValue ?? "void");
}
return result;
}
示例4: Invoke
public IMethodReturn Invoke(IMethodInvocation input, GetNextHandlerDelegate getNext)
{
if (input.Arguments.Count > 0)
{
var arguments = new Argument[input.Arguments.Count];
for (int i = 0; i < input.Arguments.Count; i++)
{
arguments[i] = new Argument
{
Name = input.Arguments.ParameterName(i),
Value = input.Arguments[i]
};
}
_tape.RecordRequest(arguments, input.MethodBase.ReflectedType, input.MethodBase.Name);
}
Console.WriteLine("> Intercepting " + input.MethodBase.Name);
Console.WriteLine("> Intercepting " + input.MethodBase.ReflectedType);
IMethodReturn methodReturn = getNext()(input, getNext);
Console.WriteLine("> Intercepted return value: " + methodReturn.ReturnValue.GetType().Name);
if (methodReturn.ReturnValue != null)
{
_tape.RecordResponse(methodReturn.ReturnValue, input.MethodBase.ReflectedType, input.MethodBase.Name);
}
return methodReturn;
}
示例5: Invoke
public IMethodReturn Invoke(IMethodInvocation input, GetNextHandlerDelegate getNext)
{
if (this.targetMethodReturnsVoid(input) == true)
{
return (getNext()(input, getNext));
}
Object [] inputs = new Object [ input.Inputs.Count ];
for (Int32 i = 0; i < inputs.Length; ++i)
{
inputs [ i ] = input.Inputs [ i ];
}
String cacheKey = this.createCacheKey(input.MethodBase, inputs);
ObjectCache cache = MemoryCache.Default;
Object [] cachedResult = (Object []) cache.Get(cacheKey);
if (cachedResult == null)
{
IMethodReturn realReturn = getNext()(input, getNext);
if (realReturn.Exception == null)
{
this.addToCache(cacheKey, realReturn.ReturnValue);
}
return (realReturn);
}
IMethodReturn cachedReturn = input.CreateMethodReturn(cachedResult [ 0 ], input.Arguments);
return (cachedReturn);
}
示例6: Invoke
/// <exception cref="SapphireUserFriendlyException"><c>SapphireUserFriendlyException</c>.</exception>
public IMethodReturn Invoke(IMethodInvocation input, GetNextHandlerDelegate getNext)
{
var result = getNext()(input, getNext);
if (result.Exception == null)
return result;
throw new SapphireUserFriendlyException();
}
示例7: Invoke
public IMethodReturn Invoke(IMethodInvocation input, GetNextHandlerDelegate getNext)
{
if (this.Before == true)
{
String arguments = String.Join(",", input.Arguments.Cast<Object>().Select(a => a != null ? a.ToString() : "null").ToArray());
String beforeMessage = String.Format(this.Message, input.MethodBase, arguments);
Logger.Write(beforeMessage, this.Categories, this.Priority, 0, this.Severity);
}
IMethodReturn result = getNext()(input, getNext);
if (result.Exception != null)
{
if (this.Exception == true)
{
String afterMessage = String.Format(this.Message, input.MethodBase, result.Exception);
Logger.Write(afterMessage, this.Categories, this.Priority, 0, this.Severity);
}
}
else
{
if (this.After == true)
{
String afterMessage = String.Format(this.Message, input.MethodBase, result.ReturnValue);
Logger.Write(afterMessage, this.Categories, this.Priority, 0, this.Severity);
}
}
return (result);
}
示例8: Invoke
public IMethodReturn Invoke(IMethodInvocation input, GetNextHandlerDelegate getNext)
{
IMethodReturn methodReturn;
using (var transaction = this.Factory.GetCurrentSession().BeginTransaction())
{
// Here next attribute is called or original method, if no more attributes exist on operation
methodReturn = getNext()(input, getNext);
if (methodReturn.Exception == null || ShouldCommitDespiteOf(methodReturn.Exception))
{
transaction.Commit();
}
else
{
transaction.Rollback();
}
}
// Required in cases (exceptions>) when instead of normal values NHibernate returns lazy proxies.
this.Factory.GetCurrentSession().GetSessionImplementation().PersistenceContext.Unproxy(methodReturn.ReturnValue);
// Get back to previous attribute handler or back to caller
return methodReturn;
}
示例9: Invoke
public IMethodReturn Invoke(IMethodInvocation input, GetNextHandlerDelegate getNext)
{
if (TargetMethodReturnsVoid(input))
{
return getNext()(input, getNext);
}
var inputs = new object[input.Inputs.Count];
for (var i = 0; i < inputs.Length; ++i)
{
inputs[i] = input.Inputs[i];
}
var cacheKey = keyGenerator.CreateCacheKey(input.MethodBase, inputs);
var cachedResult = MemoryCache.Default.Get(cacheKey);
if (cachedResult == null)
{
var realReturn = getNext()(input, getNext);
if (realReturn.Exception == null)
{
AddToCache(cacheKey, realReturn.ReturnValue);
}
return realReturn;
}
var cachedReturn = input.CreateMethodReturn(cachedResult, input.Arguments);
return cachedReturn;
}
示例10: Invoke
/// <summary>
/// Implement this method to execute your handler processing.
/// </summary>
/// <param name="input">
/// Inputs to the current call to the target.
/// </param>
/// <param name="getNext">
/// Delegate to execute to get the next delegate in the handler chain.
/// </param>
/// <returns>
/// Return value from the target.
/// </returns>
public IMethodReturn Invoke(IMethodInvocation input, GetNextHandlerDelegate getNext)
{
IMethodReturn methodReturn;
try
{
Stopwatch stopwatch;
string className;
string methodName;
className = input.MethodBase.DeclaringType.Name;
methodName = input.MethodBase.Name;
stopwatch = new Stopwatch();
stopwatch.Start();
methodReturn = getNext()(input, getNext);
stopwatch.Stop();
Debug.WriteLine(string.Format("Executing on object {0} method {1} took: {2}ms", className, methodName, stopwatch.ElapsedMilliseconds));
}
catch (Exception exception)
{
throw;
}
return methodReturn;
}
示例11: Invoke
public IMethodReturn Invoke(IMethodInvocation input, GetNextHandlerDelegate getNext)
{
if (TargetMethodReturnsVoid(input))
{
return getNext()(input, getNext);
}
object[] inputs = new object[input.Inputs.Count];
for (int i = 0; i < inputs.Length; ++i)
{
inputs[i] = input.Inputs[i];
}
string cacheKey = KeyGenerator.CreateCacheKey(input.MethodBase, inputs);
object[] cachedResult = (object[])HttpRuntime.Cache.Get(cacheKey);
if (cachedResult == null)
{
IMethodReturn realReturn = getNext()(input, getNext);
if (realReturn.Exception == null)
{
AddToCache(cacheKey, realReturn.ReturnValue);
}
return realReturn;
}
IMethodReturn cachedReturn = input.CreateMethodReturn(cachedResult[0], input.Arguments);
return cachedReturn;
}
示例12: 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);
}
示例13: Invoke
public IMethodReturn Invoke(IMethodInvocation input, GetNextHandlerDelegate getNext)
{
ISession session = SessionFactory.GetCurrentSession();
ITransaction transaction = null;
if (IsolationLevel == IsolationLevel.Unspecified)
{
transaction = session.BeginTransaction();
}
else
{
transaction = session.BeginTransaction(IsolationLevel);
}
Debug.WriteLine("Started transaction");
IMethodReturn result = getNext()(input, getNext);
if (result.Exception != null)
{
transaction.Rollback();
Debug.WriteLine("Rolled transaction");
}
else
{
transaction.Commit();
Debug.WriteLine("Committed transaction");
}
transaction.Dispose();
return result;
}
示例14: Invoke
public IMethodReturn Invoke(IMethodInvocation input, GetNextHandlerDelegate getNext)
{
var cacheAttr = GetAttribute(input);
if (cacheAttr == null) return getNext()(input, getNext);
string cacheKey = GetCacheKey(cacheAttr, input);
ICache cacheHandler = CacheProxy.GetCacheHandler(cacheAttr.CacheMode);
switch (cacheAttr.CacheType)
{
case CacheType.Fetch:
if (cacheHandler.Contain(cacheAttr.Group, cacheKey))
{
return input.CreateMethodReturn(cacheHandler.Get(cacheAttr.Group, cacheKey));
}
else
{
var r = getNext()(input, getNext);
cacheHandler.Add(cacheAttr.Group, cacheKey, r.ReturnValue);
return r;
}
case CacheType.Clear:
cacheHandler.Remove(cacheAttr.Group, cacheKey);
return getNext()(input, getNext);
}
return getNext()(input, getNext);
}
示例15: Invoke
public IMethodReturn Invoke(IMethodInvocation input, GetNextHandlerDelegate getNext)
{
TransactionScope trans;
switch (transAttrib.Option)
{
case TransactinOptionEnum.Required:
trans = new TransactionScope(TransactionScopeOption.Required);
break;
case TransactinOptionEnum.RequiresNew:
trans = new TransactionScope(TransactionScopeOption.RequiresNew);
break;
case TransactinOptionEnum.NotSuppoted:
trans = new TransactionScope(TransactionScopeOption.Suppress);
break;
default:
{
trans = null;
break;
}
}
var result = getNext()(input, getNext);
if (trans != null)
{
trans.Complete();
}
return result;
//throw new NotImplementedException();
}