static void Main(string[] args) { IExample[] examples = new IExample[] { new DFS(), new BFS() }; Console.WriteLine("Select algorithm example:\r\n"); for (int i = 0; i < examples.Length; i++) { Console.WriteLine("[{0}]\t\t{1}", i + 1, examples[i].Name); } int result; if (int.TryParse(Console.ReadLine(), out result)) { IExample example = examples[result - 1]; example.Execute(); } Console.WriteLine("Press any key to exit..."); Console.ReadKey(); }
private void ExecuteExample(IExample example) { try { panel1.Controls.Clear(); panel1.Controls.Add(example.View); example.Execute(); } catch (Exception er) { MessageBox.Show(er.Message); } }
private static async Task InvokeExample(string exampleNameToInvoke, IServiceProvider serviceProvider) { IEnumerable <IExample> examples = serviceProvider.GetServices <IExample>(); IExample exampleToExecute = examples.FirstOrDefault(x => x.GetType().Name.Equals(exampleNameToInvoke, StringComparison.OrdinalIgnoreCase)); if (exampleToExecute == null) { ILogger <Program> logger = serviceProvider.GetService <ILogger <Program> >(); logger.LogWarning($"Unable to find example with the name '{exampleNameToInvoke}'."); return; } await exampleToExecute.Execute(); }
public static void Execute(NestClient client, IExample example) { var exampleName = example.GetType().GetCustomAttribute <ExampleAttribute>()?.Name ?? example.GetType().Name; log.Info($"--------------------------------------------------------------------------------"); log.Info($"---------------- EXAMPLE \"{exampleName}\" START"); try { example.Execute(client); } catch (Exception ex) { log.Error("Failed to execute \"{exampleName}\".", ex); } finally { log.Info($"---------------- EXAMPLE \"{exampleName}\" END"); log.Info($"--------------------------------------------------------------------------------"); log.Info($"Presss ENTER to continue."); Console.ReadLine(); } }
public void Execute(String[] args) { int index = 0; bool pause = false; bool success = false; // process any options while (index < args.Length && args[index][0] == '-') { String option = args[index].Substring(1).ToLower(); if ("pause".Equals(option)) { pause = true; } index++; } if (index >= args.Length) { Console.WriteLine(@"Must specify the example to run as the first argument"); ListCommands(); if (pause) { Pause(); } return; } String command = args[index++]; // get any arguments var pargs = new String[args.Length - index]; for (int i = 0; i < pargs.Length; i++) { pargs[i] = args[index + i]; } foreach (ExampleInfo info in examples) { if (String.Compare(command, info.Command, true) == 0) { IExample example = info.CreateInstance(); example.Execute(new ConsoleInterface(pargs)); success = true; break; } } if (!success) { Console.WriteLine("Unknown command: " + command); ListCommands(); } if (pause) { Pause(); } }