Ejemplo n.º 1
0
        private void Application_Startup(object sender, StartupEventArgs e)
        {
            // allow long term logging (for report box)
            Log.Singleton.EnableLongTermStore();

            // catch unhandled exceptions
            SetupExceptionHandling();

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

            var exePath = System.Reflection.Assembly.GetEntryAssembly()?.Location;

            Options.ReplaceCurr(InferOptions(exePath, e.Args));

            // search for plugins?
            if (Options.Curr.PluginDir != null)
            {
                var searchDir = System.IO.Path.Combine(
                    System.IO.Path.GetDirectoryName(exePath),
                    Options.Curr.PluginDir);

                Log.Singleton.Info(
                    "Searching for the plugins in the plugin directory: {0}", searchDir);

                var pluginDllInfos = Plugins.TrySearchPlugins(searchDir);

                Log.Singleton.Info(
                    $"Found {pluginDllInfos.Count} plugin(s) in the plugin directory: {searchDir}");

                Options.Curr.PluginDll.AddRange(pluginDllInfos);
            }

            Log.Singleton.Info(
                $"Loading and activating {Options.Curr.PluginDll.Count} plugin(s)...");

            Plugins.LoadedPlugins = LoadAndActivatePlugins(Options.Curr.PluginDll);

            // at end, write all default options to JSON?
            if (Options.Curr.WriteDefaultOptionsFN != null)
            {
                // info
                var fullFilename = System.IO.Path.GetFullPath(Options.Curr.WriteDefaultOptionsFN);
                Log.Singleton.Info($"Writing resulting options to a JSON file: {fullFilename}");

                // retrieve
                Plugins.TryGetDefaultOptionsForPlugins(Options.Curr.PluginDll, Plugins.LoadedPlugins);
                OptionsInformation.WriteJson(Options.Curr, fullFilename);
            }

            // 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((OptionsInformation.ColorNames)i))
                    {
                        this.Resources[resNames[i]] = AnyUiDisplayContextWpf.GetWpfBrush(
                            Options.Curr.GetColor((OptionsInformation.ColorNames)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((OptionsInformation.ColorNames)(3 + i)))
                    {
                        this.Resources[resNames[i]] = AnyUiDisplayContextWpf.GetWpfColor(
                            Options.Curr.GetColor((OptionsInformation.ColorNames)(3 + i)));
                    }
                }
            }

            Pref pref = Pref.Read();

            // show splash (required for licenses of open source)
            if (Options.Curr.SplashTime != 0)
            {
                var splash = new CustomSplashScreenNew(pref);
                splash.Show();
            }

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

            wnd.Show();
        }
