public void Setup()
        {
            var logger  = Substitute.For <ILogger <TaskExecutioner> >();
            var capture = Substitute.For <IVideoCapture>();

            //logger.Log<object>(Arg.Any<LogLevel>(),
            //           Arg.Any<EventId>(),
            //           Arg.Any<object>(),
            //           Arg.Any<Exception>(),
            //           Arg.Any<Func<object, Exception, string>>()).Returns()
            _executioner = new TaskExecutioner(logger);
        }
예제 #2
0
        private void ConfigureSerivces(ServiceCollection serviceCollection)
        {
            var            uiLogger      = new CustomUiLoggerProvider();
            ILoggerFactory loggerFactory = LoggerFactory.Create(
                (builder) =>
            {
                builder
                .AddProvider(new CustomConsoleProvider())
                .AddProvider(new CustomTraceProvider())
                .AddProvider(uiLogger)
                .SetMinimumLevel(LogLevel.Debug);
            });

            Directory.CreateDirectory("Settings");
            var path = Path.Combine("Settings", "config.json");

            var setupDefaultConfig = !File.Exists(path);

            var settings = new ConfigurationBuilder <ISettings>()
                           .UseJsonFile(path).
                           Build();

            if (setupDefaultConfig)
            {
                SetupDefaultConfiguration(settings);
            }
            else
            {
                EnsureValidValues(settings);
            }

            serviceCollection.AddSingleton(settings);

            var recognition = new TextRecognition();

            var executioner   = new TaskExecutioner(loggerFactory.CreateLogger <TaskExecutioner>());
            var window        = SetupWindow(settings, loggerFactory, recognition);
            var videoProvider = new VideoProvider(window, settings.VideoCapture.FrameRate);

            serviceCollection.AddSingleton <IVideoProvider>(videoProvider);
            serviceCollection.AddSingleton <IVideoCapture, VideoCapture>();

            var repository = new Repository();

            repository.Load();
            var game = new GameImpl(window, videoProvider, repository, loggerFactory, recognition, settings);

            var overlay = new ImGuiOverlay(game, window, repository);

            if (settings.EnableOverlay)
            {
                //circular dependency. find better solution.
                game.Overlay = overlay;
                overlay.Setup();
            }
            serviceCollection.AddSingleton <IEmulatorOverlay>(overlay);

            var picker = new AreaPicker(window, overlay);

            serviceCollection.AddSingleton <ITaskExecutioner>(executioner);
            serviceCollection.AddSingleton <ITaskQueue>(executioner);
            serviceCollection.AddSingleton <IGame>(game);
            serviceCollection.AddSingleton <IAreaPicker>(picker);
            serviceCollection.AddSingleton <IUiRepository>(repository);
            serviceCollection.AddSingleton(window);
            serviceCollection.AddSingleton <IUiLogger>(uiLogger);
            ViewModelLocator.ConfigureServices(serviceCollection);

            if (settings.EnableOverlay)
            {
                Dispatcher.BeginInvoke(async() => await UpdateOverlay(overlay));
            }
        }