using XFEEDToolBox.Controls; using XFEEDToolBox.Core.Outfitting; using XFEEDToolBox.Views; namespace XFEEDToolBox; public partial class App { private static async Task RunRefitWorkbenchProbeAsync(string reportPath) { AppShellPage.Current!.Navigate(typeof(RefitPage)); await Task.Delay(200); ViewModel.RebuildRefitCommand.Execute(null); var page=AppShellPage.Current.CurrentPage!; var slotList=Descendants(page).OfType().Single(v=>v.Name=="SlotList"); var categoryList=Descendants(page).OfType().Single(v=>v.Name=="RefitCategoryList"); var inspector=Descendants(page).OfType().Single(v=>v.Name=="InspectorPanel"); var tabs=Descendants(inspector).OfType().Single(); var selected=ViewModel.RefitSlot?.Slot; var categories=new List(); foreach(var (index,category) in new[]{(0,"hardpoint"),(1,"utility"),(2,"standard"),(3,"internal")}) { categoryList.SelectedIndex=index;await Task.Delay(60); categories.Add(new{index,count=ViewModel.RefitVisibleSlots.Count,bound=ViewModel.RefitCategoryIndex==index,filtered=ViewModel.RefitVisibleSlots.All(s=>s.Category==category),selectionVisible=ViewModel.RefitSlot is null||ViewModel.RefitVisibleSlots.Contains(ViewModel.RefitSlot)}); } var unrequestedTargets=ViewModel.RefitDocument?.Slots.Count(s=>s.Target is not null)??0; ViewModel.RefitCategoryIndex=0; var sample=ViewModel.RefitSlots.FirstOrDefault(s=>s.Module?.Engineering?.Modifiers.Count>0)??ViewModel.RefitSlots.FirstOrDefault(s=>s.Module is not null); if(sample is not null){ViewModel.RefitCategoryIndex=Array.IndexOf(new[]{"hardpoint","utility","standard","internal"},sample.Category);slotList.SelectedItem=ViewModel.RefitVisibleSlots.FirstOrDefault(s=>s.Slot==sample.Slot);} await Task.Delay(80); var selectedNameBound=Descendants(inspector).OfType().Any(t=>t.Text==sample?.Module?.DisplayName); var parameterRows=ViewModel.RefitModifiers.Count; var grade=Descendants(inspector).OfType().Single(); var originalGrade=grade.Value; grade.Value=4;await Task.Delay(60); var gradeBound=ViewModel.RefitGrade==4; var next=ViewModel.RefitVisibleSlots.FirstOrDefault(s=>s.Slot!=sample?.Slot&&s.Module is not null); if(next is not null)slotList.SelectedItem=next; var gradePersisted=sample is null||ViewModel.RefitDocument?.Slots.Single(s=>s.Slot==sample.Slot).Target?.Grade==4; if(sample is not null)slotList.SelectedItem=ViewModel.RefitVisibleSlots.First(s=>s.Slot==sample.Slot); await Task.Delay(60); var gradeRestored=ViewModel.RefitGrade==4&&grade.Value==4; var realizedNames=Descendants(slotList).OfType().ToArray(); var namesOnly=realizedNames.Length>0&&realizedNames.All(t=>ViewModel.RefitSlots.Any(s=>s.Caption==t.Text&&s.OriginalName==t.Original)); ViewModel.RefitSlotSearch=sample?.Module?.OriginalName??""; await Task.Delay(60); var searchMatches=ViewModel.RefitVisibleSlots.All(s=>s.Caption.Contains(ViewModel.RefitSlotSearch,StringComparison.OrdinalIgnoreCase)||s.OriginalName.Contains(ViewModel.RefitSlotSearch,StringComparison.OrdinalIgnoreCase)); ViewModel.RefitSlotSearch=""; if(sample is not null)ViewModel.RefitSlot=ViewModel.RefitVisibleSlots.First(s=>s.Slot==sample.Slot); var module=ViewModel.RefitSlot?.Module; var installChoice=ViewModel.RefitAvailableModules.FirstOrDefault(c=>!c.Owned&&c.Module.Item!=module?.Item); var installationVerified=false; if(installChoice is not null&&sample is not null) { ViewModel.RefitInstallModule=installChoice; ViewModel.InstallRefitModuleCommand.Execute(null); installationVerified=ViewModel.RefitSlot?.Module?.Item==installChoice.Module.Item&&ViewModel.RefitSelectedName==installChoice.Module.DisplayName; ViewModel.UninstallRefitModuleCommand.Execute(null); var unloaded=ViewModel.RefitSlot?.Module is null&&ViewModel.RefitSelectedName=="空槽"; var originalChoice=ViewModel.RefitAvailableModules.FirstOrDefault(c=>c.InstanceKey==sample.InstanceKey&&c.Module.Item==module?.Item); if(originalChoice is not null){ViewModel.RefitInstallModule=originalChoice;ViewModel.InstallRefitModuleCommand.Execute(null);} installationVerified&=unloaded&&ViewModel.RefitSlot?.Module?.Item==module?.Item; } var folder=Path.Combine(Path.GetDirectoryName(Path.GetFullPath(reportPath))!,"screenshots"); for(var index=0;index().Single(v=>v.Name=="CategoryPanel"); var centre=Descendants(page).OfType().Single(v=>v.Name=="SlotPanel"); var positions=new[]{categoriesPanel,centre,inspector}.Select(p=>new{p.Name,x=p.TransformToVisual(page).TransformPoint(new(0,0)).X,y=p.TransformToVisual(page).TransformPoint(new(0,0)).Y,width=p.ActualWidth,height=p.ActualHeight}).ToArray(); ViewModel.RebuildRefitCommand.Execute(null); await ViewModel.ExportEdsyCommand.ExecuteAsync(null); var originalUrl=ViewModel.RefitEdsyLink; var actualExported=originalUrl.StartsWith("https://edsy.org/#/L="); var exportStatus=ViewModel.RefitEdsyStatus; var actualModulesBefore=ViewModel.RefitDocument?.Slots.Where(s=>s.Module is not null&&s.Category.Length>0).Select(s=>s.Module!.Item).Order().ToArray()??[]; if(actualExported)await ViewModel.ImportEdsyCommand.ExecuteAsync(null); var actualModulesAfter=ViewModel.RefitDocument?.Slots.Where(s=>s.Module is not null&&s.Category.Length>0).Select(s=>s.Module!.Item).Order().ToArray()??[]; var actualMissing=actualModulesBefore.Except(actualModulesAfter).ToArray(); var actualAdded=actualModulesAfter.Except(actualModulesBefore).ToArray(); var actualImportMatched=actualExported&&actualModulesBefore.SequenceEqual(actualModulesAfter); await ViewModel.ExportEdsyCommand.ExecuteAsync(null); var actualLinkRoundTrip=actualImportMatched&&ViewModel.RefitEdsyLink==originalUrl; await File.WriteAllTextAsync(Path.Combine(Path.GetDirectoryName(Path.GetFullPath(reportPath))!,"actual-edsy-exports.json"),System.Text.Json.JsonSerializer.Serialize(new[]{new{name="actual-current-ship",url=originalUrl}})); var panel=new EdsyLinkPanel{DataContext=ViewModel}; var dialog=new ContentDialog{Title="EDSY 装配链接",Content=panel,CloseButtonText="关闭",XamlRoot=page.XamlRoot}; var showing=dialog.ShowAsync();await Task.Delay(200); var linkBox=Descendants(panel).OfType().Single(); var dialogBound=linkBox.Text==ViewModel.RefitEdsyLink&&Descendants(panel).OfType