Free cookie consent management tool by TermsFeed Policy Generator

Changeset 8818


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

#1926:

  • added OpenArgument
  • refactored argument handling infrastructure
Location:
trunk/sources
Files:
1 added
15 edited

Legend:

Unmodified
Added
Removed
  • trunk/sources/HeuristicLab.MainForm.WindowsForms/3.3/MainForms/MainForm.cs

    r7259 r8818  
    6868    }
    6969
     70    private IEnumerable<ICommandLineArgument> arguments;
     71    public IEnumerable<ICommandLineArgument> Arguments {
     72      get { return arguments; }
     73      set {
     74        if (arguments == null) arguments = value;
     75        else throw new InvalidOperationException("Arguments can only be set once and were already set.");
     76      }
     77    }
     78
    7079    public override Cursor Cursor {
    7180      get { return base.Cursor; }
  • trunk/sources/HeuristicLab.MainForm/3.3/Interfaces/IMainForm.cs

    r7259 r8818  
    2323using System.Collections.Generic;
    2424using HeuristicLab.Common;
     25using HeuristicLab.PluginInfrastructure;
    2526
    2627namespace HeuristicLab.MainForm {
    2728  public interface IMainForm {
    2829    string Title { get; set; }
     30    IEnumerable<ICommandLineArgument> Arguments { get; set; }
    2931
    3032    IView ActiveView { get; }
  • trunk/sources/HeuristicLab.Optimizer/3.3/FileManager.cs

    r8587 r8818  
    2121
    2222using System;
     23using System.Collections.Generic;
    2324using System.Linq;
    2425using System.Windows.Forms;
     
    5960
    6061      if (openFileDialog.ShowDialog() == DialogResult.OK) {
    61         foreach (string filename in openFileDialog.FileNames) {
    62           ((MainForm.WindowsForms.MainForm)MainFormManager.MainForm).SetAppStartingCursor();
    63           ContentManager.LoadAsync(filename, LoadingCompleted);
    64         }
     62        OpenFiles(openFileDialog.FileNames);
    6563      }
    6664    }
     65
     66    public static void OpenFiles(IEnumerable<string> fileNames) {
     67      foreach (string filename in fileNames) {
     68        ((MainForm.WindowsForms.MainForm)MainFormManager.MainForm).SetAppStartingCursor();
     69        ContentManager.LoadAsync(filename, LoadingCompleted);
     70      }
     71    }
     72
    6773    private static void LoadingCompleted(IStorableContent content, Exception error) {
    6874      try {
  • trunk/sources/HeuristicLab.Optimizer/3.3/Plugin.cs.frame

    r8246 r8818  
    2020#endregion
    2121
     22using System.Linq;
    2223using System.Windows.Forms;
    2324using HeuristicLab.Clients.Access;
     
    4849  [Application("Optimizer", "HeuristicLab Optimizer 3.3.7.$WCREV$")]
    4950  internal class HeuristicLabOptimizerApplication : ApplicationBase {
    50     public override void Run() {
    51      HeuristicLab.MainForm.WindowsForms.MainForm mainForm = null;
     51    public override void Run(ICommandLineArgument[] args) {
     52      HeuristicLab.MainForm.WindowsForms.MainForm mainForm = null;
    5253
    5354      if (Settings.Default.MainFormType == OptimizerMainFormTypes.DockingMainForm) {
     
    6465
    6566        mainForm.ShowContentInViewHost = true;
     67        mainForm.Arguments = args;
     68        var filesToOpen = mainForm.Arguments.OfType<OpenArgument>().Select(x => x.Value);
     69        mainForm.Load += (sender, eventArgs) => FileManager.OpenFiles(filesToOpen);
    6670        Application.Run(mainForm);
    6771      } else {
  • trunk/sources/HeuristicLab.Persistence.GUI/3.3/Plugin.cs.frame

    r8246 r8818  
    1313  [Application("Persistence Configuration", "Configure type mappings of persistence")]
    1414  public class HeuristicLabPersistenceGUIApplication : ApplicationBase {
    15     public override void Run() {
     15    public override void Run(ICommandLineArgument[] args) {
    1616      Application.EnableVisualStyles();
    1717      Application.SetCompatibleTextRenderingDefault(false);
  • 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.