Exemple #1
0
        public static Dictionary <string, Plugins.PluginInstance> LoadAndActivatePlugins(
            IReadOnlyList <OptionsInformation.PluginDllInfo> pluginDllInfos)
        {
            // Plugins to be loaded
            if (pluginDllInfos.Count == 0)
            {
                return(new Dictionary <string, Plugins.PluginInstance>());
            }

            Log.Singleton.Info(
                $"Trying to load and activate {pluginDllInfos.Count} plug-in(s)...");
            var loadedPlugins = Plugins.TryActivatePlugins(pluginDllInfos);

            Plugins.TrySetOptionsForPlugins(pluginDllInfos, loadedPlugins);

            return(loadedPlugins);
        }
Exemple #2
0
        private void Application_Startup(object sender, StartupEventArgs e)
        {
            // allow long term logging (for report box)
            Log.LogInstance.EnableLongTermStore();

            // Build up of options
            Log.Info("Application startup.");

            // there is a special case for having "no" command line options ..
            string directAasx = null;

            if (e.Args.Length == 1 && !e.Args[0].StartsWith("-"))
            {
                directAasx = e.Args[0];
                Log.Info("Direct request to load AASX {0} ..", directAasx);
            }

            // If no command line args given, read options via default filename
            if (directAasx != null || e.Args.Length < 1)
            {
                var exePath = System.Reflection.Assembly.GetEntryAssembly()?.Location;
                var defFn   = System.IO.Path.Combine(
                    System.IO.Path.GetDirectoryName("" + exePath),
                    System.IO.Path.GetFileNameWithoutExtension("" + exePath) + ".options.json");

                Log.Info("Check {0} for default options in JSON ..", defFn);
                if (File.Exists(defFn))
                {
                    Options.Curr.ReadJson(defFn);
                }

                // overrule
                if (directAasx != null)
                {
                    Options.Curr.AasxToLoad = directAasx;
                }
            }
            else
            {
                // 2nd parse options
                Log.Info("Parsing commandline options ..");
                foreach (var a in e.Args)
                {
                    Log.Info("argument {0}", a);
                }
                Options.Curr.ParseArgs(e.Args);
            }

            // 3rd further commandline options in extra file
            if (Options.Curr.OptionsTextFn != null)
            {
                Log.Info("Parsing options from distinct file {0} ..", Options.Curr.OptionsTextFn);
                var fullfn = System.IO.Path.GetFullPath(Options.Curr.OptionsTextFn);
                Options.Curr.TryReadOptionsFile(fullfn);
            }

            // search for plugins?
            if (Options.Curr.PluginDir != null)
            {
                var searchDir = System.IO.Path.Combine(
                    System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetEntryAssembly()?.Location),
                    Options.Curr.PluginDir);
                Log.Info("Searching for plug-ins in {0} ..", searchDir);
                Plugins.TrySearchPlugins(searchDir, Options.Curr.PluginDll);
            }

            // Plugins to be loaded
            Log.Info("Try load and activate plug-ins ..");
            Plugins.TryActivatePlugins(Options.Curr.PluginDll);
            Plugins.TrySetOptionsForPlugins(Options.Curr);

            // at end, write all default options to JSON?
            if (Options.Curr.WriteDefaultOptionsFN != null)
            {
                // info
                var fullfn = System.IO.Path.GetFullPath(Options.Curr.WriteDefaultOptionsFN);
                Log.Info("Writing resulting options into JSOnN {0}", fullfn);

                // retrieve
                Plugins.TrGetDefaultOptionsForPlugins(Options.Curr);
                Options.Curr.WriteJson(fullfn);
            }

            // colors
            if (true)
            {
                var resNames = new[] {
                    "LightAccentColor", "DarkAccentColor", "DarkestAccentColor", "FocusErrorBrush"
                };
                for (int i = 0; i < resNames.Length; i++)
                {
                    var x = this.FindResource(resNames[i]);
                    if (x != null &&
                        x is System.Windows.Media.SolidColorBrush && Options.Curr.AccentColors.ContainsKey(i))
                    {
                        this.Resources[resNames[i]] = new System.Windows.Media.SolidColorBrush(
                            Options.Curr.AccentColors[i]);
                    }
                }
                resNames = new[] { "FocusErrorColor" };
                for (int i = 0; i < resNames.Length; i++)
                {
                    var x = this.FindResource(resNames[i]);
                    if (x != null && x is System.Windows.Media.Color && Options.Curr.AccentColors.ContainsKey(3 + i))
                    {
                        this.Resources[resNames[i]] = Options.Curr.AccentColors[3 + i];
                    }
                }
            }

            // show splash (required for licenses of open source)
            var splash = new CustomSplashScreenNew();

            splash.Show();

            // show main window
            MainWindow wnd = new MainWindow();

            wnd.Show();
        }