示例#1
0
        public override void Intercept(IInvocation invocation)
        {
            try {
                invocation.Proceed();
            } catch (Exception eOnInvocation) {
                if (Preferences.Log)
                {
//                    try {
                    if (invocation.TargetType.IsSubclassOf(typeof(UiaCommand)))
                    {
                        AutomationFactory.GetLogHelper(string.Empty).Error(eOnInvocation.Message);
//                            var cmdlet =
//                                (invocation.InvocationTarget as UiaCommand).Cmdlet;
//                            var logger =
//                                AutomationFactory.GetLogger();
//                            logger.LogCmdlet(cmdlet);
                    }
//                    }
//                    catch (Exception eLoggingAspect) {
//                        // Console.WriteLine(eLoggingAspect.Message);
//                    }
                }

                var eNewException =
                    new Exception("Class " + invocation.TargetType.Name + ", method " + invocation.Method.Name + ": " + eOnInvocation.Message);
                throw eNewException;
            }
        }
示例#2
0
        public override void Intercept(IInvocation invocation)
        {
            if (Preferences.Log)
            {
                try {
                    if (invocation.TargetType.IsSubclassOf(typeof(UiaCommand)))
                    {
                        var cmdlet =
                            (invocation.InvocationTarget as UiaCommand).Cmdlet;
                        var logger =
                            AutomationFactory.GetLogHelper(string.Empty);
                        logger.LogCmdlet(cmdlet);
                    }
                }
                catch (Exception) {
                    // Console.WriteLine(eLoggingAspect.Message);
                }
            }

            invocation.Proceed();
        }
示例#3
0
        public virtual void LogMethodCall(string methodName, object[] arguments)
        {
            if (string.IsNullOrEmpty(methodName))
            {
                return;
            }

            var excludeList = new List <string> {
                "get_Current",
                "get_Cached",
                "GetSourceElement",
                "SetSourceElement",
                "FindAll",
                "FindFirst",
                "GetSupportedPatterns",
                "GetCurrentPattern",
                "Equals",
                "GetPatternPropertyValue",
                "get_CachedChildren",
                "get_CachedParent",
                "get_Control",
                "get_Descendants",
                "get_Children",
                "get_Mouse",
                "get_Keyboard",
                "OnStartHook",
                "BeforeSearchHook",
                // "SearchForElements(UIAutomation.WindowSearcherData)
                "SearchForElements",
                "AfterSearchHook",
                "OnFailureHook",
                "OnSuccessHook",
                "GetCurrent",
                "GetCached",
                "GetCachedChildren",
                "GetCachedParent"
            };

            if (!excludeList.Contains(methodName))
            {
                if (methodName.Contains("get_"))
                {
                    methodName = methodName.Replace("get_", string.Empty);
                }
                else if (methodName.Contains("set_"))
                {
                    methodName = methodName.Replace("set_", string.Empty);
                }
                else
                {
                    methodName += "(";
                    // foreach (var argument in invocation.Arguments) {
                    foreach (var argument in arguments)
                    {
                        methodName += argument.ToString();
                        methodName += ",";
                    }
                    if (!string.IsNullOrEmpty(methodName) && methodName.Substring(methodName.Length - 1) == ",")
                    {
                        methodName = methodName.Substring(0, methodName.Length - 1);
                    }
                    methodName += ")";
                }
                if (!string.IsNullOrEmpty(methodName))
                {
                    AutomationFactory.GetLogHelper(string.Empty).Info(methodName);
                }
            }
        }