using System.Collections.Generic; namespace Ariadne.Vellum.UnitTests.Library { public class Vault { public readonly HashSet Open = new HashSet(); } /// /// Holds passages for the scripts that derive from it, built into an assembly of their own. /// public abstract partial class VaultHost : Arc { public string Note = "idle"; protected void Hold(Vault vault, int bonus) { int seen = 0; hold: while (!vault.Open.Contains("go")) { seen++; Yield(); } Note = "held " + (seen + bonus); } protected int Count(Vault vault) { int seen = 0; count: while (!vault.Open.Contains("go")) { seen++; Yield(); } return seen; } protected void Weigh(Vault vault, ItemType item) { ItemType weighed = item; weigh: while (!vault.Open.Contains("go")) { Yield(); } Note = "weighed " + weighed; } protected void Descend(Vault vault, int depth) { int level = depth; if (depth > 0) { deeper: Descend(vault, depth - 1); } landed: while (!vault.Open.Contains("go")) { Yield(); } Note += "level" + level + ";"; } } /// /// Holds passages in a base class with a type parameter of its own, built into an assembly of its own. /// public abstract partial class VaultTagged : Arc { public TagType Last; public string Log = ""; protected void Settle(Vault vault, TagType tag) { TagType kept = tag; settle: while (!vault.Open.Contains("go")) { Yield(); } Last = kept; } protected void Hold(Vault vault, TagType tag, ItemType item) { TagType kept = tag; ItemType carried = item; hold: while (!vault.Open.Contains("held")) { Yield(); } Last = kept; Log += carried + ";"; } } /// /// Offers passages for arcs of other assemblies to run, from a class with a type parameter of its own. /// public partial class VaultShelf : Arc { public string Note = "idle"; public void Stock(Vault vault, ItemType item) { ItemType stocked = item; stock: while (!vault.Open.Contains("go")) { Yield(); } Note = "stocked " + stocked; } public void Label(Vault vault, ItemType item, TagType tag) { ItemType labeled = item; TagType kept = tag; label: while (!vault.Open.Contains("labeled")) { Yield(); } Note = "labeled " + labeled + kept; } protected override void Run(Vault vault) { } } /// /// Holds a Run for the scripts that derive from it to extend, built into an assembly of their own. /// public abstract partial class VaultTemplate : Arc { public string TemplateNote = "idle"; protected override void Run(Vault vault) { int count = 1; template: while (!vault.Open.Contains("go")) { Yield(); } TemplateNote = "template " + count; } } /// /// Offers passages for arcs of other assemblies to run. /// public partial class VaultPlant : Arc { public int Updates; public string Note = "idle"; public void Update(Vault vault, int bonus) { int waited = 0; wait: while (!vault.Open.Contains("go")) { waited++; Yield(); } Updates += waited + bonus; Note = "updated after " + waited; } public int Measure(Vault vault) { int waited = 0; measure: while (!vault.Open.Contains("go")) { waited++; Yield(); } return waited; } public void Ponder(Vault vault, ItemType item) { ItemType held = item; ponder: while (!vault.Open.Contains("go")) { Yield(); } Note = "pondered " + held; } public void Dig(Vault vault, int depth) { int level = depth; if (depth > 0) { deeper: Dig(vault, depth - 1); } dug: while (!vault.Open.Contains("go")) { Yield(); } Updates += level; } protected override void Run(Vault vault) { } } }