Changeset 13389


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

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

Location:
branches/RefactorPluginInfrastructure-2522
Files:
15 edited

Legend:

Unmodified
Added
Removed
  • branches/RefactorPluginInfrastructure-2522/HeuristicLab.Optimizer/3.3/Plugin.cs.frame

    r13321 r13389  
    5050  internal class HeuristicLabOptimizerApplication : ApplicationBase {
    5151    public override void Run(ICommandLineArgument[] args) {
     52      Application.EnableVisualStyles();
     53      Application.SetCompatibleTextRenderingDefault(false);
    5254      HeuristicLab.MainForm.WindowsForms.MainForm mainForm = null;
    5355
  • branches/RefactorPluginInfrastructure-2522/HeuristicLab.PluginInfrastructure.UI/HeuristicLab.PluginInfrastructure.UI-4.0.csproj

    r13363 r13389  
    7474      <DependentUpon>SplashScreen.cs</DependentUpon>
    7575    </Compile>
    76     <Compile Include="StarterForm.cs">
    77       <SubType>Form</SubType>
    78     </Compile>
    79     <Compile Include="StarterForm.Designer.cs">
    80       <DependentUpon>StarterForm.cs</DependentUpon>
    81     </Compile>
    8276    <Service Include="{94E38DFF-614B-4cbd-B67C-F211BB35CE8B}" />
    8377  </ItemGroup>
  • branches/RefactorPluginInfrastructure-2522/HeuristicLab.PluginInfrastructure.UI/Properties

    • Property svn:ignore set to
      AssemblyInfo.cs
  • branches/RefactorPluginInfrastructure-2522/HeuristicLab.PluginInfrastructure.UI/SplashScreen.cs

    r13353 r13389  
    2424using System.Reflection;
    2525using System.Windows.Forms;
    26 using HeuristicLab.PluginInfrastructure.Manager;
    2726
    2827namespace HeuristicLab.PluginInfrastructure.UI {
    29   internal partial class SplashScreen : Form {
     28  public partial class SplashScreen : Form {
    3029    private const int FADE_INTERVAL = 50;
    3130    private Timer fadeTimer;
    3231    private int initialInterval;
    33     private PluginManager pluginManager;
    3432
    35     internal SplashScreen() {
     33    private SplashScreen() {
    3634      InitializeComponent();
    3735    }
    3836
    39     internal SplashScreen(PluginManager manager, int initialInterval)
     37    public SplashScreen(string initialText, int initialInterval)
    4038      : this() {
    4139      this.initialInterval = initialInterval;
    42       this.pluginManager = manager;
    4340
    4441      var entryAssembly = Assembly.GetEntryAssembly();
    45       RegisterPluginManagerEventHandlers();
     42      // RegisterPluginManagerEventHandlers();
    4643
    47       versionLabel.Text = "Version " + entryAssembly.GetFileVersion() + " " 
     44      versionLabel.Text = "Version " + entryAssembly.GetFileVersion() + " "
    4845        + entryAssembly.GetCustomAttributes().OfType<AssemblyInformationalVersionAttribute>().First().InformationalVersion; // code name
    4946      infoLabel.Text = "";
     
    5552      fadeTimer.Tick += fadeTimer_Elapsed;
    5653      fadeTimer.Interval = initialInterval;
     54      fadeTimer.Start();
     55
     56      Opacity = 1;
     57      infoLabel.Text = initialText;
     58
    5759    }
    5860
    59     #region events
    60     private void RegisterPluginManagerEventHandlers() {
    61       pluginManager.ApplicationStarted += new EventHandler<PluginInfrastructureEventArgs>(manager_ApplicationStarted);
    62       pluginManager.ApplicationStarting += new EventHandler<PluginInfrastructureEventArgs>(manager_ApplicationStarting);
    63       pluginManager.Initializing += new EventHandler<PluginInfrastructureEventArgs>(manager_Initializing);
    64       pluginManager.Initialized += new EventHandler<PluginInfrastructureEventArgs>(manager_Initialized);
    65       pluginManager.PluginLoaded += new EventHandler<PluginInfrastructureEventArgs>(manager_PluginLoaded);
    66       pluginManager.PluginUnloaded += new EventHandler<PluginInfrastructureEventArgs>(manager_PluginUnloaded);
    67     }
    68 
    69     private void DeregisterPluginManagerEventHandlers() {
    70       pluginManager.ApplicationStarted -= new EventHandler<PluginInfrastructureEventArgs>(manager_ApplicationStarted);
    71       pluginManager.ApplicationStarting -= new EventHandler<PluginInfrastructureEventArgs>(manager_ApplicationStarting);
    72       pluginManager.Initializing -= new EventHandler<PluginInfrastructureEventArgs>(manager_Initializing);
    73       pluginManager.Initialized -= new EventHandler<PluginInfrastructureEventArgs>(manager_Initialized);
    74       pluginManager.PluginLoaded -= new EventHandler<PluginInfrastructureEventArgs>(manager_PluginLoaded);
    75       pluginManager.PluginUnloaded -= new EventHandler<PluginInfrastructureEventArgs>(manager_PluginUnloaded);
    76     }
    77 
    78     private void manager_PluginUnloaded(object sender, PluginInfrastructureEventArgs e) {
    79       SafeUpdateMessage("Unloaded " + e.Entity);
    80     }
    81 
    82     private void manager_PluginLoaded(object sender, PluginInfrastructureEventArgs e) {
    83       SafeUpdateMessage("Loaded " + e.Entity);
    84     }
    85 
    86     private void manager_Initialized(object sender, PluginInfrastructureEventArgs e) {
    87       SafeUpdateMessage("Initialized");
    88     }
    89 
    90     private void manager_Initializing(object sender, PluginInfrastructureEventArgs e) {
    91       SafeUpdateMessage("Initializing");
    92     }
    93 
    94     private void manager_ApplicationStarting(object sender, PluginInfrastructureEventArgs e) {
    95       SafeUpdateMessage("Starting " + e.Entity);
    96     }
    97 
    98     private void manager_ApplicationStarted(object sender, PluginInfrastructureEventArgs e) {
    99       SafeUpdateMessage("Started " + e.Entity);
    100     }
    101     // called from event handlers
    102     private void SafeUpdateMessage(string msg) {
     61    public void UpdateMessage(string msg) {
    10362      try {
    104         Invoke((Action<string>)UpdateMessage, msg);
     63        if (InvokeRequired) Invoke((Action<string>)UpdateMessage, msg);
     64        else {
     65          ResetFadeTimer();
     66          infoLabel.Text = msg;
     67        }
    10568      } catch (ObjectDisposedException) { }
    10669    }
     
    11174      FadeOut();
    11275    }
    113     #endregion
    114 
    115     public void Show(string initialText) {
    116       if (InvokeRequired) Invoke((Action<string>)Show, initialText);
    117       else {
    118         Opacity = 1;
    119         infoLabel.Text = initialText;
    120         ResetFadeTimer();
    121         Show();
    122       }
    123     }
    124 
    125     public void Show(IWin32Window owner, string initialText) {
    126       if (InvokeRequired) Invoke((Action<IWin32Window, string>)Show, owner, initialText);
    127       else {
    128         Opacity = 1;
    129         infoLabel.Text = initialText;
    130         ResetFadeTimer();
    131         Show(owner);
    132       }
    133     }
    13476
    13577    private void ResetFadeTimer() {
     
    13880      fadeTimer.Interval = initialInterval;
    13981      fadeTimer.Start();
    140     }
    141 
    142     private void UpdateMessage(string msg) {
    143       ResetFadeTimer();
    144       infoLabel.Text = msg;
    145       Application.DoEvents(); // force immediate update of splash screen control
    14682    }
    14783
     
    15692        Opacity = 0;
    15793        fadeTimer.Stop();
    158         Hide();
     94        Close();
    15995      }
    160     }
    161 
    162     protected override void OnClosing(System.ComponentModel.CancelEventArgs e) {
    163       // deregister events when form is closing
    164       DeregisterPluginManagerEventHandlers();
    165       base.OnClosing(e);
    16696    }
    16797  }
  • branches/RefactorPluginInfrastructure-2522/HeuristicLab.PluginInfrastructure/3.3/ApplicationDescription.cs

    r13341 r13389  
    2222using System;
    2323
    24 namespace HeuristicLab.PluginInfrastructure.Manager {
     24namespace HeuristicLab.PluginInfrastructure {
    2525  /// <summary>
    2626  /// Class that provides information about an application.
  • branches/RefactorPluginInfrastructure-2522/HeuristicLab.PluginInfrastructure/3.3/PluginDescription.cs

    r13341 r13389  
    2424using System.Linq;
    2525
    26 namespace HeuristicLab.PluginInfrastructure.Manager {
     26namespace HeuristicLab.PluginInfrastructure {
    2727  /// <summary>
    2828  /// Holds information of loaded plugins that is needed for plugin management.
  • branches/RefactorPluginInfrastructure-2522/HeuristicLab.PluginInfrastructure/3.3/PluginDescriptionIterator.cs

    r12012 r13389  
    2323using System.Linq;
    2424
    25 namespace HeuristicLab.PluginInfrastructure.Manager {
     25namespace HeuristicLab.PluginInfrastructure {
    2626  internal static class PluginDescriptionIterator {
    2727    internal static IEnumerable<PluginDescription> IterateDependenciesBottomUp(IEnumerable<PluginDescription> pluginDescriptions) {
  • branches/RefactorPluginInfrastructure-2522/HeuristicLab.PluginInfrastructure/3.3/PluginFile.cs

    r13341 r13389  
    2222using System;
    2323
    24 namespace HeuristicLab.PluginInfrastructure.Manager {
     24namespace HeuristicLab.PluginInfrastructure {
    2525  /// <summary>
    2626  /// Plugin files have a name and a type.
  • branches/RefactorPluginInfrastructure-2522/HeuristicLab.PluginInfrastructure/3.3/PluginInfrastructureEventArgs.cs

    r13341 r13389  
    2222using System;
    2323
    24 namespace HeuristicLab.PluginInfrastructure.Manager {
     24namespace HeuristicLab.PluginInfrastructure {
    2525  [Serializable]
    2626  public sealed class PluginInfrastructureEventArgs : EventArgs {
  • branches/RefactorPluginInfrastructure-2522/HeuristicLab.PluginInfrastructure/3.3/PluginManager.cs

    r13341 r13389  
    2626using System.Security.Permissions;
    2727
    28 namespace HeuristicLab.PluginInfrastructure.Manager {
     28namespace HeuristicLab.PluginInfrastructure {
    2929
    3030  // must extend MarshalByRefObject because of event passing between Loader and PluginManager (each in it's own AppDomain)
  • branches/RefactorPluginInfrastructure-2522/HeuristicLab.PluginInfrastructure/3.3/PluginValidator.cs

    r13363 r13389  
    2929
    3030
    31 namespace HeuristicLab.PluginInfrastructure.Manager {
     31namespace HeuristicLab.PluginInfrastructure {
    3232  /// <summary>
    3333  /// Discovers all installed plugins in the plugin directory. Checks correctness of plugin meta-data and if
  • branches/RefactorPluginInfrastructure-2522/HeuristicLab.PluginInfrastructure/3.3/SandboxApplicationManager.cs

    r12012 r13389  
    2525using System.Linq;
    2626using System.Reflection;
    27 using HeuristicLab.PluginInfrastructure.Manager;
    2827
    2928namespace HeuristicLab.PluginInfrastructure {
  • branches/RefactorPluginInfrastructure-2522/HeuristicLab.PluginInfrastructure/3.3/SandboxManager.cs

    r13341 r13389  
    2424using System.Security;
    2525using System.Security.Permissions;
    26 using HeuristicLab.PluginInfrastructure.Manager;
    2726
    28 namespace HeuristicLab.PluginInfrastructure.Sandboxing {
     27namespace HeuristicLab.PluginInfrastructure {
    2928  // used by Hive Slave
    3029  public static class SandboxManager {
  • branches/RefactorPluginInfrastructure-2522/HeuristicLab/3.3/HeuristicLab-3.3.csproj

    r13340 r13389  
    193193      <Private>False</Private>
    194194    </ProjectReference>
     195    <ProjectReference Include="..\..\HeuristicLab.PluginInfrastructure\3.3\HeuristicLab.PluginInfrastructure-3.3.csproj">
     196      <Project>{94186A6A-5176-4402-AE83-886557B53CCA}</Project>
     197      <Name>HeuristicLab.PluginInfrastructure-3.3</Name>
     198    </ProjectReference>
    195199  </ItemGroup>
    196200  <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
  • 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.