Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
11/24/15 19:02:57 (8 years ago)
Author:
gkronber
Message:

#2522: removed Starter form and instead init plugin discovery and launch of application from Startup project (.exe)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/RefactorPluginInfrastructure-2522/HeuristicLab/3.3/Program.cs

    r13338 r13389  
    2121
    2222using System;
     23using System.IO;
     24using System.Linq;
     25using System.Threading;
     26using System.Threading.Tasks;
    2327using System.Windows.Forms;
     28using HeuristicLab.PluginInfrastructure;
    2429using HeuristicLab.PluginInfrastructure.UI;
    2530
     
    4146          Application.EnableVisualStyles();
    4247          Application.SetCompatibleTextRenderingDefault(false);
    43           Application.Run(new StarterForm(args));
     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);
    4463        } catch (Exception ex) {
    4564          MessageBox.Show(ex.Message, "Exception", MessageBoxButtons.OK, MessageBoxIcon.Error);
     
    4766      }
    4867    }
     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    }
    4985  }
    5086}
Note: See TracChangeset for help on using the changeset viewer.