private void RunUpdate(UpdateNode <TTrigger> node, UpdateChain chain) { var triggers = chain.CurrentTriggers; triggers.Clear(); triggers.UnionWith(node.IncommingTriggers); triggers.IntersectWith(TriggeredUpdatesSinceStart); if (triggers.Count <= 0) { return; } try { SetCurrentNode(node); node.Function.Invoke(chain); } catch (Exception e) { var messageBuilder = new StringBuilder(); messageBuilder .Append(CurrentNodeExceptionHeader) .AppendLine(" threw an exception:") .AppendLine(e.Message) .AppendLine() .Append(UpdateChainAsString); ThrowUpdateError(new UpdateGraphException(messageBuilder.ToString(), e)); } }
public void AddUpdate(IEnumerable <TTrigger> incomming, UpdateFunction <TTrigger> function, IEnumerable <TTrigger> potentialTriggers) { if (!UpdaterToNodeDictionary.TryGetValue(function.Updater, out var node)) { node = new UpdateNode <TTrigger>(function); UpdaterToNodeDictionary.Add(function.Updater, node); } node.NodeRegisterCount++; node.AddName(function.Name); foreach (var inc in incomming) { if (node.AddIncomming(inc)) { TriggerToTriggeredNodesDictionary.Add(inc, node); } } foreach (var inc in potentialTriggers) { if (node.AddOutgoing(inc)) { TriggerToTriggeringNodesDictionary.Add(inc, node); } } }
private bool Visit(List <UpdateNode <TTrigger> > L, UpdateNode <TTrigger> n) { if (n.Mark == Mark.PermanentMark) { return(false); } if (n.Mark == Mark.TemporaryMark) { return(true); // Cycle found } n.Mark = Mark.TemporaryMark; foreach (var m in GetTriggeredNodes(n.OutgoingTriggers)) { if (Visit(L, m)) { return(true); } } n.Mark = Mark.PermanentMark; L.Add(n); return(false); }
private void SetCurrentNode(UpdateNode <TTrigger> node) { CurrentUpdateNode = node; RunUpdateNodes.Add(node); }