Beispiel #1
0
        public static void Main()
        {
            try
            {
                // add unhandled exception handler
                app.DispatcherUnhandledException           += App_DispatcherUnhandledException;
                AppDomain.CurrentDomain.UnhandledException += CurrentDomainOnUnhandledException;
                TaskScheduler.UnobservedTaskException      += TaskSchedulerOnUnobservedTaskException;

                // Setup logging
                var levelSwitch = new Serilog.Core.LoggingLevelSwitch(Serilog.Events.LogEventLevel.Error);
                var config      = new LoggerConfiguration()
                                  .ReadFrom.AppSettings()
                                  .MinimumLevel.ControlledBy(levelSwitch);

                var logPath = Path.Combine(ApplicationPaths.LogPath, Constants.StandaloneLogFileName);
                config.WriteTo.RollingFile(logPath
                                           , retainedFileCountLimit: 10);

                log        = config.CreateLogger();
                Log.Logger = log;

                // add the custom DAX Studio accent color theme
                app.AddDaxStudioAccentColor();

                // TODO - do we need to customize the navigator window to fix the styling?
                //app.AddResourceDictionary("pack://application:,,,/DaxStudio.UI;Component/Resources/Styles/AvalonDock.NavigatorWindow.xaml");

                // then load Caliburn Micro bootstrapper
                AppBootstrapper bootstrapper = new AppBootstrapper(Assembly.GetAssembly(typeof(DaxStudioHost)), true);

                _eventAggregator = bootstrapper.GetEventAggregator();
                // read command line arguments
                app.ReadCommandLineArgs();

                // check if user is holding shift key down
                bool isLoggingKeyDown = (System.Windows.Input.Keyboard.IsKeyDown(Constants.LoggingHotKey1) ||
                                         System.Windows.Input.Keyboard.IsKeyDown(Constants.LoggingHotKey2));

                app.Args().LoggingEnabledByHotKey = isLoggingKeyDown;

                var logCmdLineSwitch = app.Args().LoggingEnabled;

#if DEBUG
                levelSwitch.MinimumLevel = Serilog.Events.LogEventLevel.Information;
                Log.Debug("Information Logging Enabled due to running in debug mode");
#endif

                if (isLoggingKeyDown || logCmdLineSwitch)
                {
#if DEBUG
                    levelSwitch.MinimumLevel = Serilog.Events.LogEventLevel.Verbose;
                    Log.Debug("Verbose Logging Enabled");
#else
                    levelSwitch.MinimumLevel = Serilog.Events.LogEventLevel.Debug;
                    Log.Debug("Debug Logging Enabled");
#endif
                }


#if DEBUG
                Serilog.Debugging.SelfLog.Enable(Console.Out);
#endif

                Log.Information("============ DaxStudio Startup =============");
                //SsasAssemblyResolver.Instance.BuildAssemblyCache();
                SystemInfo.WriteToLog();

                if (isLoggingKeyDown)
                {
                    Log.Information($"Logging enabled due to {Constants.LoggingHotKeyName} key being held down");
                }
                if (logCmdLineSwitch)
                {
                    Log.Information("Logging enabled by Excel Add-in");
                }
                Log.Information("Startup Parameters Port: {Port} File: {FileName} LoggingEnabled: {LoggingEnabled}", app.Args().Port, app.Args().FileName, app.Args().LoggingEnabled);
                Log.Information($"Portable Mode: {ApplicationPaths.IsInPortableMode}");

                AppDomain.CurrentDomain.AssemblyResolve += ResolveAssembly;

                if (app.Args().TriggerCrashTest)
                {
                    throw new ArgumentException("Test Exception triggered by command line argument");
                }

                // force control tooltips to display even if disabled
                ToolTipService.ShowOnDisabledProperty.OverrideMetadata(
                    typeof(Control),
                    new FrameworkPropertyMetadata(true));

                // get the global options
                var options = bootstrapper.GetOptions();
                options.Initialize();


                // load selected theme
                var themeManager = bootstrapper.GetThemeManager();
                themeManager.SetTheme(options.Theme);

                //var theme = options.Theme;// "Light";
                //if (theme == "Dark") app.LoadDarkTheme();
                //else app.LoadLightTheme();

                // log startup switches
                var args = app.Args().AsDictionaryForTelemetry();
                Telemetry.TrackEvent("App.Startup", args);

                // Launch the User Interface
                app.Run();
            }
            //catch (ArgumentOutOfRangeException argEx)
            //{
            //    var st = new System.Diagnostics.StackTrace(argEx);
            //    var sf = st.GetFrame(0);
            //    if (sf.GetMethod().Name == "GetLineByOffset")
            //    {
            //        if (_eventAggregator != null) _eventAggregator.PublishOnUIThread(new OutputMessage(MessageType.Warning, "Editor syntax highlighting attempted to scan beyond the end of the current line"));
            //        Log.Warning(argEx, "{class} {method} AvalonEdit TextDocument.GetLineByOffset: {message}", "EntryPoint", "Main", "Argument out of range exception");
            //    }
            //}
            catch (Exception ex)
            {
                Log.Fatal(ex, "Class: {0} Method: {1} Error: {2} Stack: {3}", "EntryPoint", "Main", ex.Message, ex.StackTrace);
                Log.CloseAndFlush();
//#if DEBUG
//                MessageBox.Show(ex.Message, "DAX Studio Standalone unhandled exception");
//#else
                // use CrashReporter.Net to send bug to DrDump
                CrashReporter.ReportCrash(ex, "DAX Studio Standalone Fatal crash in Main() method");
//#endif
            }
            finally
            {
                Log.Information("============ DaxStudio Shutdown =============");
                Log.CloseAndFlush();
            }
        }
