[2492] | 1 | #region License Information
|
---|
| 2 | /* HeuristicLab
|
---|
[15973] | 3 | * Copyright (C) 2002-2018 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
|
---|
[2492] | 4 | *
|
---|
| 5 | * This file is part of HeuristicLab.
|
---|
| 6 | *
|
---|
| 7 | * HeuristicLab is free software: you can redistribute it and/or modify
|
---|
| 8 | * it under the terms of the GNU General Public License as published by
|
---|
| 9 | * the Free Software Foundation, either version 3 of the License, or
|
---|
| 10 | * (at your option) any later version.
|
---|
| 11 | *
|
---|
| 12 | * HeuristicLab is distributed in the hope that it will be useful,
|
---|
| 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
| 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
---|
| 15 | * GNU General Public License for more details.
|
---|
| 16 | *
|
---|
| 17 | * You should have received a copy of the GNU General Public License
|
---|
| 18 | * along with HeuristicLab. If not, see <http://www.gnu.org/licenses/>.
|
---|
| 19 | */
|
---|
| 20 | #endregion
|
---|
| 21 |
|
---|
| 22 | using System;
|
---|
[13389] | 23 | using System.IO;
|
---|
| 24 | using System.Linq;
|
---|
| 25 | using System.Threading;
|
---|
| 26 | using System.Threading.Tasks;
|
---|
[13338] | 27 | using System.Windows.Forms;
|
---|
[13389] | 28 | using HeuristicLab.PluginInfrastructure;
|
---|
[13338] | 29 | using HeuristicLab.PluginInfrastructure.UI;
|
---|
[2492] | 30 |
|
---|
[2643] | 31 | namespace HeuristicLab {
|
---|
[2492] | 32 | static class Program {
|
---|
| 33 | [STAThread]
|
---|
[13338] | 34 | /// <summary>
|
---|
| 35 | /// Main entry point of the plugin infrastructure. Loads the starter form.
|
---|
| 36 | /// </summary>
|
---|
| 37 | /// <param name="args">Command line arguments</param>
|
---|
[2492] | 38 | static void Main(string[] args) {
|
---|
[13338] | 39 | if ((!FrameworkVersionErrorDialog.NET4_5Installed && !FrameworkVersionErrorDialog.MonoInstalled)
|
---|
| 40 | || (FrameworkVersionErrorDialog.MonoInstalled && !FrameworkVersionErrorDialog.MonoCorrectVersionInstalled)) {
|
---|
| 41 | Application.EnableVisualStyles();
|
---|
| 42 | Application.SetCompatibleTextRenderingDefault(false);
|
---|
| 43 | Application.Run(new FrameworkVersionErrorDialog());
|
---|
| 44 | } else {
|
---|
| 45 | try {
|
---|
| 46 | Application.EnableVisualStyles();
|
---|
| 47 | Application.SetCompatibleTextRenderingDefault(false);
|
---|
[13389] | 48 |
|
---|
| 49 | string pluginPath = Path.GetFullPath(Application.StartupPath);
|
---|
| 50 |
|
---|
| 51 | var pluginManager = new PluginManager(pluginPath);
|
---|
| 52 |
|
---|
| 53 | var splashScreen = new SplashScreen("Loading plugins...", 3000);
|
---|
| 54 | pluginManager.Initializing += (sender, eventArgs) => splashScreen.UpdateMessage("Loading plugins...");
|
---|
| 55 | pluginManager.PluginLoaded += (sender, eventArgs) => splashScreen.UpdateMessage("Loaded " + eventArgs.Entity.ToString());
|
---|
| 56 | pluginManager.ApplicationStarting += (sender, eventArgs) => splashScreen.UpdateMessage("Starting " + eventArgs.Entity.ToString());
|
---|
| 57 | pluginManager.ApplicationStarted += (sender, eventArgs) => splashScreen.UpdateMessage("Started " + eventArgs.Entity.ToString());
|
---|
| 58 |
|
---|
| 59 |
|
---|
| 60 | DiscoverPluginsAndRunOptimizerAsync(pluginManager, args);
|
---|
| 61 |
|
---|
| 62 | Application.Run(splashScreen);
|
---|
[13338] | 63 | } catch (Exception ex) {
|
---|
| 64 | MessageBox.Show(ex.Message, "Exception", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
---|
| 65 | }
|
---|
| 66 | }
|
---|
[2492] | 67 | }
|
---|
[13389] | 68 |
|
---|
| 69 | private static void DiscoverPluginsAndRunOptimizerAsync(PluginManager pluginManager, string[] args) {
|
---|
| 70 | // STAThread is necessary for a UI component we are using in the application
|
---|
| 71 | var t = new Thread(() => {
|
---|
| 72 | try {
|
---|
| 73 | pluginManager.DiscoverAndCheckPlugins();
|
---|
| 74 | var optimizerApp = pluginManager.Applications.FirstOrDefault(app => app.Name == "Optimizer");
|
---|
| 75 | pluginManager.Run(optimizerApp, CommandLineArgumentHandling.GetArguments(args));
|
---|
| 76 | } catch (Exception ex) {
|
---|
| 77 | MessageBox.Show(ex.Message, "Exception", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
---|
| 78 | }
|
---|
| 79 | });
|
---|
| 80 |
|
---|
| 81 | // cannot use a task because we need to set STA
|
---|
| 82 | t.SetApartmentState(ApartmentState.STA);
|
---|
| 83 | t.Start();
|
---|
| 84 | }
|
---|
[2492] | 85 | }
|
---|
| 86 | }
|
---|