Ejemplo n.º 1
0
        public App()
        {
            var cmdArgs = Environment.GetCommandLineArgs().Skip(1);

            App.CommandLineArguments = new CommandLineArguments(cmdArgs);
            if (App.CommandLineArguments.SingleInstance ?? true)
            {
                cmdArgs = cmdArgs.Select(FullyQualifyPath);
                string message = string.Join(Environment.NewLine, cmdArgs);
                if (SendToPreviousInstance("ILSpy:\r\n" + message, !App.CommandLineArguments.NoActivate))
                {
                    Environment.Exit(0);
                }
            }
            InitializeComponent();

            var catalog = new AggregateCatalog();

            catalog.Catalogs.Add(new AssemblyCatalog(typeof(App).Assembly));
            // Don't use DirectoryCatalog, that causes problems if the plugins are from the Internet zone
            // see http://stackoverflow.com/questions/8063841/mef-loading-plugins-from-a-network-shared-folder
            string appPath = Path.GetDirectoryName(typeof(App).Module.FullyQualifiedName);

            foreach (string plugin in Directory.GetFiles(appPath, "*.Plugin.dll"))
            {
                string shortName = Path.GetFileNameWithoutExtension(plugin);
                try {
                    var asm = Assembly.Load(shortName);
                    asm.GetTypes();
                    catalog.Catalogs.Add(new AssemblyCatalog(asm));
                } catch (Exception ex) {
                    // Cannot show MessageBox here, because WPF would crash with a XamlParseException
                    // Remember and show exceptions in text output, once MainWindow is properly initialized
                    StartupExceptions.Add(new ExceptionData {
                        Exception = ex, PluginName = shortName
                    });
                }
            }

            compositionContainer = new CompositionContainer(catalog);

            Languages.Initialize(compositionContainer);

            if (!System.Diagnostics.Debugger.IsAttached)
            {
                AppDomain.CurrentDomain.UnhandledException      += ShowErrorBox;
                Dispatcher.CurrentDispatcher.UnhandledException += Dispatcher_UnhandledException;
            }

            EventManager.RegisterClassHandler(typeof(Window),
                                              Hyperlink.RequestNavigateEvent,
                                              new RequestNavigateEventHandler(Window_RequestNavigate));

            try {
                DebuggerService.SetDebugger(compositionContainer.GetExport <IDebugger>());
            } catch {
                // unable to find a IDebugger
            }
        }
Ejemplo n.º 2
0
        public App()
        {
            var cmdArgs = Environment.GetCommandLineArgs().Skip(1);

            App.CommandLineArguments = new CommandLineArguments(cmdArgs);
            if (App.CommandLineArguments.SingleInstance ?? true)
            {
                cmdArgs = cmdArgs.Select(FullyQualifyPath);
                string message = string.Join(Environment.NewLine, cmdArgs);
                if (SendToPreviousInstance("ILSpy:\r\n" + message, !App.CommandLineArguments.NoActivate))
                {
                    Environment.Exit(0);
                }
            }
            InitializeComponent();

            var catalog = new AggregateCatalog();

            catalog.Catalogs.Add(new AssemblyCatalog(typeof(App).Assembly));
            catalog.Catalogs.Add(new DirectoryCatalog(".", "*.Plugin.dll"));

            compositionContainer = new CompositionContainer(catalog);

            Languages.Initialize(compositionContainer);

            if (!System.Diagnostics.Debugger.IsAttached)
            {
                AppDomain.CurrentDomain.UnhandledException      += ShowErrorBox;
                Dispatcher.CurrentDispatcher.UnhandledException += Dispatcher_UnhandledException;
            }

            EventManager.RegisterClassHandler(typeof(Window),
                                              Hyperlink.RequestNavigateEvent,
                                              new RequestNavigateEventHandler(Window_RequestNavigate));

            try {
                DebuggerService.SetDebugger(compositionContainer.GetExport <IDebugger>());
            } catch {
                // unable to find a IDebugger
            }
        }