From 04dc020c91067abc19079cb132ce09503a1f1219 Mon Sep 17 00:00:00 2001 From: YanZhiwei Date: Thu, 20 Jun 2024 20:35:12 +0800 Subject: [PATCH] =?UTF-8?q?=E6=96=B0=E5=A2=9EUseLocalStorage=E6=94=AF?= =?UTF-8?q?=E6=8C=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Samples/WindowsHighlightSample/MainForm.cs | 105 +++++++++++------- Samples/WindowsHighlightSample/Program.cs | 4 + .../WindowsHighlightSample.csproj | 14 ++- 3 files changed, 79 insertions(+), 44 deletions(-) diff --git a/Samples/WindowsHighlightSample/MainForm.cs b/Samples/WindowsHighlightSample/MainForm.cs index aab18a5..81288b7 100644 --- a/Samples/WindowsHighlightSample/MainForm.cs +++ b/Samples/WindowsHighlightSample/MainForm.cs @@ -1,9 +1,9 @@ using System.Collections.Concurrent; using System.Globalization; using System.Text; -using System.Text.Json; using FlaUI.Core.AutomationElements; using Mortise.Accessibility.Abstractions; +using Mortise.Accessibility.Locator.Abstractions; using Mortise.UiaAccessibility; using Tenon.Automation.Windows; using Tenon.Infra.Windows.Form.Common; @@ -21,6 +21,7 @@ public partial class MainForm : Form private readonly Accessible _accessible; private readonly string[] _ignoreProcessNames; private readonly ISerializer _serializer; + private readonly IAccessibleLocatorStorage _accessibleLocatorStorage; private readonly WindowsHighlightRectangle _windowsHighlight; protected readonly ConcurrentStack MouseDownQueue = new(); protected readonly ConcurrentStack MouseMoveQueue = new(); @@ -28,10 +29,12 @@ public partial class MainForm : Form private bool _shutdown; protected Thread? WorkerThread; - public MainForm(Accessible accessible, ISerializer serializer) + public MainForm(Accessible accessible, ISerializer serializer, IAccessibleLocatorStorage accessibleLocatorStorage) { _accessible = accessible ?? throw new ArgumentNullException(nameof(accessible)); _serializer = serializer; + _accessibleLocatorStorage = accessibleLocatorStorage ?? + throw new ArgumentNullException(nameof(accessibleLocatorStorage)); InitializeComponent(); _windowsHighlight = new WindowsHighlightRectangle(); _ignoreProcessNames = [Process.GetCurrentProcess().ProcessName]; @@ -214,10 +217,11 @@ private void button5_Click(object sender, EventArgs e) { buttonTest?.Invoke(); _accessible.Record(buttonTest); - - var jsonString = _serializer.SerializeObject(_accessible); + + var jsonString = _serializer.SerializeObject(_accessible); File.WriteAllText("locator.path", jsonString, Encoding.UTF8); - var findElement = _accessible.FindComponent(jsonString); + var accessible1 = _serializer.DeserializeObject(jsonString); + var findElement = _accessible.FindComponent(accessible1); AddLog(findElement != null ? "find Element" : "not find Element"); if (findElement is UiaAccessibleComponent component) component.Click(); @@ -242,42 +246,61 @@ private void button7_Click(object sender, EventArgs e) var accessibleDict = new ConcurrentDictionary(StringComparer.OrdinalIgnoreCase); var locator1 = @"{ - ""fileName"": ""CalculatorApp"", - ""provider"": ""Uia"", - ""platform"": ""Win32NT"", - ""version"": ""3.0.0"", - ""components"": [ - { - ""name"": ""¼ÆËãÆ÷"", - ""controlType"": ""Window"", - ""isDialog"": false, - ""id"": null - }, - { - ""name"": null, - ""controlType"": ""Custom"", - ""isDialog"": false, - ""id"": ""NavView"" - }, - { - ""name"": null, - ""controlType"": ""Group"", - ""isDialog"": false, - ""id"": null - }, - { - ""name"": ""Êý×Ö¼üÅÌ"", - ""controlType"": ""Group"", - ""isDialog"": false, - ""id"": ""NumberPad"" - }, - { - ""name"": ""Ò»"", - ""controlType"": ""Button"", - ""isDialog"": false, - ""id"": ""num1Button"" - } - ] + ""uniqueId"": ""num1Button"", + ""fileName"": ""CalculatorApp"", + ""provider"": ""Uia"", + ""platform"": ""Win32NT"", + ""version"": ""3.0.0"", + ""components"": [ + { + ""className"": ""ApplicationFrameWindow"", + ""name"": ""\u8BA1\u7B97\u5668"", + ""controlType"": ""Window"", + ""isDialog"": false, + ""id"": null, + ""isPassword"": false + }, + { + ""className"": ""Windows.UI.Core.CoreWindow"", + ""name"": ""\u8BA1\u7B97\u5668"", + ""controlType"": ""Window"", + ""isDialog"": false, + ""id"": null, + ""isPassword"": false + }, + { + ""className"": null, + ""name"": null, + ""controlType"": ""Custom"", + ""isDialog"": false, + ""id"": ""NavView"", + ""isPassword"": false + }, + { + ""className"": ""LandmarkTarget"", + ""name"": null, + ""controlType"": ""Group"", + ""isDialog"": false, + ""id"": null, + ""isPassword"": false + }, + { + ""className"": ""NamedContainerAutomationPeer"", + ""name"": ""\u6570\u5B57\u952E\u76D8"", + ""controlType"": ""Group"", + ""isDialog"": false, + ""id"": ""NumberPad"", + ""isPassword"": false + }, + { + ""className"": ""Button"", + ""name"": ""\u4E00"", + ""controlType"": ""Button"", + ""isDialog"": false, + ""id"": ""num1Button"", + ""isPassword"": false + } + ] }"; var accessible1 = _serializer.DeserializeObject(locator1); AddLog(accessible1.FileName); diff --git a/Samples/WindowsHighlightSample/Program.cs b/Samples/WindowsHighlightSample/Program.cs index 89c4028..6b50b60 100644 --- a/Samples/WindowsHighlightSample/Program.cs +++ b/Samples/WindowsHighlightSample/Program.cs @@ -1,4 +1,7 @@ using Microsoft.Extensions.DependencyInjection; +using Mortise.Accessibility.Locator.Json.Configurations; +using Mortise.Accessibility.Locator.Json.Extensions; +using Mortise.UiaAccessibility.Converters; using Mortise.UiaAccessibility.Extensions; using Mortise.UiaAccessibility.WeChat.Configurations; @@ -37,5 +40,6 @@ private static void ConfigureServices(ServiceCollection services) { services.AddScoped(); services.AddUiaAccessible(option => { option.AddWeChatAccessible(); }); + services.AddJsonLocator(option => { option.UseLocalStorage(); }, [new UiaAccessibleComponentConverter()]); } } \ No newline at end of file diff --git a/Samples/WindowsHighlightSample/WindowsHighlightSample.csproj b/Samples/WindowsHighlightSample/WindowsHighlightSample.csproj index 5d68001..d93544c 100644 --- a/Samples/WindowsHighlightSample/WindowsHighlightSample.csproj +++ b/Samples/WindowsHighlightSample/WindowsHighlightSample.csproj @@ -10,9 +10,11 @@ - - - + + + + + @@ -27,6 +29,12 @@ ..\..\..\Mortise\src\Mortise.Accessibility.Abstractions\bin\Debug\net8.0\Mortise.Accessibility.Abstractions.dll + + ..\..\..\Mortise\src\Mortise.Accessibility.Locator.Json\bin\Debug\net8.0\Mortise.Accessibility.Locator.Abstractions.dll + + + ..\..\..\Mortise\src\Mortise.Accessibility.Locator.Json\bin\Debug\net8.0\Mortise.Accessibility.Locator.Json.dll + ..\..\..\Mortise\src\UIA\Mortise.UIAAccessibility\bin\Debug\net8.0-windows\Mortise.UiaAccessibility.dll