-
Notifications
You must be signed in to change notification settings - Fork 344
/
CustomResourceSnapshot.cs
123 lines (104 loc) · 3.97 KB
/
CustomResourceSnapshot.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
using System.Collections.Immutable;
namespace Aspire.Hosting.ApplicationModel;
/// <summary>
/// An immutable snapshot of the state of a resource.
/// </summary>
public sealed record CustomResourceSnapshot
{
/// <summary>
/// The type of the resource.
/// </summary>
public required string ResourceType { get; init; }
/// <summary>
/// The properties that should show up in the dashboard for this resource.
/// </summary>
public required ImmutableArray<ResourcePropertySnapshot> Properties { get; init; }
/// <summary>
/// The creation timestamp of the resource.
/// </summary>
public DateTime? CreationTimeStamp { get; init; }
/// <summary>
/// Represents the state of the resource.
/// </summary>
public ResourceStateSnapshot? State { get; init; }
/// <summary>
/// The exit code of the resource.
/// </summary>
public int? ExitCode { get; init; }
/// <summary>
/// The environment variables that should show up in the dashboard for this resource.
/// </summary>
public ImmutableArray<EnvironmentVariableSnapshot> EnvironmentVariables { get; init; } = [];
/// <summary>
/// The URLs that should show up in the dashboard for this resource.
/// </summary>
public ImmutableArray<UrlSnapshot> Urls { get; init; } = [];
}
/// <summary>
/// A snapshot of the resource state
/// </summary>
/// <param name="Text">The text for the state update.</param>
/// <param name="Style">The style for the state update. Use <seealso cref="KnownResourceStateStyles"/> for the supported styles.</param>
public sealed record ResourceStateSnapshot(string Text, string? Style)
{
/// <summary>
/// Convert text to state snapshot. The style will be null by default
/// </summary>
/// <param name="s"></param>
public static implicit operator ResourceStateSnapshot?(string? s) =>
s is null ? null : new(Text: s, Style: null);
}
/// <summary>
/// A snapshot of an environment variable.
/// </summary>
/// <param name="Name">The name of the environment variable.</param>
/// <param name="Value">The value of the environment variable.</param>
/// <param name="IsFromSpec">Determines if this environment variable was defined in the resource explicitly or computed (for e.g. inherited from the process hierarchy).</param>
public sealed record EnvironmentVariableSnapshot(string Name, string? Value, bool IsFromSpec);
/// <summary>
/// A snapshot of the url.
/// </summary>
/// <param name="Name">Name of the url.</param>
/// <param name="Url">The full uri.</param>
/// <param name="IsInternal">Determines if this url is internal.</param>
public sealed record UrlSnapshot(string Name, string Url, bool IsInternal);
/// <summary>
/// A snapshot of the resource property.
/// </summary>
/// <param name="Name">The name of the property.</param>
/// <param name="Value">The value of the property.</param>
public sealed record ResourcePropertySnapshot(string Name, object? Value);
/// <summary>
/// The set of well known resource states
/// </summary>
public static class KnownResourceStateStyles
{
/// <summary>
/// The success state
/// </summary>
public static readonly string Success = "success";
/// <summary>
/// The error state. Useful for error messages.
/// </summary>
public static readonly string Error = "error";
/// <summary>
/// The info state. Useful for infomational messages.
/// </summary>
public static readonly string Info = "info";
/// <summary>
/// The warn state. Useful for showing warnings.
/// </summary>
public static readonly string Warn = "warn";
}
/// <summary>
/// The set of well known resource states
/// </summary>
public static class KnownResourceStates
{
/// <summary>
/// The hidden state. Useful for hiding the resource.
/// </summary>
public static readonly string Hidden = "Hidden";
}