Beispiel #2
0
        public static void Main()
        {
            try
            {
                // Setup logging
                var levelSwitch = new Serilog.Core.LoggingLevelSwitch(Serilog.Events.LogEventLevel.Error);
                var config      = new LoggerConfiguration()
                                  .ReadFrom.AppSettings()
                                  .MinimumLevel.ControlledBy(levelSwitch);

                var logPath = Path.Combine(Environment.ExpandEnvironmentVariables(Constants.LogFolder),
                                           Constants.StandaloneLogFileName);

                // if we have a local settings.json file we are running in "portable" mode
                if (JsonSettingProvider.SettingsFileExists())
                {
                    logPath = Path.Combine(JsonSettingProvider.LogPath, Constants.StandaloneLogFileName);
                }


                config.WriteTo.RollingFile(logPath
                                           , retainedFileCountLimit: 10);

                log = config.CreateLogger();

                // need to create application first
                var app = new Application();
                //var app2 = IoC.Get<Application>();

                // add the custom DAX Studio accent color theme
                app.AddDaxStudioAccentColor();


                // load selected theme


                // TODO: Theme - read from settings

                var theme = "Light"; // settingProvider.GetValue<string>("Theme", "Light");
                if (theme == "Dark")
                {
                    app.LoadDarkTheme();
                }
                else
                {
                    app.LoadLightTheme();
                }


                // add unhandled exception handler
                app.DispatcherUnhandledException += App_DispatcherUnhandledException;

                // then load Caliburn Micro bootstrapper
                AppBootstrapper bootstrapper = new AppBootstrapper(Assembly.GetAssembly(typeof(DaxStudioHost)), true);

                _eventAggregator = bootstrapper.GetEventAggregator();
                // read command line arguments
                app.ReadCommandLineArgs();

                // check if user is holding shift key down
                bool isLoggingKeyDown = (System.Windows.Input.Keyboard.IsKeyDown(Constants.LoggingHotKey1) ||
                                         System.Windows.Input.Keyboard.IsKeyDown(Constants.LoggingHotKey2));

                app.Args().LoggingEnabledByHotKey = isLoggingKeyDown;

                var logCmdLineSwitch = app.Args().LoggingEnabled;

                //if (RegistryHelper.IsFileLoggingEnabled() || isLoggingKeyDown || logCmdLineSwitch)
                if (isLoggingKeyDown || logCmdLineSwitch)
                {
#if DEBUG
                    levelSwitch.MinimumLevel = Serilog.Events.LogEventLevel.Verbose;
                    Log.Debug("Verbose Logging Enabled");
#else
                    levelSwitch.MinimumLevel = Serilog.Events.LogEventLevel.Debug;
                    Log.Debug("Debug Logging Enabled");
#endif
                }

                //RegistryHelper.IsFileLoggingEnabled();

#if DEBUG
                Serilog.Debugging.SelfLog.Enable(Console.Out);
#endif
                Log.Logger = log;
                Log.Information("============ DaxStudio Startup =============");
                //SsasAssemblyResolver.Instance.BuildAssemblyCache();
                SystemInfo.WriteToLog();
                if (isLoggingKeyDown)
                {
                    log.Information($"Logging enabled due to {Constants.LoggingHotKeyName} key being held down");
                }
                if (logCmdLineSwitch)
                {
                    log.Information("Logging enabled by Excel Add-in");
                }
                Log.Information("Startup Parameters Port: {Port} File: {FileName} LoggingEnabled: {LoggingEnabled}", app.Args().Port, app.Args().FileName, app.Args().LoggingEnabled);

                AppDomain.CurrentDomain.AssemblyResolve += ResolveAssembly;

                if (app.Args().TriggerCrashTest)
                {
                    throw new ArgumentException("Test Exception triggered by command line argument");
                }

                // force control tooltips to display even if disabled
                ToolTipService.ShowOnDisabledProperty.OverrideMetadata(
                    typeof(Control),
                    new FrameworkPropertyMetadata(true));

                app.Run();
            }
            catch (ArgumentOutOfRangeException argEx)
            {
                var st = new System.Diagnostics.StackTrace(argEx);
                var sf = st.GetFrame(0);
                if (sf.GetMethod().Name == "GetLineByOffset")
                {
                    if (_eventAggregator != null)
                    {
                        _eventAggregator.PublishOnUIThread(new OutputMessage(MessageType.Warning, "Editor syntax highlighting attempted to scan byond the end of the current line"));
                    }
                    log.Warning(argEx, "{class} {method} AvalonEdit TextDocument.GetLineByOffset: {message}", "EntryPoint", "Main", "Argument out of range exception");
                }
            }
            catch (Exception ex)
            {
                Log.Fatal(ex, "Class: {0} Method: {1} Error: {2} Stack: {3}", "EntryPoint", "Main", ex.Message, ex.StackTrace);
#if DEBUG
                MessageBox.Show(ex.Message, "DAX Studio Standalone unhandled exception");
#else
                // use CrashReporter.Net to send bug to DrDump
                CrashReporter.ReportCrash(ex, "DAX Studio Standalone Fatal crash in Main() method");
#endif
            }
            finally
            {
                Log.Information("============ DaxStudio Shutdown =============");
                Log.CloseAndFlush();
            }
        }
