Beispiel #1
0
        public Task StartBot(ISkypeAdapter skype, ITeamCityClient teamCity, BotParameters botParameters,
                             Dictionary <string, string> moduleParameters, TimeConfig timeConfig)
        {
            _working       = true;
            _skype         = skype;
            _teamcity      = teamCity;
            _botParameters = botParameters;
            _timeConfig    = timeConfig;

            var task = Task.Run(delegate
            {
                try
                {
                    _publishChat = _skype.GetChat(botParameters.PublishChatName);
                    if (_publishChat != null)
                    {
                        Console.WriteLine("publish chat found!");
                    }
                    else
                    {
                        Console.WriteLine("publish chat NOT found!");
                    }
                    _skype.OnMessageReceived += OnMessageReceived;

                    _timer = new Timer {
                        Interval = timeConfig.BuildCheckInterval.TotalMilliseconds
                    };
                    _timer.Elapsed  += timer_Elapsed;
                    _timer.AutoReset = false;
                    _timer.Start();

                    while (_working)
                    {
                        Thread.Sleep(5);
                    }
                }
                catch (Exception ex)
                {
                    Console.WriteLine("top lvl exception : " + ex);
                }
            });

            buildCheckers =
                _botParameters.Branches.Select(
                    x =>
                    new TeamCityBuildChecker(
                        BuildLocator.WithDimensions(BuildTypeLocator.WithId(_botParameters.BuildConfigId),
                                                    branch: x), _teamcity, x, _timeConfig)).ToList();

            _bot = new HelloBot(moduleParameters, buildCheckers, MailSettingsSectionGroup => SendMessage(MailSettingsSectionGroup, _publishChat));
            _bot.OnErrorOccured += BotOnErrorOccured;

            return(task);
        }
Beispiel #2
0
        private static void Main(string[] args)
        {
            if (args.Length < 5)
            {
                Console.WriteLine("Usage: <chat name> <TC server> <login> <password> <build config id>");
                return;
            }

            var botParameters = new BotParameters
            {
                PublishChatName  = args[0],
                TeamCityServer   = args[1],
                TeamCityLogin    = args[2],
                TeamCityPassword = args[3],
                BuildConfigId    = args[4],
                Branches         = args[5].Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries)
            };

            var moduleParameters = new Dictionary <string, string>();

            foreach (var arg in args.Skip(6))
            {
                var p = arg.Split(':');
                if (p.Length == 2)
                {
                    moduleParameters[p[0]] = p[1];
                }
            }

            var skype          = new Skype();
            var skypeAdapter   = new SkypeAdapter(skype);
            var teamCityClient = new TeamCityClient(botParameters.TeamCityServer);

            teamCityClient.Connect(botParameters.TeamCityLogin, botParameters.TeamCityPassword);

            TeamCityBot.StartBot(skypeAdapter, teamCityClient, botParameters, moduleParameters,
                                 new TimeConfig
            {
                BuildCheckInterval = TimeSpan.FromSeconds(15),
                StillBrokenDelay   = TimeSpan.FromMinutes(30)
            });

            while (true)
            {
                Thread.Sleep(1000);
            }
        }