XFE Git
XFE Studio Git
Git 首页 全局搜索
XFE 主站 文档 NuGet

XFEEDToolBox

【WinUI】XFE精英危险工具箱

公开
关注 0 Fork 0 Star 0
UTF-8
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<object> 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<navWidth-200&&Math.Abs(map.ActualWidth-mapWidth)<1,"Navigation must fold horizontally without resizing the map.");nav.IsExpanded=true;
        var placesWidth=places.ActualWidth;places.IsExpanded=false;await Task.Delay(80);
        Require(places.ActualWidth<placesWidth-200,"Common functions must fold horizontally.");places.IsExpanded=true;
        Require(!Descendants(places).OfType<ComboBox>().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.UtcNow<deadline)await Task.Delay(50);
        Require(ViewModel.GalaxyPlaces.Count>0&&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<PersonPicture>().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<choiceDeadline)await Task.Delay(50);
        Require(choices.Items.Count>=40,"Ship names did not populate: "+((TextBlock)page.FindName("PlaceChoiceHint")).Text);
        choices.SelectedItem=choices.Items.OfType<ViewModels.GalacticPlaceChoice>().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<deadline)await Task.Delay(20);
        Require(!ViewModel.SearchGalacticPlacesCommand.IsRunning&&cancel.ElapsedMilliseconds<1000&&ViewModel.GalaxyPlaces.Count==0,"Cancel must stop the request without publishing stale results.");
        var cancelMilliseconds=cancel.ElapsedMilliseconds;

        kinds.SelectedIndex=6;await Task.Delay(50);var categories=(ListView)page.FindName("GatheringCategoryInput");
        categories.SelectedIndex=1;await Task.Delay(50);var materials=(ListView)page.FindName("GatheringMaterialInput");
        Require(((Border)page.FindName("GatheringMaterialPane")).Visibility==Visibility.Visible,"Raw gathering category must open its material pane.");
        materials.SelectedItem=materials.Items.OfType<GatheringMaterial>().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};
    }
}