Пример #1
0
        private static int Main(string[] args)
        {
            AppTools.Init("Development Utility", true, new GlobalLogic());
            try {
                return(AppTools.ExecuteAppWithStandardExceptionHandling(
                           () => {
                    try {
                        if (args.Count() < 2)
                        {
                            throw new UserCorrectableException("You must specify the installation path as the first argument and the operation name as the second.");
                        }

                        // Get installation.
                        var installationPath = args[0];
                        DevelopmentInstallation installation;
                        try {
                            installation = getInstallation(installationPath);
                        }
                        catch (Exception e) {
                            throw new UserCorrectableException("The installation at \"" + installationPath + "\" is invalid.", e);
                        }

                        // Get operation.
                        var operations = AssemblyTools.BuildSingletonDictionary <Operation, string>(Assembly.GetExecutingAssembly(), i => i.GetType().Name);
                        var operationName = args[1];
                        if (!operations.ContainsKey(operationName))
                        {
                            throw new UserCorrectableException(operationName + " is not a known operation.");
                        }
                        var operation = operations[operationName];

                        if (!operation.IsValid(installation))
                        {
                            throw new UserCorrectableException("The " + operation.GetType().Name + " operation cannot be performed on this installation.");
                        }
                        operation.Execute(installation, new OperationResult());
                    }
                    catch (Exception e) {
                        Output.WriteTimeStampedError(e.ToString());
                        if (e is UserCorrectableException)
                        {
                            throw new DoNotEmailOrLogException();
                        }
                        throw;
                    }
                }));
            }
            finally {
                AppTools.CleanUp();
            }
        }