using System.Text.Json; using Microsoft.UI.Xaml.Automation; using XFEWorkflow.Abstractions; using XFEWorkflow.Controls; using XFEWorkflow.Services; using XFEWorkflow.Space.Contracts; namespace XFEWorkflow.Views; public sealed partial class SpacePage { private Task ShowDetailAsync(SpaceCardModel card, IReadOnlyList? versions = null) { var revision = ++detailVersion; var section = mode; detail.Children.Clear(); detail.Children.Add(new FontIcon { Glyph = card.Glyph, FontSize = 32, HorizontalAlignment = HorizontalAlignment.Left }); detail.Children.Add(new TextBlock { Text = card.Name, FontSize = 22, FontWeight = Microsoft.UI.Text.FontWeights.SemiBold, TextWrapping = TextWrapping.Wrap }); detail.Children.Add(Caption(card.VersionLabel + " · " + card.StateLabel)); detail.Children.Add(Label(card.Description)); detail.Children.Add(Caption(card.ResourceId)); detail.Children.Add(Caption($"提交于 {card.SubmittedAt.ToLocalTime():yyyy-MM-dd HH:mm} · {card.PackageBytes / 1024d:0.#} KiB")); if (card.ReviewReason.Length > 0) detail.Children.Add(Label("审核说明:" + card.ReviewReason)); if (versions is { Count: > 0 }) { var selector = new ComboBox { Header = "发布版本", ItemsSource = versions, DisplayMemberPath = "Version", SelectedItem = versions.FirstOrDefault(x => x.Id == card.Id), HorizontalAlignment = HorizontalAlignment.Stretch }; AutomationProperties.SetAutomationId(selector, "SpaceVersions"); selector.SelectionChanged += async (_, _) => { if (selector.SelectedItem is SpaceCardModel choice && choice.Id != card.Id) await Guard(() => ShowDetailAsync(choice, versions)); }; detail.Children.Add(selector); } else if (IsCatalog) detail.Children.Add(ActionButton("查看所有版本", async () => { var result = await Services.Space.RequestAsync(card.IsWorkflow ? "workflows/detail" : "plugins/detail", new() { [card.IsWorkflow ? "workflowId" : "pluginId"] = card.ResourceId }); var all = card.IsWorkflow ? result.Deserialize>(WorkflowJson.Options)!.Select(x => new SpaceCardModel { Workflow = x }).ToList() : result.Deserialize>(WorkflowJson.Options)!.Select(x => new SpaceCardModel { Plugin = x }).ToList(); if (revision == detailVersion && loaded) await ShowDetailAsync(card, all); }, "SpaceAllVersions")); if (card.Workflow is { } workflow) { detail.Children.Add(Caption(card.Capabilities)); detail.Children.Add(ActionButton("预览图形与代码", async () => { using var timeout = new CancellationTokenSource(TimeSpan.FromSeconds(30)); var data = await Services.Space.PreviewWorkflowAsync(workflow, timeout.Token); if (!loaded || revision != detailVersion) return; using var preview = new WorkflowPreviewControl(data) { Width = Math.Max(320, Math.Min(1180, XamlRoot.Size.Width - 110)), Height = Math.Max(260, Math.Min(700, XamlRoot.Size.Height - 210)) }; var dialog = new ContentDialog { Title = workflow.Workflow.Name + " · v" + workflow.Workflow.Version, Content = preview, CloseButtonText = "关闭", XamlRoot = XamlRoot }; dialog.Resources["ContentDialogMaxWidth"] = 1300d; AutomationProperties.SetAutomationId(dialog, "SpaceWorkflowPreviewDialog"); await dialog.ShowAsync(); }, "SpacePreviewWorkflow")); var dependencies = workflow.Workflow.PluginVersions; var dependencyText = dependencies.Count == 0 ? "无需额外插件" : string.Join("\n", dependencies.Select(pair => pair.Key + " " + pair.Value + (Services.Plugins.Installed.Any(p => p.Manifest.Id == pair.Key && p.Manifest.Version == pair.Value && !p.PendingRemoval && p.Enabled) ? " · 已安装并启用" : " · 待安装或启用"))); detail.Children.Add(new Expander { Header = $"插件依赖 · {dependencies.Count}", Content = Label(dependencyText), IsExpanded = true, HorizontalAlignment = HorizontalAlignment.Stretch, HorizontalContentAlignment = HorizontalAlignment.Stretch }); if (workflow.Status == PublicationStatus.Published) { var install = new CheckBox { Content = "自动安装并启用锁定版本的插件", IsChecked = true, Visibility = dependencies.Count > 0 ? Visibility.Visible : Visibility.Collapsed }; AutomationProperties.SetAutomationId(install, "SpaceWorkflowDependencies"); detail.Children.Add(install); detail.Children.Add(ActionButton("下载并导入工作流", async () => { var imported = await Services.Space.DownloadWorkflowAsync(workflow, Services.Paths, Services.Plugins, Services.Workflows, install.IsChecked == true, new Progress(p => { if (loaded) Status.Text = $"下载 {p:P0}"; })); await Services.Scheduler.RefreshAsync(); Status.Text = "已导入“" + imported.Name + "”,可在工作流列表中开启"; if (revision == detailVersion && loaded) { await ShowDetailAsync(card, versions); detail.Children.OfType().Single().IsChecked = install.IsChecked; var download = detail.Children.OfType