예제 #1
0
        static void Main(string[] args)
        {
            TaskScheduler.UnobservedTaskException      += TaskScheduler_UnobservedTaskException;
            AppDomain.CurrentDomain.UnhandledException += (s, e) =>
            {
                Console.WriteLine((e.ExceptionObject as Exception).Message);
            };
            var teamcityConfig = new Rest.TeamCity.ConfigurationProvider();
            var restClient     = new RestClient(
                teamcityConfig.Host,
                teamcityConfig.Login,
                teamcityConfig.Password,
                MediaType.Json);
            var tc               = new TeamCityApi(restClient);
            var gateway          = new Gateway(new[] { tc });
            var presenterFactory = new PresenterFactory();
            var output           = new Output(
                presenterFactory,
                new IOutputStream[] {
                new ConsoleStream(),
                new FileStream("log.txt")
            });
            var cancellationSource = new CancellationTokenSource();

            output.Write("build bot greetings you");
            output.Write("type exit to leave bot");

            var client   = new TelegramBotClient(new ConfigurationProvider().ApiKey);
            var commands = new List <CommandBase>
            {
                new StartCommand(cancellationSource),
                new ExitCommand(cancellationSource),
                new TeamcityGetBuildQueueCommand(gateway.For <ITeamCity>(), cancellationSource),
                new TeamcityGetProjectsCommand(gateway.For <ITeamCity>(), cancellationSource),
                new TeamcityGetProjectCommand(gateway.For <ITeamCity>(), cancellationSource),
                new TeamcityGetBranchesCommand(gateway.For <ITeamCity>(), cancellationSource),
                new TeamcityGetBuildsCommand(gateway.For <ITeamCity>(), cancellationSource),
                new TeamcityGetBuildTypesCommand(gateway.For <ITeamCity>(), cancellationSource),
                new TeamcityGetBuildCommand(gateway.For <ITeamCity>(), cancellationSource),
                new TeamcityGetAgentsCommand(gateway.For <ITeamCity>(), cancellationSource),
                new TeamcityEnqueueBuild(gateway.For <ITeamCity>(), cancellationSource),
                new TeamcityGetRunningBuildsCommand(gateway.For <ITeamCity>(), cancellationSource),
                new TeamcityEnqueueAgentCommand(gateway.For <ITeamCity>(), cancellationSource),
                new TeamcityGetBranchCommand(gateway.For <ITeamCity>(), cancellationSource)
            };
            var help = new HelpCommand(commands, cancellationSource);

            commands.Add(help);
            var commandsExecutor = new CommandsExecutor(commands);
            var inputStream      = new InputPipeline();
            var consoleListener  = new ConsoleCommandProducer(inputStream);
            var runLooper        = new RunLooper(inputStream, commandsExecutor, consoleListener, output, cancellationSource);
            var store            = new MemoryStore();

            using (var botWrapper = new BotWrapper(client, inputStream, presenterFactory, cancellationSource, commandsExecutor, output, store))
            {
                botWrapper.Start();
                runLooper.Run();
            }
        }
예제 #2
0
 public RunLooper(InputPipeline inputPipeline, CommandsExecutor context, ConsoleCommandProducer consoleCommandProducer, Output output, CancellationTokenSource cancellationTokenSource)
 {
     _inputPipeline          = inputPipeline;
     _context                = context;
     _consoleCommandProducer = consoleCommandProducer;
     _output = output;
     _cancellationTokenSource = cancellationTokenSource;
 }
예제 #3
0
        public BotWrapper(TelegramBotClient client, InputPipeline inputPipeline, IPresenterFactory presenterFactory, CancellationTokenSource cancellationTokenSource, CommandsExecutor commandsExecutor, Output output, IStore store)
        {
            _client                  = client;
            this._inputPipeline      = inputPipeline;
            _cancellationTokenSource = cancellationTokenSource;
            _output                  = output;
            _store = store;

            _client.OnMessage       += BotOnOnMessage;
            _client.OnCallbackQuery += _client_OnCallbackQuery;
        }