public static void Main(string[] args) { ConfigureLog4net(); WriteVanityBanner(); using (MachineContainer container = new MachineContainer()) { container.Initialize(); container.PrepareForServices(); ContainerRegistrationHelper helper = new ContainerRegistrationHelper(container); helper.AddServiceCollectionsFrom(typeof(PartstoreServices).Assembly); container.Start(); IoC.Container = container; CommandLineParser parser = new CommandLineParser(); parser.ParseCommandLine(args); string commandName = "help"; if (parser.OrphanedArguments.Count > 0) { commandName = parser.OrphanedArguments[0].Value; parser.OrphanedArguments.RemoveAt(0); } CommandFactory commandFactory = new CommandFactory(container); commandFactory.AddCommand<ShowCommand>("show"); commandFactory.AddCommand<UnpackageCommand>("unpackage"); commandFactory.AddCommand<AddDependencyCommand>("add"); commandFactory.AddCommand<AddNewVersionCommand>("publish"); commandFactory.AddCommand<AddNewVersionCommand>("archive"); commandFactory.AddCommand<SeachRepositoryCommand>("search"); commandFactory.AddCommand<RefreshCommand>("refresh"); commandFactory.AddCommand<ConfigureCommand>("config"); commandFactory.AddCommand<HelpCommand>("help"); ICommand command = commandFactory.CreateCommand(commandName); CommandLineOptionBinder bind = new CommandLineOptionBinder(parser, command); bind.Required<AddDependencyCommand>(x => x.ProjectName, bind.Named("project"), bind.Named("p"), bind.First()); bind.Optional<AddDependencyCommand>(x => x.RepositoryName, bind.Named("repository"), bind.Named("r")); bind.Optional<AddNewVersionCommand>(x => x.RepositoryName, bind.Named("repository"), bind.Named("r")); bind.Optional<AddNewVersionCommand>(x => x.Tags, bind.Named("tags"), bind.Named("t")); if (bind.HasErrors) { foreach (BindingError error in bind.Errors) { Console.WriteLine(error); } return; } command.Run(); Console.WriteLine(); } }
static void Main(string[] args) { Console.WriteLine(Constants.GreetingMessage); MeetingManager meetingManager = new MeetingManager(); meetingManager.Reminder.Notify += Reminder_Notify; var commandFactory = new CommandFactory(); commandFactory .AddCommand(Constants.AddCommandName, new AddCommand()) .AddCommand(Constants.DeleteCommandName, new DeleteCommand()) .AddCommand(Constants.EditDurationCommandName, new EditDurationCommand()) .AddCommand(Constants.EditNotificationCommandName, new EditNotificationCommand()) .AddCommand(Constants.EditStartTimeCommandName, new EditStartTimeCommand()) .AddCommand(Constants.ExportCommandName, new ExportCommand()) .AddCommand(Constants.PrintCommandName, new PrintCommand()); while (true) { string userInput = Console.ReadLine(); var values = userInput.Split(" "); string commandName = values.First(); commandFactory.GetCommand(commandName).Execute(meetingManager, values); } }