예제 #1
0
        private static void MiniDumpToFile(string fileToDump, MinidumpTypes dumpType)
        {
            using var fsToDump    = File.Open(fileToDump, FileMode.Create, FileAccess.ReadWrite, FileShare.Write);
            using var thisProcess = Process.GetCurrentProcess();
            var mINIDUMP_EXCEPTION_INFORMATION = new MINIDUMP_EXCEPTION_INFORMATION
            {
                ClientPointers = false,
#if WITH_EXCEPTIONPOINTERS
                ExceptionPointers = Marshal.GetExceptionPointers(),
#else
                ExceptionPointers = IntPtr.Zero,
#endif
                ThreadId = SafeNativeMethods.GetCurrentThreadId(),
            };
            var error = SafeNativeMethods.MiniDumpWriteDump(
                thisProcess.Handle,
                thisProcess.Id,
                fsToDump.SafeFileHandle,
                dumpType,
                ref mINIDUMP_EXCEPTION_INFORMATION,
                IntPtr.Zero,
                IntPtr.Zero);

            if (error > 0)
            {
                DumpMessage?.Invoke(typeof(MiniDump), new MessageEventArgs($"Mini-dumping failed with Code: {error}", "Error!", ErrorLevel.Error));
            }
        }
예제 #2
0
        internal static void ExceptionEventHandlerCode(Exception e, bool threadException)
        {
            var exceptionData = $"{e.GetType()}: {e.Message}{Environment.NewLine}{e.StackTrace}{Environment.NewLine}";

            PrintInnerExceptions(e, ref exceptionData);

            // do not dump or close if in a debugger.
            if (!Debugger.IsAttached)
            {
                ForceClosure.ForceClose = true;

                // if this is not Windows, MiniDumpToFile(), which calls MiniDumpWriteDump() in dbghelp.dll
                // cannot be used as it does not exist. I need to figure out mini-dumping for
                // these platforms manually. In that case I guess it does not matter much anyway
                // with the world of debugging and running in a IDE.
#if NET5_0_OR_GREATER
                if (OperatingSystem.IsWindows())
#else
                if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
#endif
                {
                    if (string.IsNullOrEmpty(MiniDumpAttribute.CurrentInstance.DumpLogFileName))
                    {
                        MiniDumpAttribute.CurrentInstance.DumpLogFileName = SettingsFile.ErrorLogPath;
                    }

                    if (string.IsNullOrEmpty(MiniDumpAttribute.CurrentInstance.DumpFileName))
                    {
                        MiniDumpAttribute.CurrentInstance.DumpFileName = SettingsFile.MiniDumpPath;
                    }

                    File.WriteAllText(MiniDumpAttribute.CurrentInstance.DumpLogFileName, exceptionData);
                    MiniDumpToFile(MiniDumpAttribute.CurrentInstance.DumpFileName, MiniDumpAttribute.CurrentInstance.DumpType);
                    DumpMessage?.Invoke(typeof(MiniDump), new MessageEventArgs(string.Format(CultureInfo.InvariantCulture, MiniDumpAttribute.CurrentInstance.Text, MiniDumpAttribute.CurrentInstance.DumpLogFileName), threadException ? MiniDumpAttribute.CurrentInstance.ThreadExceptionTitle : MiniDumpAttribute.CurrentInstance.ExceptionTitle, ErrorLevel.Error));
                }
            }
        }
예제 #3
0
        /*
         * /// <summary>
         * /// Occurs when a mini-dump fails with any sort of error code.
         * /// </summary>
         * public static event EventHandler<MessageEventArgs> DumpFailed;
         */

        internal static void ExceptionEventHandlerCode(Exception e, bool threadException)
        {
            var exceptionData = $"{e.GetType()}: {e.Message}{Environment.NewLine}{e.StackTrace}{Environment.NewLine}";
            var outputData    = Encoding.ASCII.GetBytes(exceptionData);

            // do not dump or close if in a debugger.
            if (!Debugger.IsAttached)
            {
                ForceClosure.ForceClose = true;

                // if this is not Windows, MiniDumpToFile(), which calls MiniDumpWriteDump() in dbghelp.dll
                // cannot be used as it does not exist. I need to figure out mini-dumping for
                // these platforms manually. In that case I guess it does not matter much anyway
                // with the world of debugging and running in a IDE.
                if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
                {
                    if (string.IsNullOrEmpty(MiniDumpAttribute.CurrentInstance.DumpLogFileName))
                    {
                        MiniDumpAttribute.CurrentInstance.DumpLogFileName = SettingsFile.ErrorLogPath;
                    }

                    if (string.IsNullOrEmpty(MiniDumpAttribute.CurrentInstance.DumpFileName))
                    {
                        MiniDumpAttribute.CurrentInstance.DumpFileName = SettingsFile.MiniDumpPath;
                    }

                    using (var fileStream = File.OpenWrite(MiniDumpAttribute.CurrentInstance.DumpLogFileName))
                    {
                        fileStream.Write(outputData, 0, outputData.Length);
                    }

                    MiniDumpToFile(MiniDumpAttribute.CurrentInstance.DumpFileName, MiniDumpAttribute.CurrentInstance.DumpType);
                    DumpMessage?.Invoke(typeof(MiniDump), new MessageEventArgs(string.Format(MiniDumpAttribute.CurrentInstance.Text, MiniDumpAttribute.CurrentInstance.DumpLogFileName), threadException ? MiniDumpAttribute.CurrentInstance.ThreadExceptionTitle : MiniDumpAttribute.CurrentInstance.ExceptionTitle, ErrorLevel.Error));
                }
            }
        }
