Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
10/17/12 21:46:00 (12 years ago)
Author:
jkarder
Message:

#1926:

  • added OpenArgument
  • refactored argument handling infrastructure
Location:
trunk/sources/HeuristicLab.PluginInfrastructure/3.3
Files:
1 added
10 edited

Legend:

Unmodified
Added
Removed
  • trunk/sources/HeuristicLab.PluginInfrastructure/3.3/BaseClasses/ApplicationBase.cs

    r7259 r8818  
    6767    /// Runs the application.
    6868    /// </summary>
    69     public abstract void Run();
     69    public abstract void Run(ICommandLineArgument[] args);
    7070
    7171    #endregion
  • trunk/sources/HeuristicLab.PluginInfrastructure/3.3/CommandLineArgumentHandling/Arguments/HideStarterArgument.cs

    r8748 r8818  
    2020#endregion
    2121
     22using System;
     23
    2224namespace HeuristicLab.PluginInfrastructure {
     25  [Serializable]
    2326  public class HideStarterArgument : CommandLineArgument<bool> {
    2427    public const string TOKEN = "hideStarter";
  • trunk/sources/HeuristicLab.PluginInfrastructure/3.3/CommandLineArgumentHandling/Arguments/StartArgument.cs

    r8748 r8818  
    2020#endregion
    2121
     22using System;
     23
    2224namespace HeuristicLab.PluginInfrastructure {
     25  [Serializable]
    2326  public class StartArgument : CommandLineArgument<string> {
    2427    public const string TOKEN = "start";
  • trunk/sources/HeuristicLab.PluginInfrastructure/3.3/CommandLineArgumentHandling/CommandLineArgument.cs

    r8748 r8818  
    2020#endregion
    2121
     22using System;
     23
    2224namespace HeuristicLab.PluginInfrastructure {
     25  [Serializable]
    2326  public abstract class CommandLineArgument<T> : ICommandLineArgument<T> {
    2427    object ICommandLineArgument.Value { get { return Value; } }
  • trunk/sources/HeuristicLab.PluginInfrastructure/3.3/CommandLineArgumentHandling/CommandLineArgumentHandling.cs

    r8748 r8818  
    2222using System;
    2323using System.Collections.Generic;
     24using System.IO;
    2425using System.Linq;
    2526using System.Text.RegularExpressions;
     
    4344    private static ICommandLineArgument ParseArgument(string entry) {
    4445      var regex = new Regex(@"^/[A-Za-z]+(:[A-Za-z0-9\s]+)?$");
    45       if (!regex.IsMatch(entry)) return null;
    46       entry = entry.Remove(0, 1);
    47       var parts = entry.Split(':');
    48       string key = parts[0].Trim();
    49       string value = parts.Length == 2 ? parts[1].Trim() : string.Empty;
    50       switch (key) {
    51         case StartArgument.TOKEN: return new StartArgument(value);
    52         case HideStarterArgument.TOKEN: return new HideStarterArgument(value);
    53         default: return null;
    54       }
     46      bool isFile = File.Exists(entry);
     47      if (!regex.IsMatch(entry) && !isFile) return null;
     48      if (!isFile) {
     49        entry = entry.Remove(0, 1);
     50        var parts = entry.Split(':');
     51        string key = parts[0].Trim();
     52        string value = parts.Length == 2 ? parts[1].Trim() : string.Empty;
     53        switch (key) {
     54          case StartArgument.TOKEN: return new StartArgument(value);
     55          case HideStarterArgument.TOKEN: return new HideStarterArgument(value);
     56          default: return null;
     57        }
     58      } else return new OpenArgument(entry);
    5559    }
    5660  }
  • trunk/sources/HeuristicLab.PluginInfrastructure/3.3/HeuristicLab.PluginInfrastructure-3.3.csproj

    r8748 r8818  
    215215      <DependentUpon>PluginView.cs</DependentUpon>
    216216    </Compile>
     217    <Compile Include="CommandLineArgumentHandling\Arguments\OpenArgument.cs" />
    217218    <Compile Include="CommandLineArgumentHandling\Arguments\HideStarterArgument.cs" />
    218219    <Compile Include="CommandLineArgumentHandling\Arguments\StartArgument.cs" />
  • trunk/sources/HeuristicLab.PluginInfrastructure/3.3/Interfaces/IApplication.cs

    r7259 r8818  
    3737    /// Main entry point for the application.
    3838    /// </summary>
    39     void Run();
     39    void Run(ICommandLineArgument[] args);
    4040  }
    4141}
  • trunk/sources/HeuristicLab.PluginInfrastructure/3.3/Manager/PluginManager.cs

    r7259 r8818  
    110110    /// </summary>
    111111    /// <param name="appInfo">application to run</param>
    112     public void Run(ApplicationDescription appInfo) {
     112    public void Run(ApplicationDescription appInfo, ICommandLineArgument[] args) {
    113113      if (!initialized) throw new InvalidOperationException("PluginManager is not initialized. DiscoverAndCheckPlugins() must be called before Run()");
    114114      // create a separate AppDomain for the application
     
    129129        applicationManager.PrepareApplicationDomain(applications, plugins);
    130130        OnApplicationStarted(new PluginInfrastructureEventArgs(appInfo));
    131         applicationManager.Run(appInfo);
     131        applicationManager.Run(appInfo, args);
    132132      }
    133133      finally {
  • trunk/sources/HeuristicLab.PluginInfrastructure/3.3/SandboxApplicationManager.cs

    r8571 r8818  
    115115    /// </summary>
    116116    /// <param name="appInfo">Description of the application to run</param>
    117     internal void Run(ApplicationDescription appInfo) {
     117    internal void Run(ApplicationDescription appInfo, ICommandLineArgument[] args) {
    118118      IApplication runnablePlugin = (IApplication)Activator.CreateInstance(appInfo.DeclaringAssemblyName, appInfo.DeclaringTypeName).Unwrap();
    119119      try {
    120         runnablePlugin.Run();
     120        runnablePlugin.Run(args);
    121121      }
    122122      finally {
  • trunk/sources/HeuristicLab.PluginInfrastructure/3.3/Starter/StarterForm.cs

    r8748 r8818  
    3939    private const string pluginManagerItemName = "Plugin Manager";
    4040    private const string updatePluginsItemName = "Updates Available";
     41    private const string optimizerItemName = "Optimizer";
    4142
    4243    private readonly ICommandLineArgument[] arguments;
     
    8485
    8586    protected override void SetVisibleCore(bool value) {
    86       value &= !arguments.OfType<HideStarterArgument>().Any();
     87      value &= !(arguments.OfType<HideStarterArgument>().Any() || arguments.OfType<OpenArgument>().Any());
    8788      if (!value) HandleArguments();
    8889      base.SetVisibleCore(value);
     
    144145        } else {
    145146          ApplicationDescription app = (ApplicationDescription)applicationsListView.SelectedItems[0].Tag;
    146           StartApplication(app);
     147          StartApplication(app, arguments);
    147148        }
    148149      }
     
    171172    private void splashScreen_VisibleChanged(object sender, EventArgs e) {
    172173      // close hidden starter form
    173       if (!splashScreen.Visible && arguments != null && arguments.OfType<HideStarterArgument>().Any())
     174      if (!splashScreen.Visible && arguments != null &&
     175           (arguments.OfType<HideStarterArgument>().Any() || arguments.OfType<OpenArgument>().Any()))
    174176        Close();
    175177    }
     
    263265    private void HandleArguments() {
    264266      try {
     267        if (arguments.OfType<OpenArgument>().Any() && !arguments.OfType<StartArgument>().Any()) {
     268          InitiateApplicationStart(optimizerItemName);
     269        }
    265270        foreach (var argument in arguments) {
    266271          if (argument is StartArgument) {
    267             var appDesc = (from desc in pluginManager.Applications
    268                            where desc.Name.Equals(argument.Value)
    269                            select desc).SingleOrDefault();
    270             if (appDesc != null) {
    271               StartApplication(appDesc);
    272             } else {
    273               MessageBox.Show("Cannot start application " + argument.Value + ".",
    274                               "HeuristicLab",
    275                               MessageBoxButtons.OK,
    276                               MessageBoxIcon.Warning);
    277             }
     272            var arg = (StartArgument)argument;
     273            InitiateApplicationStart(arg.Value);
    278274          }
    279275        }
     
    284280    }
    285281
    286     private void StartApplication(ApplicationDescription app) {
     282    private void InitiateApplicationStart(string appName) {
     283      var appDesc = (from desc in pluginManager.Applications
     284                     where desc.Name.Equals(appName)
     285                     select desc).SingleOrDefault();
     286      if (appDesc != null) {
     287        StartApplication(appDesc, arguments);
     288      } else {
     289        MessageBox.Show("Cannot start application " + appName + ".",
     290                        "HeuristicLab",
     291                        MessageBoxButtons.OK,
     292                        MessageBoxIcon.Warning);
     293      }
     294    }
     295
     296    private void StartApplication(ApplicationDescription app, ICommandLineArgument[] args) {
    287297      splashScreen.Show("Loading " + app.Name);
    288298      Thread t = new Thread(delegate() {
     
    291301          try {
    292302            if (!abortRequested) {
    293               pluginManager.Run(app);
     303              pluginManager.Run(app, args);
    294304            }
    295305            stopped = true;
Note: See TracChangeset for help on using the changeset viewer.