Changeset 8818 for trunk/sources/HeuristicLab.PluginInfrastructure
- Timestamp:
- 10/17/12 21:46:00 (12 years ago)
- 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 67 67 /// Runs the application. 68 68 /// </summary> 69 public abstract void Run( );69 public abstract void Run(ICommandLineArgument[] args); 70 70 71 71 #endregion -
trunk/sources/HeuristicLab.PluginInfrastructure/3.3/CommandLineArgumentHandling/Arguments/HideStarterArgument.cs
r8748 r8818 20 20 #endregion 21 21 22 using System; 23 22 24 namespace HeuristicLab.PluginInfrastructure { 25 [Serializable] 23 26 public class HideStarterArgument : CommandLineArgument<bool> { 24 27 public const string TOKEN = "hideStarter"; -
trunk/sources/HeuristicLab.PluginInfrastructure/3.3/CommandLineArgumentHandling/Arguments/StartArgument.cs
r8748 r8818 20 20 #endregion 21 21 22 using System; 23 22 24 namespace HeuristicLab.PluginInfrastructure { 25 [Serializable] 23 26 public class StartArgument : CommandLineArgument<string> { 24 27 public const string TOKEN = "start"; -
trunk/sources/HeuristicLab.PluginInfrastructure/3.3/CommandLineArgumentHandling/CommandLineArgument.cs
r8748 r8818 20 20 #endregion 21 21 22 using System; 23 22 24 namespace HeuristicLab.PluginInfrastructure { 25 [Serializable] 23 26 public abstract class CommandLineArgument<T> : ICommandLineArgument<T> { 24 27 object ICommandLineArgument.Value { get { return Value; } } -
trunk/sources/HeuristicLab.PluginInfrastructure/3.3/CommandLineArgumentHandling/CommandLineArgumentHandling.cs
r8748 r8818 22 22 using System; 23 23 using System.Collections.Generic; 24 using System.IO; 24 25 using System.Linq; 25 26 using System.Text.RegularExpressions; … … 43 44 private static ICommandLineArgument ParseArgument(string entry) { 44 45 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); 55 59 } 56 60 } -
trunk/sources/HeuristicLab.PluginInfrastructure/3.3/HeuristicLab.PluginInfrastructure-3.3.csproj
r8748 r8818 215 215 <DependentUpon>PluginView.cs</DependentUpon> 216 216 </Compile> 217 <Compile Include="CommandLineArgumentHandling\Arguments\OpenArgument.cs" /> 217 218 <Compile Include="CommandLineArgumentHandling\Arguments\HideStarterArgument.cs" /> 218 219 <Compile Include="CommandLineArgumentHandling\Arguments\StartArgument.cs" /> -
trunk/sources/HeuristicLab.PluginInfrastructure/3.3/Interfaces/IApplication.cs
r7259 r8818 37 37 /// Main entry point for the application. 38 38 /// </summary> 39 void Run( );39 void Run(ICommandLineArgument[] args); 40 40 } 41 41 } -
trunk/sources/HeuristicLab.PluginInfrastructure/3.3/Manager/PluginManager.cs
r7259 r8818 110 110 /// </summary> 111 111 /// <param name="appInfo">application to run</param> 112 public void Run(ApplicationDescription appInfo ) {112 public void Run(ApplicationDescription appInfo, ICommandLineArgument[] args) { 113 113 if (!initialized) throw new InvalidOperationException("PluginManager is not initialized. DiscoverAndCheckPlugins() must be called before Run()"); 114 114 // create a separate AppDomain for the application … … 129 129 applicationManager.PrepareApplicationDomain(applications, plugins); 130 130 OnApplicationStarted(new PluginInfrastructureEventArgs(appInfo)); 131 applicationManager.Run(appInfo );131 applicationManager.Run(appInfo, args); 132 132 } 133 133 finally { -
trunk/sources/HeuristicLab.PluginInfrastructure/3.3/SandboxApplicationManager.cs
r8571 r8818 115 115 /// </summary> 116 116 /// <param name="appInfo">Description of the application to run</param> 117 internal void Run(ApplicationDescription appInfo ) {117 internal void Run(ApplicationDescription appInfo, ICommandLineArgument[] args) { 118 118 IApplication runnablePlugin = (IApplication)Activator.CreateInstance(appInfo.DeclaringAssemblyName, appInfo.DeclaringTypeName).Unwrap(); 119 119 try { 120 runnablePlugin.Run( );120 runnablePlugin.Run(args); 121 121 } 122 122 finally { -
trunk/sources/HeuristicLab.PluginInfrastructure/3.3/Starter/StarterForm.cs
r8748 r8818 39 39 private const string pluginManagerItemName = "Plugin Manager"; 40 40 private const string updatePluginsItemName = "Updates Available"; 41 private const string optimizerItemName = "Optimizer"; 41 42 42 43 private readonly ICommandLineArgument[] arguments; … … 84 85 85 86 protected override void SetVisibleCore(bool value) { 86 value &= ! arguments.OfType<HideStarterArgument>().Any();87 value &= !(arguments.OfType<HideStarterArgument>().Any() || arguments.OfType<OpenArgument>().Any()); 87 88 if (!value) HandleArguments(); 88 89 base.SetVisibleCore(value); … … 144 145 } else { 145 146 ApplicationDescription app = (ApplicationDescription)applicationsListView.SelectedItems[0].Tag; 146 StartApplication(app );147 StartApplication(app, arguments); 147 148 } 148 149 } … … 171 172 private void splashScreen_VisibleChanged(object sender, EventArgs e) { 172 173 // 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())) 174 176 Close(); 175 177 } … … 263 265 private void HandleArguments() { 264 266 try { 267 if (arguments.OfType<OpenArgument>().Any() && !arguments.OfType<StartArgument>().Any()) { 268 InitiateApplicationStart(optimizerItemName); 269 } 265 270 foreach (var argument in arguments) { 266 271 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); 278 274 } 279 275 } … … 284 280 } 285 281 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) { 287 297 splashScreen.Show("Loading " + app.Name); 288 298 Thread t = new Thread(delegate() { … … 291 301 try { 292 302 if (!abortRequested) { 293 pluginManager.Run(app );303 pluginManager.Run(app, args); 294 304 } 295 305 stopped = true;
Note: See TracChangeset
for help on using the changeset viewer.