Esempio n. 1
0
        public static void Shutdown(bool errorShutdown = false)
        {
            if (Configuration.SendTelemetry && Telemetry.UseApplicationInsights && AppInsights != null)
            {
                var t = AppRunTelemetry.Telemetry;
                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.Stop();

                try
                {
                    AppInsights.StopOperation(AppRunTelemetry);
                }
                catch (Exception ex)
                {
                    LogToLogfile("Failed to Stop Telemetry Client: " + ex.GetBaseException().Message);
                }
                AppInsights.Flush();
                AppInsights = null;
            }
            else
            {
                SendTelemetry("shutdown");
            }
        }
Esempio n. 2
0
        /// <summary>
        /// Logs messages to the log file
        /// </summary>
        /// <param name="msg"></param>
        public static void Log(string msg, Exception ex = null)
        {
            string exMsg = string.Empty;

            if (ex != null)
            {
                var version    = mmApp.GetVersion();
                var winVersion = ComputerInfo.WinMajorVersion + "." + ComputerInfo.WinMinorVersion + "." +
                                 ComputerInfo.WinBuildLabVersion + " - " + 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);
            }

            var text = msg + exMsg;

            StringUtils.LogString(text, Path.Combine(Configuration.CommonFolder,
                                                     "MarkdownMonsterErrors.txt"), Encoding.UTF8);
        }
Esempio n. 3
0
        protected override void OnStartup(StartupEventArgs e)
        {
            if (_noStart)
            {
                return;
            }

            var dotnetVersion = ComputerInfo.GetDotnetVersion();

            if (String.Compare(dotnetVersion, "4.6", StringComparison.Ordinal) < 0)
            {
                new TaskFactory().StartNew(() => MessageBox.Show("Markdown Monster requires .NET 4.6 or later to run.\r\n\r\n" +
                                                                 "Please download and install the latest version of .NET version from:\r\n" +
                                                                 "https://www.microsoft.com/net/download/framework\r\n\r\n" +
                                                                 "Exiting application and navigating to .NET Runtime Downloads page.",
                                                                 "Markdown Monster",
                                                                 MessageBoxButton.OK,
                                                                 MessageBoxImage.Warning
                                                                 ));

                Thread.Sleep(10000);
                ShellUtils.GoUrl("https://www.microsoft.com/net/download/framework");
                Environment.Exit(0);
            }

            new TaskFactory().StartNew(LoadAddins);

            if (mmApp.Configuration.DisableHardwareAcceleration)
            {
                RenderOptions.ProcessRenderMode = System.Windows.Interop.RenderMode.SoftwareOnly;
            }

            // always set directory tocurrent location
            var dir = Assembly.GetExecutingAssembly().Location;

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

            ThemeCustomizations();

            if (!mmApp.Configuration.DisableAddins)
            {
                new TaskFactory().StartNew(() =>
                {
                    ComputerInfo.EnsureBrowserEmulationEnabled("MarkdownMonster.exe");
                    ComputerInfo.EnsureSystemPath();
                    ComputerInfo.EnsureAssociations();

                    if (!Directory.Exists(mmApp.Configuration.InternalCommonFolder))
                    {
                        Directory.CreateDirectory(mmApp.Configuration.InternalCommonFolder);
                    }
                });
            }
        }
Esempio n. 4
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);
        }
Esempio n. 5
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);
        }
Esempio n. 6
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);
        }