Free cookie consent management tool by TermsFeed Policy Generator

source: trunk/sources/HeuristicLab.PluginInfrastructure/Main.cs @ 3289

Last change on this file since 3289 was 3289, checked in by swagner, 14 years ago

Implemented logs of engines (#963).

File size: 4.3 KB
Line 
1#region License Information
2/* HeuristicLab
3 * Copyright (C) 2002-2010 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
4 *
5 * This file is part of HeuristicLab.
6 *
7 * HeuristicLab is free software: you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation, either version 3 of the License, or
10 * (at your option) any later version.
11 *
12 * HeuristicLab is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with HeuristicLab. If not, see <http://www.gnu.org/licenses/>.
19 */
20#endregion
21
22using System;
23using System.Windows.Forms;
24using System.Text;
25using System.Linq;
26using HeuristicLab.PluginInfrastructure.Starter;
27using System.IO;
28using HeuristicLab.PluginInfrastructure.Advanced;
29
30namespace HeuristicLab.PluginInfrastructure {
31  /// <summary>
32  /// Static class that contains the main entry point of the plugin infrastructure.
33  /// </summary>
34  public static class Main {
35    /// <summary>
36    /// Main entry point of the plugin infrastructure. Either loads a starter form or a console dialog.
37    /// </summary>
38    /// <param name="args">Command line arguments</param>
39    public static void Run(string[] args) {
40      if (args.Length == 0) {  // normal mode
41        try {
42          Application.EnableVisualStyles();
43          Application.SetCompatibleTextRenderingDefault(false);
44          Application.Run(new StarterForm());
45        }
46        catch (Exception ex) {
47          ShowErrorMessageBox(ex);
48        }
49
50      } else {
51        var cmd = args[0].ToUpperInvariant();
52        string pluginDir = Path.GetFullPath(Application.StartupPath);
53        switch (cmd) {
54          case "START": {
55              if (args.Length != 2) {
56                PrintUsage();
57              } else {
58                Application.EnableVisualStyles();
59                Application.SetCompatibleTextRenderingDefault(false);
60                Application.Run(new StarterForm(args[1]));
61              }
62              break;
63            }
64          case "SHOW": {
65              InstallationManagerConsole managerConsole = new InstallationManagerConsole(pluginDir);
66              managerConsole.Show(args.Skip(1));
67              break;
68            }
69          case "INSTALL": {
70              InstallationManagerConsole managerConsole = new InstallationManagerConsole(pluginDir);
71              managerConsole.Install(args.Skip(1));
72              break;
73            }
74          case "UPDATE": {
75              InstallationManagerConsole managerConsole = new InstallationManagerConsole(pluginDir);
76              managerConsole.Update(args.Skip(1));
77              break;
78            }
79          case "REMOVE": {
80              InstallationManagerConsole managerConsole = new InstallationManagerConsole(pluginDir);
81              managerConsole.Remove(args.Skip(1));
82              break;
83            }
84          default: PrintUsage(); break;
85        }
86      }
87    }
88
89    private static void PrintUsage() {
90      Console.WriteLine("Usage: HeuristicLab.exe <command> <args>");
91      Console.WriteLine("Commands:");
92      Console.WriteLine("\tstart <application name>");
93      Console.WriteLine("\tshow <plugin name(s)>");
94      Console.WriteLine("\tupdate <plugin name(s)>");
95      Console.WriteLine("\tremove <plugin name(s)>");
96      Console.WriteLine("\tinstall <plugin name(s)>");
97    }
98
99    private static void ShowErrorMessageBox(Exception ex) {
100      MessageBox.Show(null,
101        BuildErrorMessage(ex),
102        "Error - " + ex.GetType().Name,
103        MessageBoxButtons.OK,
104        MessageBoxIcon.Error, MessageBoxDefaultButton.Button1, MessageBoxOptions.DefaultDesktopOnly);
105    }
106
107    private static string BuildErrorMessage(Exception ex) {
108      string nl = Environment.NewLine;
109      StringBuilder sb = new StringBuilder();
110      sb.Append(ex.Message + nl + ex.StackTrace);
111
112      while (ex.InnerException != null) {
113        ex = ex.InnerException;
114        sb.Append(nl + "-----" + nl + ex.Message + nl + ex.StackTrace);
115      }
116      return sb.ToString();
117    }
118  }
119}
Note: See TracBrowser for help on using the repository browser.