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

XFEWorkflow

【WinUI】XFE基于windows的工作流

公开
关注 0 Fork 0 Star 0
UTF-8
using XFEWorkflow.Abstractions;

namespace XFEWorkflow.Space.Contracts;

public enum PublicationStatus { Pending, Published, Rejected, Withdrawn }
public enum SpaceRole { Author = 1, Administrator = 100 }
public enum SpaceResourceKind { Plugin, Workflow }
public sealed record SpaceUser(string Id, string UserName, string NickName, SpaceRole Role, string AvatarUrl = "");
public sealed class SpaceLogin
{
    public string Session { get; set; } = "";
    public SpaceUser? UserInfo { get; set; }
}
public sealed class PluginPublication
{
    public string Id { get; set; } = Guid.NewGuid().ToString("N");
    public PluginManifest Manifest { get; set; } = new();
    public string AuthorId { get; set; } = "";
    public string AuthorName { get; set; } = "";
    public PublicationStatus Status { get; set; }
    public string Sha256 { get; set; } = "";
    public long PackageBytes { get; set; }
    public DateTimeOffset SubmittedAt { get; set; } = DateTimeOffset.UtcNow;
    public DateTimeOffset? ReviewedAt { get; set; }
    public string ReviewReason { get; set; } = "";
    public override string ToString() => $"{Manifest.Name}  {Manifest.Version}  ·  {Status}";
}
public sealed class CatalogPage
{
    public List<PluginPublication> Items { get; set; } = [];
    public int Total { get; set; }
}
public sealed class UploadSession
{
    public SpaceResourceKind Kind { get; set; }
    public string Version { get; set; } = "";
    public string Id { get; set; } = Guid.NewGuid().ToString("N");
    public string AuthorId { get; set; } = "";
    public string Sha256 { get; set; } = "";
    public long Length { get; set; }
    public int ChunkCount { get; set; }
    public DateTimeOffset CreatedAt { get; set; } = DateTimeOffset.UtcNow;
}
public static class SpaceRoutes
{
    public static readonly string[] All =
    [
        "register", "login", "relogin", "plugins/search", "plugins/detail", "plugins/mine",
        "uploads/begin", "uploads/chunk", "uploads/complete", "packages/chunk",
        "reviews/list", "reviews/decide", "plugins/withdraw", "health", "account/profile", "account/update", "uploads/cancel",
        "workflows/search", "workflows/detail", "workflows/mine", "workflows/withdraw", "workflows/preview", "workflows/preview/private"
    ];
}

public sealed class WorkflowSummary
{
    public string Id { get; set; } = "";
    public string Name { get; set; } = "";
    public string Description { get; set; } = "";
    public string Version { get; set; } = "1.0.0";
    public WorkflowKind Kind { get; set; }
    public Dictionary<string, string> PluginVersions { get; set; } = [];
    public List<PortDefinition> Inputs { get; set; } = [];
    public List<PortDefinition> Outputs { get; set; } = [];
    public static WorkflowSummary From(WorkflowDefinition workflow, string version) => new()
    {
        Id = workflow.Id, Name = workflow.Name, Description = workflow.Description, Version = version, Kind = workflow.Kind,
        PluginVersions = WorkflowJson.Clone(workflow.PluginVersions), Inputs = WorkflowJson.Clone(workflow.Inputs), Outputs = WorkflowJson.Clone(workflow.Outputs)
    };
}
public sealed class WorkflowPublication
{
    public string Id { get; set; } = Guid.NewGuid().ToString("N");
    public WorkflowSummary Workflow { get; set; } = new();
    public string AuthorId { get; set; } = "";
    public string AuthorName { get; set; } = "";
    public PublicationStatus Status { get; set; }
    public string Sha256 { get; set; } = "";
    public long PackageBytes { get; set; }
    public DateTimeOffset SubmittedAt { get; set; } = DateTimeOffset.UtcNow;
    public DateTimeOffset? ReviewedAt { get; set; }
    public string ReviewReason { get; set; } = "";
}
public sealed class WorkflowCatalogPage
{
    public List<WorkflowPublication> Items { get; set; } = [];
    public int Total { get; set; }
}

public sealed class WorkflowPreview
{
    public string PublicationId { get; set; } = "";
    public string Sha256 { get; set; } = "";
    public WorkflowDefinition Definition { get; set; } = new();
    public List<PluginManifest> Plugins { get; set; } = [];
}