Example #1
0
        public static void Shutdown(bool errorShutdown = false)
        {
            if (Configuration.SendTelemetry && Telemetry.UseApplicationInsights && AppInsights != null)
            {
                var t = AppRunTelemetry.Telemetry;

                // multi-instance shutdown - ignore
                if (t.Properties.ContainsKey("usage"))
                {
                    return;
                }

                t.Properties.Add("usage", Configuration.ApplicationUpdates.AccessCount.ToString());
                t.Properties.Add("registered", UnlockKey.IsRegistered().ToString());
                t.Properties.Add("version", GetVersion());
                t.Properties.Add("dotnetversion", ComputerInfo.GetDotnetVersion());
                t.Properties.Add("culture", CultureInfo.CurrentUICulture.IetfLanguageTag);
                t.Stop();

                try
                {
                    AppInsights.StopOperation(AppRunTelemetry);
                }
                catch (Exception ex)
                {
                    LogToLogfile("Failed to Stop Telemetry Client: " + ex.GetBaseException().Message);
                }
                AppInsights.Flush();
                AppInsights = null;
            }
            else
            {
                SendTelemetry("shutdown");
            }

            var tempPath = Path.GetTempPath();

            // Cleanup temp files
            File.Delete(Path.Combine(tempPath, "_MarkdownMonster_Preview.html"));
            FileUtils.DeleteTimedoutFiles(Path.Combine(tempPath, "mm_diff_*.*"), 1);
        }
Example #2
0
        public static void SendBugReport(Exception ex, string msg = null)
        {
            var bug = new BugReport()
            {
                TimeStamp  = DateTime.UtcNow,
                Message    = ex.Message,
                Product    = "Markdown Monster",
                Version    = mmApp.GetVersion(),
                WinVersion = ComputerInfo.GetWindowsVersion() +
                             " - " + CultureInfo.CurrentUICulture.IetfLanguageTag +
                             " - .NET " + ComputerInfo.GetDotnetVersion() + " - " +
                             (Environment.Is64BitProcess ? "64 bit" : "32 bit"),
                StackTrace = (ex.Source + "\r\n\r\n" + ex.StackTrace).Trim()
            };

            if (!string.IsNullOrEmpty(msg))
            {
                bug.Message = msg + "\r\n" + bug.Message;
            }

            new TaskFactory().StartNew(
                (bg) =>
            {
                try
                {
                    var temp = HttpUtils.JsonRequest <BugReport>(new HttpRequestSettings()
                    {
                        Url      = mmApp.Configuration.BugReportUrl,
                        HttpVerb = "POST",
                        Content  = bg,
                        Timeout  = 3000
                    });
                }
                catch (Exception ex2)
                {
                    // don't log with exception otherwise we get an endless loop
                    Log("Unable to report bug: " + ex2.Message);
                }
            }, bug);
        }
Example #3
0
        protected override void OnStartup(StartupEventArgs e)
        {
            if (mmApp.Configuration.DisableHardwareAcceleration)
            {
                RenderOptions.ProcessRenderMode = System.Windows.Interop.RenderMode.SoftwareOnly;
            }

            var dir = Assembly.GetExecutingAssembly().Location;

            Directory.SetCurrentDirectory(Path.GetDirectoryName(dir));

            mmApp.SetTheme(mmApp.Configuration.ApplicationTheme, App.Current.MainWindow as MetroWindow);


            if (!mmApp.Configuration.DisableAddins)
            {
                new TaskFactory().StartNew(() =>
                {
                    ComputerInfo.EnsureBrowserEmulationEnabled("MarkdownMonster.exe");
                    ComputerInfo.EnsureSystemPath();
                });
            }
        }
Example #4
0
        /// <summary>
        /// Logs messages to the log file
        /// </summary>
        /// <param name="msg"></param>
        public static void Log(string msg, Exception ex = null, bool unhandledException = false)
        {
            string version    = GetVersion();
            string winVersion = null;

            string exMsg = string.Empty;

            if (ex != null)
            {
                winVersion = ComputerInfo.GetWindowsVersion() +
                             " - " + CultureInfo.CurrentUICulture.IetfLanguageTag +
                             " - NET " + ComputerInfo.GetDotnetVersion() + " - " +
                             (Environment.Is64BitProcess ? "64 bit" : "32 bit");

                ex    = ex.GetBaseException();
                exMsg = $@"
Markdown Monster v{version}
{winVersion}
---
{ex.Source}
{ex.StackTrace}
---------------------------


";
                SendBugReport(ex, msg);
            }

            if (Telemetry.UseApplicationInsights)
            {
                if (ex != null)
                {
                    AppRunTelemetry.Telemetry.Success = false;
                    AppInsights.TrackException(ex,
                                               new Dictionary <string, string>
                    {
                        { "msg", msg },
                        { "exmsg", ex.Message },
                        { "exsource", ex.Source },
                        { "extrace", ex.StackTrace },
                        { "severity", unhandledException ? "unhandled" : "" },
                        { "version", version },
                        { "winversion", winVersion },
                        { "usage", Configuration.ApplicationUpdates.AccessCount.ToString() },
                        { "registered", UnlockKey.IsRegistered().ToString() }
                    });
                }
                else
                {
                    var props = new Dictionary <string, string>()
                    {
                        { "msg", msg },
                        { "version", GetVersion() },
                        { "usage", Configuration.ApplicationUpdates.AccessCount.ToString() },
                        { "registered", UnlockKey.IsRegistered().ToString() }
                    };
                    AppInsights.TrackTrace(msg, props);
                }
            }
            var text = msg + exMsg;

            LogToLogfile(text);
        }