Skip to content

Commit

Permalink
Correctly respecting disabling blocks.
Browse files Browse the repository at this point in the history
  • Loading branch information
JMS-1 committed Oct 11, 2024
1 parent 066e88b commit f567569
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 14 deletions.
11 changes: 9 additions & 2 deletions Library/Core/Model/Block.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,11 @@ public abstract class Block : IFragment
/// </summary>
public string Id { get; set; } = null!;

/// <summary>
/// Unset to exclude this block from execution.
/// </summary>
public bool Enabled { get; set; } = true;

/// <summary>
/// All fields (constant values) of the block.
/// </summary>
Expand Down Expand Up @@ -62,8 +67,10 @@ public abstract class Block : IFragment
throw new ScriptStoppedEarlyException();

/* Run the next block if we are not forcefully exiting a loop. */
if (Next != null && context.EscapeMode == EscapeMode.None)
return await Next.EvaluateAsync(context);
if (context.EscapeMode == EscapeMode.None)
for (var next = Next; next != null; next = next.Next)
if (next.Enabled)
return await next.EvaluateAsync(context);

return null;
}
Expand Down
18 changes: 10 additions & 8 deletions Library/Core/Model/Workspace.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,18 +29,19 @@ public class Workspace : IFragment
var functions = new List<Block>();

foreach (var block in Blocks.OfType<ProceduresDef>())
{
/* Create the function itself and remember it. */
context.Cancellation.ThrowIfCancellationRequested();
if (block.Enabled)
{
/* Create the function itself and remember it. */
context.Cancellation.ThrowIfCancellationRequested();

await block.EvaluateAsync(context);
await block.EvaluateAsync(context);

functions.Add(block);
}
functions.Add(block);
}

/* Process any block which is not a function. */
foreach (var block in Blocks)
if (!functions.Contains(block))
if (!functions.Contains(block) && block.Enabled)
{
/* Remember the result and report the last result afterwards. */
context.Cancellation.ThrowIfCancellationRequested();
Expand Down Expand Up @@ -107,7 +108,8 @@ public async Task<List<GroupInfo>> GetGroupTreeAsync()

/* Find all functions and generate the block list. */
foreach (var block in Blocks.OfType<ProceduresDef>())
await block.EvaluateAsync(context);
if (block.Enabled)
await block.EvaluateAsync(context);

/* Inspect all blocks. */
foreach (var block in Blocks)
Expand Down
8 changes: 4 additions & 4 deletions Library/Core/XmlParser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -68,16 +68,16 @@ public override Workspace Parse(string xml, bool preserveWhitespace = false)

private Block? ParseBlock(XmlNode node)
{
if (bool.Parse(node.GetAttribute("disabled") ?? "false"))
return null;

var type = node.GetAttribute("type");

if (!blocks.ContainsKey(type))
throw new ApplicationException($"block type not registered: '{type}'");

var block = blocks[type]();

block.Type = type;
block.Enabled = node.GetAttribute("disabled-reasons") == null;
block.Id = node.GetAttribute("id");
block.Type = type;

foreach (XmlNode childNode in node.ChildNodes)
{
Expand Down

0 comments on commit f567569

Please sign in to comment.