Beispiel #3
0
        public static void Main()
        {
            //try
            //{

            // add unhandled exception handler
            App.DispatcherUnhandledException           += App_DispatcherUnhandledException;
            AppDomain.CurrentDomain.UnhandledException += CurrentDomainOnUnhandledException;
            TaskScheduler.UnobservedTaskException      += TaskSchedulerOnUnobservedTaskException;

            // Setup logging, default to information level to start with to log the startup and key system information
            var levelSwitch = new Serilog.Core.LoggingLevelSwitch(Serilog.Events.LogEventLevel.Information);

            Log.Information("============ DaxStudio Startup =============");
            ConfigureLogging(levelSwitch);

            // Default web requests like AAD Auth to use windows credentials for proxy auth
            System.Net.WebRequest.DefaultWebProxy.Credentials = System.Net.CredentialCache.DefaultNetworkCredentials;

            // add the custom DAX Studio accent color theme
            App.AddDaxStudioAccentColor();

            // TODO - do we need to customize the navigator window to fix the styling?
            //app.AddResourceDictionary("pack://application:,,,/DaxStudio.UI;Component/Resources/Styles/AvalonDock.NavigatorWindow.xaml");

            // then load Caliburn Micro bootstrapper
            Log.Debug("Loading Caliburn.Micro bootstrapper");
            AppBootstrapper bootstrapper = new AppBootstrapper(Assembly.GetAssembly(typeof(DaxStudioHost)), true);

            _eventAggregator = bootstrapper.GetEventAggregator();
            // read command line arguments
            App.ReadCommandLineArgs();

            AppDomain.CurrentDomain.AssemblyResolve += ResolveAssembly;



            // force control tooltips to display even if disabled
            ToolTipService.ShowOnDisabledProperty.OverrideMetadata(
                typeof(Control),
                new FrameworkPropertyMetadata(true));

            // get the global options
            _options = bootstrapper.GetOptions();
            _options.Initialize();
            Log.Information("User Options initialized");

            // check if we are running portable that we have write access to the settings
            if (_options.IsRunningPortable)
            {
                if (CanWriteToSettings())
                {
                    Log.Information(Constants.LogMessageTemplate, nameof(EntryPoint), nameof(Main), "Test for read/write access to Settings.json: PASS");
                }
                else
                {
                    Log.Error(Constants.LogMessageTemplate, nameof(EntryPoint), nameof(Main), "Test for read/write access to Settings.json: FAIL");

                    ShowSettingPermissionErrorDialog();
                    App.Shutdown(3);
                    return;
                }
            }

            // load selected theme
            var themeManager = bootstrapper.GetThemeManager();

            themeManager.SetTheme(_options.Theme);
            Log.Information("ThemeManager configured");

            //var theme = options.Theme;// "Light";
            //if (theme == "Dark") app.LoadDarkTheme();
            //else app.LoadLightTheme();

            // log startup switches
            if (_options.AnyExternalAccessAllowed())
            {
                var args = App.Args().AsDictionaryForTelemetry();
                Telemetry.TrackEvent("App.Startup", args);
            }

            // only used for testing of crash reporting UI
            if (App.Args().TriggerCrashTest)
            {
                throw new ArgumentException("Test Exception triggered by command line argument");
            }

            // Launch the User Interface
            Log.Information("Launching User Interface");
            bootstrapper.DisplayShell();
            App.Run();
            //}

            //catch (Exception ex)
            //{
            //    Log.Fatal(ex, "Class: {0} Method: {1} Error: {2}", "EntryPoint", "Main", ex.Message);
            //    Log.CloseAndFlush();
            //    //#if DEBUG
            //    //                MessageBox.Show(ex.Message, "DAX Studio Standalone unhandled exception");
            //    //#else
            //    // use CrashReporter.Net to send bug to DrDump
            //    LogFatalCrash(ex, ex.Message, _options);
            //    //#endif

            //}
            //finally
            //{
            Log.Information("============ DaxStudio Shutdown =============");
            Log.CloseAndFlush();
            //}
        }
