예제 #1
0
        public static LoggerConfigurator CreateLogConfig(Options options)
        {
            var logConfig = new LoggerConfigurator(options.Verbose ? LogLevel.Debug : LogLevel.Info);

            if (Environment.UserInteractive)
            {
                logConfig.ConfigureForConsole();
            }
            else
            {
                logConfig.AddTraceListener();
            }

            var logger = logConfig.GetLogger();

            if (!string.IsNullOrWhiteSpace(options.LogFile))
            {
                if (Directory.Exists(Path.GetDirectoryName(options.LogFile)))
                {
                    logConfig.ConfigureForFile(options.LogFile);
                }
                else
                {
                    logger.Warn(string.Format("Failed to load log file.  Path for {0} does not exist.", options.LogFile));
                }
            }
            return(logConfig);
        }
예제 #2
0
        public async Task XmppRobot()
        {
            //enter config values to enable this test
            var config = new Dictionary <string, string>();

            //config.Add("MMBOT_XMPP_HOST", "userver");
            //config.Add("MMBOT_XMPP_CONNECT_HOST", "userver");
            //config.Add("MMBOT_XMPP_USERNAME", "mmbot");
            //config.Add("MMBOT_XMPP_PASSWORD", "password");
            //config.Add("MMBOT_XMPP_CONFERENCE_SERVER", "conference.userver");
            //config.Add("MMBOT_XMPP_ROOMS", "testroom");
            //config.Add("MMBOT_XMPP_LOGROOMS", "logroom");

            if (config.Count() == 0)
            {
                return;
            }

            var logConfig = new LoggerConfigurator(LogLevel.Trace);

            logConfig.AddTraceListener();

            var robot = new RobotBuilder(logConfig)
                        .WithConfiguration(config)
                        .UseAdapter <XmppAdapter>()
                        .Build();

            robot.AutoLoadScripts = false;
            robot.LoadScript <CompiledScripts.Ping>();

            bool robotReady = false;

            robot.On <bool>("RobotReady", result =>
            {
                robotReady = result;
            });

            await robot.Run();

            Assert.True(robotReady);

            int cmdReceived = 0;

            robot.Hear("mmbot", msg => { cmdReceived++; });

            //will wait for two commands
            while (cmdReceived < 2)
            {
                Thread.Sleep(1000);
            }
        }