|
| 1 | +#!/usr/bin/env dotnet-script |
| 2 | +#r "nuget: Maa.Framework.Native, 4.0.0-preview.25163.6" |
| 3 | +#r "nuget: Maa.Framework.Runtime.win-x64, 4.0.0" |
| 4 | + |
| 5 | +using System.Diagnostics; |
| 6 | +using MaaFramework.Binding; |
| 7 | + |
| 8 | +var toolkit = new MaaToolkit(true); |
| 9 | +var resource = new MaaResource(); |
| 10 | +var maa = new MaaTasker |
| 11 | +{ |
| 12 | + Controller = toolkit.AdbDevice.Find().First().ToAdbController(), |
| 13 | + Resource = resource, |
| 14 | + DisposeOptions = DisposeOptions.All, |
| 15 | + Toolkit = toolkit, |
| 16 | +}; |
| 17 | + |
| 18 | +if (!maa.Initialized) |
| 19 | + throw new InvalidOperationException("Failed to init tasker."); |
| 20 | + |
| 21 | +var agent = new MaaAgentClient |
| 22 | +{ |
| 23 | + Resource = resource, |
| 24 | + DisposeOptions = DisposeOptions.All, |
| 25 | +}; |
| 26 | + |
| 27 | +var socketId = agent.CreateSocket(string.Empty) |
| 28 | + ?? throw new InvalidOperationException("Failed to create socket."); |
| 29 | + |
| 30 | +var p = Process.Start(new ProcessStartInfo( |
| 31 | + "dotnet",["script", |
| 32 | + "AgentChild.cs", |
| 33 | + NativeBindingInfo.NativeAssemblyDirectory |
| 34 | + ?? throw new ArgumentNullException("Native.BindingInfo.NativeAssemblyDirectory"), |
| 35 | + Environment.CurrentDirectory, |
| 36 | + socketId]) { UseShellExecute = true }); |
| 37 | + |
| 38 | +if (!agent.LinkStart()) |
| 39 | + throw new InvalidOperationException("Failed to connect."); |
| 40 | + |
| 41 | +var ppover = """ |
| 42 | +{ |
| 43 | + "Entry": {"next": "Rec"}, |
| 44 | + "Rec": { |
| 45 | + "recognition": "Custom", |
| 46 | + "custom_recognition": "MyRec", |
| 47 | + "action": "Custom", |
| 48 | + "custom_action": "MyAct", |
| 49 | + "custom_action_param": { |
| 50 | + "param": "Hello Server!" |
| 51 | + } |
| 52 | + } |
| 53 | +} |
| 54 | +"""; |
| 55 | +Console.WriteLine(ppover); |
| 56 | + |
| 57 | +var detail = maa |
| 58 | + .AppendTask("Entry", ppover) |
| 59 | + .WaitFor(MaaJobStatus.Succeeded) |
| 60 | + .QueryTaskDetail() |
| 61 | + ?? throw new InvalidOperationException("Failed to pipeline."); |
| 62 | +Console.WriteLine($"pipeline detail: {detail}"); |
| 63 | +Console.WriteLine($"MyRec detail: {detail.QueryRecognitionDetail(maa, 1)?.Detail}"); |
| 64 | + |
| 65 | +agent.LinkStop(); |
| 66 | + |
| 67 | +Console.Write("Press any key to exit:"); |
| 68 | +Console.ReadKey(); |
0 commit comments