public static void Dispatch(RunConfiguration config, TopshelfArguments args) { if (!string.IsNullOrEmpty(args.Instance)) { _log.Info("Using instance name from commandline."); config.WinServiceSettings.ServiceName = new ServiceName( config.WinServiceSettings.ServiceName.Name, args.Instance); } //find the command by the args 'Command' var run = new RunCommand(config.Coordinator, config.WinServiceSettings.ServiceName); var command = new List<Command> { run, new InstallService(config.WinServiceSettings), new UninstallService(config.WinServiceSettings) } .Where(x => x.Name == args.ActionName) .DefaultIfEmpty(run) .SingleOrDefault(); _log.DebugFormat("Running command: '{0}'", command.Name); command.Execute(); }
public static TopshelfArguments Parse(string commandLine) { var result = new TopshelfArguments(); Set(result, P(commandLine)); return result; }
static void Set(TopshelfArguments args, IEnumerable<ICommandLineElement> commandLineElements) { var command = commandLineElements .Take(1) .Select(x => (IArgumentElement) x) .Select(x => x.Id) .DefaultIfEmpty("commandline") .SingleOrDefault(); args.Command = command; //leftovers args.CommandArgs = commandLineElements.Skip(1).ToList(); }
static void Set(TopshelfArguments args, IEnumerable<ICommandLineElement> commandLineElements) { var command = commandLineElements .DefaultIfEmpty(new ArgumentElement("Run")) .ToList() .OfType<IArgumentElement>() .Select(x=>x.Id) .SingleOrDefault(); args.ActionName = (command ?? "Run").ToEnum<ServiceActionNames>(); args.Instance = commandLineElements .OfType<IDefinitionElement>() .Where(x => x.Key == "instance") .Select(x => x.Value) .DefaultIfEmpty("") .Single(); }
public static void Dispatch(RunConfiguration config, TopshelfArguments args) { //find the command by the args 'Command' var run = new RunCommand(config.Coordinator, config.WinServiceSettings.ServiceName); var command = new List<Command> { run, new InstallService(config.WinServiceSettings), new UninstallService(config.WinServiceSettings) } .Where(x => x.Name == args.ActionName) .DefaultIfEmpty(run) .SingleOrDefault(); _log.DebugFormat("Running command: '{0}'", command.Name); command.Execute(); }
public static void Dispatch(RunConfiguration config, TopshelfArguments args) { //find the command by the args 'Command' var run = new RunCommand(config.Coordinator, config.WinServiceSettings.ServiceName); Command command = new List<Command> { run, new ServiceCommand(config.Coordinator, config.WinServiceSettings) } .Where(x => x.Name == args.Command) .DefaultIfEmpty(run) .SingleOrDefault(); _log.DebugFormat("Running command: '{0}'", command.Name); //what to do with the config? //flow the args down command.Execute(args.CommandArgs); }