-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add the process runner and cook dialog
- Loading branch information
Showing
15 changed files
with
276 additions
and
36 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
13 changes: 13 additions & 0 deletions
13
tools/Titan.Tools.ManifestBuilder/Services/IApplicationState.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
namespace Titan.Tools.ManifestBuilder.Services; | ||
|
||
|
||
public record AppState(string? ProjectPath = null); | ||
public interface IApplicationState | ||
{ | ||
string? ProjectPath { get; set; } | ||
} | ||
|
||
public class ApplicationState : IApplicationState | ||
{ | ||
public string? ProjectPath { get; set; } | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
111 changes: 111 additions & 0 deletions
111
tools/Titan.Tools.ManifestBuilder/ViewModels/Dialogs/ExternalProcessViewModel.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,111 @@ | ||
using System; | ||
using System.Diagnostics; | ||
using System.IO; | ||
using System.Threading; | ||
using System.Threading.Tasks; | ||
using Avalonia.Threading; | ||
using DynamicData.Binding; | ||
|
||
namespace Titan.Tools.ManifestBuilder.ViewModels.Dialogs; | ||
|
||
public record ExternalProcess(string Filename, string Arguments, string? WorkingDir = null); | ||
|
||
public class ExternalProcessViewModel : ViewModelBase | ||
{ | ||
private bool _isRunning; | ||
public bool IsRunning | ||
{ | ||
get => _isRunning; | ||
set => SetProperty(ref _isRunning, value); | ||
} | ||
|
||
private string _status = "Running"; | ||
public string Status | ||
{ | ||
get => _status; | ||
set => SetProperty(ref _status, value); | ||
} | ||
|
||
public IObservableCollection<string> LogOutput { get; } = new ObservableCollectionExtended<string>(); | ||
|
||
|
||
private int _lineCount; | ||
public ExternalProcessViewModel(ExternalProcess externalProcess) | ||
{ | ||
WriteLine($"Starting process {Path.GetFileNameWithoutExtension(externalProcess.Filename)} {externalProcess.Arguments}\n"); | ||
|
||
var _ = Run(externalProcess); | ||
} | ||
|
||
private async Task Run(ExternalProcess externalProcess) | ||
{ | ||
try | ||
{ | ||
IsRunning = true; | ||
using var process = new Process | ||
{ | ||
StartInfo = new ProcessStartInfo(externalProcess.Filename, externalProcess.Arguments) | ||
{ | ||
CreateNoWindow = true, | ||
RedirectStandardError = true, | ||
RedirectStandardOutput = true | ||
}, | ||
}; | ||
process.OutputDataReceived += async (_, args) => | ||
{ | ||
if (args.Data != null) | ||
{ | ||
await WriteLineAsync(args.Data); | ||
} | ||
}; | ||
|
||
process.ErrorDataReceived += async (_, args) => | ||
{ | ||
if (args.Data != null) | ||
{ | ||
await WriteLineAsync(args.Data); | ||
} | ||
}; | ||
if (!process.Start()) | ||
{ | ||
Status = "Failed to start the process."; | ||
return; | ||
} | ||
process.BeginErrorReadLine(); | ||
process.BeginOutputReadLine(); | ||
await process.WaitForExitAsync(CancellationToken.None); //NOTE(Jens): add support for cancellation token | ||
var exitCode = process.ExitCode; | ||
Status = $"Completed with exit code {exitCode}"; | ||
} | ||
catch (Exception e) | ||
{ | ||
Status = $"Exception occurred: {e.GetType().Name} - {e.Message}"; | ||
} | ||
finally | ||
{ | ||
IsRunning = false; | ||
} | ||
} | ||
public ExternalProcessViewModel() | ||
{ | ||
for (var i = 0; i < 100; ++i) | ||
WriteLine("Design mode"); | ||
} | ||
|
||
private async ValueTask WriteLineAsync(string line) | ||
{ | ||
if (Dispatcher.UIThread.CheckAccess()) | ||
{ | ||
WriteLine(line); | ||
} | ||
else | ||
{ | ||
await Dispatcher.UIThread.InvokeAsync(() => WriteLine(line)); | ||
} | ||
} | ||
|
||
private void WriteLine(string line) | ||
=> LogOutput.Add($"{_lineCount++,4}: {line}"); | ||
} | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1 change: 1 addition & 0 deletions
1
tools/Titan.Tools.ManifestBuilder/ViewModels/MainWindowViewModel.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
using System.Linq; | ||
using System.Threading.Tasks; | ||
using System.Windows.Input; | ||
using ReactiveUI; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.