Ejemplo n.º 2
0
        public static void ParseArgs(string[] args, OptionsInformation optionsInformation)
        {
            // This is a sweep line for plugin arguments.
            var pluginArgs = new List <string>();

            for (int index = 0; index < args.Length; index++)
            {
                var arg     = args[index].Trim().ToLower();
                var morearg = (args.Length - 1) - index;

                // flags
                if (arg == "-maximized")
                {
                    optionsInformation.WindowMaximized = true;
                    continue;
                }
                if (arg == "-noflyouts")
                {
                    optionsInformation.UseFlyovers = false;
                    continue;
                }
                if (arg == "-intbrowse")
                {
                    optionsInformation.InternalBrowser = true;
                    continue;
                }
                if (arg == "-twopass")
                {
                    optionsInformation.EclassTwoPass = true;
                    continue;
                }
                if (arg == "-indirect-load-save")
                {
                    optionsInformation.IndirectLoadSave = true;
                    continue;
                }
                if (arg == "-load-without-prompt")
                {
                    optionsInformation.LoadWithoutPrompt = true;
                    continue;
                }

                // commands, which are executed on the fly ..
                if (arg == "-read-json" && morearg > 0)
                {
                    // parse
                    var fn = System.IO.Path.GetFullPath(args[index + 1]);
                    index++;

                    // execute in-line, in order to represent to correct order to the human operator
                    OptionsInformation.ReadJson(fn, optionsInformation);

                    // next arg
                    continue;
                }
                if (arg == "-write-json" && morearg > 0)
                {
                    // parse
                    var filename = System.IO.Path.GetFullPath(args[index + 1]);
                    index++;

                    // do
                    OptionsInformation.WriteJson(optionsInformation, filename);

                    // next arg
                    continue;
                }

                // options
                if (arg == "-left" && morearg > 0)
                {
                    if (Int32.TryParse(args[index + 1], out int i))
                    {
                        optionsInformation.WindowLeft = i;
                    }
                    index++;
                    continue;
                }
                if (arg == "-top" && morearg > 0)
                {
                    if (Int32.TryParse(args[index + 1], out int i))
                    {
                        optionsInformation.WindowTop = i;
                    }
                    index++;
                    continue;
                }
                if (arg == "-width" && morearg > 0)
                {
                    if (Int32.TryParse(args[index + 1], out int i))
                    {
                        optionsInformation.WindowWidth = i;
                    }
                    index++;
                    continue;
                }
                if (arg == "-height" && morearg > 0)
                {
                    if (Int32.TryParse(args[index + 1], out int i))
                    {
                        optionsInformation.WindowHeight = i;
                    }
                    index++;
                    continue;
                }

                if (arg == "-id-aas" && morearg > 0)
                {
                    optionsInformation.TemplateIdAas = args[index + 1];
                    index++;
                    continue;
                }
                if (arg == "-id-asset" && morearg > 0)
                {
                    optionsInformation.TemplateIdAsset = args[index + 1];
                    index++;
                    continue;
                }
                if (arg == "-id-sm-template" && morearg > 0)
                {
                    optionsInformation.TemplateIdSubmodelTemplate = args[index + 1];
                    index++;
                    continue;
                }
                if (arg == "-id-sm-instance" && morearg > 0)
                {
                    optionsInformation.TemplateIdSubmodelInstance = args[index + 1];
                    index++;
                    continue;
                }
                if (arg == "-id-cd" && morearg > 0)
                {
                    optionsInformation.TemplateIdConceptDescription = args[index + 1];
                    index++;
                    continue;
                }
                if (arg == "-eclass" && morearg > 0)
                {
                    optionsInformation.EclassDir = args[index + 1];
                    index++;
                    continue;
                }
                if (arg == "-qualifiers" && morearg > 0)
                {
                    optionsInformation.QualifiersFile = args[index + 1];
                    index++;
                    continue;
                }
                if (arg == "-logo" && morearg > 0)
                {
                    optionsInformation.LogoFile = args[index + 1];
                    index++;
                    continue;
                }
                if (arg == "-aasxrepo" && morearg > 0)
                {
                    optionsInformation.AasxRepositoryFn = args[index + 1];
                    index++;
                    continue;
                }
                if (arg == "-contenthome" && morearg > 0)
                {
                    optionsInformation.ContentHome = args[index + 1];
                    index++;
                    continue;
                }
                if (arg == "-splash" && morearg > 0)
                {
                    if (Int32.TryParse(args[index + 1], out int i))
                    {
                        optionsInformation.SplashTime = i;
                    }
                    index++;
                    continue;
                }
                if (arg == "-options" && morearg > 0)
                {
                    string pathToOptions = args[index + 1];
                    AasxPackageExplorer.Log.Singleton.Info(
                        $"Parsing options from a non-default options file: {pathToOptions}");
                    var fullFilename = System.IO.Path.GetFullPath(pathToOptions);
                    OptionsInformation.TryReadOptionsFile(fullFilename, optionsInformation);

                    index++;
                    continue;
                }
                if (arg == "-backupdir" && morearg > 0)
                {
                    optionsInformation.BackupDir = args[index + 1];
                    index++;
                    continue;
                }
                if (arg == "-resthost" && morearg > 0)
                {
                    optionsInformation.RestServerHost = args[index + 1];
                    index++;
                    continue;
                }
                if (arg == "-restport" && morearg > 0)
                {
                    optionsInformation.RestServerPort = args[index + 1];
                    index++;
                    continue;
                }
                if (arg == "-rem" && morearg > 0)
                {
                    // Add one argument to the plugin list
                    optionsInformation.Remarks.Add(args[index + 1]);
                    index++;
                    continue;
                }
                if (arg == "-write-all-json" && morearg > 0)
                {
                    // will be executed very late!
                    optionsInformation.WriteDefaultOptionsFN = args[index + 1];
                    index++;
                    continue;
                }
                if (arg == "-plugin-dir" && morearg > 0)
                {
                    optionsInformation.PluginDir = args[index + 1];
                    index++;
                    continue;
                }

                // Sweep-line options for plugins and DLL path
                if (arg == "-p" && morearg > 0)
                {
                    // Add exactly one following argument to the sweep line of plugin arguments
                    pluginArgs.Add(args[index + 1]);
                    index += 1;
                    continue;
                }
                if (arg == "-dll" && morearg > 0)
                {
                    // Process and reset the sweep line
                    optionsInformation.PluginDll.Add(
                        new PluginDllInfo(args[index + 1], pluginArgs.ToArray()));
                    pluginArgs.Clear();
                    index++;
                    continue;
                }

                // Colors
                {
                    var found = false;
                    for (int i = 0; i < 10; i++)
                    {
                        if (arg == $"-c{i:0}" && morearg > 0)
                        {
                            // ReSharper disable PossibleNullReferenceException
                            try
                            {
                                var c = (Color)ColorConverter.ConvertFromString(args[index + 1]);
                                optionsInformation.AccentColors.Add(i, c);
                            }
                            catch (Exception ex)
                            {
                                AdminShellNS.LogInternally.That.SilentlyIgnoredError(ex);
                            }
                            // ReSharper enable PossibleNullReferenceException

                            index++;
                            found = true;
                        }
                    }
                    if (found)
                    {
                        continue;
                    }
                }

                // if come to this point and obviously not an option, take this as load argument
                // allow for more options to come (motivation: allow "-write-json options.json" to be the last argument)
                if (!arg.StartsWith("-"))
                {
                    if (System.IO.File.Exists(args[index]))
                    {
                        optionsInformation.AasxToLoad = args[index];
                    }
                }
            }
        }