コード例 #1
0
        /// <summary>
        /// Creates the IPC request.
        /// </summary>
        /// <param name="methodName">Name of the method.</param>
        /// <param name="args">The arguments to the method.</param>
        /// <returns>IpcRequest object</returns>
        protected static IpcRequest CreateIpcRequest(string methodName, params object[] args)
        {
            MethodBase method = null;

            // Try to find the matching method based on name and args
            try
            {
                if (args.All(x => x != null))
                {
                    method = typeof(FactoryOrchestratorClient).GetMethod(methodName, args.Select(x => x.GetType()).ToArray());
                }

                if (method == null)
                {
                    method = typeof(FactoryOrchestratorClient).GetMethod(methodName);
                }
            }
            catch (Exception)
            {
                method = null;
            }

            if (method == null)
            {
                // Multiple methods with the same name were found or no method was found, try to find the unique method via stack trace
                var frame = new StackTrace().GetFrames().Where(x => x.GetMethod()?.Name == methodName);

                if (!frame.Any())
                {
                    throw new Exception(string.Format(CultureInfo.CurrentCulture, Resources.NoMethodFound, methodName));
                }
                if (frame.Count() > 1)
                {
                    throw new Exception(string.Format(CultureInfo.CurrentCulture, Resources.TooManyMethodsFound, methodName));
                }

                method = frame.First().GetMethod();
            }

            var methodParams   = method.GetParameters();
            var parameterTypes = new IpcRequestParameterType[methodParams.Length];

            for (int i = 0; i < methodParams.Length; i++)
            {
                parameterTypes[i] = new IpcRequestParameterType(methodParams[i].ParameterType);
            }

            var request = new IpcRequest()
            {
                MethodName           = methodName,
                Parameters           = args,
                ParameterTypesByName = parameterTypes
            };

            return(request);
        }
コード例 #2
0
ファイル: DbgWin.cs プロジェクト: Mashrien/PackRat
        public static void Log(string line, LogType lt)
        {
            StackFrame[] sf         = new StackTrace().GetFrames();
            string       callerName = "";
            string       className  = "";

            for (int i = 1; i < sf.Count() - 1; i++)
            {
                StackFrame f = sf[i];
                if (f.GetMethod().Name == ".ctor")
                {
                    callerName = f.GetMethod().ReflectedType.Name;
                    className  = f.GetMethod().ReflectedType.FullName;
                    if (callerName.ToUpper() == "LOG")
                    {
                        continue;
                    }
                    break;
                }
                if (f.GetMethod().Name == "Log")
                {
                    continue;
                }
                callerName = f.GetMethod().Name;
                className  = f.GetMethod().ReflectedType.FullName;
                if (callerName.ToUpper() == "LOG")
                {
                    continue;
                }
                break;
            }

            className = className.Remove(0, className.IndexOf('.') + 1);
            string memberName = className + "->" + callerName + "";

            if (processing)
            {
                Program.LogWin.LogQueueBusy.Add(new LogQueueItem(line, lt, memberName));
                return;
            }
            else
            {
                if (Program.LogWin.LogQueueBusy.Count != 0)
                {
                    foreach (LogQueueItem li in Program.LogWin.LogQueueBusy)
                    {
                        Program.LogWin.LogQueue.Add(li);
                    }
                    Program.LogWin.LogQueueBusy.Clear();
                }
            }

            Program.LogWin.LogQueue.Add(new LogQueueItem(line, lt, memberName));
        }
コード例 #3
0
        /// <summary>
        /// Send a diagnostic event corresponding to a log
        /// </summary>
        /// <param name="message">The message</param>
        /// <param name="level">The severity level of the diagnostic event</param>
        /// <param name="correlationId">current correlation id</param>
        private static void SendDiagnosticEvent(string message, LogLevel level, Guid correlationId)
        {
            //the logger could potentially reach a circular call when sending diagnostic events, don't send yet another diagnostic event if that happens
            var stackTraceFrames   = new StackTrace().GetFrames();
            int currentMethodCount = stackTraceFrames.Count(frame => frame.GetMethod().Equals(stackTraceFrames[0].GetMethod()));

            if (currentMethodCount > 1)
            {
                return;
            }

            SystemEvents.DispatchDiagnosicEvent(message, level);
        }
コード例 #4
0
        private static string GetStackFrameString()
        {
            var frames        = new StackTrace().GetFrames();
            var method        = "?";
            var declaringType = "?";

            // Frames:
            //     0: Current method (GetStackFrameString)
            //     1: Caller
            //     2: Caller of Caller
            //     etc
            for (var frameNum = 5; frameNum < frames.Count() && frameNum < 15; frameNum++)
            {
                var theMethod = frames[frameNum].GetMethod();
                if (theMethod.DeclaringType != null && theMethod.DeclaringType.Name != "Check" && theMethod.DeclaringType.Name != "UpdateDelegates")
                {
                    method        = theMethod.Name;
                    declaringType = theMethod.DeclaringType.FullName;
                    break;
                }
            }
            return(string.Format("{0}.{1}.", declaringType, method));
        }