static Type GetEntryType()
        {
            var stackTraceToExamine = new StackTrace();
            var entryAssembly = Assembly.GetEntryAssembly();
            if (entryAssembly?.EntryPoint != null)
            {
                return entryAssembly.EntryPoint.ReflectedType;
            }

            StackFrame targetFrame = null;

            var stackFrames = new StackTrace().GetFrames();
            if (stackFrames != null)
            {
                targetFrame =
                    stackFrames.FirstOrDefault(
                        f => typeof(HttpApplication).IsAssignableFrom(f.GetMethod().DeclaringType));
            }

            if (targetFrame != null)
            {
                return targetFrame.GetMethod().ReflectedType;
            }

            stackFrames = stackTraceToExamine.GetFrames();
            if (stackFrames != null)
            {
                targetFrame =
                    stackFrames.FirstOrDefault(
                        f =>
                        {
                            var declaringType = f.GetMethod().DeclaringType;
                            return declaringType != typeof(EndpointConfiguration);
                        });
            }

            if (targetFrame == null)
            {
                targetFrame = stackFrames.FirstOrDefault(
                    f => f.GetMethod().DeclaringType.Assembly != typeof(EndpointConfiguration).Assembly);
            }

            if (targetFrame != null)
            {
                return targetFrame.GetMethod().ReflectedType;
            }
            throw new Exception("Could not derive EndpointName");
        }
예제 #2
0
        /// <summary>
        /// Gets the name of this endpoint
        /// </summary>
        /// <returns></returns>
        public static string Get()
        {
            var entryAssembly = Assembly.GetEntryAssembly();
            if (entryAssembly != null && entryAssembly.EntryPoint != null)
            {
                return entryAssembly.EntryPoint.ReflectedType.Namespace ??
                       entryAssembly.EntryPoint.ReflectedType.Assembly.GetName().Name;
            }

            var stackFrames = new StackTrace().GetFrames();
            StackFrame targetFrame = null;
            if (stackFrames != null)
            {
                targetFrame =
                    stackFrames.FirstOrDefault(
                        f => typeof (HttpApplication).IsAssignableFrom(f.GetMethod().DeclaringType));
            }

            if (targetFrame != null)
                return targetFrame.GetMethod().ReflectedType.Namespace ??
                       targetFrame.GetMethod().ReflectedType.Assembly.GetName().Name;

            throw new InvalidOperationException(
                "No endpoint name could be generated, please specify your own convention using Configure.DefineEndpointName(...)");
        }
