Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Pvc.CLI/Pvc.CLI.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
<FileAlignment>512</FileAlignment>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<PlatformTarget>AnyCPU</PlatformTarget>
<PlatformTarget>x86</PlatformTarget>
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
Expand Down
21 changes: 21 additions & 0 deletions Pvc.CLI/ScriptCs/PvcScriptHost.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<PvcCore.PvcStream>, IEnumerable<PvcCore.PvcStream>> 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);
Expand Down
1 change: 1 addition & 0 deletions Pvc.Core/Pvc.Core.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
<Compile Include="Lib\Minimatch.cs" />
<Compile Include="Pvc.cs" />
<Compile Include="PvcConsole.cs" />
<Compile Include="PvcDelayedPipe.cs" />
<Compile Include="PvcDependencyGraph.cs" />
<Compile Include="PvcException.cs" />
<Compile Include="PvcPlugin.cs" />
Expand Down
69 changes: 69 additions & 0 deletions Pvc.Core/PvcDelayedPipe.cs
Original file line number Diff line number Diff line change
@@ -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<Func<object>>();
this.Pipe = new PvcPipe();
}

public PvcPipe Pipe { get; set; }

public List<Func<object>> 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<PvcCore.PvcStream>, IEnumerable<PvcCore.PvcStream>>)
{
this.Pipe.Pipe((Func<IEnumerable<PvcCore.PvcStream>, IEnumerable<PvcCore.PvcStream>>)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<PvcStream>, IEnumerable<PvcStream>> action)
{
delayedPipe.Stack.Add(() => action(delayedPipe.Pipe.streams));
return delayedPipe;
}
}
}
18 changes: 18 additions & 0 deletions Pvc.Core/PvcPipe.cs
Original file line number Diff line number Diff line change
Expand Up @@ -262,5 +262,23 @@ private void resetStreamPositions(IEnumerable<PvcStream> 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;
}
}
}