Exemplo n.º 1
0
        public async Task SelectTest()
        {
            using var cancellationTokenSource = new CancellationTokenSource(TimeSpan.FromSeconds(30));
            var cancellationToken = cancellationTokenSource.Token;

            using var app = await TestWpfApp.CreateAsync(cancellationToken);

            await using var hookService = new HookService
                        {
                            new (new Command("select"), ConsoleKey.S, isProcessing : true),
                        };
            await using var moduleService = new StaticModuleService(
                            new SelectRunner(app.Dispatcher)
                            );
            await using var runnerService = new RunnerService(
                            moduleService,
                            moduleService,
                            hookService
                            );
            using var exceptions = new IServiceBase[]
                  {
                      moduleService, runnerService, hookService
                  }.EnableLogging(cancellationTokenSource);

            await hookService.InitializeAsync(cancellationToken);

            await Task.Delay(TimeSpan.FromSeconds(15), cancellationToken);

            await runnerService.WaitAllAsync(cancellationToken);
        }
Exemplo n.º 2
0
        public async Task ScreenshotTest()
        {
            using var cancellationTokenSource = new CancellationTokenSource(TimeSpan.FromSeconds(30));
            var cancellationToken = cancellationTokenSource.Token;

            using var app = await TestWpfApp.CreateAsync(cancellationToken);

            using var runner = new SelectRunner(app.Dispatcher).WithLogging();

            var process = new Process <ICommand>();
            var task    = runner.SelectAsync(process, cancellationToken);

            await Task.Delay(TimeSpan.FromSeconds(5), cancellationToken);

            await process.StopAsync(cancellationToken);

            var rectangle = await task;

            Console.WriteLine($"{rectangle.Left}, {rectangle.Top}, {rectangle.Right}, {rectangle.Bottom}");

            using var screenshotRunner = new ScreenshotRunner().WithLogging();
            var image = await screenshotRunner.ShotAsync(rectangle, cancellationToken);

            using var clipboardRunner = new ClipboardRunner(app.Dispatcher).WithLogging();
            await clipboardRunner.SetClipboardImageAsync(image, cancellationToken);
        }
Exemplo n.º 3
0
        public async Task ClipboardSetGet123Test()
        {
            using var cancellationTokenSource = new CancellationTokenSource(TimeSpan.FromSeconds(30));
            var cancellationToken = cancellationTokenSource.Token;

            using var app = await TestWpfApp.CreateAsync(cancellationToken);

            using var runner = new ClipboardRunner(app.Dispatcher).WithLogging();

            await runner.SetClipboardTextAsync("123", cancellationToken);

            var text = await runner.GetClipboardTextAsync(cancellationToken);

            Assert.AreEqual("123", text);
        }
Exemplo n.º 4
0
        public async Task ClipboardSetGet123CommandTest()
        {
            using var cancellationTokenSource = new CancellationTokenSource(TimeSpan.FromSeconds(30));
            var cancellationToken = cancellationTokenSource.Token;

            using var app = await TestWpfApp.CreateAsync(cancellationToken);

            using var runner = new ClipboardRunner(app.Dispatcher).WithLogging();

            await runner.CallAsync(new Command("clipboard-set-text", "123"), cancellationToken);

            var output = await runner.CallAsync(new Command("clipboard-get-text"), cancellationToken);

            Console.WriteLine($"Output: {output}");

            Assert.AreEqual("123", output.Output.Argument);
        }
