summaryrefslogtreecommitdiff
path: root/Models/AvalarPipeline.cs
diff options
context:
space:
mode:
Diffstat (limited to 'Models/AvalarPipeline.cs')
-rw-r--r--Models/AvalarPipeline.cs47
1 files changed, 47 insertions, 0 deletions
diff --git a/Models/AvalarPipeline.cs b/Models/AvalarPipeline.cs
new file mode 100644
index 0000000..14e32d0
--- /dev/null
+++ b/Models/AvalarPipeline.cs
@@ -0,0 +1,47 @@
+using Avalonia.Media.Imaging;
+using System;
+using System.Collections.Generic;
+using System.ComponentModel;
+using System.Linq;
+using System.Threading;
+using System.Threading.Tasks;
+
+namespace Avalar.Models
+{
+ public class AvalarPipeline
+ {
+ private readonly IEnumerable<IPipelineStep> m_steps;
+
+ public AvalarPipeline(IEnumerable<IPipelineStep> steps)
+ {
+ m_steps = steps ?? throw new ArgumentNullException(nameof(steps));
+ foreach (var step in m_steps)
+ {
+ step.PropertyChanged += OnPipelineComponentChanged;
+ }
+ }
+
+ private void OnPipelineComponentChanged(object sender, PropertyChangedEventArgs e)
+ {
+ foreach (var step in m_steps.SkipWhile(step => step != sender))
+ {
+ step.InvalidateResult();
+ }
+
+ PipelineChanged?.Invoke(this, EventArgs.Empty);
+ }
+
+ public event EventHandler PipelineChanged;
+
+ public async Task<IBitmap> Run(IBitmap bitmap, CancellationToken token)
+ {
+ var input = bitmap;
+ foreach(var step in m_steps)
+ {
+ token.ThrowIfCancellationRequested();
+ input = await step.Run(input, token).ConfigureAwait(false);
+ }
+ return input;
+ }
+ }
+}