Example #1
0
 private static void Stop(ILifetimeScope scope, IBotMain botMain)
 {
     Console.WriteLine("Bot stopping....");
     botMain?.Stop();
     scope?.Dispose();
     Console.WriteLine("Bot stopped");
     Console.WriteLine("==============================");
 }
Example #2
0
 private static void Start(IContainer container, out ILifetimeScope scope, out IBotMain botMain)
 {
     Console.WriteLine("Bot starting....");
     scope   = container.BeginLifetimeScope();
     botMain = scope.Resolve <IBotMain>();
     botMain.Run();
     Console.WriteLine("Bot started");
     Console.WriteLine("==============================");
 }
Example #3
0
        private static void WaitForCommands(IContainer container)
        {
            Console.WriteLine("==============================");
            Console.WriteLine("Available bot commands : start, stop, restart, exit");
            Console.WriteLine("==============================");

            ILifetimeScope scope = null;

            try
            {
                IBotMain botMain = null;
                var      command = "start";
                while (true)
                {
                    switch (command)
                    {
                    case "stop":
                        Stop(scope, botMain);
                        break;

                    case "start":
                        Start(container, out scope, out botMain);
                        break;

                    case "restart":
                        Stop(scope, botMain);
                        Start(container, out scope, out botMain);
                        break;

                    case "exit":
                        return;

                    default:
                    {
                        Console.WriteLine($"{command} is not a valid command");
                        break;
                    }
                    }

                    Console.Write("Bot:");
                    command = Console.ReadLine();
                }
            }
            finally
            {
                scope?.Dispose();
            }
        }