Skip to content

Commit

Permalink
Make the pipeline form look presentable
Browse files Browse the repository at this point in the history
  • Loading branch information
jvyden committed Sep 19, 2024
1 parent 7b9c5d8 commit 0a0ea4e
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 12 deletions.
5 changes: 4 additions & 1 deletion Refresher.Core/Pipelines/Pipeline.cs
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,11 @@ public void Initialize()

public async Task ExecuteAsync(CancellationToken cancellationToken = default)
{
if(this.State != PipelineState.NotStarted)
if (this.State != PipelineState.NotStarted)
{
this.State = PipelineState.Error;
throw new InvalidOperationException("Pipeline must be restarted before it can be executed again.");
}

this.State = PipelineState.Running;

Expand Down
40 changes: 29 additions & 11 deletions Refresher/UI/PipelineForm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,44 +8,62 @@ namespace Refresher.UI;
{
private TPipeline? _pipeline;

private ProgressBar _progressBar;
private readonly Label _stateLabel;
private readonly ProgressBar _progressBar;

public PipelineForm() : base(typeof(TPipeline).Name, new Size(700, 1), false)
{
this.InitializePipeline();

this.Content = new StackLayout([
new Button(this.ExecutePipeline),
this._stateLabel = new Label(),
new Button(this.ExecutePipeline) { Text = "Execute" },
this._progressBar = new ProgressBar(),
]);
])
{
Padding = new Padding(0, 10, 0, 0),
Spacing = 5,
HorizontalContentAlignment = HorizontalAlignment.Stretch,
VerticalContentAlignment = VerticalAlignment.Bottom,
};

this.InitializePipeline();

Thread progressThread = new(() =>
{
while (!this.IsDisposed && !Application.Instance.IsDisposed)
{
Application.Instance.Invoke(() =>
{
this._progressBar.Value = (int)((this._pipeline?.Progress ?? 0) * 100);
this._progressBar.Enabled = this._pipeline?.State == PipelineState.Running;
});
Thread.Sleep(100);
Application.Instance.Invoke(this.UpdateFormState);
Thread.Sleep(this._pipeline?.State == PipelineState.Running ? 50 : 250);
}
});

progressThread.Start();
}

private void UpdateFormState()
{
this._progressBar.Value = (int)((this._pipeline?.Progress ?? 0) * 100);
this._progressBar.Enabled = this._pipeline?.State == PipelineState.Running;
this._stateLabel.Text = this._pipeline?.State.ToString() ?? "Uninitialized";
}

private void InitializePipeline()
{
this._pipeline = new TPipeline();
this._pipeline.Initialize();

this.UpdateFormState();
}

private void ExecutePipeline(object? sender, EventArgs e)
{
if (this._pipeline == null)
return;

Task.Run(async () =>
{
await this._pipeline.ExecuteAsync();
});

this.UpdateFormState();
}
}

0 comments on commit 0a0ea4e

Please sign in to comment.