Ejemplo n.º 1
0
        public static void Run(IConfiguration config)
        {
            string buildTypeName = null;

#if TelegramDev
            buildTypeName = "Telegram Dev";
#elif TelegramAlpha
            buildTypeName = "Telegram Alpha";
#elif TelegramLive
            buildTypeName = "Telegram Live";
#elif DiscordAlpha
            buildTypeName = "Discord Alpha";
#elif DiscordLive
            buildTypeName = "Discord Live";
#elif KikLive
            buildTypeName = "Kik Live";
#endif
            ConfigSetting.DynamicApplicationName = buildTypeName;
            var configSetupService = new AppSettingsConfigurationService(config);
            configSetupService.SetConfig("TypeName", buildTypeName);

            RegisterAutofac(config, buildTypeName);

            var connectionString = configSetupService.GetConfig("DatabaseConnectionString");

            ContainerStore.Container = Container;

            ServiceStore.HttpLockObj = new object();

            using (var scope = Container.BeginLifetimeScope())
            {
                var configService = scope.Resolve <IConfigurationService>();

#if !TelegramDev
                Log.EnableReporting(scope.Resolve <IReporter>());
#endif
                // List games straight away, so there is no long delay when the first person sends a message
                scope.Resolve <IGameRetrieverService>().ListGames();

                var inputController = scope.Resolve <IInputController>();
                inputController.Setup();

                scope.Resolve <IHeartbeatMonitor>().BeginMonitor(configService.GetConfigOrDefault("HeartbeatUrl", null, true));


                if (IsInConsoleMode)
                {
                    _quitEvent.WaitOne();
                }
            }
        }
Ejemplo n.º 2
0
        public static async Task Main(string[] args)
        {
            var builder = new ContainerBuilder();

            builder.RegisterType <TextParsing>().As <ITextParsing>().InstancePerLifetimeScope();
            builder.RegisterType <GameDataService>().As <IGameDataService>().InstancePerLifetimeScope();
            builder.RegisterType <GameProcessor>().As <IGameProcessor>().InstancePerLifetimeScope();
            builder.RegisterType <DrawStore>().As <IGameStore>().SingleInstance();
            builder.RegisterType <ConfigSettingsGoogleDriveAuthenticator>().As <IGoogleDriveAuthenticator>().SingleInstance();
            builder.RegisterType <GoogleDriveService>().As <IGoogleDriveService>().SingleInstance();
            builder.RegisterType <AppSettingsConfigurationService>().As <IConfigurationService>().SingleInstance();
            builder.RegisterType <DrawGameTestExecutor>().As <DrawGameTestExecutor>().SingleInstance();
            builder.RegisterType <AzureSpellChecker>().As <ISpellChecker>().SingleInstance();
            builder.RegisterType <EmptyImagineService>().As <IImagingService>().SingleInstance();
            builder.RegisterType <ImageBuildDataTracker>().As <ImageBuildDataTracker>().SingleInstance();

            Console.WriteLine("Game Tester");
            Console.Write("Output to Slack or File? (Slack/File): ");

            var connection = Environment.GetEnvironmentVariable("ConnectionString");

            IConfiguration Configuration = new ConfigurationBuilder()
                                           .AddAzureAppConfiguration(connection)
                                           .AddJsonFile("appsettings.json")
                                           .Build();

            var configSetupService = new AppSettingsConfigurationService(Configuration);

            configSetupService.SetConfig("TypeName", "GameTester");
            ConfigSetting.DynamicApplicationName = "GameTester";

            builder.RegisterInstance(Configuration);

            var line = Console.ReadLine();

            if (line.ToLower() == "slack")
            {
                builder.RegisterType <SlackReport>().As <IReporter>().SingleInstance();
            }
            else
            {
                builder.RegisterType <FileReporter>().As <IReporter>().SingleInstance();
            }

            Container = builder.Build();

            while (true)
            {
                using (var scope = Container.BeginLifetimeScope())
                {
                    var drawStore    = scope.Resolve <IGameStore>();
                    var testExecutor = scope.Resolve <DrawGameTestExecutor>();
                    var reporter     = scope.Resolve <IReporter>();
                    var spellChecker = scope.Resolve <ISpellChecker>();
                    reporter.Initialise();
                    var games = drawStore.ListGames();

                    int i = 0;
                    foreach (var game in games)
                    {
                        Console.Write(i++ + " - ");
                        Console.WriteLine(game.GameName);
                    }

                    Console.Write("Enter game to test: ");
                    var num = Console.ReadLine();

                    if (!int.TryParse(num, out int numberChosen) || numberChosen < 0 || numberChosen >= games.Count)
                    {
                        Console.WriteLine("That is an invalid input...");
                        continue;
                    }

                    var gameToTest = games[numberChosen];

                    Console.WriteLine("You have chosen to test: " + gameToTest.GameName);
                    Console.Write("How long (in seconds) would you like the test to run for?: ");

                    var num2 = Console.ReadLine();
                    if (!int.TryParse(num2, out int secondsChosen) || secondsChosen <= 0)
                    {
                        Console.WriteLine("That is an invalid input...");
                        continue;
                    }

                    Console.Write("How many actions per run? (0 for unlimited): ");
                    var actionsPerRunString = Console.ReadLine();
                    if (!int.TryParse(actionsPerRunString, out int actionsPerRun))
                    {
                        Console.WriteLine("That is an invalid input...");
                        continue;
                    }

                    Console.Write("Enter state ID of the starting state to test (enter nothing to use the games start state): ");
                    var stateId = Console.ReadLine();

                    DateTime finishTime = DateTime.Now.AddSeconds(secondsChosen);

                    Console.WriteLine("Test will run until: " + finishTime.ToLongTimeString());

                    Console.WriteLine("Press any key to begin");
                    Console.ReadKey();

                    Console.WriteLine("Running test....");

                    var results = await testExecutor.RunTestAsync(gameToTest, finishTime, actionsPerRun, stateId);

                    Console.WriteLine("A total of: " + results.totalActionsDone + " actions were made in the test");

                    Console.WriteLine("### Errors ###");
                    results.errors.ForEach(a => { Console.WriteLine(a); Console.WriteLine(); });
                    Console.WriteLine("### Warnings ###");
                    results.warnings.ForEach(a => { Console.WriteLine(a); Console.WriteLine(); });

                    reporter.ReportMessage("--- Test report for game: " + gameToTest.GameName + " ---");
                    reporter.ReportMessage("~~~~~~~~~ ERRORS ~~~~~~~~~");
                    results.errors.ForEach(a => { reporter.ReportMessage(a); });
                    reporter.ReportMessage("~~~~~~~~~ WARNINGS ~~~~~~~~~");
                    results.warnings.ForEach(a => { reporter.ReportMessage(a); });
                    reporter.ReportMessage("~~~~~~~~~ End of report ~~~~~~~~~");
                    reporter.ReportMessage("A total of: " + results.totalActionsDone + " actions were made in the test");

                    Console.WriteLine("Check spelling? (Y/N): ");
                    if (Console.ReadLine().ToLower() == "y")
                    {
                        Console.WriteLine("Running spell checks on: " + results.allText.Count + " messages");
                        await RunSpellingAsync(results.allText, spellChecker, reporter);
                    }

                    Console.WriteLine("Finished!");
                    Console.ReadLine();
                }
            }
        }