diff --git a/Pvc.CLI/Pvc.CLI.csproj b/Pvc.CLI/Pvc.CLI.csproj index 0908276..786936e 100644 --- a/Pvc.CLI/Pvc.CLI.csproj +++ b/Pvc.CLI/Pvc.CLI.csproj @@ -13,7 +13,7 @@ 512 - AnyCPU + x86 true full false diff --git a/Pvc.CLI/ScriptCs/PvcScriptHost.cs b/Pvc.CLI/ScriptCs/PvcScriptHost.cs index a4e62cb..67ad4c2 100644 --- a/Pvc.CLI/ScriptCs/PvcScriptHost.cs +++ b/Pvc.CLI/ScriptCs/PvcScriptHost.cs @@ -19,6 +19,27 @@ public PvcScriptHost(IScriptPackManager scriptPackManager, ScriptEnvironment env public PvcCore.Pvc pvc { get { return PVCInstance; } } + public PvcCore.PvcDelayedPipe Source(params string[] inputs) + { + var delayedPipe = new PvcCore.PvcDelayedPipe(); + delayedPipe.Stack.Add(() => pvc.Source(inputs)); + + return delayedPipe; + } + + public PvcCore.PvcDelayedPipe Plugin(Func, IEnumerable> plugin) + { + var delayedPipe = new PvcCore.PvcDelayedPipe(); + delayedPipe.Stack.Add(() => plugin); + + return delayedPipe; + } + + public PvcCore.PvcTask Task(string name, PvcCore.PvcDelayedPipe delayedPipe) + { + return pvc.Task(name, () => delayedPipe.ExecuteStack()); + } + public static void RunTask(string taskName) { PVCInstance.Start(taskName); diff --git a/Pvc.Core/Pvc.Core.csproj b/Pvc.Core/Pvc.Core.csproj index 1c17427..b0962d9 100644 --- a/Pvc.Core/Pvc.Core.csproj +++ b/Pvc.Core/Pvc.Core.csproj @@ -42,6 +42,7 @@ + diff --git a/Pvc.Core/PvcDelayedPipe.cs b/Pvc.Core/PvcDelayedPipe.cs new file mode 100644 index 0000000..0764eee --- /dev/null +++ b/Pvc.Core/PvcDelayedPipe.cs @@ -0,0 +1,69 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace PvcCore +{ + public class PvcDelayedPipe + { + public PvcDelayedPipe() + { + this.Stack = new List>(); + this.Pipe = new PvcPipe(); + } + + public PvcPipe Pipe { get; set; } + + public List> Stack { get; set; } + + public void ExecuteStack() + { + foreach (var item in this.Stack) + { + var result = item(); + if (result is PvcPipe) + { + this.Pipe = (PvcPipe)result; + } + else if (result is PvcPlugins.PvcPlugin) + { + this.Pipe.Pipe((PvcPlugins.PvcPlugin)result); + } + else if (result is Func, IEnumerable>) + { + this.Pipe.Pipe((Func, IEnumerable>)result); + } + } + } + + public static PvcDelayedPipe operator &(PvcDelayedPipe delayedPipe, PvcPlugins.PvcPlugin plugin) + { + delayedPipe.Stack.Add(() => plugin); + return delayedPipe; + } + + public static PvcDelayedPipe operator &(PvcDelayedPipe delayedPipe1, PvcDelayedPipe delayedPipe2) + { + delayedPipe1.Stack.AddRange(delayedPipe2.Stack); + return delayedPipe1; + } + + public static PvcDelayedPipe operator &(PvcDelayedPipe delayedPipe, Action action) + { + delayedPipe.Stack.Add(() => { + action(); + return null; + }); + + return delayedPipe; + } + + public static PvcDelayedPipe operator &(PvcDelayedPipe delayedPipe, Func, IEnumerable> action) + { + delayedPipe.Stack.Add(() => action(delayedPipe.Pipe.streams)); + return delayedPipe; + } + } +} diff --git a/Pvc.Core/PvcPipe.cs b/Pvc.Core/PvcPipe.cs index 33699cc..b779c94 100644 --- a/Pvc.Core/PvcPipe.cs +++ b/Pvc.Core/PvcPipe.cs @@ -262,5 +262,23 @@ private void resetStreamPositions(IEnumerable resetStreams) { resetStreams.ToList().ForEach(x => x.ResetStreamPosition()); } + + // operator overloading! + public static PvcDelayedPipe operator &(PvcPipe pipe, PvcPlugins.PvcPlugin plugin) + { + var delayedPipe = new PvcDelayedPipe(); + delayedPipe.Stack.Add(() => plugin); + + return delayedPipe; + } + + // This is effectively a switch to a new pipe (usually via a new Source command) + public static PvcDelayedPipe operator &(PvcPipe pipe1, PvcPipe pipe2) + { + var delayedPipe = new PvcDelayedPipe(); + delayedPipe.Stack.Add(() => pipe2); + + return delayedPipe; + } } }