You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

48 line
1.4 KiB

  1. // Licensed to the .NET Foundation under one or more agreements.
  2. // The .NET Foundation licenses this file to you under the MIT license.
  3. // See the LICENSE file in the project root for more information.
  4. using System.Reflection;
  5. Console.WriteLine("Welcome to MQTTnet samples!");
  6. Console.WriteLine();
  7. var sampleClasses = Assembly.GetExecutingAssembly().GetExportedTypes().OrderBy(c => c.Name).ToList();
  8. var index = 0;
  9. foreach (var sampleClass in sampleClasses)
  10. {
  11. Console.WriteLine($"{index} = {sampleClass.Name}");
  12. index++;
  13. }
  14. Console.Write("Please choose sample class (press Enter to continue): ");
  15. var input = Console.ReadLine();
  16. var selectedIndex = int.Parse(input ?? "0");
  17. var selectedSampleClass = sampleClasses[selectedIndex];
  18. var sampleMethods = selectedSampleClass.GetMethods(BindingFlags.Static | BindingFlags.Public).OrderBy(m => m.Name).ToList();
  19. index = 0;
  20. foreach (var sampleMethod in sampleMethods)
  21. {
  22. Console.WriteLine($"{index} = {sampleMethod.Name}");
  23. index++;
  24. }
  25. Console.Write("Please choose sample (press Enter to continue): ");
  26. input = Console.ReadLine();
  27. selectedIndex = int.Parse(input ?? "0");
  28. var selectedSampleMethod = sampleMethods[selectedIndex];
  29. Console.WriteLine("Executing sample...");
  30. Console.WriteLine();
  31. try
  32. {
  33. var task = selectedSampleMethod.Invoke(null, null) as Task;
  34. task?.Wait();
  35. }
  36. catch (Exception exception)
  37. {
  38. Console.WriteLine(exception.ToString());
  39. }