예제 #3
0
        void Initialize()
        {
            if (initialized)
                return;
            try
            {
                var entryAssembly = Assembly.GetEntryAssembly();
                if (entryAssembly != null && entryAssembly.EntryPoint != null)
                {
                    entryType = entryAssembly.EntryPoint.ReflectedType;
                    return;
                }

                StackFrame targetFrame = null;

                var stackFrames = new StackTrace().GetFrames();
                if (stackFrames != null)
                {
                    targetFrame =
                        stackFrames.FirstOrDefault(
                            f => typeof(HttpApplication).IsAssignableFrom(f.GetMethod().DeclaringType));
                }

                if (targetFrame != null)
                {
                    entryType = targetFrame.GetMethod().ReflectedType;
                    return;
                }

                if (stackTraceToExamine != null)
                {
                    stackFrames = stackTraceToExamine.GetFrames();
                    if (stackFrames != null)
                    {
                        targetFrame =
                            stackFrames.FirstOrDefault(
                                f =>
                                {
                                    var declaringType = f.GetMethod().DeclaringType;
                                    return declaringType != typeof(Configure) && declaringType != typeof(BusConfiguration);
                                });
                    }
                }

                if (targetFrame == null)
                    targetFrame = stackFrames.FirstOrDefault(
                       f => f.GetMethod().DeclaringType.Assembly != typeof(Configure).Assembly);

                if (targetFrame != null)
                {
                    entryType = targetFrame.GetMethod().ReflectedType;
                }
            }
            finally
            {
                initialized = true;
            }
        }
        private SocketPurpose GetSocketPurpose()
        {
            var stackFrames = new StackTrace(1).GetFrames();
            if (stackFrames
                    .FirstOrDefault(sf => sf.GetMethod().Name == CreateClusterMonitorSendingSocketMethod) != null)
            {
                return SocketPurpose.ClusterMonitorSendingSocket;
            }
            if (stackFrames
                    .FirstOrDefault(sf => sf.GetMethod().Name == CreateClusterMonitorSubscriptionSocketMethod) != null)
            {
                return SocketPurpose.ClusterMonitorSubscriptionSocket;
            }
            if (stackFrames
                    .FirstOrDefault(sf => sf.GetMethod().Name == CreateRouterCommunicationSocketMethod) != null)
            {
                return SocketPurpose.RouterCommunicationSocket;
            }

            throw new Exception($"Socket creation method is unexpected: {string.Join(" @ ", stackFrames.Select(sf => sf.ToString()))}");
        }
        public static string GetCurrentPositionText()
        {
            try
            {
                var frames = new StackTrace(true).GetFrames();
                if (frames != null)
                {
                    var featureFileFrame = frames.FirstOrDefault(f =>
                    {
                        var fileName = f.GetFileName();
                        return fileName != null && fileName.EndsWith(".feature");
                    });

                    if (featureFileFrame != null)
                    {
                        var lines = File.ReadAllLines(featureFileFrame.GetFileName());
                        const int frameSize = 20;
                        var currentLine = featureFileFrame.GetFileLineNumber() - 1;
                        var minLine = Math.Max(0, currentLine - frameSize);
                        var maxLine = Math.Min(lines.Length - 1, currentLine + frameSize);

                        for (var lineNo = currentLine - 1; lineNo >= minLine; lineNo--)
                        {
                            if (!lines[lineNo].TrimStart().StartsWith("Scenario:")) continue;
                            minLine = lineNo + 1;
                            break;
                        }

                        for (var lineNo = currentLine + 1; lineNo <= maxLine; lineNo++)
                        {
                            if (!lines[lineNo].TrimStart().StartsWith("Scenario:")) continue;
                            maxLine = lineNo - 1;
                            break;
                        }

                        for (var lineNo = minLine; lineNo <= maxLine; lineNo++)
                        {
                            if (lineNo == currentLine)
                            {
                                return string.Format("->" + lines[lineNo]);
                            }
                        }
                    }
                }
            }
            catch (Exception)
            {
            }

            return "(Unable to detect current step)";
        }
        private static int GetCurrentPositionText(StringBuilder messageBoxText)
        {
            int currentPositionText = 0;
            try
            {
                var frames = new StackTrace(true).GetFrames();
                if (frames != null)
                {
                    var featureFileFrame = frames.FirstOrDefault(f =>
                                                                 f.GetFileName() != null &&
                                                                 f.GetFileName().EndsWith(".feature"));

                    if (featureFileFrame != null)
                    {
                        var lines = File.ReadAllLines(featureFileFrame.GetFileName());
                        const int frameSize = 20;
                        int currentLine = featureFileFrame.GetFileLineNumber() - 1;
                        int minLine = Math.Max(0, currentLine - frameSize);
                        int maxLine = Math.Min(lines.Length - 1, currentLine + frameSize);

                        for (int lineNo = currentLine - 1; lineNo >= minLine; lineNo--)
                        {
                            if (lines[lineNo].TrimStart().StartsWith("Scenario:"))
                            {
                                minLine = lineNo + 1;
                                break;
                            }
                        }

                        for (int lineNo = currentLine + 1; lineNo <= maxLine; lineNo++)
                        {
                            if (lines[lineNo].TrimStart().StartsWith("Scenario:"))
                            {
                                maxLine = lineNo - 1;
                                break;
                            }
                        }

                        for (int lineNo = minLine; lineNo <= maxLine; lineNo++)
                        {
                            messageBoxText.Append(lineNo == currentLine ? "->  " : "    ");
                            messageBoxText.AppendLine(lines[lineNo]);
                            if (lineNo == currentLine)
                                currentPositionText = lineNo - minLine;
                        }
                        
                        return currentPositionText;
                    }
                }
            }
            catch(Exception ex)
            {
                Debug.WriteLine(ex, "GetCurrentPositionText");
            }

            messageBoxText.AppendLine("(Unable to detect current step)");

            return currentPositionText;
        }