Exemple #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();
            }
        }
Exemple #2
0
        private static int Main(string[] args)
        {
            GlobalInitializationOps.InitStatics(new GlobalInitializer(), "Development Utility", true);
            try {
                return(GlobalInitializationOps.ExecuteAppWithStandardExceptionHandling(
                           () => {
                    try {
                        AppStatics.Init();

                        if (args.Length < 2)
                        {
                            throw new UserCorrectableException("You must specify the installation path as the first argument and the operation name as the second.");
                        }

                        // Create installations folder from template if necessary.
                        var installationPath = args[0];
                        var templateFolderPath = getInstallationsFolderPath(installationPath, true);
                        var message = "";
                        if (!Directory.Exists(templateFolderPath))
                        {
                            message = "No installation-configuration template exists.";
                        }
                        else
                        {
                            var configurationFolderPath = getInstallationsFolderPath(installationPath, false);
                            if (IoMethods.GetFilePathsInFolder(configurationFolderPath, searchOption: SearchOption.AllDirectories).Any())
                            {
                                message = "Installation configuration already exists.";
                            }
                            else
                            {
                                IoMethods.CopyFolder(templateFolderPath, configurationFolderPath, false);
                                Console.WriteLine("Created installation configuration from template.");
                            }
                        }

                        if (args[1] == "CreateInstallationConfiguration")
                        {
                            if (message.Any())
                            {
                                throw new UserCorrectableException(message);
                            }
                            return;
                        }

                        // Get installation.
                        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, args.Skip(2).ToImmutableArray(), new OperationResult());
                    }
                    catch (Exception e) {
                        Output.WriteTimeStampedError(e.ToString());
                        if (e is UserCorrectableException)
                        {
                            throw new DoNotEmailOrLogException();
                        }
                        throw;
                    }
                }));
            }
            finally {
                GlobalInitializationOps.CleanUpStatics();
            }
        }