Beispiel #4
0
        public static void Main()
        {
            try
            {
                // add unhandled exception handler
                App.DispatcherUnhandledException           += App_DispatcherUnhandledException;
                AppDomain.CurrentDomain.UnhandledException += CurrentDomainOnUnhandledException;
                TaskScheduler.UnobservedTaskException      += TaskSchedulerOnUnobservedTaskException;

                // Setup logging
                var levelSwitch = new Serilog.Core.LoggingLevelSwitch(Serilog.Events.LogEventLevel.Error);


                ConfigureLogging(levelSwitch);

                Log.Information("============ DaxStudio Startup =============");

                // add the custom DAX Studio accent color theme
                App.AddDaxStudioAccentColor();

                // TODO - do we need to customize the navigator window to fix the styling?
                //app.AddResourceDictionary("pack://application:,,,/DaxStudio.UI;Component/Resources/Styles/AvalonDock.NavigatorWindow.xaml");

                // then load Caliburn Micro bootstrapper
                Log.Debug("Loading Caliburn.Micro bootstrapper");
                AppBootstrapper bootstrapper = new AppBootstrapper(Assembly.GetAssembly(typeof(DaxStudioHost)), true);

                _eventAggregator = bootstrapper.GetEventAggregator();
                // read command line arguments
                App.ReadCommandLineArgs();

                AppDomain.CurrentDomain.AssemblyResolve += ResolveAssembly;

                if (App.Args().TriggerCrashTest)
                {
                    throw new ArgumentException("Test Exception triggered by command line argument");
                }

                // force control tooltips to display even if disabled
                ToolTipService.ShowOnDisabledProperty.OverrideMetadata(
                    typeof(Control),
                    new FrameworkPropertyMetadata(true));

                // get the global options
                _options = bootstrapper.GetOptions();
                _options.Initialize();
                Log.Information("User Options initialized");

                // check if we are running portable that we have write access to the settings
                if (_options.IsRunningPortable)
                {
                    if (CanWriteToSettings())
                    {
                        Log.Information(Constants.LogMessageTemplate, nameof(EntryPoint), nameof(Main), "Test for read/write access to Settings.json: PASS");
                    }
                    else
                    {
                        Log.Error(Constants.LogMessageTemplate, nameof(EntryPoint), nameof(Main), "Test for read/write access to Settings.json: FAIL");

                        ShowSettingPermissionErrorDialog();
                        App.Shutdown(3);
                        return;
                    }
                }

                // load selected theme
                var themeManager = bootstrapper.GetThemeManager();
                themeManager.SetTheme(_options.Theme);
                Log.Information("ThemeManager configured");

                //var theme = options.Theme;// "Light";
                //if (theme == "Dark") app.LoadDarkTheme();
                //else app.LoadLightTheme();

                // log startup switches
                var args = App.Args().AsDictionaryForTelemetry();
                Telemetry.TrackEvent("App.Startup", args);

                // Launch the User Interface
                Log.Information("Launching User Interface");
                bootstrapper.DisplayShell();
                App.Run();
            }
            //catch (ArgumentOutOfRangeException argEx)
            //{
            //    var st = new System.Diagnostics.StackTrace(argEx);
            //    var sf = st.GetFrame(0);
            //    if (sf.GetMethod().Name == "GetLineByOffset")
            //    {
            //        if (_eventAggregator != null) _eventAggregator.PublishOnUIThread(new OutputMessage(MessageType.Warning, "Editor syntax highlighting attempted to scan beyond the end of the current line"));
            //        Log.Warning(argEx, "{class} {method} AvalonEdit TextDocument.GetLineByOffset: {message}", "EntryPoint", "Main", "Argument out of range exception");
            //    }
            //}
            catch (Exception ex)
            {
                Log.Fatal(ex, "Class: {0} Method: {1} Error: {2} Stack: {3}", "EntryPoint", "Main", ex.Message, ex.StackTrace);
                Log.CloseAndFlush();
//#if DEBUG
//                MessageBox.Show(ex.Message, "DAX Studio Standalone unhandled exception");
//#else
                // use CrashReporter.Net to send bug to DrDump
                CrashReporter.ReportCrash(ex, "DAX Studio Standalone Fatal crash in Main() method");
//#endif
            }
            finally
            {
                Log.Information("============ DaxStudio Shutdown =============");
                Log.CloseAndFlush();
            }
        }