Exemplo n.º 5
0
        public async Task SelectScreenshotClipboardTest()
        {
            using var cancellationTokenSource = new CancellationTokenSource(TimeSpan.FromSeconds(30));
            var cancellationToken = cancellationTokenSource.Token;

            using var app = await TestWpfApp.CreateAsync(cancellationToken);

            await using var hookService = new HookService
                        {
                            new (new Command(
                                     "process-sequence",
                                     "3",
                                     "select",
                                     "screenshot",
                                     "clipboard-set-image"
                                     ),
                                 new Keys(Key.RAlt),
                                 true),
                        };
            await using var moduleService = new StaticModuleService(
                            new SelectRunner(app.Dispatcher),
                            new ScreenshotRunner(),
                            new ClipboardRunner(app.Dispatcher)
                            );
            await using var runnerService = new RunnerService(
                            moduleService,
                            moduleService,
                            hookService
                            );
            using var exceptions = new IServiceBase[]
                  {
                      moduleService, runnerService, hookService
                  }.EnableLogging(cancellationTokenSource);

            moduleService.Add(new ProcessSequenceRunner(runnerService));

            await hookService.InitializeAsync(cancellationToken);

            await Task.Delay(TimeSpan.FromSeconds(15), cancellationToken);

            await runnerService.WaitAllAsync(cancellationToken);
        }
Exemplo n.º 6
0
        public async Task SelectTest()
        {
            using var cancellationTokenSource = new CancellationTokenSource(TimeSpan.FromSeconds(30));
            var cancellationToken = cancellationTokenSource.Token;

            using var app = await TestWpfApp.CreateAsync(cancellationToken);

            using var runner = new SelectRunner(app.Dispatcher).WithLogging();

            var process = new Process <ICommand>();
            var task    = runner.SelectAsync(process, cancellationToken);

            await Task.Delay(TimeSpan.FromSeconds(5), cancellationToken).ConfigureAwait(false);

            await process.StopAsync(cancellationToken).ConfigureAwait(false);

            var rectangle = await task.ConfigureAwait(false);

            Console.WriteLine($"{rectangle.Left}, {rectangle.Top}, {rectangle.Right}, {rectangle.Bottom}");
        }
Exemplo n.º 7
0
        public async Task RussianNameTest()
        {
            using var cancellationTokenSource = new CancellationTokenSource(TimeSpan.FromSeconds(30));
            var cancellationToken = cancellationTokenSource.Token;

            using var app = await TestWpfApp.CreateAsync(cancellationToken);

            await using var moduleService = new StaticModuleService(
                            new AliasRunner(
                                new Command("sequence", "2", "clipboard-set-text", "keyboard CTRL+V"),
                                "вставь"),
                            new KeyboardRunner(),
                            new ClipboardRunner(app.Dispatcher),
                            new SequenceRunner()
                            );
            await using var runnerService = new RunnerService(moduleService, moduleService);

            using var exceptions = new IServiceBase[]
                  {
                      moduleService, runnerService
                  }.EnableLogging(cancellationTokenSource);

            await runnerService.RunAsync(Command.Parse("вставь 123"), cancellationToken);
        }
Exemplo n.º 8
0
        public async Task ScreenshotCallTest()
        {
            using var cancellationTokenSource = new CancellationTokenSource(TimeSpan.FromSeconds(30));
            var cancellationToken = cancellationTokenSource.Token;

            using var app = await TestWpfApp.CreateAsync(cancellationToken);

            using var selectRunner = new SelectRunner(app.Dispatcher).WithLogging();

            var process    = new Process <ICommand>();
            var selectTask = selectRunner.CallAsync(new Command("select"), process, cancellationToken);

            await Task.Delay(TimeSpan.FromSeconds(5), cancellationToken);

            await process.StopAsync(cancellationToken);

            var selectOutput = await selectTask;

            Console.WriteLine($"{nameof(selectOutput)}: {selectOutput.Output}");

            using var screenshotRunner = new ScreenshotRunner().WithLogging();

            var screenshotOutput = await screenshotRunner.CallAsync(
                new Command("screenshot", selectOutput.Output),
                cancellationToken);

            Console.WriteLine($"{nameof(screenshotOutput)}: {screenshotOutput.Output}");

            using var clipboardRunner = new ClipboardRunner(app.Dispatcher).WithLogging();

            var clipboardOutput = await clipboardRunner.CallAsync(
                new Command("clipboard-set-image", screenshotOutput.Output),
                cancellationToken);

            Console.WriteLine($"{nameof(clipboardOutput)}: {clipboardOutput.Output}");
        }