Free cookie consent management tool by TermsFeed Policy Generator

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

Last change on this file since 3051 was 2916, checked in by swagner, 15 years ago

Operator architecture refactoring (#95)

  • worked on engines and algorithms
File size: 4.0 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  public static class Main {
32    public static void Run(string[] args) {
33      if (args.Length == 0) {  // normal mode
34        try {
35          Application.EnableVisualStyles();
36          Application.SetCompatibleTextRenderingDefault(false);
37          Application.Run(new StarterForm());
38        }
39        catch (Exception ex) {
40          ShowErrorMessageBox(ex);
41        }
42
43      } else {
44        var cmd = args[0].ToUpperInvariant();
45        string pluginDir = Path.GetFullPath(Application.StartupPath);
46        switch (cmd) {
47          case "START": {
48              if (args.Length != 2) {
49                PrintUsage();
50              } else {
51                Application.EnableVisualStyles();
52                Application.SetCompatibleTextRenderingDefault(false);
53                Application.Run(new StarterForm(args[1]));
54              }
55              break;
56            }
57          case "SHOW": {
58              InstallationManagerConsole managerConsole = new InstallationManagerConsole(pluginDir);
59              managerConsole.Show(args.Skip(1));
60              break;
61            }
62          case "INSTALL": {
63              InstallationManagerConsole managerConsole = new InstallationManagerConsole(pluginDir);
64              managerConsole.Install(args.Skip(1));
65              break;
66            }
67          case "UPDATE": {
68              InstallationManagerConsole managerConsole = new InstallationManagerConsole(pluginDir);
69              managerConsole.Update(args.Skip(1));
70              break;
71            }
72          case "REMOVE": {
73              InstallationManagerConsole managerConsole = new InstallationManagerConsole(pluginDir);
74              managerConsole.Remove(args.Skip(1));
75              break;
76            }
77          default: PrintUsage(); break;
78        }
79      }
80    }
81
82    private static void PrintUsage() {
83      Console.WriteLine("Usage: HeuristicLab.exe <command> <args>");
84      Console.WriteLine("Commands:");
85      Console.WriteLine("\tstart <application name>");
86      Console.WriteLine("\tshow <plugin name(s)>");
87      Console.WriteLine("\tupdate <plugin name(s)>");
88      Console.WriteLine("\tremove <plugin name(s)>");
89      Console.WriteLine("\tinstall <plugin name(s)>");
90    }
91
92    private static void ShowErrorMessageBox(Exception ex) {
93      MessageBox.Show(null,
94        BuildErrorMessage(ex),
95        "Error - " + ex.GetType().Name,
96        MessageBoxButtons.OK,
97        MessageBoxIcon.Error, MessageBoxDefaultButton.Button1, MessageBoxOptions.DefaultDesktopOnly);
98    }
99
100    private static string BuildErrorMessage(Exception ex) {
101      string nl = Environment.NewLine;
102      StringBuilder sb = new StringBuilder();
103      sb.Append("Sorry, but something went wrong!" +  nl + ex.Message + nl + ex.StackTrace);
104
105      while (ex.InnerException != null) {
106        ex = ex.InnerException;
107        sb.Append(nl + "-----" + nl + ex.Message + nl + ex.StackTrace);
108      }
109      return sb.ToString();
110    }
111  }
112}
Note: See TracBrowser for help on using the repository browser.