Free cookie consent management tool by TermsFeed Policy Generator

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

Last change on this file since 2526 was 2517, checked in by gkronber, 15 years ago

Worked on plugin installation manager and update location service. #799

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