コード例 #1
0
ファイル: AppBootstrapper.cs プロジェクト: sky7sea/DaxStudio
        /// <summary>
        /// By default, we are configured to use MEF
        /// </summary>
        protected override void Configure()
        {
            try
            {
                var splashScreen = new SplashScreen(Assembly.GetAssembly(typeof(AppBootstrapper)), "daxstudio-splash.png");
                splashScreen.Show(true);

                // Tell Caliburn Micro how to find controls in Fluent Ribbon

                /*
                 * defaultElementLookup = BindingScope.GetNamedElements;
                 * BindingScope.GetNamedElements = new Func<System.Windows.DependencyObject, IEnumerable<System.Windows.FrameworkElement>>(
                 *  k =>
                 *  {
                 *      List<FrameworkElement> namedElements = new List<FrameworkElement>();
                 *      namedElements.AddRange(defaultElementLookup(k));
                 *      Fluent.Ribbon ribbon = LookForRibbon(k);
                 *      if (null != ribbon)
                 *          AppendRibbonNamedItem(ribbon, namedElements);
                 *      return namedElements;
                 *  }
                 *  );
                 */

                ConventionManager.AddElementConvention <Fluent.Spinner>(Fluent.Spinner.ValueProperty, "Value", "ValueChanged");
                ConventionManager.AddElementConvention <Xceed.Wpf.Toolkit.DoubleUpDown>(Xceed.Wpf.Toolkit.DoubleUpDown.ValueProperty, "Value", "ValueChanged");
                ConventionManager.AddElementConvention <Xceed.Wpf.Toolkit.IntegerUpDown>(Xceed.Wpf.Toolkit.IntegerUpDown.ValueProperty, "Value", "ValueChanged");
                ConventionManager.AddElementConvention <Xceed.Wpf.Toolkit.WatermarkTextBox>(Xceed.Wpf.Toolkit.WatermarkTextBox.TextProperty, "Text", "TextChanged");

                // Add Fluent Ribbon resovler
                BindingScope.AddChildResolver <Fluent.Ribbon>(FluentRibbonChildResolver);


                // Fixes the default datetime format in the results listview
                // from: http://stackoverflow.com/questions/1993046/datetime-region-specific-formatting-in-wpf-listview
                FrameworkElement.LanguageProperty.OverrideMetadata(
                    typeof(FrameworkElement),
                    new FrameworkPropertyMetadata(XmlLanguage.GetLanguage(CultureInfo.CurrentCulture.IetfLanguageTag)));

                var catalog = new AggregateCatalog(
                    AssemblySource.Instance.Select(x => new AssemblyCatalog(x)).OfType <ComposablePartCatalog>()
                    );
                //_container = new CompositionContainer(catalog,true);
                _container = new CompositionContainer(catalog);
                var batch = new CompositionBatch();

                if (JsonSettingProvider.SettingsFileExists())
                {
                    batch.AddExportedValue <ISettingProvider>(new JsonSettingProvider());
                }
                else
                {
                    batch.AddExportedValue <ISettingProvider>(new RegistrySettingProvider());
                }

                batch.AddExportedValue <IWindowManager>(new WindowManager());
                batch.AddExportedValue <IEventAggregator>(new EventAggregator());
                batch.AddExportedValue <Func <DocumentViewModel> >(() => _container.GetExportedValue <DocumentViewModel>());
                batch.AddExportedValue <Func <IWindowManager, IEventAggregator, DocumentViewModel> >(
                    (w, e) => _container.GetExportedValue <DocumentViewModel>());
                batch.AddExportedValue(_container);
                batch.AddExportedValue(catalog);

                _container.Compose(batch);

                // Add AvalonDock binding convetions
                AvalonDockConventions.Install();

                ConfigureKeyBindings();

                // TODO - not working
                //VisibilityBindingConvention.Install();

                LogManager.GetLog = type => new DebugLogger(type);

                // Add Application object to MEF catalog
                _container.ComposeExportedValue <Application>("System.Windows.Application", Application.Current);
            }
            catch (Exception e)
            {
                Debug.WriteLine(e);
            }
        }
コード例 #2
0
ファイル: EntryPoint.cs プロジェクト: sky7sea/DaxStudio
        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();
            }
        }