本文整理汇总了C#中MethodExecutionArgs类的典型用法代码示例。如果您正苦于以下问题:C# MethodExecutionArgs类的具体用法?C# MethodExecutionArgs怎么用?C# MethodExecutionArgs使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
MethodExecutionArgs类属于命名空间,在下文中一共展示了MethodExecutionArgs类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: OnEntry
public override void OnEntry(MethodExecutionArgs args)
{
if (!ValidationFlags.HasFlag(ValidationFlags.Arguments)) return;
var method = MethodInformation.GetMethodInformation(args);
if (method == null
|| !method.HasArguments
|| (!ValidationFlags.HasFlag(ValidationFlags.NonPublic) && !method.IsPublic)
|| (!ValidationFlags.HasFlag(ValidationFlags.Properties) && method.IsProperty)
|| (!ValidationFlags.HasFlag(ValidationFlags.Methods) && !method.IsProperty)
// TODO: What about events?
)
return;
var invalidArgument = (from arg in args.Method.GetParameters()
where arg.MayNotBeNull() && args.Arguments[arg.Position] == null
select arg).FirstOrDefault();
if (invalidArgument == null) return;
if (method.IsProperty)
{
throw new ArgumentNullException(invalidArgument.Name,
String.Format(CultureInfo.InvariantCulture,
"Cannot set the value of property '{0}' to null.",
method.Name));
}
throw new ArgumentNullException(invalidArgument.Name);
}
示例2: OnEntry
public override void OnEntry(MethodExecutionArgs args)
{
var cmdlet = args.Instance as CmdletProvider;
if( null == cmdlet )
{
return;
}
string parameters = "";
if( null != args.Arguments && args.Arguments.Any() )
{
parameters = String.Join("; ", args.Arguments.ToList().ConvertAll(a => (a ?? "null").ToString()).ToArray());
}
try
{
var s = String.Format(
"[{0}] >> Entering [{1}] ( [{2}] )",
args.Instance.GetType().FullName,
args.Method.Name,
parameters);
cmdlet.WriteDebug(s);
}
catch
{
}
}
示例3: OnEntry
// Executed at runtime, before the method.
public override void OnEntry( MethodExecutionArgs eventArgs )
{
// Compose the cache key.
string key = this.formatStrings.Format(
eventArgs.Instance, eventArgs.Method, eventArgs.Arguments.ToArray() );
// Test whether the cache contains the current method call.
lock ( cache )
{
object value;
if ( !cache.TryGetValue( key, out value ) )
{
// If not, we will continue the execution as normally.
// We store the key in a state variable to have it in the OnExit method.
eventArgs.MethodExecutionTag = key;
}
else
{
// If it is in cache, we set the cached value as the return value
// and we force the method to return immediately.
eventArgs.ReturnValue = value;
eventArgs.FlowBehavior = FlowBehavior.Return;
}
}
}
示例4: OnException
public override void OnException(MethodExecutionArgs args)
{
Console.WriteLine(String.Format("Exception in :[{0}] , Message:[{1}]", args.Method, args.Exception.Message));
args.FlowBehavior = FlowBehavior.Continue;
base.OnException(args);
}
示例5: OnException
public override void OnException(MethodExecutionArgs args)
{
InternalError internalError;
HttpStatusCode httpStatusCode;
var exceptionType = args.Exception.GetType();
if (exceptionType == typeof(KeyNotFoundException))
{
httpStatusCode = HttpStatusCode.NotFound;
var keyNotFoundException = args.Exception as KeyNotFoundException;
internalError = InternalError.CreateNotFound(keyNotFoundException);
}
else if (exceptionType == typeof(ValidationException))
{
httpStatusCode = HttpStatusCode.BadRequest;
var validationException = args.Exception as ValidationException;
internalError = InternalError.CreateValidation(validationException);
}
else if (exceptionType == typeof(AuthenticationException))
{
httpStatusCode = HttpStatusCode.Unauthorized;
var authenticationException = args.Exception as AuthenticationException;
internalError = InternalError.CreateAuthentication(authenticationException);
}
else
{
httpStatusCode = HttpStatusCode.InternalServerError;
internalError = InternalError.CreateUnexpected();
}
_log.Error(internalError.Id, args.Exception);
throw new WebFaultException<InternalError>(internalError, httpStatusCode);
}
示例6: OnEntry
public override void OnEntry(MethodExecutionArgs args)
{
// It is equiavlent to the start of the "try"
Stopwatch sw = new Stopwatch();
args.MethodExecutionTag = sw;
sw.Start();
}
示例7: OnEntry
/// <summary>
/// Called at runtime before the method is executed.
/// </summary>
/// <param name="eventArgs">Event arguments.</param>
public override void OnEntry( MethodExecutionArgs eventArgs )
{
Trace.TraceInformation(
"Entering " + this.strings.Format( eventArgs.Instance, eventArgs.Method, eventArgs.Arguments.ToArray() )
);
Trace.Indent();
}
示例8: OnSuccess
public override void OnSuccess(MethodExecutionArgs args)
{
var status = args.ReturnValue as Status;
if (status != null && status.Success)
{
var campaignId = AspectUtility.GetArgument<string>(args, AspectUtility.GetArgumentPosition(args, "campaignId"));
var affiliateId = AspectUtility.GetArgument<string>(args, AspectUtility.GetArgumentPosition(args, "affiliateId"));
var accessKeyId = AspectUtility.GetArgument<string>(args, AspectUtility.GetArgumentPosition(args, "accessKeyId"));
Guid validCampaignId;
Guid validAccessKeyId;
if (Guid.TryParse(campaignId, out validCampaignId) && Guid.TryParse(accessKeyId, out validAccessKeyId))
{
using (var context = new DataContext())
{
var accessKey = context.AccessKeys.SingleOrDefault(key => key.Id == validAccessKeyId);
if (accessKey != null && accessKey.UserId != null)
{
processAffiliate(context, accessKey.UserId ?? Guid.Empty, validCampaignId, affiliateId);
}
}
}
}
}
示例9: OnException
public override void OnException(MethodExecutionArgs args)
{
object key = OperationContext.Current.IncomingMessageHeaders.MessageId;
ObjectServiceExceptionStore.SetException(key, args.Exception.Message);
throw args.Exception;
}
示例10: OnEntry
public override void OnEntry(MethodExecutionArgs args)
{
_methodKey = args.Instance.ToString() + "." + args.Method.Name;
System.Diagnostics.Stopwatch w = new System.Diagnostics.Stopwatch();
w.Start();
args.MethodExecutionTag = w;
}
示例11: OnExit
public override void OnExit(MethodExecutionArgs args)
{
System.Diagnostics.Stopwatch w = (System.Diagnostics.Stopwatch) args.MethodExecutionTag;
w.Stop();
Metrics.Timer(_methodKey, (int)w.ElapsedMilliseconds);
}
示例12: OnEntry
public override void OnEntry(MethodExecutionArgs args)
{
args.MethodExecutionTag = Stopwatch.StartNew();
//private static readonly ILog Log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
Logging.Info("Called Entry " + args.Method.Name);
base.OnEntry(args);
}
示例13: Current
int Current( MethodExecutionArgs args, int move )
{
var dictionary = cache.Get( args.Instance ?? args.Method.DeclaringType );
var key = Keys.For( args );
var result = dictionary[key] = dictionary.Ensure( key, i => 0 ) + move;
return result;
}
示例14: OnEntry
public override void OnEntry( MethodExecutionArgs eventArgs )
{
TransactionOptions options = new TransactionOptions();
options.IsolationLevel = IsolationLevel.ReadCommitted;
options.Timeout = TimeSpan.FromSeconds( this.timeout );
eventArgs.MethodExecutionTag = new TransactionScope( this.transactionScopeOption, options );
}
示例15: OnEntry
public override void OnEntry(MethodExecutionArgs args)
{
_start = DateTime.Now;
//note: this is a terrible example, aspects should be "method agnostic"
//but I'm doing it to prove a point
Console.WriteColorLine(string.Format("Starting search for {0}", args.Arguments[0]), ConsoleColor.Blue);
}