Exemple #1
0
        public App()
        {
            var cmdArgs = Environment.GetCommandLineArgs().Skip(1);

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

            if (!System.Diagnostics.Debugger.IsAttached)
            {
                AppDomain.CurrentDomain.UnhandledException      += ShowErrorBox;
                Dispatcher.CurrentDispatcher.UnhandledException += Dispatcher_UnhandledException;
            }
            TaskScheduler.UnobservedTaskException += DotNet40_UnobservedTaskException;
            InitializeMef().GetAwaiter().GetResult();
            Languages.Initialize(ExportProvider);
            EventManager.RegisterClassHandler(typeof(Window),
                                              Hyperlink.RequestNavigateEvent,
                                              new RequestNavigateEventHandler(Window_RequestNavigate));
            ILSpyTraceListener.Install();
        }
Exemple #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 (!Debugger.IsAttached)
            {
                AppDomain.CurrentDomain.UnhandledException      += ShowErrorBox;
                Dispatcher.CurrentDispatcher.UnhandledException += Dispatcher_UnhandledException;
            }

            EventManager.RegisterClassHandler(typeof(Window),
                                              Hyperlink.RequestNavigateEvent,
                                              new RequestNavigateEventHandler(Window_RequestNavigate));
        }
Exemple #3
0
        public App()
        {
            // Add Ctrl+Shift+Z as a redo command. Don't know why it isn't enabled by default.
            ApplicationCommands.Redo.InputGestures.Add(new KeyGesture(Key.Z, ModifierKeys.Control | ModifierKeys.Shift));

            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("dnSpy:\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;
            }
            TaskScheduler.UnobservedTaskException += DotNet40_UnobservedTaskException;

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

            FixEditorContextMenuStyle();
        }
Exemple #4
0
        public App()
        {
            var cmdArgs = Environment.GetCommandLineArgs().Skip(1);

            App.CommandLineArguments = new CommandLineArguments(cmdArgs);
            bool forceSingleInstance = (App.CommandLineArguments.SingleInstance ?? true) &&
                                       !MiscSettingsPanel.CurrentMiscSettings.AllowMultipleInstances;

            if (forceSingleInstance)
            {
                bool isFirst;
                try
                {
                    SingleInstanceMutex = new Mutex(initiallyOwned: true, @"Local\ILSpyInstance", out isFirst);
                }
                catch (WaitHandleCannotBeOpenedException)
                {
                    isFirst = true;
                }
                if (!isFirst)
                {
                    try
                    {
                        SingleInstanceMutex.WaitOne(10000);
                    }
                    catch (AbandonedMutexException)
                    {
                        // continue, there is no concurrent start happening.
                    }
                }
                cmdArgs = cmdArgs.Select(FullyQualifyPath);
                string message = string.Join(Environment.NewLine, cmdArgs);
                if (SendToPreviousInstance("ILSpy:\r\n" + message, !App.CommandLineArguments.NoActivate))
                {
                    ReleaseSingleInstanceMutex();
                    Environment.Exit(0);
                }
            }
            InitializeComponent();

            Resources.RegisterDefaultStyles();

            if (!System.Diagnostics.Debugger.IsAttached)
            {
                AppDomain.CurrentDomain.UnhandledException      += ShowErrorBox;
                Dispatcher.CurrentDispatcher.UnhandledException += Dispatcher_UnhandledException;
            }
            TaskScheduler.UnobservedTaskException += DotNet40_UnobservedTaskException;
            InitializeMef().GetAwaiter().GetResult();
            Languages.Initialize(ExportProvider);
            EventManager.RegisterClassHandler(typeof(Window),
                                              Hyperlink.RequestNavigateEvent,
                                              new RequestNavigateEventHandler(Window_RequestNavigate));
            ILSpyTraceListener.Install();
        }
Exemple #5
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 {
                    catalog.Catalogs.Add(new AssemblyCatalog(Assembly.Load(shortName)));
                } catch (Exception ex) {
                    MessageBox.Show(ex.ToString(), "Error loading plugin " + 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
            }
        }
Exemple #6
0
        public App()
        {
            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 (!Debugger.IsAttached)
            {
                AppDomain.CurrentDomain.UnhandledException      += ShowErrorBox;
                Dispatcher.CurrentDispatcher.UnhandledException += Dispatcher_UnhandledException;
            }

            EventManager.RegisterClassHandler(typeof(Window),
                                              Hyperlink.RequestNavigateEvent,
                                              new RequestNavigateEventHandler(Window_RequestNavigate));
        }
Exemple #7
0
        public App()
        {
            var cmdArgs = Environment.GetCommandLineArgs().Skip(1);

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

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

            // Cannot show MessageBox here, because WPF would crash with a XamlParseException
            // Remember and show exceptions in text output, once MainWindow is properly initialized
            try {
                // Set up VS MEF. For now, only do MEF1 part discovery, since that was in use before.
                // To support both MEF1 and MEF2 parts, just change this to:
                // var discovery = PartDiscovery.Combine(new AttributedPartDiscoveryV1(Resolver.DefaultInstance),
                //                                       new AttributedPartDiscovery(Resolver.DefaultInstance));
                var discovery = new AttributedPartDiscoveryV1(Resolver.DefaultInstance);
                var catalog   = ComposableCatalog.Create(Resolver.DefaultInstance);
                var pluginDir = Path.GetDirectoryName(typeof(App).Module.FullyQualifiedName);
                if (pluginDir != null)
                {
                    foreach (var plugin in Directory.GetFiles(pluginDir, "*.Plugin.dll"))
                    {
                        var name = Path.GetFileNameWithoutExtension(plugin);
                        try {
                            var asm   = Assembly.Load(name);
                            var parts = discovery.CreatePartsAsync(asm).Result;
                            catalog = catalog.AddParts(parts);
                        } catch (Exception ex) {
                            StartupExceptions.Add(new ExceptionData {
                                Exception = ex, PluginName = name
                            });
                        }
                    }
                }
                // Add the built-in parts
                catalog = catalog.AddParts(discovery.CreatePartsAsync(Assembly.GetExecutingAssembly()).Result);
                // If/When the project switches to .NET Standard/Core, this will be needed to allow metadata interfaces (as opposed
                // to metadata classes). When running on .NET Framework, it's automatic.
                //   catalog.WithDesktopSupport();
                // If/When any part needs to import ICompositionService, this will be needed:
                //   catalog.WithCompositionService();
                var config = CompositionConfiguration.Create(catalog);
                exportProviderFactory = config.CreateExportProviderFactory();
                exportProvider        = exportProviderFactory.CreateExportProvider();
                // This throws exceptions for composition failures. Alternatively, the configuration's CompositionErrors property
                // could be used to log the errors directly. Used at the end so that it does not prevent the export provider setup.
                config.ThrowOnErrors();
            } catch (Exception ex) {
                StartupExceptions.Add(new ExceptionData {
                    Exception = ex
                });
            }

            Languages.Initialize(exportProvider);

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