namespace MauiDotnetFlake open System open System.Collections.Immutable open System.ComponentModel open Newtonsoft.Json type [) ; TypeConverter (typeof)>] PackKey = | PackKey of string /// Human-readable round-trip representation override this.ToString () = match this with | PackKey p -> p and PackKeyJsonConverter () = inherit JsonConverter () override _.ReadJson (reader : JsonReader, objectType : Type, _existingValue : PackKey, _ : bool, _ : JsonSerializer) = if objectType <> typeof then failwith $"Unexpected object type for pack key: {objectType}" let value = reader.Value |> unbox PackKey value override _.WriteJson (writer : JsonWriter, PackKey key, _ : JsonSerializer) : unit = writer.WriteValue key and PackKeyTypeConverter () = inherit TypeConverter () override _.CanConvertFrom (_, t : Type) : bool = t = typeof override _.ConvertFrom (_, _, v : obj) : obj = v |> unbox |> PackKey |> box type [) ; TypeConverter (typeof)>] WorkloadKey = | WorkloadKey of string and WorkloadKeyJsonConverter () = inherit JsonConverter () override _.ReadJson (reader : JsonReader, objectType : Type, _existingValue : _, _ : bool, _ : JsonSerializer) : WorkloadKey = if objectType <> typeof then failwith $"Unexpected object type for workload key: {objectType}" let value = reader.Value |> unbox |> WorkloadKey value override _.WriteJson (_ : JsonWriter, _ : WorkloadKey, _ : JsonSerializer) : unit = failwith "do not call" and WorkloadKeyTypeConverter () = inherit TypeConverter () override _.CanConvertFrom (_, t : Type) : bool = t = typeof override _.ConvertFrom (_, _, v : obj) : obj = v |> unbox |> WorkloadKey |> box type WorkloadManifest = { /// e.g. ".NET MAUI SDK for all platforms" Description : string /// e.g. ["maui-blazor"] Extends : WorkloadKey list /// e.g. ["Microsoft.MAUI.Dependencies"] Packs : PackKey list } type [) ; TypeConverter (typeof)>] PackManifestKind = | Library | Framework | Sdk | Template static member Parse (value : string) = match value.ToLowerInvariant () with | "library" -> PackManifestKind.Library | "sdk" -> PackManifestKind.Sdk | "framework" -> PackManifestKind.Framework | "template" -> PackManifestKind.Template | _ -> failwith $"Unexpected value in pack manifest kind: {value}" member this.ToInt = match this with | Library -> 2 | Framework -> 1 | Sdk -> 0 | Template -> 3 override this.ToString () = match this with | Library -> "library" | Framework -> "framework" | Sdk -> "sdk" | Template -> "template" and PackManifestKindJsonConverter () = inherit JsonConverter () override _.ReadJson (reader : JsonReader, objectType : Type, _existingValue : PackManifestKind, _ : bool, _ : JsonSerializer) : PackManifestKind = if objectType <> typeof then failwith $"Unexpected object type for pack manifest kind: {objectType}" PackManifestKind.Parse (reader.Value |> unbox) override _.WriteJson (w : JsonWriter, v : PackManifestKind, _ : JsonSerializer) : unit = w.WriteValue v.ToInt and PackManifestKindTypeConverter () = inherit TypeConverter () override _.CanConvertFrom (_, t : Type) : bool = t = typeof override _.CanConvertTo (_, t : Type) : bool = t = typeof override _.ConvertFrom (_, _, v : obj) : obj = v |> unbox |> PackManifestKind.Parse |> box override _.ConvertTo (_, _, v : obj, _destType : Type) : obj = (v |> unbox).ToInt type PackManifest = { Kind : PackManifestKind Version : Version /// Map of "win-x64": "nuget-package-name", for example [] AliasTo : ImmutableDictionary } type Manifest = { Version : Version Workloads : Map Packs : Map } type Registration = { Id : PackKey Version : Version Kind : PackManifestKind ResolvedPackageId : PackKey Path : string IsStillPacked : bool } type HashString = | HashString of string override this.ToString () = match this with | HashString s -> s /// A NuGet package such as "Microsoft.Maui.Controls.Ref.android". type Pack = { Name : PackKey Version : Version Hash : HashString Type : PackManifestKind } type WorkloadCollation = { /// The NuGet package that defines the manifest for this workload. Package : string /// The version of the NuGet package that defines the manifest for this workload. Version : string /// The SHA256 of the NuGet package that defines the manifest for this workload. Hash : HashString /// The rendered manifest of this workload. Manifest : Manifest } type Platform = | Platform of string override this.ToString () = match this with | Platform p -> p