1
+ #region BSD License
2
+ /*
3
+ * New BSD 3-Clause License (https://github.com/Krypton-Suite/Standard-Toolkit/blob/master/LICENSE)
4
+ * Modifications by Peter Wagner (aka Wagnerp), Simon Coghlan (aka Smurf-IV), Giduac & tobitege et al. 2025 - 2025. All rights reserved.
5
+ */
6
+ #endregion
7
+
8
+ namespace Krypton . Build ;
9
+
10
+ /// <summary>
11
+ /// Represents the application state for the Krypton Modern Build tool.
12
+ /// This class maintains all the configuration, runtime state, and data necessary for the build process.
13
+ /// </summary>
14
+ public sealed class AppState
15
+ {
16
+ #region Build Configuration
17
+
18
+ /// <summary>
19
+ /// Gets or sets the build channel type (Nightly, Canary, Stable, LTS).
20
+ /// </summary>
21
+ public ChannelType Channel { get ; set ; }
22
+
23
+ /// <summary>
24
+ /// Gets or sets the build action to perform (Build, Rebuild, Pack, etc.).
25
+ /// </summary>
26
+ public BuildAction Action { get ; set ; }
27
+
28
+ /// <summary>
29
+ /// Gets or sets the build configuration (Debug, Release, etc.). Defaults to "Release".
30
+ /// </summary>
31
+ public string Configuration { get ; set ; } = "Release" ;
32
+
33
+ /// <summary>
34
+ /// Gets or sets the root path of the repository.
35
+ /// </summary>
36
+ public string RootPath { get ; set ; } = string . Empty ;
37
+
38
+ /// <summary>
39
+ /// Gets or sets the path to the MSBuild executable.
40
+ /// </summary>
41
+ public string MsBuildPath { get ; set ; } = string . Empty ;
42
+
43
+ /// <summary>
44
+ /// Gets or sets the project file path for the build operation.
45
+ /// </summary>
46
+ public string ProjectFile { get ; set ; } = string . Empty ;
47
+
48
+ #endregion
49
+
50
+ #region Logging Configuration
51
+
52
+ /// <summary>
53
+ /// Gets or sets the path for text log output.
54
+ /// </summary>
55
+ public string TextLogPath { get ; set ; } = string . Empty ;
56
+
57
+ /// <summary>
58
+ /// Gets or sets the path for binary log output.
59
+ /// </summary>
60
+ public string BinLogPath { get ; set ; } = string . Empty ;
61
+
62
+ #endregion
63
+
64
+ #region Runtime State
65
+
66
+ /// <summary>
67
+ /// Gets the tail buffer for capturing and displaying recent build output.
68
+ /// </summary>
69
+ public TailBuffer Tail { get ; } = new TailBuffer ( 200 ) ;
70
+
71
+ /// <summary>
72
+ /// Gets or sets the number of tail lines to display.
73
+ /// </summary>
74
+ public int TailLines { get ; set ; }
75
+
76
+ /// <summary>
77
+ /// Gets or sets whether the build process is currently running.
78
+ /// </summary>
79
+ public bool IsRunning { get ; set ; }
80
+
81
+ /// <summary>
82
+ /// Gets or sets the last exit code from the build process.
83
+ /// </summary>
84
+ public int LastExitCode { get ; set ; }
85
+
86
+ /// <summary>
87
+ /// Gets or sets the UTC start time of the current build operation.
88
+ /// </summary>
89
+ public DateTime ? StartTimeUtc { get ; set ; }
90
+
91
+ /// <summary>
92
+ /// Gets or sets the count of errors encountered during the build.
93
+ /// </summary>
94
+ public int ErrorCount { get ; set ; }
95
+
96
+ /// <summary>
97
+ /// Gets or sets the count of warnings encountered during the build.
98
+ /// </summary>
99
+ public int WarningCount { get ; set ; }
100
+
101
+ #endregion
102
+
103
+ #region Summary and Output
104
+
105
+ /// <summary>
106
+ /// Gets or sets whether the build summary is ready for display.
107
+ /// </summary>
108
+ public bool SummaryReady { get ; set ; }
109
+
110
+ /// <summary>
111
+ /// Gets or sets the lines of the build summary.
112
+ /// </summary>
113
+ public IReadOnlyList < string > ? SummaryLines { get ; set ; }
114
+
115
+ /// <summary>
116
+ /// Gets or sets the offset for summary display positioning.
117
+ /// </summary>
118
+ public int SummaryOffset { get ; set ; }
119
+
120
+ /// <summary>
121
+ /// Gets or sets the callback action for handling output messages.
122
+ /// </summary>
123
+ public Action < string > ? OnOutput { get ; set ; }
124
+
125
+ #endregion
126
+
127
+ #region Process Management
128
+
129
+ /// <summary>
130
+ /// Gets or sets the current build process instance.
131
+ /// </summary>
132
+ public Process ? Process { get ; set ; }
133
+
134
+ /// <summary>
135
+ /// Gets or sets the queue of pending build targets.
136
+ /// </summary>
137
+ public Queue < string > ? PendingTargets { get ; set ; }
138
+
139
+ /// <summary>
140
+ /// Gets or sets the last completed build target.
141
+ /// </summary>
142
+ public string ? LastCompletedTarget { get ; set ; }
143
+
144
+ #endregion
145
+
146
+ #region Pack Configuration
147
+
148
+ /// <summary>
149
+ /// Gets or sets the pack mode for NuGet packaging (Pack, PackLite, PackAll).
150
+ /// </summary>
151
+ public PackMode PackMode { get ; set ; } = PackMode . Pack ;
152
+
153
+ #endregion
154
+
155
+ #region UI State
156
+
157
+ /// <summary>
158
+ /// Gets or sets the callback action to request a full UI render.
159
+ /// </summary>
160
+ public Action ? RequestRenderAll { get ; set ; }
161
+
162
+ /// <summary>
163
+ /// Gets or sets whether auto-scroll is enabled in the output display.
164
+ /// </summary>
165
+ public bool AutoScroll { get ; set ; } = true ;
166
+
167
+ #endregion
168
+
169
+ #region NuGet Configuration
170
+
171
+ /// <summary>
172
+ /// Gets or sets the queue of packages waiting to be pushed to NuGet.
173
+ /// </summary>
174
+ public Queue < string > ? NuGetPushQueue { get ; set ; }
175
+
176
+ /// <summary>
177
+ /// Gets or sets the current tasks page being displayed (Ops or NuGet).
178
+ /// </summary>
179
+ public TasksPage TasksPage { get ; set ; } = TasksPage . Ops ;
180
+
181
+ /// <summary>
182
+ /// Gets or sets the NuGet action to perform (RebuildPack, Push, etc.).
183
+ /// </summary>
184
+ public NuGetAction NuGetAction { get ; set ; } = NuGetAction . RebuildPack ;
185
+
186
+ /// <summary>
187
+ /// Gets or sets the NuGet source for package operations (Default, NuGetOrg, GitHub, Custom).
188
+ /// </summary>
189
+ public NuGetSource NuGetSource { get ; set ; } = NuGetSource . Default ;
190
+
191
+ /// <summary>
192
+ /// Gets or sets whether to create a ZIP archive of NuGet packages.
193
+ /// </summary>
194
+ public bool NuGetCreateZip { get ; set ; }
195
+
196
+ /// <summary>
197
+ /// Gets or sets the custom NuGet source URL when using Custom source type.
198
+ /// </summary>
199
+ public string NuGetCustomSource { get ; set ; } = string . Empty ;
200
+
201
+ /// <summary>
202
+ /// Gets or sets whether to include symbols in NuGet packages.
203
+ /// </summary>
204
+ public bool NuGetIncludeSymbols { get ; set ; }
205
+
206
+ /// <summary>
207
+ /// Gets or sets the path to the last created NuGet ZIP archive.
208
+ /// </summary>
209
+ public string ? NuGetLastZipPath { get ; set ; }
210
+
211
+ /// <summary>
212
+ /// Gets or sets whether to run NuGet push after MSBuild completes.
213
+ /// </summary>
214
+ public bool NuGetRunPushAfterMsBuild { get ; set ; }
215
+
216
+ /// <summary>
217
+ /// Gets or sets whether to run ZIP creation after MSBuild completes.
218
+ /// </summary>
219
+ public bool NuGetRunZipAfterMsBuild { get ; set ; }
220
+
221
+ /// <summary>
222
+ /// Gets or sets whether to skip duplicate packages during NuGet operations. Defaults to true.
223
+ /// </summary>
224
+ public bool NuGetSkipDuplicate { get ; set ; } = true ;
225
+
226
+ #endregion
227
+ }
228
+
229
+ /// <summary>
230
+ /// A thread-safe circular buffer that maintains a fixed number of recent lines.
231
+ /// Used for capturing and displaying the tail of build output in the UI.
232
+ /// </summary>
233
+ public sealed class TailBuffer
234
+ {
235
+ private int capacity ;
236
+ private readonly LinkedList < string > lines = new LinkedList < string > ( ) ;
237
+ private readonly object sync = new object ( ) ;
238
+
239
+ /// <summary>
240
+ /// Initializes a new instance of the <see cref="TailBuffer"/> class with the specified capacity.
241
+ /// </summary>
242
+ /// <param name="capacity">The maximum number of lines to store in the buffer.</param>
243
+ public TailBuffer ( int capacity )
244
+ {
245
+ this . capacity = capacity ;
246
+ }
247
+
248
+ /// <summary>
249
+ /// Sets the capacity of the buffer and trims excess lines if necessary.
250
+ /// </summary>
251
+ /// <param name="newCapacity">The new capacity for the buffer. Must be greater than 0.</param>
252
+ public void SetCapacity ( int newCapacity )
253
+ {
254
+ if ( newCapacity <= 0 )
255
+ {
256
+ return ;
257
+ }
258
+ lock ( sync )
259
+ {
260
+ capacity = newCapacity ;
261
+ while ( lines . Count > capacity )
262
+ {
263
+ lines . RemoveFirst ( ) ;
264
+ }
265
+ }
266
+ }
267
+
268
+ /// <summary>
269
+ /// Clears all lines from the buffer.
270
+ /// </summary>
271
+ public void Clear ( )
272
+ {
273
+ lock ( sync )
274
+ {
275
+ lines . Clear ( ) ;
276
+ }
277
+ }
278
+ }
0 commit comments