Exemplo n.º 1
0
        public static void Main(string[] args)
        {
            var rootCommand = new RootCommand
            {
                new Option("--list", "List all audio devices"),
                new Option <string>("--set", "Set device"),
                new Option <string>("--set-comm", "Set communication device")
            };

            rootCommand.Description = "AudioDeviceSelector";

            // Note that the parameters of the handler method are matched according to the names of the options
            rootCommand.Handler = CommandHandler.Create <string, string>(
                (set, setComm) =>
            {
                var controller = new CoreAudioController();
                var devices    = controller.GetDevices();

                if (args.Count() < 1)
                {
                    Console.WriteLine($"{Assembly.GetExecutingAssembly().GetName().Name}.exe --help");
                }

                if (args.Any(x => x.ToString().ToLower() == "--list"))
                {
                    devices
                    .OrderBy(d => d.DeviceType)
                    .ToList()
                    .ForEach(d => Console.WriteLine($"DeviceType: {d.DeviceType}, Id: {d.Id}, InterfaceName: {d.InterfaceName}, Name: {d.Name}"));
                }

                _ = set != null && controller.SetDeviceByName(set);
                _ = setComm != null && controller.SetCommDeviceByName(setComm);
            });

            rootCommand.Invoke(args);
        }