using System.Diagnostics; using Microsoft.UI.Xaml.Automation.Peers; using Microsoft.UI.Xaml.Automation.Provider; using XFEEDToolBox.Controls; using XFEEDToolBox.Core.Galaxy; using XFEEDToolBox.Views; namespace XFEEDToolBox; public partial class App { private static async Task RunPlacesProbeAsync(string directory) { static void Require(bool condition,string message){if(!condition)throw new InvalidOperationException(message);} static void Invoke(Button button)=>((IInvokeProvider)new ButtonAutomationPeer(button).GetPattern(PatternInterface.Invoke)).Invoke(); ViewModel.DemoMode=true;AppShellPage.Current!.Navigate(typeof(NavigationPage));await Task.Delay(300); var page=(NavigationPage)AppShellPage.Current.CurrentPage!; var nav=(HorizontalPanel)page.FindName("SidebarExpander");var places=(HorizontalPanel)page.FindName("PlacesExpander"); var map=(GalaxyMapView)page.FindName("Map");var mapWidth=map.ActualWidth; Require(nav.IsExpanded&&places.IsExpanded,"Both independent horizontal panels must start expanded."); var navWidth=nav.ActualWidth;nav.IsExpanded=false;await Task.Delay(80); Require(nav.ActualWidth().Any(),"Common functions must use cascading panes rather than stacked dropdowns."); var kinds=(ListView)page.FindName("PlaceKindInput");var trader=(ListView)page.FindName("TraderCategoryInput"); var resultPane=(StackPanel)page.FindName("PlacesResultPane");var search=(Button)page.FindName("SearchPlacesButton"); trader.SelectedIndex=-1;trader.SelectedIndex=0;await Task.Delay(100); var child=(Grid)page.FindName("PlaceChildPanel"); Require(resultPane.Visibility==Visibility.Visible&&resultPane.TransformToVisual(places).TransformPoint(new()).X>child.TransformToVisual(places).TransformPoint(new()).X+200,"Trader category must open its next pane to the right."); Invoke(search);await Task.Delay(100); Require(search.Content as string=="取消"&&search.IsEnabled,"The initiating search button must become cancel."); var deadline=DateTimeOffset.UtcNow.AddSeconds(20);while(ViewModel.SearchGalacticPlacesCommand.IsRunning&&DateTimeOffset.UtcNow0&&search.Content as string=="查找地点",ViewModel.GalaxyPlacesStatus); await CapturePageAsync(page,Path.Combine(directory,"places-trader-results.png")); var traderCount=ViewModel.GalaxyPlaces.Count; kinds.SelectedIndex=2;await Task.Delay(100);var engineers=(ListView)page.FindName("EngineerLocationInput"); engineers.SelectedIndex=-1;engineers.SelectedIndex=0;await Task.Delay(80); Require(engineers.Items.Count>=38&&Descendants(engineers).OfType().Any(p=>p.ProfilePicture is not null),"Engineer pane must retain portraits."); Require(resultPane.Visibility==Visibility.Visible,"Engineer selection must open the result pane."); Invoke(search);await Task.Delay(80);Require(ViewModel.GalaxyPlaces.Count==1,"Local engineer lookup must work."); await CapturePageAsync(page,Path.Combine(directory,"places-engineers.png")); kinds.SelectedIndex=3;var choiceDeadline=DateTimeOffset.UtcNow.AddSeconds(20);var choices=(ListView)page.FindName("PlaceChoiceList"); while(choices.Items.Count==0&&DateTimeOffset.UtcNow=40,"Ship names did not populate: "+((TextBlock)page.FindName("PlaceChoiceHint")).Text); choices.SelectedItem=choices.Items.OfType().First(c=>c.Name=="Anaconda");await Task.Delay(80); Require(resultPane.Visibility==Visibility.Visible&&ViewModel.GalaxyPlaceQuery=="Anaconda","Ship selection must open its next pane."); Invoke(search);await Task.Delay(50);Require(search.Content as string=="取消","Slow query did not offer cancellation."); var cancel=Stopwatch.StartNew();Invoke(search);deadline=DateTimeOffset.UtcNow.AddSeconds(2); while(ViewModel.SearchGalacticPlacesCommand.IsRunning&&DateTimeOffset.UtcNow().First(m=>m.Name=="Selenium");await Task.Delay(80); Invoke(search);await Task.Delay(60);Require(ViewModel.GalaxyPlaces.Single().SystemName=="HR 3230","Raw material leaf did not find the fixed site."); await CapturePageAsync(page,Path.Combine(directory,"places-gathering.png")); categories.SelectedIndex=2;await Task.Delay(60);Invoke(search);await Task.Delay(60); Require(ViewModel.GalaxyPlaces.Single().SystemName=="HIP 12099","Data leaf did not find Jameson."); return new{horizontalPanelsDefaultExpanded=true,cascadingChoices=true,traderResults=traderCount,engineerPortraits=engineers.Items.Count,shipNames=choices.Items.Count,cancelMilliseconds,localRawAndDataLookup=true,flightCommandsInvoked=false}; } }