Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
01/04/10 18:55:46 (14 years ago)
Author:
gkronber
Message:

Fixed projects to work with new plugin infrastructure. #799

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/PluginInfrastructure Refactoring/HeuristicLab/Program.cs

    r1107 r2587  
    2626using System.Threading;
    2727using System.Text;
     28using System.Linq;
    2829using HeuristicLab.PluginInfrastructure;
     30using HeuristicLab.PluginInfrastructure.Advanced;
     31using System.Runtime.InteropServices;
     32using HeuristicLab.PluginInfrastructure.Starter;
     33using System.IO;
    2934
    3035namespace HeuristicLab {
     
    3237    [STAThread]
    3338    static void Main(string[] args) {
    34       try {
    35         if (args.Length == 0) {  // normal mode
     39      if (args.Length == 0) {  // normal mode
     40        try {
    3641          Application.EnableVisualStyles();
    3742          Application.SetCompatibleTextRenderingDefault(false);
    38           Application.Run(new MainForm());
    39         } else if (args.Length == 1) {  // start specific application
    40           PluginManager.Manager.Initialize();
     43          Application.Run(new StarterForm());
     44        }
     45        catch (Exception ex) {
     46          ShowErrorMessageBox(ex);
     47        }
    4148
    42           ApplicationInfo app = null;
    43           foreach (ApplicationInfo info in PluginManager.Manager.InstalledApplications) {
    44             if (info.Name == args[0])
    45               app = info;
    46           }
    47           if (app == null) {  // application not found
    48             MessageBox.Show("Cannot start application.\nApplication " + args[0] + " is not installed.\n\nStarting HeuristicLab in normal mode ...",
    49                             "HeuristicLab",
    50                             MessageBoxButtons.OK,
    51                             MessageBoxIcon.Warning);
    52             Application.EnableVisualStyles();
    53             Application.SetCompatibleTextRenderingDefault(false);
    54             Application.Run(new MainForm());
    55           } else {
    56             PluginManager.Manager.Run(app);
    57           }
     49      } else {
     50        var cmd = args[0].ToUpperInvariant();
     51        string pluginDir = Path.GetFullPath(Application.StartupPath);
     52        switch (cmd) {
     53          case "START": {
     54              if (args.Length != 2) {
     55                PrintUsage();
     56              } else {
     57                Application.EnableVisualStyles();
     58                Application.SetCompatibleTextRenderingDefault(false);
     59                Application.Run(new StarterForm(args[1]));
     60              }
     61              break;
     62            }
     63          case "SHOW": {
     64              InstallationManagerConsole managerConsole = new InstallationManagerConsole(pluginDir);
     65              managerConsole.Show(args.Skip(1));
     66              break;
     67            }
     68          case "INSTALL": {
     69              InstallationManagerConsole managerConsole = new InstallationManagerConsole(pluginDir);
     70              managerConsole.Install(args.Skip(1));
     71              break;
     72            }
     73          case "UPDATE": {
     74              InstallationManagerConsole managerConsole = new InstallationManagerConsole(pluginDir);
     75              managerConsole.Update(args.Skip(1));
     76              break;
     77            }
     78          case "REMOVE": {
     79              InstallationManagerConsole managerConsole = new InstallationManagerConsole(pluginDir);
     80              managerConsole.Remove(args.Skip(1));
     81              break;
     82            }
     83          default: PrintUsage(); break;
    5884        }
    59       }
    60       catch (Exception ex) {
    61         ShowErrorMessageBox(ex);
    6285      }
    6386    }
    6487
    65     public static void ShowErrorMessageBox(Exception ex) {
    66       MessageBox.Show(BuildErrorMessage(ex),
    67                       "Error - " + ex.GetType().Name,
    68                       MessageBoxButtons.OK,
    69                       MessageBoxIcon.Error);
     88    private static void PrintUsage() {
     89      Console.WriteLine("Usage: HeuristicLab.exe <command> <args>");
     90      Console.WriteLine("Commands:");
     91      Console.WriteLine("\tstart <application name>");
     92      Console.WriteLine("\tshow <plugin name(s)>");
     93      Console.WriteLine("\tupdate <plugin name(s)>");
     94      Console.WriteLine("\tremove <plugin name(s)>");
     95      Console.WriteLine("\tinstall <plugin name(s)>");
     96    }
     97
     98    private static void ShowErrorMessageBox(Exception ex) {
     99      MessageBox.Show(null,
     100        BuildErrorMessage(ex),
     101        "Error - " + ex.GetType().Name,
     102        MessageBoxButtons.OK,
     103        MessageBoxIcon.Error, MessageBoxDefaultButton.Button1, MessageBoxOptions.DefaultDesktopOnly);
    70104    }
    71105
Note: See TracChangeset for help on using the changeset viewer.