Beispiel #1
0
        static int Configure(ConfigureActionOptions configureActionOptions)
        {
            if (ConfigurationRepository.Exists(configureActionOptions.ConfigFilePath))
            {
                Console.WriteLine($"{configureActionOptions.ConfigFilePath} already exists. Overwrite (Y/N)?");
                if (char.ToLowerInvariant(Console.ReadKey().KeyChar) != 'y')
                {
                    return(0);
                }
                Console.WriteLine();
            }

            Console.WriteLine("Available devices:");
            var availableDevices = NetworkMonitor.GetAllDeviceNames().ToArray();

            for (var i = 0; i < availableDevices.Length; i++)
            {
                Console.WriteLine($"[{i + 1}] {availableDevices[i]}");
            }

            Console.WriteLine("Make a selection: ");
            var selectedDeviceIndex = int.Parse(Console.ReadLine());

            var exampleConfiguration = new ProgramConfiguration
            {
                DeviceName = availableDevices[selectedDeviceIndex - 1],
                Actions    = new List <ActionConfiguration>
                {
                    new ActionConfiguration
                    {
                        Name       = "be_a_thoughtful_husband",
                        URL        = "https://maker.ifttt.com/trigger/send_email/with/key/your-key-here",
                        HttpMethod = "POST",
                        Body       = "{ \"value1\": \"[email protected]\", \"value2\": \"I love you\", \"value3\": \"I just pressed this button to show my love for you\" }"
                    }
                },
                Triggers = new List <TriggerConfiguration>
                {
                    new TriggerConfiguration
                    {
                        ActionName       = "be_a_thoughtful_husband",
                        PacketType       = PacketType.Any,
                        SourceMacAddress = "B47C9C94C67F"
                    }
                }
            };

            Console.WriteLine($"Writing example configuration to {configureActionOptions.ConfigFilePath}");
            ConfigurationRepository.Save(configureActionOptions.ConfigFilePath, exampleConfiguration);
            Console.WriteLine("Done");

            return(0);
        }