コード例 #1
0
        public static void Main(string[] args)
        {
            AddAssemblyResolver();

            Bootstrapper.Configure();

            var            commandName = string.Empty;
            IList <string> commandArgs = new List <string>();

            // shift the first arg off
            int count = 0;

            foreach (var arg in args)
            {
                if (count == 0)
                {
                    count += 1;
                    continue;
                }

                commandArgs.Add(arg);
            }

            var configuration = new ChocolateyGuiConfiguration();

            SetUpGlobalOptions(args, configuration, Bootstrapper.Container);
            SetEnvironmentOptions(configuration);

            if (configuration.RegularOutput)
            {
#if DEBUG
                Bootstrapper.Logger.Information("{0} v{1} (DEBUG BUILD)".format_with("Chocolatey GUI", configuration.Information.ChocolateyGuiProductVersion));
#else
                Bootstrapper.Logger.Information("{0} v{1}".format_with("Chocolatey GUI", configuration.Information.ChocolateyGuiProductVersion));
#endif

                if (args.Length == 0)
                {
                    Bootstrapper.Logger.Information(ChocolateyGui.Common.Properties.Resources.Command_CommandsText.format_with("chocolateyguicli"));
                }
            }

            var runner = new GenericRunner();
            runner.Run(configuration, Bootstrapper.Container, command =>
            {
                ParseArgumentsAndUpdateConfiguration(
                    commandArgs,
                    configuration,
                    (optionSet) => command.ConfigureArgumentParser(optionSet, configuration),
                    (unparsedArgs) =>
                {
                    command.HandleAdditionalArgumentParsing(unparsedArgs, configuration);
                },
                    () =>
                {
                    Bootstrapper.Logger.Debug("Performing validation checks...");
                    command.HandleValidation(configuration);
                },
                    () => command.HelpMessage(configuration));
            });
        }
コード例 #2
0
        public static void Main(string[] args)
        {
            try
            {
                AddAssemblyResolver();

                Bootstrapper.Configure();

                var            commandName = string.Empty;
                IList <string> commandArgs = new List <string>();

                // shift the first arg off
                int count = 0;
                foreach (var arg in args)
                {
                    if (count == 0)
                    {
                        count += 1;
                        continue;
                    }

                    commandArgs.Add(arg);
                }

                var configuration = new ChocolateyGuiConfiguration();
                SetUpGlobalOptions(args, configuration, Bootstrapper.Container);
                SetEnvironmentOptions(configuration);

                if (configuration.RegularOutput)
                {
    #if DEBUG
                    Bootstrapper.Logger.Warning(" (DEBUG BUILD)".format_with("Chocolatey GUI", configuration.Information.DisplayVersion));
    #else
                    Bootstrapper.Logger.Warning("{0}".format_with(configuration.Information.DisplayVersion));
    #endif

                    if (args.Length == 0)
                    {
                        Bootstrapper.Logger.Information(ChocolateyGui.Common.Properties.Resources.Command_CommandsText.format_with("chocolateyguicli"));
                    }
                }

                var runner = new GenericRunner();
                runner.Run(configuration, Bootstrapper.Container, command =>
                {
                    ParseArgumentsAndUpdateConfiguration(
                        commandArgs,
                        configuration,
                        (optionSet) => command.ConfigureArgumentParser(optionSet, configuration),
                        (unparsedArgs) =>
                    {
                        command.HandleAdditionalArgumentParsing(unparsedArgs, configuration);
                    },
                        () =>
                    {
                        Bootstrapper.Logger.Debug("Performing validation checks...");
                        command.HandleValidation(configuration);
                    },
                        () => command.HelpMessage(configuration));
                });
            }
            catch (Exception ex)
            {
                Bootstrapper.Logger.Error(ex.Message);
            }
            finally
            {
                Log.CloseAndFlush();

                if (Bootstrapper.Container != null)
                {
                    if (Bootstrapper.Container.IsRegisteredWithName <LiteDatabase>(Bootstrapper.GlobalConfigurationDatabaseName))
                    {
                        var globalDatabase = Bootstrapper.Container.ResolveNamed <LiteDatabase>(Bootstrapper.GlobalConfigurationDatabaseName);
                        globalDatabase.Dispose();
                    }

                    if (Bootstrapper.Container.IsRegisteredWithName <LiteDatabase>(Bootstrapper.UserConfigurationDatabaseName))
                    {
                        var userDatabase = Bootstrapper.Container.ResolveNamed <LiteDatabase>(Bootstrapper.UserConfigurationDatabaseName);
                        userDatabase.Dispose();
                    }

                    Bootstrapper.Container.Dispose();
                }
            }
        }