Free cookie consent management tool by TermsFeed Policy Generator

source: branches/PluginInfrastructure Refactoring/HeuristicLab/Program.cs @ 2515

Last change on this file since 2515 was 2513, checked in by gkronber, 15 years ago

Worked on command line interface for plugin management. #799

File size: 3.9 KB
Line 
1#region License Information
2/* HeuristicLab
3 * Copyright (C) 2002-2008 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.Collections.Generic;
24using System.Windows.Forms;
25using System.Xml;
26using System.Threading;
27using System.Text;
28using System.Linq;
29using HeuristicLab.PluginInfrastructure;
30using HeuristicLab.PluginInfrastructure.Advanced;
31
32namespace HeuristicLab {
33  static class Program {
34    [STAThread]
35    static void Main(string[] args) {
36      if (args.Length == 0) {  // normal mode
37        try {
38          Application.EnableVisualStyles();
39          Application.SetCompatibleTextRenderingDefault(false);
40          Application.Run(new StarterForm());
41        }
42        catch (Exception ex) {
43          ShowErrorMessageBox(ex);
44        }
45
46      } else {
47        var cmd = args[0].ToUpperInvariant();
48        switch (cmd) {
49          case "START": {
50              if (args.Length != 2) {
51                PrintUsage();
52              } else {
53                Application.EnableVisualStyles();
54                Application.SetCompatibleTextRenderingDefault(false);
55                Application.Run(new StarterForm(args[1]));
56              }
57              break;
58            }
59          case "SHOW": {
60              InstallationManager manager = new InstallationManager();
61              foreach (string info in manager.Show(args.Skip(1))) {
62                Console.WriteLine(info);
63              }
64              break;
65            }
66          case "INSTALL": {
67              InstallationManager manager = new InstallationManager();
68              manager.Install(args.Skip(1));
69              break;
70            }
71          case "UPDATE": {
72              InstallationManager manager = new InstallationManager();
73              manager.Update(args.Skip(1));
74              break;
75            }
76          case "REMOVE": {
77              InstallationManager manager = new InstallationManager();
78              manager.Remove(args.Skip(1));
79              break;
80            }
81          default: PrintUsage(); break;
82        }
83      }
84    }
85
86    private static void PrintUsage() {
87      Console.WriteLine("Usage: HeuristicLab.exe <command> <args>");
88      Console.WriteLine("Commands:");
89      Console.WriteLine("\tstart <application name>");
90      Console.WriteLine("\tshow <plugin name(s)>");
91      Console.WriteLine("\tupdate <plugin name(s)>");
92      Console.WriteLine("\tremove <plugin name(s)>");
93      Console.WriteLine("\tinstall <plugin name(s)>");
94    }
95
96    private static void ShowErrorMessageBox(Exception ex) {
97      MessageBox.Show(null,
98        BuildErrorMessage(ex),
99        "Error - " + ex.GetType().Name,
100        MessageBoxButtons.OK,
101        MessageBoxIcon.Error, MessageBoxDefaultButton.Button1, MessageBoxOptions.DefaultDesktopOnly);
102    }
103
104    private static string BuildErrorMessage(Exception ex) {
105      StringBuilder sb = new StringBuilder();
106      sb.Append("Sorry, but something went wrong!\n\n" + ex.Message + "\n\n" + ex.StackTrace);
107
108      while (ex.InnerException != null) {
109        ex = ex.InnerException;
110        sb.Append("\n\n-----\n\n" + ex.Message + "\n\n" + ex.StackTrace);
111      }
112      return sb.ToString();
113    }
114  }
115}
Note: See TracBrowser for help on using the repository browser.