Exemplo n.º 1
0
    void ProcessMethod(MethodDefinition method)
    {
        if (method.IsYield())
        {
            if (method.ContainsTimeAttribute())
            {
                LogError("Could not process '" + method.FullName + "' since methods that yield are currently not supported. Please remove the [Time] attribute from that method.");
                return;
            }
            LogInfo("Skipping '" + method.FullName + "' since methods that yield are not supported.");
            return;
        }


        if (method.IsAsync())
        {
            var asyncProcessor = new AsyncMethodProcessor
            {
                ModuleWeaver = this,
                Method       = method,
            };

            asyncProcessor.Process();
            return;
        }
        var methodProcessor = new MethodProcessor
        {
            ModuleWeaver = this,
            Method       = method,
        };

        methodProcessor.Process();
    }
Exemplo n.º 2
0
    void ProcessMethod(MethodDefinition method)
    {
        if (method.IsYield())
        {
            if (method.ContainsTimeAttribute())
            {
                LogError("Could not process '" + method.FullName + "' since methods that yield are currently not supported. Please remove the [Time] attribute from that method.");
                return;
            }
            LogInfo("Skipping '" + method.FullName + "' since methods that yield are not supported.");
            return;
        }

        if (method.IsAsync())
        {
            var asyncProcessor = new AsyncMethodProcessor
            {
                ModuleWeaver = this,
                Method = method,
            };

            asyncProcessor.Process();
            return;
        }
        var methodProcessor = new MethodProcessor
        {
            ModuleWeaver = this,
            Method = method,
        };

        methodProcessor.Process();
    }
Exemplo n.º 3
0
 public override void LeaveMethod(Method method)
 {
     if (ContextAnnotations.IsAsync(method))
     {
         var entity    = (InternalMethod)method.Entity;
         var processor = new AsyncMethodProcessor(Context, entity);
         processor.Run();
     }
     else
     {
         base.LeaveMethod(method);
     }
 }
Exemplo n.º 4
0
    void ProcessMethod(MethodDefinition method)
    {
        if (method.IsYield())
        {
            if (method.ContainsTimeAttribute())
            {
                WriteError("Could not process '" + method.FullName + "' since methods that yield are currently not supported. Please remove the [Time] attribute from that method.");
                return;
            }

            WriteInfo("Skipping '" + method.FullName + "' since methods that yield are not supported.");
            return;
        }

        var timeAttribute = method.GetTimeAttribute();

        if (timeAttribute != null)
        {
            var format = timeAttribute.ConstructorArguments.FirstOrDefault().Value as string;
            if (!string.IsNullOrWhiteSpace(format))
            {
                var hasErrors = false;

                var logWithMessageMethodUsingLong     = LogWithMessageMethodUsingLong;
                var logWithMessageMethodUsingTimeSpan = LogWithMessageMethodUsingTimeSpan;

                if (logWithMessageMethodUsingLong is null && logWithMessageMethodUsingTimeSpan is null)
                {
                    hasErrors = true;
                    WriteError("Feature with parameter formatting is being used, but no useable log method can be found. Either disable the feature usage or update the logger signature to 'public static void Log(MethodBase methodBase, long milliseconds, string message)' or 'public static void Log(MethodBase methodBase, TimeSpan elapsed, string message)'");
                }

                var info = parameterFormattingProcessor.ParseParameterFormatting(format);
                for (var i = 0; i < info.ParameterNames.Count; i++)
                {
                    var parameterName = info.ParameterNames[i];
                    if (string.Equals(parameterName, "this"))
                    {
                        if (method.IsStatic)
                        {
                            hasErrors = true;
                            WriteError($"Could not process '{method.FullName}' because the format uses 'this' in a static context.");
                        }
                    }
                    else
                    {
                        var containsParameter = method.Parameters.Any(x => x.Name.Equals(parameterName));
                        if (!containsParameter)
                        {
                            hasErrors = true;
                            WriteError($"Could not process '{method.FullName}' because the format uses '{parameterName}' which is not available as method parameter.");
                        }
                    }
                }

                if (hasErrors)
                {
                    return;
                }
            }
        }

        if (method.IsAsync())
        {
            var asyncProcessor = new AsyncMethodProcessor
            {
                ModuleWeaver = this,
                Method       = method,
            };

            asyncProcessor.Process();
            return;
        }

        var methodProcessor = new MethodProcessor
        {
            ModuleWeaver = this,
            Method       = method,
        };

        methodProcessor.Process();
    }