Esempio n. 1
0
        private async Task ExecuteChainSourcesAsync(IChain chain, CancellationToken cancellationToken)
        {
            Console.WriteLine($"Starting: {chain.Name}");

            foreach (var connector in chain.Connectors)
            {
                Console.WriteLine($"{connector.Index}" +
                                  new string(' ', connector.Depth * 2) +
                                  $" -> {connector.Name}" +
                                  $" -> {connector.OutputType.Name}");
            }

            try
            {
                chain.StartAllSources();

                while (true)
                {
                    var key = await ReadKey(cancellationToken);

                    if (key.Key == ConsoleKey.Escape)
                    {
                        break;
                    }
                }
            }
            catch (OperationCanceledException e) when(e.CancellationToken == cancellationToken)
            {
            }
            finally
            {
                Console.WriteLine($"Stopping {chain.Name}");
                await chain.StopAllSourcesAsync(false);

                Console.WriteLine($"{chain.Name} stopped");
            }
        }