예제 #4
0
 public Task Dump(DumpMessage message)
 {
     _host.OnDumped(message.Results);
     return(Task.CompletedTask);
 }
예제 #5
0
 public Task Dump(DumpMessage message)
 {
     return(InvokeAsync(nameof(Dump), message));
 }
        private void MessageRouterHandler(MessageContext <object, string> messageContext)
        {
            try
            {
                var dumpMessage = new DumpMessage()
                {
                    EventId     = "Line",
                    Source      = DumpSource.FROM_FEED,
                    MessageBody = messageContext.State,
                    MessageType = messageContext.Message.GetType().Name
                };

                switch (messageContext.Message)
                {
                case LoginResponseMessage msg:
                    startSubscribingActionBlock.Post(messageContext.Next(msg));
                    messageDumper.Write(messageContext.Next(dumpMessage));
                    break;

                case PingMessage msg:
                    pingToAdapterActionBlock.Post(messageContext.Next(msg));
                    messageDumper.Write(messageContext.Next(dumpMessage));
                    break;

                case EventsMessage msg:
                    eventsDataToAdapterActionBlock.Post(messageContext.Next(msg));

                    foreach (var item in msg.Events)
                    {
                        var dm = new DumpMessage()
                        {
                            EventId     = item.TranslationId,
                            Source      = DumpSource.FROM_FEED,
                            MessageType = item.EventCode,
                            MessageBody = JsonConvert.SerializeObject(item)
                        };

                        messageDumper.Write(messageContext.Next(dm));
                    }

                    break;

                case SubscribeResponseMessage msg:

                    dumpMessage.EventId = msg.TranslationId;
                    messageDumper.Write(messageContext.Next(dumpMessage));

                    if (msg.Status != "success")
                    {
                        throw new Exception("Can't subrcribe translation.");
                    }
                    break;

                case SubscribeHistorySentMessage msg:

                    dumpMessage.EventId = msg.TranslationId;
                    messageDumper.Write(messageContext.Next(dumpMessage));
                    break;

                case Translation msg:
                    // Begin emululator testing block ***************
                    subscriptions.GetOrAdd(msg.Id, id => new TranslationSubscription(() => { }));                             // add subscription

                    translationToAdapterActionBlock.Post(messageContext.Next(msg));

                    dumpMessage.EventId = msg.Id.ToString();
                    messageDumper.Write(messageContext.Next(dumpMessage));
                    // End emululator testing block ***************

                    break;

                default:
                    messageDumper.Write(messageContext.Next(dumpMessage));
                    throw new Exception($"Unknown message. {messageContext.Message.GetType().FullName}");
                }
            }
            catch (Exception ex)
            {
                logger.LogError(ex, $"Message routing error. ContextId: {messageContext.IncomingId}");
            }
        }
 private void OnDump(DumpMessage message)
 {
     PageObject.Activity = message.DumpInfo.Activity;
     PageObject.Package  = message.DumpInfo.Package;
     _topNode            = message.TopNode;
 }
 private void OnDump(DumpMessage message)
 {
     Nodes = new ObservableCollection <NodeTreeItem> {
         new NodeTreeItem(message.TopNode)
     };
 }
 public void SetUp()
 {
     _dumpMessage = new DumpMessage();
 }
 private void OnNewDump(DumpMessage message)
 {
     IsDumpingScreen = false;
     LoadImage?.Invoke(this, message.DumpInfo);
     _topNode = message.TopNode;
 }